jquery.inputmask.bundle.js 216 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868
  1. /*!
  2. * jquery.inputmask.bundle.js
  3. * https://github.com/RobinHerbots/Inputmask
  4. * Copyright (c) 2010 - 2018 Robin Herbots
  5. * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. * Version: 4.0.4
  7. */
  8. (function(modules) {
  9. var installedModules = {};
  10. function __webpack_require__(moduleId) {
  11. if (installedModules[moduleId]) {
  12. return installedModules[moduleId].exports;
  13. }
  14. var module = installedModules[moduleId] = {
  15. i: moduleId,
  16. l: false,
  17. exports: {}
  18. };
  19. modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  20. module.l = true;
  21. return module.exports;
  22. }
  23. __webpack_require__.m = modules;
  24. __webpack_require__.c = installedModules;
  25. __webpack_require__.d = function(exports, name, getter) {
  26. if (!__webpack_require__.o(exports, name)) {
  27. Object.defineProperty(exports, name, {
  28. enumerable: true,
  29. get: getter
  30. });
  31. }
  32. };
  33. __webpack_require__.r = function(exports) {
  34. if (typeof Symbol !== "undefined" && Symbol.toStringTag) {
  35. Object.defineProperty(exports, Symbol.toStringTag, {
  36. value: "Module"
  37. });
  38. }
  39. Object.defineProperty(exports, "__esModule", {
  40. value: true
  41. });
  42. };
  43. __webpack_require__.t = function(value, mode) {
  44. if (mode & 1) value = __webpack_require__(value);
  45. if (mode & 8) return value;
  46. if (mode & 4 && typeof value === "object" && value && value.__esModule) return value;
  47. var ns = Object.create(null);
  48. __webpack_require__.r(ns);
  49. Object.defineProperty(ns, "default", {
  50. enumerable: true,
  51. value: value
  52. });
  53. if (mode & 2 && typeof value != "string") for (var key in value) __webpack_require__.d(ns, key, function(key) {
  54. return value[key];
  55. }.bind(null, key));
  56. return ns;
  57. };
  58. __webpack_require__.n = function(module) {
  59. var getter = module && module.__esModule ? function getDefault() {
  60. return module["default"];
  61. } : function getModuleExports() {
  62. return module;
  63. };
  64. __webpack_require__.d(getter, "a", getter);
  65. return getter;
  66. };
  67. __webpack_require__.o = function(object, property) {
  68. return Object.prototype.hasOwnProperty.call(object, property);
  69. };
  70. __webpack_require__.p = "";
  71. return __webpack_require__(__webpack_require__.s = 0);
  72. })([ function(module, exports, __webpack_require__) {
  73. "use strict";
  74. __webpack_require__(1);
  75. __webpack_require__(6);
  76. __webpack_require__(7);
  77. var _inputmask = __webpack_require__(2);
  78. var _inputmask2 = _interopRequireDefault(_inputmask);
  79. var _inputmask3 = __webpack_require__(3);
  80. var _inputmask4 = _interopRequireDefault(_inputmask3);
  81. var _jquery = __webpack_require__(4);
  82. var _jquery2 = _interopRequireDefault(_jquery);
  83. function _interopRequireDefault(obj) {
  84. return obj && obj.__esModule ? obj : {
  85. default: obj
  86. };
  87. }
  88. if (_inputmask4.default === _jquery2.default) {
  89. __webpack_require__(8);
  90. }
  91. window.Inputmask = _inputmask2.default;
  92. }, function(module, exports, __webpack_require__) {
  93. "use strict";
  94. var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;
  95. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function(obj) {
  96. return typeof obj;
  97. } : function(obj) {
  98. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  99. };
  100. (function(factory) {
  101. if (true) {
  102. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [ __webpack_require__(2) ], __WEBPACK_AMD_DEFINE_FACTORY__ = factory,
  103. __WEBPACK_AMD_DEFINE_RESULT__ = typeof __WEBPACK_AMD_DEFINE_FACTORY__ === "function" ? __WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__) : __WEBPACK_AMD_DEFINE_FACTORY__,
  104. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  105. } else {}
  106. })(function(Inputmask) {
  107. Inputmask.extendDefinitions({
  108. A: {
  109. validator: "[A-Za-z\u0410-\u044f\u0401\u0451\xc0-\xff\xb5]",
  110. casing: "upper"
  111. },
  112. "&": {
  113. validator: "[0-9A-Za-z\u0410-\u044f\u0401\u0451\xc0-\xff\xb5]",
  114. casing: "upper"
  115. },
  116. "#": {
  117. validator: "[0-9A-Fa-f]",
  118. casing: "upper"
  119. }
  120. });
  121. Inputmask.extendAliases({
  122. cssunit: {
  123. regex: "[+-]?[0-9]+\\.?([0-9]+)?(px|em|rem|ex|%|in|cm|mm|pt|pc)"
  124. },
  125. url: {
  126. regex: "(https?|ftp)//.*",
  127. autoUnmask: false
  128. },
  129. ip: {
  130. mask: "i[i[i]].i[i[i]].i[i[i]].i[i[i]]",
  131. definitions: {
  132. i: {
  133. validator: function validator(chrs, maskset, pos, strict, opts) {
  134. if (pos - 1 > -1 && maskset.buffer[pos - 1] !== ".") {
  135. chrs = maskset.buffer[pos - 1] + chrs;
  136. if (pos - 2 > -1 && maskset.buffer[pos - 2] !== ".") {
  137. chrs = maskset.buffer[pos - 2] + chrs;
  138. } else chrs = "0" + chrs;
  139. } else chrs = "00" + chrs;
  140. return new RegExp("25[0-5]|2[0-4][0-9]|[01][0-9][0-9]").test(chrs);
  141. }
  142. }
  143. },
  144. onUnMask: function onUnMask(maskedValue, unmaskedValue, opts) {
  145. return maskedValue;
  146. },
  147. inputmode: "numeric"
  148. },
  149. email: {
  150. mask: "*{1,64}[.*{1,64}][.*{1,64}][.*{1,63}]@-{1,63}.-{1,63}[.-{1,63}][.-{1,63}]",
  151. greedy: false,
  152. casing: "lower",
  153. onBeforePaste: function onBeforePaste(pastedValue, opts) {
  154. pastedValue = pastedValue.toLowerCase();
  155. return pastedValue.replace("mailto:", "");
  156. },
  157. definitions: {
  158. "*": {
  159. validator: "[0-9\uff11-\uff19A-Za-z\u0410-\u044f\u0401\u0451\xc0-\xff\xb5!#$%&'*+/=?^_`{|}~-]"
  160. },
  161. "-": {
  162. validator: "[0-9A-Za-z-]"
  163. }
  164. },
  165. onUnMask: function onUnMask(maskedValue, unmaskedValue, opts) {
  166. return maskedValue;
  167. },
  168. inputmode: "email"
  169. },
  170. mac: {
  171. mask: "##:##:##:##:##:##"
  172. },
  173. vin: {
  174. mask: "V{13}9{4}",
  175. definitions: {
  176. V: {
  177. validator: "[A-HJ-NPR-Za-hj-npr-z\\d]",
  178. casing: "upper"
  179. }
  180. },
  181. clearIncomplete: true,
  182. autoUnmask: true
  183. }
  184. });
  185. return Inputmask;
  186. });
  187. }, function(module, exports, __webpack_require__) {
  188. "use strict";
  189. var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;
  190. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function(obj) {
  191. return typeof obj;
  192. } : function(obj) {
  193. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  194. };
  195. (function(factory) {
  196. if (true) {
  197. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [ __webpack_require__(3), __webpack_require__(5) ],
  198. __WEBPACK_AMD_DEFINE_FACTORY__ = factory, __WEBPACK_AMD_DEFINE_RESULT__ = typeof __WEBPACK_AMD_DEFINE_FACTORY__ === "function" ? __WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__) : __WEBPACK_AMD_DEFINE_FACTORY__,
  199. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  200. } else {}
  201. })(function($, window, undefined) {
  202. var document = window.document, ua = navigator.userAgent, ie = ua.indexOf("MSIE ") > 0 || ua.indexOf("Trident/") > 0, mobile = isInputEventSupported("touchstart"), iemobile = /iemobile/i.test(ua), iphone = /iphone/i.test(ua) && !iemobile;
  203. function Inputmask(alias, options, internal) {
  204. if (!(this instanceof Inputmask)) {
  205. return new Inputmask(alias, options, internal);
  206. }
  207. this.el = undefined;
  208. this.events = {};
  209. this.maskset = undefined;
  210. this.refreshValue = false;
  211. if (internal !== true) {
  212. if ($.isPlainObject(alias)) {
  213. options = alias;
  214. } else {
  215. options = options || {};
  216. if (alias) options.alias = alias;
  217. }
  218. this.opts = $.extend(true, {}, this.defaults, options);
  219. this.noMasksCache = options && options.definitions !== undefined;
  220. this.userOptions = options || {};
  221. this.isRTL = this.opts.numericInput;
  222. resolveAlias(this.opts.alias, options, this.opts);
  223. }
  224. }
  225. Inputmask.prototype = {
  226. dataAttribute: "data-inputmask",
  227. defaults: {
  228. placeholder: "_",
  229. optionalmarker: [ "[", "]" ],
  230. quantifiermarker: [ "{", "}" ],
  231. groupmarker: [ "(", ")" ],
  232. alternatormarker: "|",
  233. escapeChar: "\\",
  234. mask: null,
  235. regex: null,
  236. oncomplete: $.noop,
  237. onincomplete: $.noop,
  238. oncleared: $.noop,
  239. repeat: 0,
  240. greedy: false,
  241. autoUnmask: false,
  242. removeMaskOnSubmit: false,
  243. clearMaskOnLostFocus: true,
  244. insertMode: true,
  245. clearIncomplete: false,
  246. alias: null,
  247. onKeyDown: $.noop,
  248. onBeforeMask: null,
  249. onBeforePaste: function onBeforePaste(pastedValue, opts) {
  250. return $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(this, pastedValue, opts) : pastedValue;
  251. },
  252. onBeforeWrite: null,
  253. onUnMask: null,
  254. showMaskOnFocus: true,
  255. showMaskOnHover: true,
  256. onKeyValidation: $.noop,
  257. skipOptionalPartCharacter: " ",
  258. numericInput: false,
  259. rightAlign: false,
  260. undoOnEscape: true,
  261. radixPoint: "",
  262. _radixDance: false,
  263. groupSeparator: "",
  264. keepStatic: null,
  265. positionCaretOnTab: true,
  266. tabThrough: false,
  267. supportsInputType: [ "text", "tel", "url", "password", "search" ],
  268. ignorables: [ 8, 9, 13, 19, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 93, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 0, 229 ],
  269. isComplete: null,
  270. preValidation: null,
  271. postValidation: null,
  272. staticDefinitionSymbol: undefined,
  273. jitMasking: false,
  274. nullable: true,
  275. inputEventOnly: false,
  276. noValuePatching: false,
  277. positionCaretOnClick: "lvp",
  278. casing: null,
  279. inputmode: "verbatim",
  280. colorMask: false,
  281. disablePredictiveText: false,
  282. importDataAttributes: true,
  283. shiftPositions: true
  284. },
  285. definitions: {
  286. 9: {
  287. validator: "[0-9\uff11-\uff19]",
  288. definitionSymbol: "*"
  289. },
  290. a: {
  291. validator: "[A-Za-z\u0410-\u044f\u0401\u0451\xc0-\xff\xb5]",
  292. definitionSymbol: "*"
  293. },
  294. "*": {
  295. validator: "[0-9\uff11-\uff19A-Za-z\u0410-\u044f\u0401\u0451\xc0-\xff\xb5]"
  296. }
  297. },
  298. aliases: {},
  299. masksCache: {},
  300. mask: function mask(elems) {
  301. var that = this;
  302. function importAttributeOptions(npt, opts, userOptions, dataAttribute) {
  303. if (opts.importDataAttributes === true) {
  304. var importOption = function importOption(option, optionData) {
  305. optionData = optionData !== undefined ? optionData : npt.getAttribute(dataAttribute + "-" + option);
  306. if (optionData !== null) {
  307. if (typeof optionData === "string") {
  308. if (option.indexOf("on") === 0) optionData = window[optionData]; else if (optionData === "false") optionData = false; else if (optionData === "true") optionData = true;
  309. }
  310. userOptions[option] = optionData;
  311. }
  312. };
  313. var attrOptions = npt.getAttribute(dataAttribute), option, dataoptions, optionData, p;
  314. if (attrOptions && attrOptions !== "") {
  315. attrOptions = attrOptions.replace(/'/g, '"');
  316. dataoptions = JSON.parse("{" + attrOptions + "}");
  317. }
  318. if (dataoptions) {
  319. optionData = undefined;
  320. for (p in dataoptions) {
  321. if (p.toLowerCase() === "alias") {
  322. optionData = dataoptions[p];
  323. break;
  324. }
  325. }
  326. }
  327. importOption("alias", optionData);
  328. if (userOptions.alias) {
  329. resolveAlias(userOptions.alias, userOptions, opts);
  330. }
  331. for (option in opts) {
  332. if (dataoptions) {
  333. optionData = undefined;
  334. for (p in dataoptions) {
  335. if (p.toLowerCase() === option.toLowerCase()) {
  336. optionData = dataoptions[p];
  337. break;
  338. }
  339. }
  340. }
  341. importOption(option, optionData);
  342. }
  343. }
  344. $.extend(true, opts, userOptions);
  345. if (npt.dir === "rtl" || opts.rightAlign) {
  346. npt.style.textAlign = "right";
  347. }
  348. if (npt.dir === "rtl" || opts.numericInput) {
  349. npt.dir = "ltr";
  350. npt.removeAttribute("dir");
  351. opts.isRTL = true;
  352. }
  353. return Object.keys(userOptions).length;
  354. }
  355. if (typeof elems === "string") {
  356. elems = document.getElementById(elems) || document.querySelectorAll(elems);
  357. }
  358. elems = elems.nodeName ? [ elems ] : elems;
  359. $.each(elems, function(ndx, el) {
  360. var scopedOpts = $.extend(true, {}, that.opts);
  361. if (importAttributeOptions(el, scopedOpts, $.extend(true, {}, that.userOptions), that.dataAttribute)) {
  362. var maskset = generateMaskSet(scopedOpts, that.noMasksCache);
  363. if (maskset !== undefined) {
  364. if (el.inputmask !== undefined) {
  365. el.inputmask.opts.autoUnmask = true;
  366. el.inputmask.remove();
  367. }
  368. el.inputmask = new Inputmask(undefined, undefined, true);
  369. el.inputmask.opts = scopedOpts;
  370. el.inputmask.noMasksCache = that.noMasksCache;
  371. el.inputmask.userOptions = $.extend(true, {}, that.userOptions);
  372. el.inputmask.isRTL = scopedOpts.isRTL || scopedOpts.numericInput;
  373. el.inputmask.el = el;
  374. el.inputmask.maskset = maskset;
  375. $.data(el, "_inputmask_opts", scopedOpts);
  376. maskScope.call(el.inputmask, {
  377. action: "mask"
  378. });
  379. }
  380. }
  381. });
  382. return elems && elems[0] ? elems[0].inputmask || this : this;
  383. },
  384. option: function option(options, noremask) {
  385. if (typeof options === "string") {
  386. return this.opts[options];
  387. } else if ((typeof options === "undefined" ? "undefined" : _typeof(options)) === "object") {
  388. $.extend(this.userOptions, options);
  389. if (this.el && noremask !== true) {
  390. this.mask(this.el);
  391. }
  392. return this;
  393. }
  394. },
  395. unmaskedvalue: function unmaskedvalue(value) {
  396. this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
  397. return maskScope.call(this, {
  398. action: "unmaskedvalue",
  399. value: value
  400. });
  401. },
  402. remove: function remove() {
  403. return maskScope.call(this, {
  404. action: "remove"
  405. });
  406. },
  407. getemptymask: function getemptymask() {
  408. this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
  409. return maskScope.call(this, {
  410. action: "getemptymask"
  411. });
  412. },
  413. hasMaskedValue: function hasMaskedValue() {
  414. return !this.opts.autoUnmask;
  415. },
  416. isComplete: function isComplete() {
  417. this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
  418. return maskScope.call(this, {
  419. action: "isComplete"
  420. });
  421. },
  422. getmetadata: function getmetadata() {
  423. this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
  424. return maskScope.call(this, {
  425. action: "getmetadata"
  426. });
  427. },
  428. isValid: function isValid(value) {
  429. this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
  430. return maskScope.call(this, {
  431. action: "isValid",
  432. value: value
  433. });
  434. },
  435. format: function format(value, metadata) {
  436. this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
  437. return maskScope.call(this, {
  438. action: "format",
  439. value: value,
  440. metadata: metadata
  441. });
  442. },
  443. setValue: function setValue(value) {
  444. if (this.el) {
  445. $(this.el).trigger("setvalue", [ value ]);
  446. }
  447. },
  448. analyseMask: function analyseMask(mask, regexMask, opts) {
  449. var tokenizer = /(?:[?*+]|\{[0-9\+\*]+(?:,[0-9\+\*]*)?(?:\|[0-9\+\*]*)?\})|[^.?*+^${[]()|\\]+|./g, regexTokenizer = /\[\^?]?(?:[^\\\]]+|\\[\S\s]?)*]?|\\(?:0(?:[0-3][0-7]{0,2}|[4-7][0-7]?)?|[1-9][0-9]*|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|c[A-Za-z]|[\S\s]?)|\((?:\?[:=!]?)?|(?:[?*+]|\{[0-9]+(?:,[0-9]*)?\})\??|[^.?*+^${[()|\\]+|./g, escaped = false, currentToken = new MaskToken(), match, m, openenings = [], maskTokens = [], openingToken, currentOpeningToken, alternator, lastMatch, groupToken;
  450. function MaskToken(isGroup, isOptional, isQuantifier, isAlternator) {
  451. this.matches = [];
  452. this.openGroup = isGroup || false;
  453. this.alternatorGroup = false;
  454. this.isGroup = isGroup || false;
  455. this.isOptional = isOptional || false;
  456. this.isQuantifier = isQuantifier || false;
  457. this.isAlternator = isAlternator || false;
  458. this.quantifier = {
  459. min: 1,
  460. max: 1
  461. };
  462. }
  463. function insertTestDefinition(mtoken, element, position) {
  464. position = position !== undefined ? position : mtoken.matches.length;
  465. var prevMatch = mtoken.matches[position - 1];
  466. if (regexMask) {
  467. if (element.indexOf("[") === 0 || escaped && /\\d|\\s|\\w]/i.test(element) || element === ".") {
  468. mtoken.matches.splice(position++, 0, {
  469. fn: new RegExp(element, opts.casing ? "i" : ""),
  470. optionality: false,
  471. newBlockMarker: prevMatch === undefined ? "master" : prevMatch.def !== element,
  472. casing: null,
  473. def: element,
  474. placeholder: undefined,
  475. nativeDef: element
  476. });
  477. } else {
  478. if (escaped) element = element[element.length - 1];
  479. $.each(element.split(""), function(ndx, lmnt) {
  480. prevMatch = mtoken.matches[position - 1];
  481. mtoken.matches.splice(position++, 0, {
  482. fn: null,
  483. optionality: false,
  484. newBlockMarker: prevMatch === undefined ? "master" : prevMatch.def !== lmnt && prevMatch.fn !== null,
  485. casing: null,
  486. def: opts.staticDefinitionSymbol || lmnt,
  487. placeholder: opts.staticDefinitionSymbol !== undefined ? lmnt : undefined,
  488. nativeDef: (escaped ? "'" : "") + lmnt
  489. });
  490. });
  491. }
  492. escaped = false;
  493. } else {
  494. var maskdef = (opts.definitions ? opts.definitions[element] : undefined) || Inputmask.prototype.definitions[element];
  495. if (maskdef && !escaped) {
  496. mtoken.matches.splice(position++, 0, {
  497. fn: maskdef.validator ? typeof maskdef.validator == "string" ? new RegExp(maskdef.validator, opts.casing ? "i" : "") : new function() {
  498. this.test = maskdef.validator;
  499. }() : new RegExp("."),
  500. optionality: false,
  501. newBlockMarker: prevMatch === undefined ? "master" : prevMatch.def !== (maskdef.definitionSymbol || element),
  502. casing: maskdef.casing,
  503. def: maskdef.definitionSymbol || element,
  504. placeholder: maskdef.placeholder,
  505. nativeDef: element
  506. });
  507. } else {
  508. mtoken.matches.splice(position++, 0, {
  509. fn: null,
  510. optionality: false,
  511. newBlockMarker: prevMatch === undefined ? "master" : prevMatch.def !== element && prevMatch.fn !== null,
  512. casing: null,
  513. def: opts.staticDefinitionSymbol || element,
  514. placeholder: opts.staticDefinitionSymbol !== undefined ? element : undefined,
  515. nativeDef: (escaped ? "'" : "") + element
  516. });
  517. escaped = false;
  518. }
  519. }
  520. }
  521. function verifyGroupMarker(maskToken) {
  522. if (maskToken && maskToken.matches) {
  523. $.each(maskToken.matches, function(ndx, token) {
  524. var nextToken = maskToken.matches[ndx + 1];
  525. if ((nextToken === undefined || nextToken.matches === undefined || nextToken.isQuantifier === false) && token && token.isGroup) {
  526. token.isGroup = false;
  527. if (!regexMask) {
  528. insertTestDefinition(token, opts.groupmarker[0], 0);
  529. if (token.openGroup !== true) {
  530. insertTestDefinition(token, opts.groupmarker[1]);
  531. }
  532. }
  533. }
  534. verifyGroupMarker(token);
  535. });
  536. }
  537. }
  538. function defaultCase() {
  539. if (openenings.length > 0) {
  540. currentOpeningToken = openenings[openenings.length - 1];
  541. insertTestDefinition(currentOpeningToken, m);
  542. if (currentOpeningToken.isAlternator) {
  543. alternator = openenings.pop();
  544. for (var mndx = 0; mndx < alternator.matches.length; mndx++) {
  545. if (alternator.matches[mndx].isGroup) alternator.matches[mndx].isGroup = false;
  546. }
  547. if (openenings.length > 0) {
  548. currentOpeningToken = openenings[openenings.length - 1];
  549. currentOpeningToken.matches.push(alternator);
  550. } else {
  551. currentToken.matches.push(alternator);
  552. }
  553. }
  554. } else {
  555. insertTestDefinition(currentToken, m);
  556. }
  557. }
  558. function reverseTokens(maskToken) {
  559. function reverseStatic(st) {
  560. if (st === opts.optionalmarker[0]) st = opts.optionalmarker[1]; else if (st === opts.optionalmarker[1]) st = opts.optionalmarker[0]; else if (st === opts.groupmarker[0]) st = opts.groupmarker[1]; else if (st === opts.groupmarker[1]) st = opts.groupmarker[0];
  561. return st;
  562. }
  563. maskToken.matches = maskToken.matches.reverse();
  564. for (var match in maskToken.matches) {
  565. if (maskToken.matches.hasOwnProperty(match)) {
  566. var intMatch = parseInt(match);
  567. if (maskToken.matches[match].isQuantifier && maskToken.matches[intMatch + 1] && maskToken.matches[intMatch + 1].isGroup) {
  568. var qt = maskToken.matches[match];
  569. maskToken.matches.splice(match, 1);
  570. maskToken.matches.splice(intMatch + 1, 0, qt);
  571. }
  572. if (maskToken.matches[match].matches !== undefined) {
  573. maskToken.matches[match] = reverseTokens(maskToken.matches[match]);
  574. } else {
  575. maskToken.matches[match] = reverseStatic(maskToken.matches[match]);
  576. }
  577. }
  578. }
  579. return maskToken;
  580. }
  581. function groupify(matches) {
  582. var groupToken = new MaskToken(true);
  583. groupToken.openGroup = false;
  584. groupToken.matches = matches;
  585. return groupToken;
  586. }
  587. if (regexMask) {
  588. opts.optionalmarker[0] = undefined;
  589. opts.optionalmarker[1] = undefined;
  590. }
  591. while (match = regexMask ? regexTokenizer.exec(mask) : tokenizer.exec(mask)) {
  592. m = match[0];
  593. if (regexMask) {
  594. switch (m.charAt(0)) {
  595. case "?":
  596. m = "{0,1}";
  597. break;
  598. case "+":
  599. case "*":
  600. m = "{" + m + "}";
  601. break;
  602. }
  603. }
  604. if (escaped) {
  605. defaultCase();
  606. continue;
  607. }
  608. switch (m.charAt(0)) {
  609. case "(?=":
  610. break;
  611. case "(?!":
  612. break;
  613. case "(?<=":
  614. break;
  615. case "(?<!":
  616. break;
  617. case opts.escapeChar:
  618. escaped = true;
  619. if (regexMask) {
  620. defaultCase();
  621. }
  622. break;
  623. case opts.optionalmarker[1]:
  624. case opts.groupmarker[1]:
  625. openingToken = openenings.pop();
  626. openingToken.openGroup = false;
  627. if (openingToken !== undefined) {
  628. if (openenings.length > 0) {
  629. currentOpeningToken = openenings[openenings.length - 1];
  630. currentOpeningToken.matches.push(openingToken);
  631. if (currentOpeningToken.isAlternator) {
  632. alternator = openenings.pop();
  633. for (var mndx = 0; mndx < alternator.matches.length; mndx++) {
  634. alternator.matches[mndx].isGroup = false;
  635. alternator.matches[mndx].alternatorGroup = false;
  636. }
  637. if (openenings.length > 0) {
  638. currentOpeningToken = openenings[openenings.length - 1];
  639. currentOpeningToken.matches.push(alternator);
  640. } else {
  641. currentToken.matches.push(alternator);
  642. }
  643. }
  644. } else {
  645. currentToken.matches.push(openingToken);
  646. }
  647. } else defaultCase();
  648. break;
  649. case opts.optionalmarker[0]:
  650. openenings.push(new MaskToken(false, true));
  651. break;
  652. case opts.groupmarker[0]:
  653. openenings.push(new MaskToken(true));
  654. break;
  655. case opts.quantifiermarker[0]:
  656. var quantifier = new MaskToken(false, false, true);
  657. m = m.replace(/[{}]/g, "");
  658. var mqj = m.split("|"), mq = mqj[0].split(","), mq0 = isNaN(mq[0]) ? mq[0] : parseInt(mq[0]), mq1 = mq.length === 1 ? mq0 : isNaN(mq[1]) ? mq[1] : parseInt(mq[1]);
  659. if (mq0 === "*" || mq0 === "+") {
  660. mq0 = mq1 === "*" ? 0 : 1;
  661. }
  662. quantifier.quantifier = {
  663. min: mq0,
  664. max: mq1,
  665. jit: mqj[1]
  666. };
  667. var matches = openenings.length > 0 ? openenings[openenings.length - 1].matches : currentToken.matches;
  668. match = matches.pop();
  669. if (match.isAlternator) {
  670. matches.push(match);
  671. matches = match.matches;
  672. var groupToken = new MaskToken(true);
  673. var tmpMatch = matches.pop();
  674. matches.push(groupToken);
  675. matches = groupToken.matches;
  676. match = tmpMatch;
  677. }
  678. if (!match.isGroup) {
  679. match = groupify([ match ]);
  680. }
  681. matches.push(match);
  682. matches.push(quantifier);
  683. break;
  684. case opts.alternatormarker:
  685. var groupQuantifier = function groupQuantifier(matches) {
  686. var lastMatch = matches.pop();
  687. if (lastMatch.isQuantifier) {
  688. lastMatch = groupify([ matches.pop(), lastMatch ]);
  689. }
  690. return lastMatch;
  691. };
  692. if (openenings.length > 0) {
  693. currentOpeningToken = openenings[openenings.length - 1];
  694. var subToken = currentOpeningToken.matches[currentOpeningToken.matches.length - 1];
  695. if (currentOpeningToken.openGroup && (subToken.matches === undefined || subToken.isGroup === false && subToken.isAlternator === false)) {
  696. lastMatch = openenings.pop();
  697. } else {
  698. lastMatch = groupQuantifier(currentOpeningToken.matches);
  699. }
  700. } else {
  701. lastMatch = groupQuantifier(currentToken.matches);
  702. }
  703. if (lastMatch.isAlternator) {
  704. openenings.push(lastMatch);
  705. } else {
  706. if (lastMatch.alternatorGroup) {
  707. alternator = openenings.pop();
  708. lastMatch.alternatorGroup = false;
  709. } else {
  710. alternator = new MaskToken(false, false, false, true);
  711. }
  712. alternator.matches.push(lastMatch);
  713. openenings.push(alternator);
  714. if (lastMatch.openGroup) {
  715. lastMatch.openGroup = false;
  716. var alternatorGroup = new MaskToken(true);
  717. alternatorGroup.alternatorGroup = true;
  718. openenings.push(alternatorGroup);
  719. }
  720. }
  721. break;
  722. default:
  723. defaultCase();
  724. }
  725. }
  726. while (openenings.length > 0) {
  727. openingToken = openenings.pop();
  728. currentToken.matches.push(openingToken);
  729. }
  730. if (currentToken.matches.length > 0) {
  731. verifyGroupMarker(currentToken);
  732. maskTokens.push(currentToken);
  733. }
  734. if (opts.numericInput || opts.isRTL) {
  735. reverseTokens(maskTokens[0]);
  736. }
  737. return maskTokens;
  738. }
  739. };
  740. Inputmask.extendDefaults = function(options) {
  741. $.extend(true, Inputmask.prototype.defaults, options);
  742. };
  743. Inputmask.extendDefinitions = function(definition) {
  744. $.extend(true, Inputmask.prototype.definitions, definition);
  745. };
  746. Inputmask.extendAliases = function(alias) {
  747. $.extend(true, Inputmask.prototype.aliases, alias);
  748. };
  749. Inputmask.format = function(value, options, metadata) {
  750. return Inputmask(options).format(value, metadata);
  751. };
  752. Inputmask.unmask = function(value, options) {
  753. return Inputmask(options).unmaskedvalue(value);
  754. };
  755. Inputmask.isValid = function(value, options) {
  756. return Inputmask(options).isValid(value);
  757. };
  758. Inputmask.remove = function(elems) {
  759. if (typeof elems === "string") {
  760. elems = document.getElementById(elems) || document.querySelectorAll(elems);
  761. }
  762. elems = elems.nodeName ? [ elems ] : elems;
  763. $.each(elems, function(ndx, el) {
  764. if (el.inputmask) el.inputmask.remove();
  765. });
  766. };
  767. Inputmask.setValue = function(elems, value) {
  768. if (typeof elems === "string") {
  769. elems = document.getElementById(elems) || document.querySelectorAll(elems);
  770. }
  771. elems = elems.nodeName ? [ elems ] : elems;
  772. $.each(elems, function(ndx, el) {
  773. if (el.inputmask) el.inputmask.setValue(value); else $(el).trigger("setvalue", [ value ]);
  774. });
  775. };
  776. Inputmask.escapeRegex = function(str) {
  777. var specials = [ "/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\", "$", "^" ];
  778. return str.replace(new RegExp("(\\" + specials.join("|\\") + ")", "gim"), "\\$1");
  779. };
  780. Inputmask.keyCode = {
  781. BACKSPACE: 8,
  782. BACKSPACE_SAFARI: 127,
  783. DELETE: 46,
  784. DOWN: 40,
  785. END: 35,
  786. ENTER: 13,
  787. ESCAPE: 27,
  788. HOME: 36,
  789. INSERT: 45,
  790. LEFT: 37,
  791. PAGE_DOWN: 34,
  792. PAGE_UP: 33,
  793. RIGHT: 39,
  794. SPACE: 32,
  795. TAB: 9,
  796. UP: 38,
  797. X: 88,
  798. CONTROL: 17
  799. };
  800. Inputmask.dependencyLib = $;
  801. function resolveAlias(aliasStr, options, opts) {
  802. var aliasDefinition = Inputmask.prototype.aliases[aliasStr];
  803. if (aliasDefinition) {
  804. if (aliasDefinition.alias) resolveAlias(aliasDefinition.alias, undefined, opts);
  805. $.extend(true, opts, aliasDefinition);
  806. $.extend(true, opts, options);
  807. return true;
  808. } else if (opts.mask === null) {
  809. opts.mask = aliasStr;
  810. }
  811. return false;
  812. }
  813. function generateMaskSet(opts, nocache) {
  814. function generateMask(mask, metadata, opts) {
  815. var regexMask = false;
  816. if (mask === null || mask === "") {
  817. regexMask = opts.regex !== null;
  818. if (regexMask) {
  819. mask = opts.regex;
  820. mask = mask.replace(/^(\^)(.*)(\$)$/, "$2");
  821. } else {
  822. regexMask = true;
  823. mask = ".*";
  824. }
  825. }
  826. if (mask.length === 1 && opts.greedy === false && opts.repeat !== 0) {
  827. opts.placeholder = "";
  828. }
  829. if (opts.repeat > 0 || opts.repeat === "*" || opts.repeat === "+") {
  830. var repeatStart = opts.repeat === "*" ? 0 : opts.repeat === "+" ? 1 : opts.repeat;
  831. mask = opts.groupmarker[0] + mask + opts.groupmarker[1] + opts.quantifiermarker[0] + repeatStart + "," + opts.repeat + opts.quantifiermarker[1];
  832. }
  833. var masksetDefinition, maskdefKey = regexMask ? "regex_" + opts.regex : opts.numericInput ? mask.split("").reverse().join("") : mask;
  834. if (Inputmask.prototype.masksCache[maskdefKey] === undefined || nocache === true) {
  835. masksetDefinition = {
  836. mask: mask,
  837. maskToken: Inputmask.prototype.analyseMask(mask, regexMask, opts),
  838. validPositions: {},
  839. _buffer: undefined,
  840. buffer: undefined,
  841. tests: {},
  842. excludes: {},
  843. metadata: metadata,
  844. maskLength: undefined,
  845. jitOffset: {}
  846. };
  847. if (nocache !== true) {
  848. Inputmask.prototype.masksCache[maskdefKey] = masksetDefinition;
  849. masksetDefinition = $.extend(true, {}, Inputmask.prototype.masksCache[maskdefKey]);
  850. }
  851. } else masksetDefinition = $.extend(true, {}, Inputmask.prototype.masksCache[maskdefKey]);
  852. return masksetDefinition;
  853. }
  854. var ms;
  855. if ($.isFunction(opts.mask)) {
  856. opts.mask = opts.mask(opts);
  857. }
  858. if ($.isArray(opts.mask)) {
  859. if (opts.mask.length > 1) {
  860. if (opts.keepStatic === null) {
  861. opts.keepStatic = "auto";
  862. for (var i = 0; i < opts.mask.length; i++) {
  863. if (opts.mask[i].charAt(0) !== opts.mask[0].charAt(0)) {
  864. opts.keepStatic = true;
  865. break;
  866. }
  867. }
  868. }
  869. var altMask = opts.groupmarker[0];
  870. $.each(opts.isRTL ? opts.mask.reverse() : opts.mask, function(ndx, msk) {
  871. if (altMask.length > 1) {
  872. altMask += opts.groupmarker[1] + opts.alternatormarker + opts.groupmarker[0];
  873. }
  874. if (msk.mask !== undefined && !$.isFunction(msk.mask)) {
  875. altMask += msk.mask;
  876. } else {
  877. altMask += msk;
  878. }
  879. });
  880. altMask += opts.groupmarker[1];
  881. return generateMask(altMask, opts.mask, opts);
  882. } else opts.mask = opts.mask.pop();
  883. }
  884. if (opts.mask && opts.mask.mask !== undefined && !$.isFunction(opts.mask.mask)) {
  885. ms = generateMask(opts.mask.mask, opts.mask, opts);
  886. } else {
  887. ms = generateMask(opts.mask, opts.mask, opts);
  888. }
  889. return ms;
  890. }
  891. function isInputEventSupported(eventName) {
  892. var el = document.createElement("input"), evName = "on" + eventName, isSupported = evName in el;
  893. if (!isSupported) {
  894. el.setAttribute(evName, "return;");
  895. isSupported = typeof el[evName] === "function";
  896. }
  897. el = null;
  898. return isSupported;
  899. }
  900. function maskScope(actionObj, maskset, opts) {
  901. maskset = maskset || this.maskset;
  902. opts = opts || this.opts;
  903. var inputmask = this, el = this.el, isRTL = this.isRTL, undoValue, $el, skipKeyPressEvent = false, skipInputEvent = false, ignorable = false, maxLength, mouseEnter = false, colorMask, originalPlaceholder;
  904. function getMaskTemplate(baseOnInput, minimalPos, includeMode, noJit, clearOptionalTail) {
  905. var greedy = opts.greedy;
  906. if (clearOptionalTail) opts.greedy = false;
  907. minimalPos = minimalPos || 0;
  908. var maskTemplate = [], ndxIntlzr, pos = 0, test, testPos, lvp = getLastValidPosition();
  909. do {
  910. if (baseOnInput === true && getMaskSet().validPositions[pos]) {
  911. testPos = clearOptionalTail && getMaskSet().validPositions[pos].match.optionality === true && getMaskSet().validPositions[pos + 1] === undefined && (getMaskSet().validPositions[pos].generatedInput === true || getMaskSet().validPositions[pos].input == opts.skipOptionalPartCharacter && pos > 0) ? determineTestTemplate(pos, getTests(pos, ndxIntlzr, pos - 1)) : getMaskSet().validPositions[pos];
  912. test = testPos.match;
  913. ndxIntlzr = testPos.locator.slice();
  914. maskTemplate.push(includeMode === true ? testPos.input : includeMode === false ? test.nativeDef : getPlaceholder(pos, test));
  915. } else {
  916. testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
  917. test = testPos.match;
  918. ndxIntlzr = testPos.locator.slice();
  919. var jitMasking = noJit === true ? false : opts.jitMasking !== false ? opts.jitMasking : test.jit;
  920. if (jitMasking === false || jitMasking === undefined || typeof jitMasking === "number" && isFinite(jitMasking) && jitMasking > pos) {
  921. maskTemplate.push(includeMode === false ? test.nativeDef : getPlaceholder(pos, test));
  922. }
  923. }
  924. if (opts.keepStatic === "auto") {
  925. if (test.newBlockMarker && test.fn !== null) {
  926. opts.keepStatic = pos - 1;
  927. }
  928. }
  929. pos++;
  930. } while ((maxLength === undefined || pos < maxLength) && (test.fn !== null || test.def !== "") || minimalPos > pos);
  931. if (maskTemplate[maskTemplate.length - 1] === "") {
  932. maskTemplate.pop();
  933. }
  934. if (includeMode !== false || getMaskSet().maskLength === undefined) getMaskSet().maskLength = pos - 1;
  935. opts.greedy = greedy;
  936. return maskTemplate;
  937. }
  938. function getMaskSet() {
  939. return maskset;
  940. }
  941. function resetMaskSet(soft) {
  942. var maskset = getMaskSet();
  943. maskset.buffer = undefined;
  944. if (soft !== true) {
  945. maskset.validPositions = {};
  946. maskset.p = 0;
  947. }
  948. }
  949. function getLastValidPosition(closestTo, strict, validPositions) {
  950. var before = -1, after = -1, valids = validPositions || getMaskSet().validPositions;
  951. if (closestTo === undefined) closestTo = -1;
  952. for (var posNdx in valids) {
  953. var psNdx = parseInt(posNdx);
  954. if (valids[psNdx] && (strict || valids[psNdx].generatedInput !== true)) {
  955. if (psNdx <= closestTo) before = psNdx;
  956. if (psNdx >= closestTo) after = psNdx;
  957. }
  958. }
  959. return before === -1 || before == closestTo ? after : after == -1 ? before : closestTo - before < after - closestTo ? before : after;
  960. }
  961. function getDecisionTaker(tst) {
  962. var decisionTaker = tst.locator[tst.alternation];
  963. if (typeof decisionTaker == "string" && decisionTaker.length > 0) {
  964. decisionTaker = decisionTaker.split(",")[0];
  965. }
  966. return decisionTaker !== undefined ? decisionTaker.toString() : "";
  967. }
  968. function getLocator(tst, align) {
  969. var locator = (tst.alternation != undefined ? tst.mloc[getDecisionTaker(tst)] : tst.locator).join("");
  970. if (locator !== "") while (locator.length < align) {
  971. locator += "0";
  972. }
  973. return locator;
  974. }
  975. function determineTestTemplate(pos, tests) {
  976. pos = pos > 0 ? pos - 1 : 0;
  977. var altTest = getTest(pos), targetLocator = getLocator(altTest), tstLocator, closest, bestMatch;
  978. for (var ndx = 0; ndx < tests.length; ndx++) {
  979. var tst = tests[ndx];
  980. tstLocator = getLocator(tst, targetLocator.length);
  981. var distance = Math.abs(tstLocator - targetLocator);
  982. if (closest === undefined || tstLocator !== "" && distance < closest || bestMatch && !opts.greedy && bestMatch.match.optionality && bestMatch.match.newBlockMarker === "master" && (!tst.match.optionality || !tst.match.newBlockMarker) || bestMatch && bestMatch.match.optionalQuantifier && !tst.match.optionalQuantifier) {
  983. closest = distance;
  984. bestMatch = tst;
  985. }
  986. }
  987. return bestMatch;
  988. }
  989. function getTestTemplate(pos, ndxIntlzr, tstPs) {
  990. return getMaskSet().validPositions[pos] || determineTestTemplate(pos, getTests(pos, ndxIntlzr ? ndxIntlzr.slice() : ndxIntlzr, tstPs));
  991. }
  992. function getTest(pos, tests) {
  993. if (getMaskSet().validPositions[pos]) {
  994. return getMaskSet().validPositions[pos];
  995. }
  996. return (tests || getTests(pos))[0];
  997. }
  998. function positionCanMatchDefinition(pos, def) {
  999. var valid = false, tests = getTests(pos);
  1000. for (var tndx = 0; tndx < tests.length; tndx++) {
  1001. if (tests[tndx].match && tests[tndx].match.def === def) {
  1002. valid = true;
  1003. break;
  1004. }
  1005. }
  1006. return valid;
  1007. }
  1008. function getTests(pos, ndxIntlzr, tstPs) {
  1009. var maskTokens = getMaskSet().maskToken, testPos = ndxIntlzr ? tstPs : 0, ndxInitializer = ndxIntlzr ? ndxIntlzr.slice() : [ 0 ], matches = [], insertStop = false, latestMatch, cacheDependency = ndxIntlzr ? ndxIntlzr.join("") : "";
  1010. function resolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) {
  1011. function handleMatch(match, loopNdx, quantifierRecurse) {
  1012. function isFirstMatch(latestMatch, tokenGroup) {
  1013. var firstMatch = $.inArray(latestMatch, tokenGroup.matches) === 0;
  1014. if (!firstMatch) {
  1015. $.each(tokenGroup.matches, function(ndx, match) {
  1016. if (match.isQuantifier === true) firstMatch = isFirstMatch(latestMatch, tokenGroup.matches[ndx - 1]); else if (match.hasOwnProperty("matches")) firstMatch = isFirstMatch(latestMatch, match);
  1017. if (firstMatch) return false;
  1018. });
  1019. }
  1020. return firstMatch;
  1021. }
  1022. function resolveNdxInitializer(pos, alternateNdx, targetAlternation) {
  1023. var bestMatch, indexPos;
  1024. if (getMaskSet().tests[pos] || getMaskSet().validPositions[pos]) {
  1025. $.each(getMaskSet().tests[pos] || [ getMaskSet().validPositions[pos] ], function(ndx, lmnt) {
  1026. if (lmnt.mloc[alternateNdx]) {
  1027. bestMatch = lmnt;
  1028. return false;
  1029. }
  1030. var alternation = targetAlternation !== undefined ? targetAlternation : lmnt.alternation, ndxPos = lmnt.locator[alternation] !== undefined ? lmnt.locator[alternation].toString().indexOf(alternateNdx) : -1;
  1031. if ((indexPos === undefined || ndxPos < indexPos) && ndxPos !== -1) {
  1032. bestMatch = lmnt;
  1033. indexPos = ndxPos;
  1034. }
  1035. });
  1036. }
  1037. if (bestMatch) {
  1038. var bestMatchAltIndex = bestMatch.locator[bestMatch.alternation];
  1039. var locator = bestMatch.mloc[alternateNdx] || bestMatch.mloc[bestMatchAltIndex] || bestMatch.locator;
  1040. return locator.slice((targetAlternation !== undefined ? targetAlternation : bestMatch.alternation) + 1);
  1041. } else {
  1042. return targetAlternation !== undefined ? resolveNdxInitializer(pos, alternateNdx) : undefined;
  1043. }
  1044. }
  1045. function isSubsetOf(source, target) {
  1046. function expand(pattern) {
  1047. var expanded = [], start, end;
  1048. for (var i = 0, l = pattern.length; i < l; i++) {
  1049. if (pattern.charAt(i) === "-") {
  1050. end = pattern.charCodeAt(i + 1);
  1051. while (++start < end) {
  1052. expanded.push(String.fromCharCode(start));
  1053. }
  1054. } else {
  1055. start = pattern.charCodeAt(i);
  1056. expanded.push(pattern.charAt(i));
  1057. }
  1058. }
  1059. return expanded.join("");
  1060. }
  1061. if (opts.regex && source.match.fn !== null && target.match.fn !== null) {
  1062. return expand(target.match.def.replace(/[\[\]]/g, "")).indexOf(expand(source.match.def.replace(/[\[\]]/g, ""))) !== -1;
  1063. }
  1064. return source.match.def === target.match.nativeDef;
  1065. }
  1066. function staticCanMatchDefinition(source, target) {
  1067. var sloc = source.locator.slice(source.alternation).join(""), tloc = target.locator.slice(target.alternation).join(""), canMatch = sloc == tloc;
  1068. canMatch = canMatch && source.match.fn === null && target.match.fn !== null ? target.match.fn.test(source.match.def, getMaskSet(), pos, false, opts, false) : false;
  1069. return canMatch;
  1070. }
  1071. function setMergeLocators(targetMatch, altMatch) {
  1072. if (altMatch === undefined || targetMatch.alternation === altMatch.alternation && targetMatch.locator[targetMatch.alternation].toString().indexOf(altMatch.locator[altMatch.alternation]) === -1) {
  1073. targetMatch.mloc = targetMatch.mloc || {};
  1074. var locNdx = targetMatch.locator[targetMatch.alternation];
  1075. if (locNdx === undefined) targetMatch.alternation = undefined; else {
  1076. if (typeof locNdx === "string") locNdx = locNdx.split(",")[0];
  1077. if (targetMatch.mloc[locNdx] === undefined) targetMatch.mloc[locNdx] = targetMatch.locator.slice();
  1078. if (altMatch !== undefined) {
  1079. for (var ndx in altMatch.mloc) {
  1080. if (typeof ndx === "string") ndx = ndx.split(",")[0];
  1081. if (targetMatch.mloc[ndx] === undefined) targetMatch.mloc[ndx] = altMatch.mloc[ndx];
  1082. }
  1083. targetMatch.locator[targetMatch.alternation] = Object.keys(targetMatch.mloc).join(",");
  1084. }
  1085. return true;
  1086. }
  1087. }
  1088. return false;
  1089. }
  1090. if (testPos > 500 && quantifierRecurse !== undefined) {
  1091. throw "Inputmask: There is probably an error in your mask definition or in the code. Create an issue on github with an example of the mask you are using. " + getMaskSet().mask;
  1092. }
  1093. if (testPos === pos && match.matches === undefined) {
  1094. matches.push({
  1095. match: match,
  1096. locator: loopNdx.reverse(),
  1097. cd: cacheDependency,
  1098. mloc: {}
  1099. });
  1100. return true;
  1101. } else if (match.matches !== undefined) {
  1102. if (match.isGroup && quantifierRecurse !== match) {
  1103. match = handleMatch(maskToken.matches[$.inArray(match, maskToken.matches) + 1], loopNdx, quantifierRecurse);
  1104. if (match) return true;
  1105. } else if (match.isOptional) {
  1106. var optionalToken = match;
  1107. match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse);
  1108. if (match) {
  1109. $.each(matches, function(ndx, mtch) {
  1110. mtch.match.optionality = true;
  1111. });
  1112. latestMatch = matches[matches.length - 1].match;
  1113. if (quantifierRecurse === undefined && isFirstMatch(latestMatch, optionalToken)) {
  1114. insertStop = true;
  1115. testPos = pos;
  1116. } else return true;
  1117. }
  1118. } else if (match.isAlternator) {
  1119. var alternateToken = match, malternateMatches = [], maltMatches, currentMatches = matches.slice(), loopNdxCnt = loopNdx.length;
  1120. var altIndex = ndxInitializer.length > 0 ? ndxInitializer.shift() : -1;
  1121. if (altIndex === -1 || typeof altIndex === "string") {
  1122. var currentPos = testPos, ndxInitializerClone = ndxInitializer.slice(), altIndexArr = [], amndx;
  1123. if (typeof altIndex == "string") {
  1124. altIndexArr = altIndex.split(",");
  1125. } else {
  1126. for (amndx = 0; amndx < alternateToken.matches.length; amndx++) {
  1127. altIndexArr.push(amndx.toString());
  1128. }
  1129. }
  1130. if (getMaskSet().excludes[pos]) {
  1131. var altIndexArrClone = altIndexArr.slice();
  1132. for (var i = 0, el = getMaskSet().excludes[pos].length; i < el; i++) {
  1133. altIndexArr.splice(altIndexArr.indexOf(getMaskSet().excludes[pos][i].toString()), 1);
  1134. }
  1135. if (altIndexArr.length === 0) {
  1136. getMaskSet().excludes[pos] = undefined;
  1137. altIndexArr = altIndexArrClone;
  1138. }
  1139. }
  1140. if (opts.keepStatic === true || isFinite(parseInt(opts.keepStatic)) && currentPos >= opts.keepStatic) altIndexArr = altIndexArr.slice(0, 1);
  1141. var unMatchedAlternation = false;
  1142. for (var ndx = 0; ndx < altIndexArr.length; ndx++) {
  1143. amndx = parseInt(altIndexArr[ndx]);
  1144. matches = [];
  1145. ndxInitializer = typeof altIndex === "string" ? resolveNdxInitializer(testPos, amndx, loopNdxCnt) || ndxInitializerClone.slice() : ndxInitializerClone.slice();
  1146. if (alternateToken.matches[amndx] && handleMatch(alternateToken.matches[amndx], [ amndx ].concat(loopNdx), quantifierRecurse)) match = true; else if (ndx === 0) {
  1147. unMatchedAlternation = true;
  1148. }
  1149. maltMatches = matches.slice();
  1150. testPos = currentPos;
  1151. matches = [];
  1152. for (var ndx1 = 0; ndx1 < maltMatches.length; ndx1++) {
  1153. var altMatch = maltMatches[ndx1], dropMatch = false;
  1154. altMatch.match.jit = altMatch.match.jit || unMatchedAlternation;
  1155. altMatch.alternation = altMatch.alternation || loopNdxCnt;
  1156. setMergeLocators(altMatch);
  1157. for (var ndx2 = 0; ndx2 < malternateMatches.length; ndx2++) {
  1158. var altMatch2 = malternateMatches[ndx2];
  1159. if (typeof altIndex !== "string" || altMatch.alternation !== undefined && $.inArray(altMatch.locator[altMatch.alternation].toString(), altIndexArr) !== -1) {
  1160. if (altMatch.match.nativeDef === altMatch2.match.nativeDef) {
  1161. dropMatch = true;
  1162. setMergeLocators(altMatch2, altMatch);
  1163. break;
  1164. } else if (isSubsetOf(altMatch, altMatch2)) {
  1165. if (setMergeLocators(altMatch, altMatch2)) {
  1166. dropMatch = true;
  1167. malternateMatches.splice(malternateMatches.indexOf(altMatch2), 0, altMatch);
  1168. }
  1169. break;
  1170. } else if (isSubsetOf(altMatch2, altMatch)) {
  1171. setMergeLocators(altMatch2, altMatch);
  1172. break;
  1173. } else if (staticCanMatchDefinition(altMatch, altMatch2)) {
  1174. if (setMergeLocators(altMatch, altMatch2)) {
  1175. dropMatch = true;
  1176. malternateMatches.splice(malternateMatches.indexOf(altMatch2), 0, altMatch);
  1177. }
  1178. break;
  1179. }
  1180. }
  1181. }
  1182. if (!dropMatch) {
  1183. malternateMatches.push(altMatch);
  1184. }
  1185. }
  1186. }
  1187. matches = currentMatches.concat(malternateMatches);
  1188. testPos = pos;
  1189. insertStop = matches.length > 0;
  1190. match = malternateMatches.length > 0;
  1191. ndxInitializer = ndxInitializerClone.slice();
  1192. } else match = handleMatch(alternateToken.matches[altIndex] || maskToken.matches[altIndex], [ altIndex ].concat(loopNdx), quantifierRecurse);
  1193. if (match) return true;
  1194. } else if (match.isQuantifier && quantifierRecurse !== maskToken.matches[$.inArray(match, maskToken.matches) - 1]) {
  1195. var qt = match;
  1196. for (var qndx = ndxInitializer.length > 0 ? ndxInitializer.shift() : 0; qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max) && testPos <= pos; qndx++) {
  1197. var tokenGroup = maskToken.matches[$.inArray(qt, maskToken.matches) - 1];
  1198. match = handleMatch(tokenGroup, [ qndx ].concat(loopNdx), tokenGroup);
  1199. if (match) {
  1200. latestMatch = matches[matches.length - 1].match;
  1201. latestMatch.optionalQuantifier = qndx >= qt.quantifier.min;
  1202. latestMatch.jit = (qndx || 1) * tokenGroup.matches.indexOf(latestMatch) >= qt.quantifier.jit;
  1203. if (latestMatch.optionalQuantifier && isFirstMatch(latestMatch, tokenGroup)) {
  1204. insertStop = true;
  1205. testPos = pos;
  1206. break;
  1207. }
  1208. if (latestMatch.jit) {
  1209. getMaskSet().jitOffset[pos] = tokenGroup.matches.indexOf(latestMatch);
  1210. }
  1211. return true;
  1212. }
  1213. }
  1214. } else {
  1215. match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse);
  1216. if (match) return true;
  1217. }
  1218. } else {
  1219. testPos++;
  1220. }
  1221. }
  1222. for (var tndx = ndxInitializer.length > 0 ? ndxInitializer.shift() : 0; tndx < maskToken.matches.length; tndx++) {
  1223. if (maskToken.matches[tndx].isQuantifier !== true) {
  1224. var match = handleMatch(maskToken.matches[tndx], [ tndx ].concat(loopNdx), quantifierRecurse);
  1225. if (match && testPos === pos) {
  1226. return match;
  1227. } else if (testPos > pos) {
  1228. break;
  1229. }
  1230. }
  1231. }
  1232. }
  1233. function mergeLocators(pos, tests) {
  1234. var locator = [];
  1235. if (!$.isArray(tests)) tests = [ tests ];
  1236. if (tests.length > 0) {
  1237. if (tests[0].alternation === undefined) {
  1238. locator = determineTestTemplate(pos, tests.slice()).locator.slice();
  1239. if (locator.length === 0) locator = tests[0].locator.slice();
  1240. } else {
  1241. $.each(tests, function(ndx, tst) {
  1242. if (tst.def !== "") {
  1243. if (locator.length === 0) locator = tst.locator.slice(); else {
  1244. for (var i = 0; i < locator.length; i++) {
  1245. if (tst.locator[i] && locator[i].toString().indexOf(tst.locator[i]) === -1) {
  1246. locator[i] += "," + tst.locator[i];
  1247. }
  1248. }
  1249. }
  1250. }
  1251. });
  1252. }
  1253. }
  1254. return locator;
  1255. }
  1256. if (pos > -1) {
  1257. if (ndxIntlzr === undefined) {
  1258. var previousPos = pos - 1, test;
  1259. while ((test = getMaskSet().validPositions[previousPos] || getMaskSet().tests[previousPos]) === undefined && previousPos > -1) {
  1260. previousPos--;
  1261. }
  1262. if (test !== undefined && previousPos > -1) {
  1263. ndxInitializer = mergeLocators(previousPos, test);
  1264. cacheDependency = ndxInitializer.join("");
  1265. testPos = previousPos;
  1266. }
  1267. }
  1268. if (getMaskSet().tests[pos] && getMaskSet().tests[pos][0].cd === cacheDependency) {
  1269. return getMaskSet().tests[pos];
  1270. }
  1271. for (var mtndx = ndxInitializer.shift(); mtndx < maskTokens.length; mtndx++) {
  1272. var match = resolveTestFromToken(maskTokens[mtndx], ndxInitializer, [ mtndx ]);
  1273. if (match && testPos === pos || testPos > pos) {
  1274. break;
  1275. }
  1276. }
  1277. }
  1278. if (matches.length === 0 || insertStop) {
  1279. matches.push({
  1280. match: {
  1281. fn: null,
  1282. optionality: false,
  1283. casing: null,
  1284. def: "",
  1285. placeholder: ""
  1286. },
  1287. locator: [],
  1288. mloc: {},
  1289. cd: cacheDependency
  1290. });
  1291. }
  1292. if (ndxIntlzr !== undefined && getMaskSet().tests[pos]) {
  1293. return $.extend(true, [], matches);
  1294. }
  1295. getMaskSet().tests[pos] = $.extend(true, [], matches);
  1296. return getMaskSet().tests[pos];
  1297. }
  1298. function getBufferTemplate() {
  1299. if (getMaskSet()._buffer === undefined) {
  1300. getMaskSet()._buffer = getMaskTemplate(false, 1);
  1301. if (getMaskSet().buffer === undefined) getMaskSet().buffer = getMaskSet()._buffer.slice();
  1302. }
  1303. return getMaskSet()._buffer;
  1304. }
  1305. function getBuffer(noCache) {
  1306. if (getMaskSet().buffer === undefined || noCache === true) {
  1307. getMaskSet().buffer = getMaskTemplate(true, getLastValidPosition(), true);
  1308. if (getMaskSet()._buffer === undefined) getMaskSet()._buffer = getMaskSet().buffer.slice();
  1309. }
  1310. return getMaskSet().buffer;
  1311. }
  1312. function refreshFromBuffer(start, end, buffer) {
  1313. var i, p;
  1314. if (start === true) {
  1315. resetMaskSet();
  1316. start = 0;
  1317. end = buffer.length;
  1318. } else {
  1319. for (i = start; i < end; i++) {
  1320. delete getMaskSet().validPositions[i];
  1321. }
  1322. }
  1323. p = start;
  1324. for (i = start; i < end; i++) {
  1325. resetMaskSet(true);
  1326. if (buffer[i] !== opts.skipOptionalPartCharacter) {
  1327. var valResult = isValid(p, buffer[i], true, true);
  1328. if (valResult !== false) {
  1329. resetMaskSet(true);
  1330. p = valResult.caret !== undefined ? valResult.caret : valResult.pos + 1;
  1331. }
  1332. }
  1333. }
  1334. }
  1335. function casing(elem, test, pos) {
  1336. switch (opts.casing || test.casing) {
  1337. case "upper":
  1338. elem = elem.toUpperCase();
  1339. break;
  1340. case "lower":
  1341. elem = elem.toLowerCase();
  1342. break;
  1343. case "title":
  1344. var posBefore = getMaskSet().validPositions[pos - 1];
  1345. if (pos === 0 || posBefore && posBefore.input === String.fromCharCode(Inputmask.keyCode.SPACE)) {
  1346. elem = elem.toUpperCase();
  1347. } else {
  1348. elem = elem.toLowerCase();
  1349. }
  1350. break;
  1351. default:
  1352. if ($.isFunction(opts.casing)) {
  1353. var args = Array.prototype.slice.call(arguments);
  1354. args.push(getMaskSet().validPositions);
  1355. elem = opts.casing.apply(this, args);
  1356. }
  1357. }
  1358. return elem;
  1359. }
  1360. function checkAlternationMatch(altArr1, altArr2, na) {
  1361. var altArrC = opts.greedy ? altArr2 : altArr2.slice(0, 1), isMatch = false, naArr = na !== undefined ? na.split(",") : [], naNdx;
  1362. for (var i = 0; i < naArr.length; i++) {
  1363. if ((naNdx = altArr1.indexOf(naArr[i])) !== -1) {
  1364. altArr1.splice(naNdx, 1);
  1365. }
  1366. }
  1367. for (var alndx = 0; alndx < altArr1.length; alndx++) {
  1368. if ($.inArray(altArr1[alndx], altArrC) !== -1) {
  1369. isMatch = true;
  1370. break;
  1371. }
  1372. }
  1373. return isMatch;
  1374. }
  1375. function alternate(pos, c, strict, fromSetValid, rAltPos) {
  1376. var validPsClone = $.extend(true, {}, getMaskSet().validPositions), lastAlt, alternation, isValidRslt = false, altPos, prevAltPos, i, validPos, decisionPos, lAltPos = rAltPos !== undefined ? rAltPos : getLastValidPosition();
  1377. if (lAltPos === -1 && rAltPos === undefined) {
  1378. lastAlt = 0;
  1379. prevAltPos = getTest(lastAlt);
  1380. alternation = prevAltPos.alternation;
  1381. } else {
  1382. for (;lAltPos >= 0; lAltPos--) {
  1383. altPos = getMaskSet().validPositions[lAltPos];
  1384. if (altPos && altPos.alternation !== undefined) {
  1385. if (prevAltPos && prevAltPos.locator[altPos.alternation] !== altPos.locator[altPos.alternation]) {
  1386. break;
  1387. }
  1388. lastAlt = lAltPos;
  1389. alternation = getMaskSet().validPositions[lastAlt].alternation;
  1390. prevAltPos = altPos;
  1391. }
  1392. }
  1393. }
  1394. if (alternation !== undefined) {
  1395. decisionPos = parseInt(lastAlt);
  1396. getMaskSet().excludes[decisionPos] = getMaskSet().excludes[decisionPos] || [];
  1397. if (pos !== true) {
  1398. getMaskSet().excludes[decisionPos].push(getDecisionTaker(prevAltPos));
  1399. }
  1400. var validInputsClone = [], staticInputsBeforePos = 0;
  1401. for (i = decisionPos; i < getLastValidPosition(undefined, true) + 1; i++) {
  1402. validPos = getMaskSet().validPositions[i];
  1403. if (validPos && validPos.generatedInput !== true) {
  1404. validInputsClone.push(validPos.input);
  1405. } else if (i < pos) staticInputsBeforePos++;
  1406. delete getMaskSet().validPositions[i];
  1407. }
  1408. while (getMaskSet().excludes[decisionPos] && getMaskSet().excludes[decisionPos].length < 10) {
  1409. var posOffset = staticInputsBeforePos * -1, validInputs = validInputsClone.slice();
  1410. getMaskSet().tests[decisionPos] = undefined;
  1411. resetMaskSet(true);
  1412. isValidRslt = true;
  1413. while (validInputs.length > 0) {
  1414. var input = validInputs.shift();
  1415. if (!(isValidRslt = isValid(getLastValidPosition(undefined, true) + 1, input, false, fromSetValid, true))) {
  1416. break;
  1417. }
  1418. }
  1419. if (isValidRslt && c !== undefined) {
  1420. var targetLvp = getLastValidPosition(pos) + 1;
  1421. for (i = decisionPos; i < getLastValidPosition() + 1; i++) {
  1422. validPos = getMaskSet().validPositions[i];
  1423. if ((validPos === undefined || validPos.match.fn == null) && i < pos + posOffset) {
  1424. posOffset++;
  1425. }
  1426. }
  1427. pos = pos + posOffset;
  1428. isValidRslt = isValid(pos > targetLvp ? targetLvp : pos, c, strict, fromSetValid, true);
  1429. }
  1430. if (!isValidRslt) {
  1431. resetMaskSet();
  1432. prevAltPos = getTest(decisionPos);
  1433. getMaskSet().validPositions = $.extend(true, {}, validPsClone);
  1434. if (getMaskSet().excludes[decisionPos]) {
  1435. var decisionTaker = getDecisionTaker(prevAltPos);
  1436. if (getMaskSet().excludes[decisionPos].indexOf(decisionTaker) !== -1) {
  1437. isValidRslt = alternate(pos, c, strict, fromSetValid, decisionPos - 1);
  1438. break;
  1439. }
  1440. getMaskSet().excludes[decisionPos].push(decisionTaker);
  1441. for (i = decisionPos; i < getLastValidPosition(undefined, true) + 1; i++) {
  1442. delete getMaskSet().validPositions[i];
  1443. }
  1444. } else {
  1445. isValidRslt = alternate(pos, c, strict, fromSetValid, decisionPos - 1);
  1446. break;
  1447. }
  1448. } else break;
  1449. }
  1450. }
  1451. getMaskSet().excludes[decisionPos] = undefined;
  1452. return isValidRslt;
  1453. }
  1454. function isValid(pos, c, strict, fromSetValid, fromAlternate, validateOnly) {
  1455. function isSelection(posObj) {
  1456. return isRTL ? posObj.begin - posObj.end > 1 || posObj.begin - posObj.end === 1 : posObj.end - posObj.begin > 1 || posObj.end - posObj.begin === 1;
  1457. }
  1458. strict = strict === true;
  1459. var maskPos = pos;
  1460. if (pos.begin !== undefined) {
  1461. maskPos = isRTL ? pos.end : pos.begin;
  1462. }
  1463. function _isValid(position, c, strict) {
  1464. var rslt = false;
  1465. $.each(getTests(position), function(ndx, tst) {
  1466. var test = tst.match;
  1467. getBuffer(true);
  1468. rslt = test.fn != null ? test.fn.test(c, getMaskSet(), position, strict, opts, isSelection(pos)) : (c === test.def || c === opts.skipOptionalPartCharacter) && test.def !== "" ? {
  1469. c: getPlaceholder(position, test, true) || test.def,
  1470. pos: position
  1471. } : false;
  1472. if (rslt !== false) {
  1473. var elem = rslt.c !== undefined ? rslt.c : c, validatedPos = position;
  1474. elem = elem === opts.skipOptionalPartCharacter && test.fn === null ? getPlaceholder(position, test, true) || test.def : elem;
  1475. if (rslt.remove !== undefined) {
  1476. if (!$.isArray(rslt.remove)) rslt.remove = [ rslt.remove ];
  1477. $.each(rslt.remove.sort(function(a, b) {
  1478. return b - a;
  1479. }), function(ndx, lmnt) {
  1480. revalidateMask({
  1481. begin: lmnt,
  1482. end: lmnt + 1
  1483. });
  1484. });
  1485. }
  1486. if (rslt.insert !== undefined) {
  1487. if (!$.isArray(rslt.insert)) rslt.insert = [ rslt.insert ];
  1488. $.each(rslt.insert.sort(function(a, b) {
  1489. return a - b;
  1490. }), function(ndx, lmnt) {
  1491. isValid(lmnt.pos, lmnt.c, true, fromSetValid);
  1492. });
  1493. }
  1494. if (rslt !== true && rslt.pos !== undefined && rslt.pos !== position) {
  1495. validatedPos = rslt.pos;
  1496. }
  1497. if (rslt !== true && rslt.pos === undefined && rslt.c === undefined) {
  1498. return false;
  1499. }
  1500. if (!revalidateMask(pos, $.extend({}, tst, {
  1501. input: casing(elem, test, validatedPos)
  1502. }), fromSetValid, validatedPos)) {
  1503. rslt = false;
  1504. }
  1505. return false;
  1506. }
  1507. });
  1508. return rslt;
  1509. }
  1510. var result = true, positionsClone = $.extend(true, {}, getMaskSet().validPositions);
  1511. if ($.isFunction(opts.preValidation) && !strict && fromSetValid !== true && validateOnly !== true) {
  1512. result = opts.preValidation(getBuffer(), maskPos, c, isSelection(pos), opts, getMaskSet());
  1513. }
  1514. if (result === true) {
  1515. trackbackPositions(undefined, maskPos, true);
  1516. if (maxLength === undefined || maskPos < maxLength) {
  1517. result = _isValid(maskPos, c, strict);
  1518. if ((!strict || fromSetValid === true) && result === false && validateOnly !== true) {
  1519. var currentPosValid = getMaskSet().validPositions[maskPos];
  1520. if (currentPosValid && currentPosValid.match.fn === null && (currentPosValid.match.def === c || c === opts.skipOptionalPartCharacter)) {
  1521. result = {
  1522. caret: seekNext(maskPos)
  1523. };
  1524. } else {
  1525. if ((opts.insertMode || getMaskSet().validPositions[seekNext(maskPos)] === undefined) && (!isMask(maskPos, true) || getMaskSet().jitOffset[maskPos])) {
  1526. if (getMaskSet().jitOffset[maskPos] && getMaskSet().validPositions[seekNext(maskPos)] === undefined) {
  1527. result = isValid(maskPos + getMaskSet().jitOffset[maskPos], c, strict);
  1528. if (result !== false) result.caret = maskPos;
  1529. } else for (var nPos = maskPos + 1, snPos = seekNext(maskPos); nPos <= snPos; nPos++) {
  1530. result = _isValid(nPos, c, strict);
  1531. if (result !== false) {
  1532. result = trackbackPositions(maskPos, result.pos !== undefined ? result.pos : nPos) || result;
  1533. maskPos = nPos;
  1534. break;
  1535. }
  1536. }
  1537. }
  1538. }
  1539. }
  1540. }
  1541. if (result === false && opts.keepStatic !== false && (opts.regex == null || isComplete(getBuffer())) && !strict && fromAlternate !== true) {
  1542. result = alternate(maskPos, c, strict, fromSetValid);
  1543. }
  1544. if (result === true) {
  1545. result = {
  1546. pos: maskPos
  1547. };
  1548. }
  1549. }
  1550. if ($.isFunction(opts.postValidation) && result !== false && !strict && fromSetValid !== true && validateOnly !== true) {
  1551. var postResult = opts.postValidation(getBuffer(true), pos.begin !== undefined ? isRTL ? pos.end : pos.begin : pos, result, opts);
  1552. if (postResult !== undefined) {
  1553. if (postResult.refreshFromBuffer && postResult.buffer) {
  1554. var refresh = postResult.refreshFromBuffer;
  1555. refreshFromBuffer(refresh === true ? refresh : refresh.start, refresh.end, postResult.buffer);
  1556. }
  1557. result = postResult === true ? result : postResult;
  1558. }
  1559. }
  1560. if (result && result.pos === undefined) {
  1561. result.pos = maskPos;
  1562. }
  1563. if (result === false || validateOnly === true) {
  1564. resetMaskSet(true);
  1565. getMaskSet().validPositions = $.extend(true, {}, positionsClone);
  1566. }
  1567. return result;
  1568. }
  1569. function trackbackPositions(originalPos, newPos, fillOnly) {
  1570. var result;
  1571. if (originalPos === undefined) {
  1572. for (originalPos = newPos - 1; originalPos > 0; originalPos--) {
  1573. if (getMaskSet().validPositions[originalPos]) break;
  1574. }
  1575. }
  1576. for (var ps = originalPos; ps < newPos; ps++) {
  1577. if (getMaskSet().validPositions[ps] === undefined && !isMask(ps, true)) {
  1578. var vp = ps == 0 ? getTest(ps) : getMaskSet().validPositions[ps - 1];
  1579. if (vp) {
  1580. var tests = getTests(ps).slice();
  1581. if (tests[tests.length - 1].match.def === "") tests.pop();
  1582. var bestMatch = determineTestTemplate(ps, tests);
  1583. bestMatch = $.extend({}, bestMatch, {
  1584. input: getPlaceholder(ps, bestMatch.match, true) || bestMatch.match.def
  1585. });
  1586. bestMatch.generatedInput = true;
  1587. revalidateMask(ps, bestMatch, true);
  1588. if (fillOnly !== true) {
  1589. var cvpInput = getMaskSet().validPositions[newPos].input;
  1590. getMaskSet().validPositions[newPos] = undefined;
  1591. result = isValid(newPos, cvpInput, true, true);
  1592. }
  1593. }
  1594. }
  1595. }
  1596. return result;
  1597. }
  1598. function revalidateMask(pos, validTest, fromSetValid, validatedPos) {
  1599. function IsEnclosedStatic(pos, valids, selection) {
  1600. var posMatch = valids[pos];
  1601. if (posMatch !== undefined && (posMatch.match.fn === null && posMatch.match.optionality !== true || posMatch.input === opts.radixPoint)) {
  1602. var prevMatch = selection.begin <= pos - 1 ? valids[pos - 1] && valids[pos - 1].match.fn === null && valids[pos - 1] : valids[pos - 1], nextMatch = selection.end > pos + 1 ? valids[pos + 1] && valids[pos + 1].match.fn === null && valids[pos + 1] : valids[pos + 1];
  1603. return prevMatch && nextMatch;
  1604. }
  1605. return false;
  1606. }
  1607. var begin = pos.begin !== undefined ? pos.begin : pos, end = pos.end !== undefined ? pos.end : pos;
  1608. if (pos.begin > pos.end) {
  1609. begin = pos.end;
  1610. end = pos.begin;
  1611. }
  1612. validatedPos = validatedPos !== undefined ? validatedPos : begin;
  1613. if (begin !== end || opts.insertMode && getMaskSet().validPositions[validatedPos] !== undefined && fromSetValid === undefined) {
  1614. var positionsClone = $.extend(true, {}, getMaskSet().validPositions), lvp = getLastValidPosition(undefined, true), i;
  1615. getMaskSet().p = begin;
  1616. for (i = lvp; i >= begin; i--) {
  1617. if (getMaskSet().validPositions[i] && getMaskSet().validPositions[i].match.nativeDef === "+") {
  1618. opts.isNegative = false;
  1619. }
  1620. delete getMaskSet().validPositions[i];
  1621. }
  1622. var valid = true, j = validatedPos, vps = getMaskSet().validPositions, needsValidation = false, posMatch = j, i = j;
  1623. if (validTest) {
  1624. getMaskSet().validPositions[validatedPos] = $.extend(true, {}, validTest);
  1625. posMatch++;
  1626. j++;
  1627. if (begin < end) i++;
  1628. }
  1629. for (;i <= lvp; i++) {
  1630. var t = positionsClone[i];
  1631. if (t !== undefined && (i >= end || i >= begin && t.generatedInput !== true && IsEnclosedStatic(i, positionsClone, {
  1632. begin: begin,
  1633. end: end
  1634. }))) {
  1635. while (getTest(posMatch).match.def !== "") {
  1636. if (needsValidation === false && positionsClone[posMatch] && positionsClone[posMatch].match.nativeDef === t.match.nativeDef) {
  1637. getMaskSet().validPositions[posMatch] = $.extend(true, {}, positionsClone[posMatch]);
  1638. getMaskSet().validPositions[posMatch].input = t.input;
  1639. trackbackPositions(undefined, posMatch, true);
  1640. j = posMatch + 1;
  1641. valid = true;
  1642. } else if (opts.shiftPositions && positionCanMatchDefinition(posMatch, t.match.def)) {
  1643. var result = isValid(posMatch, t.input, true, true);
  1644. valid = result !== false;
  1645. j = result.caret || result.insert ? getLastValidPosition() : posMatch + 1;
  1646. needsValidation = true;
  1647. } else {
  1648. valid = t.generatedInput === true || t.input === opts.radixPoint && opts.numericInput === true;
  1649. }
  1650. if (valid) break;
  1651. if (!valid && posMatch > end && isMask(posMatch, true) && (t.match.fn !== null || posMatch > getMaskSet().maskLength)) {
  1652. break;
  1653. }
  1654. posMatch++;
  1655. }
  1656. if (getTest(posMatch).match.def == "") valid = false;
  1657. posMatch = j;
  1658. }
  1659. if (!valid) break;
  1660. }
  1661. if (!valid) {
  1662. getMaskSet().validPositions = $.extend(true, {}, positionsClone);
  1663. resetMaskSet(true);
  1664. return false;
  1665. }
  1666. } else if (validTest) {
  1667. getMaskSet().validPositions[validatedPos] = $.extend(true, {}, validTest);
  1668. }
  1669. resetMaskSet(true);
  1670. return true;
  1671. }
  1672. function isMask(pos, strict) {
  1673. var test = getTestTemplate(pos).match;
  1674. if (test.def === "") test = getTest(pos).match;
  1675. if (test.fn != null) {
  1676. return test.fn;
  1677. }
  1678. if (strict !== true && pos > -1) {
  1679. var tests = getTests(pos);
  1680. return tests.length > 1 + (tests[tests.length - 1].match.def === "" ? 1 : 0);
  1681. }
  1682. return false;
  1683. }
  1684. function seekNext(pos, newBlock) {
  1685. var position = pos + 1;
  1686. while (getTest(position).match.def !== "" && (newBlock === true && (getTest(position).match.newBlockMarker !== true || !isMask(position)) || newBlock !== true && !isMask(position))) {
  1687. position++;
  1688. }
  1689. return position;
  1690. }
  1691. function seekPrevious(pos, newBlock) {
  1692. var position = pos, tests;
  1693. if (position <= 0) return 0;
  1694. while (--position > 0 && (newBlock === true && getTest(position).match.newBlockMarker !== true || newBlock !== true && !isMask(position) && (tests = getTests(position),
  1695. tests.length < 2 || tests.length === 2 && tests[1].match.def === ""))) {}
  1696. return position;
  1697. }
  1698. function writeBuffer(input, buffer, caretPos, event, triggerEvents) {
  1699. if (event && $.isFunction(opts.onBeforeWrite)) {
  1700. var result = opts.onBeforeWrite.call(inputmask, event, buffer, caretPos, opts);
  1701. if (result) {
  1702. if (result.refreshFromBuffer) {
  1703. var refresh = result.refreshFromBuffer;
  1704. refreshFromBuffer(refresh === true ? refresh : refresh.start, refresh.end, result.buffer || buffer);
  1705. buffer = getBuffer(true);
  1706. }
  1707. if (caretPos !== undefined) caretPos = result.caret !== undefined ? result.caret : caretPos;
  1708. }
  1709. }
  1710. if (input !== undefined) {
  1711. input.inputmask._valueSet(buffer.join(""));
  1712. if (caretPos !== undefined && (event === undefined || event.type !== "blur")) {
  1713. caret(input, caretPos);
  1714. } else renderColorMask(input, caretPos, buffer.length === 0);
  1715. if (triggerEvents === true) {
  1716. var $input = $(input), nptVal = input.inputmask._valueGet();
  1717. skipInputEvent = true;
  1718. $input.trigger("input");
  1719. setTimeout(function() {
  1720. if (nptVal === getBufferTemplate().join("")) {
  1721. $input.trigger("cleared");
  1722. } else if (isComplete(buffer) === true) {
  1723. $input.trigger("complete");
  1724. }
  1725. }, 0);
  1726. }
  1727. }
  1728. }
  1729. function getPlaceholder(pos, test, returnPL) {
  1730. test = test || getTest(pos).match;
  1731. if (test.placeholder !== undefined || returnPL === true) {
  1732. return $.isFunction(test.placeholder) ? test.placeholder(opts) : test.placeholder;
  1733. } else if (test.fn === null) {
  1734. if (pos > -1 && getMaskSet().validPositions[pos] === undefined) {
  1735. var tests = getTests(pos), staticAlternations = [], prevTest;
  1736. if (tests.length > 1 + (tests[tests.length - 1].match.def === "" ? 1 : 0)) {
  1737. for (var i = 0; i < tests.length; i++) {
  1738. if (tests[i].match.optionality !== true && tests[i].match.optionalQuantifier !== true && (tests[i].match.fn === null || prevTest === undefined || tests[i].match.fn.test(prevTest.match.def, getMaskSet(), pos, true, opts) !== false)) {
  1739. staticAlternations.push(tests[i]);
  1740. if (tests[i].match.fn === null) prevTest = tests[i];
  1741. if (staticAlternations.length > 1) {
  1742. if (/[0-9a-bA-Z]/.test(staticAlternations[0].match.def)) {
  1743. return opts.placeholder.charAt(pos % opts.placeholder.length);
  1744. }
  1745. }
  1746. }
  1747. }
  1748. }
  1749. }
  1750. return test.def;
  1751. }
  1752. return opts.placeholder.charAt(pos % opts.placeholder.length);
  1753. }
  1754. function HandleNativePlaceholder(npt, value) {
  1755. if (ie) {
  1756. if (npt.inputmask._valueGet() !== value) {
  1757. var buffer = getBuffer().slice(), nptValue = npt.inputmask._valueGet();
  1758. if (nptValue !== value) {
  1759. var lvp = getLastValidPosition();
  1760. if (lvp === -1 && nptValue === getBufferTemplate().join("")) {
  1761. buffer = [];
  1762. } else if (lvp !== -1) {
  1763. clearOptionalTail(buffer);
  1764. }
  1765. writeBuffer(npt, buffer);
  1766. }
  1767. }
  1768. } else if (npt.placeholder !== value) {
  1769. npt.placeholder = value;
  1770. if (npt.placeholder === "") npt.removeAttribute("placeholder");
  1771. }
  1772. }
  1773. var EventRuler = {
  1774. on: function on(input, eventName, eventHandler) {
  1775. var ev = function ev(e) {
  1776. var that = this;
  1777. if (that.inputmask === undefined && this.nodeName !== "FORM") {
  1778. var imOpts = $.data(that, "_inputmask_opts");
  1779. if (imOpts) new Inputmask(imOpts).mask(that); else EventRuler.off(that);
  1780. } else if (e.type !== "setvalue" && this.nodeName !== "FORM" && (that.disabled || that.readOnly && !(e.type === "keydown" && e.ctrlKey && e.keyCode === 67 || opts.tabThrough === false && e.keyCode === Inputmask.keyCode.TAB))) {
  1781. e.preventDefault();
  1782. } else {
  1783. switch (e.type) {
  1784. case "input":
  1785. if (skipInputEvent === true) {
  1786. skipInputEvent = false;
  1787. return e.preventDefault();
  1788. }
  1789. if (mobile) {
  1790. var args = arguments;
  1791. setTimeout(function() {
  1792. eventHandler.apply(that, args);
  1793. caret(that, that.inputmask.caretPos, undefined, true);
  1794. }, 0);
  1795. return false;
  1796. }
  1797. break;
  1798. case "keydown":
  1799. skipKeyPressEvent = false;
  1800. skipInputEvent = false;
  1801. break;
  1802. case "keypress":
  1803. if (skipKeyPressEvent === true) {
  1804. return e.preventDefault();
  1805. }
  1806. skipKeyPressEvent = true;
  1807. break;
  1808. case "click":
  1809. if (iemobile || iphone) {
  1810. var args = arguments;
  1811. setTimeout(function() {
  1812. eventHandler.apply(that, args);
  1813. }, 0);
  1814. return false;
  1815. }
  1816. break;
  1817. }
  1818. var returnVal = eventHandler.apply(that, arguments);
  1819. if (returnVal === false) {
  1820. e.preventDefault();
  1821. e.stopPropagation();
  1822. }
  1823. return returnVal;
  1824. }
  1825. };
  1826. input.inputmask.events[eventName] = input.inputmask.events[eventName] || [];
  1827. input.inputmask.events[eventName].push(ev);
  1828. if ($.inArray(eventName, [ "submit", "reset" ]) !== -1) {
  1829. if (input.form !== null) $(input.form).on(eventName, ev);
  1830. } else {
  1831. $(input).on(eventName, ev);
  1832. }
  1833. },
  1834. off: function off(input, event) {
  1835. if (input.inputmask && input.inputmask.events) {
  1836. var events;
  1837. if (event) {
  1838. events = [];
  1839. events[event] = input.inputmask.events[event];
  1840. } else {
  1841. events = input.inputmask.events;
  1842. }
  1843. $.each(events, function(eventName, evArr) {
  1844. while (evArr.length > 0) {
  1845. var ev = evArr.pop();
  1846. if ($.inArray(eventName, [ "submit", "reset" ]) !== -1) {
  1847. if (input.form !== null) $(input.form).off(eventName, ev);
  1848. } else {
  1849. $(input).off(eventName, ev);
  1850. }
  1851. }
  1852. delete input.inputmask.events[eventName];
  1853. });
  1854. }
  1855. }
  1856. };
  1857. var EventHandlers = {
  1858. keydownEvent: function keydownEvent(e) {
  1859. var input = this, $input = $(input), k = e.keyCode, pos = caret(input);
  1860. if (k === Inputmask.keyCode.BACKSPACE || k === Inputmask.keyCode.DELETE || iphone && k === Inputmask.keyCode.BACKSPACE_SAFARI || e.ctrlKey && k === Inputmask.keyCode.X && !isInputEventSupported("cut")) {
  1861. e.preventDefault();
  1862. handleRemove(input, k, pos);
  1863. writeBuffer(input, getBuffer(true), getMaskSet().p, e, input.inputmask._valueGet() !== getBuffer().join(""));
  1864. } else if (k === Inputmask.keyCode.END || k === Inputmask.keyCode.PAGE_DOWN) {
  1865. e.preventDefault();
  1866. var caretPos = seekNext(getLastValidPosition());
  1867. caret(input, e.shiftKey ? pos.begin : caretPos, caretPos, true);
  1868. } else if (k === Inputmask.keyCode.HOME && !e.shiftKey || k === Inputmask.keyCode.PAGE_UP) {
  1869. e.preventDefault();
  1870. caret(input, 0, e.shiftKey ? pos.begin : 0, true);
  1871. } else if ((opts.undoOnEscape && k === Inputmask.keyCode.ESCAPE || k === 90 && e.ctrlKey) && e.altKey !== true) {
  1872. checkVal(input, true, false, undoValue.split(""));
  1873. $input.trigger("click");
  1874. } else if (k === Inputmask.keyCode.INSERT && !(e.shiftKey || e.ctrlKey)) {
  1875. opts.insertMode = !opts.insertMode;
  1876. input.setAttribute("im-insert", opts.insertMode);
  1877. } else if (opts.tabThrough === true && k === Inputmask.keyCode.TAB) {
  1878. if (e.shiftKey === true) {
  1879. if (getTest(pos.begin).match.fn === null) {
  1880. pos.begin = seekNext(pos.begin);
  1881. }
  1882. pos.end = seekPrevious(pos.begin, true);
  1883. pos.begin = seekPrevious(pos.end, true);
  1884. } else {
  1885. pos.begin = seekNext(pos.begin, true);
  1886. pos.end = seekNext(pos.begin, true);
  1887. if (pos.end < getMaskSet().maskLength) pos.end--;
  1888. }
  1889. if (pos.begin < getMaskSet().maskLength) {
  1890. e.preventDefault();
  1891. caret(input, pos.begin, pos.end);
  1892. }
  1893. }
  1894. opts.onKeyDown.call(this, e, getBuffer(), caret(input).begin, opts);
  1895. ignorable = $.inArray(k, opts.ignorables) !== -1;
  1896. },
  1897. keypressEvent: function keypressEvent(e, checkval, writeOut, strict, ndx) {
  1898. var input = this, $input = $(input), k = e.which || e.charCode || e.keyCode;
  1899. if (checkval !== true && !(e.ctrlKey && e.altKey) && (e.ctrlKey || e.metaKey || ignorable)) {
  1900. if (k === Inputmask.keyCode.ENTER && undoValue !== getBuffer().join("")) {
  1901. undoValue = getBuffer().join("");
  1902. setTimeout(function() {
  1903. $input.trigger("change");
  1904. }, 0);
  1905. }
  1906. return true;
  1907. } else {
  1908. if (k) {
  1909. if (k === 46 && e.shiftKey === false && opts.radixPoint !== "") k = opts.radixPoint.charCodeAt(0);
  1910. var pos = checkval ? {
  1911. begin: ndx,
  1912. end: ndx
  1913. } : caret(input), forwardPosition, c = String.fromCharCode(k), offset = 0;
  1914. if (opts._radixDance && opts.numericInput) {
  1915. var caretPos = getBuffer().indexOf(opts.radixPoint.charAt(0)) + 1;
  1916. if (pos.begin <= caretPos) {
  1917. if (k === opts.radixPoint.charCodeAt(0)) offset = 1;
  1918. pos.begin -= 1;
  1919. pos.end -= 1;
  1920. }
  1921. }
  1922. getMaskSet().writeOutBuffer = true;
  1923. var valResult = isValid(pos, c, strict);
  1924. if (valResult !== false) {
  1925. resetMaskSet(true);
  1926. forwardPosition = valResult.caret !== undefined ? valResult.caret : seekNext(valResult.pos.begin ? valResult.pos.begin : valResult.pos);
  1927. getMaskSet().p = forwardPosition;
  1928. }
  1929. forwardPosition = (opts.numericInput && valResult.caret === undefined ? seekPrevious(forwardPosition) : forwardPosition) + offset;
  1930. if (writeOut !== false) {
  1931. setTimeout(function() {
  1932. opts.onKeyValidation.call(input, k, valResult, opts);
  1933. }, 0);
  1934. if (getMaskSet().writeOutBuffer && valResult !== false) {
  1935. var buffer = getBuffer();
  1936. writeBuffer(input, buffer, forwardPosition, e, checkval !== true);
  1937. }
  1938. }
  1939. e.preventDefault();
  1940. if (checkval) {
  1941. if (valResult !== false) valResult.forwardPosition = forwardPosition;
  1942. return valResult;
  1943. }
  1944. }
  1945. }
  1946. },
  1947. pasteEvent: function pasteEvent(e) {
  1948. var input = this, ev = e.originalEvent || e, $input = $(input), inputValue = input.inputmask._valueGet(true), caretPos = caret(input), tempValue;
  1949. if (isRTL) {
  1950. tempValue = caretPos.end;
  1951. caretPos.end = caretPos.begin;
  1952. caretPos.begin = tempValue;
  1953. }
  1954. var valueBeforeCaret = inputValue.substr(0, caretPos.begin), valueAfterCaret = inputValue.substr(caretPos.end, inputValue.length);
  1955. if (valueBeforeCaret === (isRTL ? getBufferTemplate().reverse() : getBufferTemplate()).slice(0, caretPos.begin).join("")) valueBeforeCaret = "";
  1956. if (valueAfterCaret === (isRTL ? getBufferTemplate().reverse() : getBufferTemplate()).slice(caretPos.end).join("")) valueAfterCaret = "";
  1957. if (window.clipboardData && window.clipboardData.getData) {
  1958. inputValue = valueBeforeCaret + window.clipboardData.getData("Text") + valueAfterCaret;
  1959. } else if (ev.clipboardData && ev.clipboardData.getData) {
  1960. inputValue = valueBeforeCaret + ev.clipboardData.getData("text/plain") + valueAfterCaret;
  1961. } else return true;
  1962. var pasteValue = inputValue;
  1963. if ($.isFunction(opts.onBeforePaste)) {
  1964. pasteValue = opts.onBeforePaste.call(inputmask, inputValue, opts);
  1965. if (pasteValue === false) {
  1966. return e.preventDefault();
  1967. }
  1968. if (!pasteValue) {
  1969. pasteValue = inputValue;
  1970. }
  1971. }
  1972. checkVal(input, false, false, pasteValue.toString().split(""));
  1973. writeBuffer(input, getBuffer(), seekNext(getLastValidPosition()), e, undoValue !== getBuffer().join(""));
  1974. return e.preventDefault();
  1975. },
  1976. inputFallBackEvent: function inputFallBackEvent(e) {
  1977. function radixPointHandler(input, inputValue, caretPos) {
  1978. if (inputValue.charAt(caretPos.begin - 1) === "." && opts.radixPoint !== "") {
  1979. inputValue = inputValue.split("");
  1980. inputValue[caretPos.begin - 1] = opts.radixPoint.charAt(0);
  1981. inputValue = inputValue.join("");
  1982. }
  1983. return inputValue;
  1984. }
  1985. function ieMobileHandler(input, inputValue, caretPos) {
  1986. if (iemobile) {
  1987. var inputChar = inputValue.replace(getBuffer().join(""), "");
  1988. if (inputChar.length === 1) {
  1989. var iv = inputValue.split("");
  1990. iv.splice(caretPos.begin, 0, inputChar);
  1991. inputValue = iv.join("");
  1992. }
  1993. }
  1994. return inputValue;
  1995. }
  1996. var input = this, inputValue = input.inputmask._valueGet();
  1997. if (getBuffer().join("") !== inputValue) {
  1998. var caretPos = caret(input);
  1999. inputValue = radixPointHandler(input, inputValue, caretPos);
  2000. inputValue = ieMobileHandler(input, inputValue, caretPos);
  2001. if (getBuffer().join("") !== inputValue) {
  2002. var buffer = getBuffer().join(""), offset = !opts.numericInput && inputValue.length > buffer.length ? -1 : 0, frontPart = inputValue.substr(0, caretPos.begin), backPart = inputValue.substr(caretPos.begin), frontBufferPart = buffer.substr(0, caretPos.begin + offset), backBufferPart = buffer.substr(caretPos.begin + offset);
  2003. var selection = caretPos, entries = "", isEntry = false;
  2004. if (frontPart !== frontBufferPart) {
  2005. var fpl = (isEntry = frontPart.length >= frontBufferPart.length) ? frontPart.length : frontBufferPart.length, i;
  2006. for (i = 0; frontPart.charAt(i) === frontBufferPart.charAt(i) && i < fpl; i++) {}
  2007. if (isEntry) {
  2008. selection.begin = i - offset;
  2009. entries += frontPart.slice(i, selection.end);
  2010. }
  2011. }
  2012. if (backPart !== backBufferPart) {
  2013. if (backPart.length > backBufferPart.length) {
  2014. entries += backPart.slice(0, 1);
  2015. } else {
  2016. if (backPart.length < backBufferPart.length) {
  2017. selection.end += backBufferPart.length - backPart.length;
  2018. if (!isEntry && opts.radixPoint !== "" && backPart === "" && frontPart.charAt(selection.begin + offset - 1) === opts.radixPoint) {
  2019. selection.begin--;
  2020. entries = opts.radixPoint;
  2021. }
  2022. }
  2023. }
  2024. }
  2025. writeBuffer(input, getBuffer(), {
  2026. begin: selection.begin + offset,
  2027. end: selection.end + offset
  2028. });
  2029. if (entries.length > 0) {
  2030. $.each(entries.split(""), function(ndx, entry) {
  2031. var keypress = new $.Event("keypress");
  2032. keypress.which = entry.charCodeAt(0);
  2033. ignorable = false;
  2034. EventHandlers.keypressEvent.call(input, keypress);
  2035. });
  2036. } else {
  2037. if (selection.begin === selection.end - 1) {
  2038. selection.begin = seekPrevious(selection.begin + 1);
  2039. if (selection.begin === selection.end - 1) {
  2040. caret(input, selection.begin);
  2041. } else {
  2042. caret(input, selection.begin, selection.end);
  2043. }
  2044. }
  2045. var keydown = new $.Event("keydown");
  2046. keydown.keyCode = opts.numericInput ? Inputmask.keyCode.BACKSPACE : Inputmask.keyCode.DELETE;
  2047. EventHandlers.keydownEvent.call(input, keydown);
  2048. }
  2049. e.preventDefault();
  2050. }
  2051. }
  2052. },
  2053. beforeInputEvent: function beforeInputEvent(e) {
  2054. if (e.cancelable) {
  2055. var input = this;
  2056. switch (e.inputType) {
  2057. case "insertText":
  2058. $.each(e.data.split(""), function(ndx, entry) {
  2059. var keypress = new $.Event("keypress");
  2060. keypress.which = entry.charCodeAt(0);
  2061. ignorable = false;
  2062. EventHandlers.keypressEvent.call(input, keypress);
  2063. });
  2064. return e.preventDefault();
  2065. case "deleteContentBackward":
  2066. var keydown = new $.Event("keydown");
  2067. keydown.keyCode = Inputmask.keyCode.BACKSPACE;
  2068. EventHandlers.keydownEvent.call(input, keydown);
  2069. return e.preventDefault();
  2070. case "deleteContentForward":
  2071. var keydown = new $.Event("keydown");
  2072. keydown.keyCode = Inputmask.keyCode.DELETE;
  2073. EventHandlers.keydownEvent.call(input, keydown);
  2074. return e.preventDefault();
  2075. }
  2076. }
  2077. },
  2078. setValueEvent: function setValueEvent(e) {
  2079. this.inputmask.refreshValue = false;
  2080. var input = this, value = e && e.detail ? e.detail[0] : arguments[1], value = value || input.inputmask._valueGet(true);
  2081. if ($.isFunction(opts.onBeforeMask)) value = opts.onBeforeMask.call(inputmask, value, opts) || value;
  2082. value = value.split("");
  2083. checkVal(input, true, false, value);
  2084. undoValue = getBuffer().join("");
  2085. if ((opts.clearMaskOnLostFocus || opts.clearIncomplete) && input.inputmask._valueGet() === getBufferTemplate().join("")) {
  2086. input.inputmask._valueSet("");
  2087. }
  2088. },
  2089. focusEvent: function focusEvent(e) {
  2090. var input = this, nptValue = input.inputmask._valueGet();
  2091. if (opts.showMaskOnFocus) {
  2092. if (nptValue !== getBuffer().join("")) {
  2093. writeBuffer(input, getBuffer(), seekNext(getLastValidPosition()));
  2094. } else if (mouseEnter === false) {
  2095. caret(input, seekNext(getLastValidPosition()));
  2096. }
  2097. }
  2098. if (opts.positionCaretOnTab === true && mouseEnter === false) {
  2099. EventHandlers.clickEvent.apply(input, [ e, true ]);
  2100. }
  2101. undoValue = getBuffer().join("");
  2102. },
  2103. mouseleaveEvent: function mouseleaveEvent(e) {
  2104. var input = this;
  2105. mouseEnter = false;
  2106. if (opts.clearMaskOnLostFocus && document.activeElement !== input) {
  2107. HandleNativePlaceholder(input, originalPlaceholder);
  2108. }
  2109. },
  2110. clickEvent: function clickEvent(e, tabbed) {
  2111. function doRadixFocus(clickPos) {
  2112. if (opts.radixPoint !== "") {
  2113. var vps = getMaskSet().validPositions;
  2114. if (vps[clickPos] === undefined || vps[clickPos].input === getPlaceholder(clickPos)) {
  2115. if (clickPos < seekNext(-1)) return true;
  2116. var radixPos = $.inArray(opts.radixPoint, getBuffer());
  2117. if (radixPos !== -1) {
  2118. for (var vp in vps) {
  2119. if (radixPos < vp && vps[vp].input !== getPlaceholder(vp)) {
  2120. return false;
  2121. }
  2122. }
  2123. return true;
  2124. }
  2125. }
  2126. }
  2127. return false;
  2128. }
  2129. var input = this;
  2130. setTimeout(function() {
  2131. if (document.activeElement === input) {
  2132. var selectedCaret = caret(input);
  2133. if (tabbed) {
  2134. if (isRTL) {
  2135. selectedCaret.end = selectedCaret.begin;
  2136. } else {
  2137. selectedCaret.begin = selectedCaret.end;
  2138. }
  2139. }
  2140. if (selectedCaret.begin === selectedCaret.end) {
  2141. switch (opts.positionCaretOnClick) {
  2142. case "none":
  2143. break;
  2144. case "select":
  2145. caret(input, 0, getBuffer().length);
  2146. break;
  2147. case "ignore":
  2148. caret(input, seekNext(getLastValidPosition()));
  2149. break;
  2150. case "radixFocus":
  2151. if (doRadixFocus(selectedCaret.begin)) {
  2152. var radixPos = getBuffer().join("").indexOf(opts.radixPoint);
  2153. caret(input, opts.numericInput ? seekNext(radixPos) : radixPos);
  2154. break;
  2155. }
  2156. default:
  2157. var clickPosition = selectedCaret.begin, lvclickPosition = getLastValidPosition(clickPosition, true), lastPosition = seekNext(lvclickPosition);
  2158. if (clickPosition < lastPosition) {
  2159. caret(input, !isMask(clickPosition, true) && !isMask(clickPosition - 1, true) ? seekNext(clickPosition) : clickPosition);
  2160. } else {
  2161. var lvp = getMaskSet().validPositions[lvclickPosition], tt = getTestTemplate(lastPosition, lvp ? lvp.match.locator : undefined, lvp), placeholder = getPlaceholder(lastPosition, tt.match);
  2162. if (placeholder !== "" && getBuffer()[lastPosition] !== placeholder && tt.match.optionalQuantifier !== true && tt.match.newBlockMarker !== true || !isMask(lastPosition, opts.keepStatic) && tt.match.def === placeholder) {
  2163. var newPos = seekNext(lastPosition);
  2164. if (clickPosition >= newPos || clickPosition === lastPosition) {
  2165. lastPosition = newPos;
  2166. }
  2167. }
  2168. caret(input, lastPosition);
  2169. }
  2170. break;
  2171. }
  2172. }
  2173. }
  2174. }, 0);
  2175. },
  2176. cutEvent: function cutEvent(e) {
  2177. var input = this, $input = $(input), pos = caret(input), ev = e.originalEvent || e;
  2178. var clipboardData = window.clipboardData || ev.clipboardData, clipData = isRTL ? getBuffer().slice(pos.end, pos.begin) : getBuffer().slice(pos.begin, pos.end);
  2179. clipboardData.setData("text", isRTL ? clipData.reverse().join("") : clipData.join(""));
  2180. if (document.execCommand) document.execCommand("copy");
  2181. handleRemove(input, Inputmask.keyCode.DELETE, pos);
  2182. writeBuffer(input, getBuffer(), getMaskSet().p, e, undoValue !== getBuffer().join(""));
  2183. },
  2184. blurEvent: function blurEvent(e) {
  2185. var $input = $(this), input = this;
  2186. if (input.inputmask) {
  2187. HandleNativePlaceholder(input, originalPlaceholder);
  2188. var nptValue = input.inputmask._valueGet(), buffer = getBuffer().slice();
  2189. if (nptValue !== "" || colorMask !== undefined) {
  2190. if (opts.clearMaskOnLostFocus) {
  2191. if (getLastValidPosition() === -1 && nptValue === getBufferTemplate().join("")) {
  2192. buffer = [];
  2193. } else {
  2194. clearOptionalTail(buffer);
  2195. }
  2196. }
  2197. if (isComplete(buffer) === false) {
  2198. setTimeout(function() {
  2199. $input.trigger("incomplete");
  2200. }, 0);
  2201. if (opts.clearIncomplete) {
  2202. resetMaskSet();
  2203. if (opts.clearMaskOnLostFocus) {
  2204. buffer = [];
  2205. } else {
  2206. buffer = getBufferTemplate().slice();
  2207. }
  2208. }
  2209. }
  2210. writeBuffer(input, buffer, undefined, e);
  2211. }
  2212. if (undoValue !== getBuffer().join("")) {
  2213. undoValue = buffer.join("");
  2214. $input.trigger("change");
  2215. }
  2216. }
  2217. },
  2218. mouseenterEvent: function mouseenterEvent(e) {
  2219. var input = this;
  2220. mouseEnter = true;
  2221. if (document.activeElement !== input && opts.showMaskOnHover) {
  2222. HandleNativePlaceholder(input, (isRTL ? getBuffer().slice().reverse() : getBuffer()).join(""));
  2223. }
  2224. },
  2225. submitEvent: function submitEvent(e) {
  2226. if (undoValue !== getBuffer().join("")) {
  2227. $el.trigger("change");
  2228. }
  2229. if (opts.clearMaskOnLostFocus && getLastValidPosition() === -1 && el.inputmask._valueGet && el.inputmask._valueGet() === getBufferTemplate().join("")) {
  2230. el.inputmask._valueSet("");
  2231. }
  2232. if (opts.clearIncomplete && isComplete(getBuffer()) === false) {
  2233. el.inputmask._valueSet("");
  2234. }
  2235. if (opts.removeMaskOnSubmit) {
  2236. el.inputmask._valueSet(el.inputmask.unmaskedvalue(), true);
  2237. setTimeout(function() {
  2238. writeBuffer(el, getBuffer());
  2239. }, 0);
  2240. }
  2241. },
  2242. resetEvent: function resetEvent(e) {
  2243. el.inputmask.refreshValue = true;
  2244. setTimeout(function() {
  2245. $el.trigger("setvalue");
  2246. }, 0);
  2247. }
  2248. };
  2249. function checkVal(input, writeOut, strict, nptvl, initiatingEvent) {
  2250. var inputmask = this || input.inputmask, inputValue = nptvl.slice(), charCodes = "", initialNdx = -1, result = undefined;
  2251. function isTemplateMatch(ndx, charCodes) {
  2252. var charCodeNdx = getMaskTemplate(true, 0, false).slice(ndx, seekNext(ndx)).join("").replace(/'/g, "").indexOf(charCodes);
  2253. return charCodeNdx !== -1 && !isMask(ndx) && (getTest(ndx).match.nativeDef === charCodes.charAt(0) || getTest(ndx).match.fn === null && getTest(ndx).match.nativeDef === "'" + charCodes.charAt(0) || getTest(ndx).match.nativeDef === " " && (getTest(ndx + 1).match.nativeDef === charCodes.charAt(0) || getTest(ndx + 1).match.fn === null && getTest(ndx + 1).match.nativeDef === "'" + charCodes.charAt(0)));
  2254. }
  2255. resetMaskSet();
  2256. if (!strict && opts.autoUnmask !== true) {
  2257. var staticInput = getBufferTemplate().slice(0, seekNext(-1)).join(""), matches = inputValue.join("").match(new RegExp("^" + Inputmask.escapeRegex(staticInput), "g"));
  2258. if (matches && matches.length > 0) {
  2259. inputValue.splice(0, matches.length * staticInput.length);
  2260. initialNdx = seekNext(initialNdx);
  2261. }
  2262. } else {
  2263. initialNdx = seekNext(initialNdx);
  2264. }
  2265. if (initialNdx === -1) {
  2266. getMaskSet().p = seekNext(initialNdx);
  2267. initialNdx = 0;
  2268. } else getMaskSet().p = initialNdx;
  2269. inputmask.caretPos = {
  2270. begin: initialNdx
  2271. };
  2272. $.each(inputValue, function(ndx, charCode) {
  2273. if (charCode !== undefined) {
  2274. if (getMaskSet().validPositions[ndx] === undefined && inputValue[ndx] === getPlaceholder(ndx) && isMask(ndx, true) && isValid(ndx, inputValue[ndx], true, undefined, undefined, true) === false) {
  2275. getMaskSet().p++;
  2276. } else {
  2277. var keypress = new $.Event("_checkval");
  2278. keypress.which = charCode.charCodeAt(0);
  2279. charCodes += charCode;
  2280. var lvp = getLastValidPosition(undefined, true);
  2281. if (!isTemplateMatch(initialNdx, charCodes)) {
  2282. result = EventHandlers.keypressEvent.call(input, keypress, true, false, strict, inputmask.caretPos.begin);
  2283. if (result) {
  2284. initialNdx = inputmask.caretPos.begin + 1;
  2285. charCodes = "";
  2286. }
  2287. } else {
  2288. result = EventHandlers.keypressEvent.call(input, keypress, true, false, strict, lvp + 1);
  2289. }
  2290. if (result) {
  2291. writeBuffer(undefined, getBuffer(), result.forwardPosition, keypress, false);
  2292. inputmask.caretPos = {
  2293. begin: result.forwardPosition,
  2294. end: result.forwardPosition
  2295. };
  2296. }
  2297. }
  2298. }
  2299. });
  2300. if (writeOut) writeBuffer(input, getBuffer(), result ? result.forwardPosition : undefined, initiatingEvent || new $.Event("checkval"), initiatingEvent && initiatingEvent.type === "input");
  2301. }
  2302. function unmaskedvalue(input) {
  2303. if (input) {
  2304. if (input.inputmask === undefined) {
  2305. return input.value;
  2306. }
  2307. if (input.inputmask && input.inputmask.refreshValue) {
  2308. EventHandlers.setValueEvent.call(input);
  2309. }
  2310. }
  2311. var umValue = [], vps = getMaskSet().validPositions;
  2312. for (var pndx in vps) {
  2313. if (vps[pndx].match && vps[pndx].match.fn != null) {
  2314. umValue.push(vps[pndx].input);
  2315. }
  2316. }
  2317. var unmaskedValue = umValue.length === 0 ? "" : (isRTL ? umValue.reverse() : umValue).join("");
  2318. if ($.isFunction(opts.onUnMask)) {
  2319. var bufferValue = (isRTL ? getBuffer().slice().reverse() : getBuffer()).join("");
  2320. unmaskedValue = opts.onUnMask.call(inputmask, bufferValue, unmaskedValue, opts);
  2321. }
  2322. return unmaskedValue;
  2323. }
  2324. function caret(input, begin, end, notranslate) {
  2325. function translatePosition(pos) {
  2326. if (isRTL && typeof pos === "number" && (!opts.greedy || opts.placeholder !== "") && el) {
  2327. pos = el.inputmask._valueGet().length - pos;
  2328. }
  2329. return pos;
  2330. }
  2331. var range;
  2332. if (begin !== undefined) {
  2333. if ($.isArray(begin)) {
  2334. end = isRTL ? begin[0] : begin[1];
  2335. begin = isRTL ? begin[1] : begin[0];
  2336. }
  2337. if (begin.begin !== undefined) {
  2338. end = isRTL ? begin.begin : begin.end;
  2339. begin = isRTL ? begin.end : begin.begin;
  2340. }
  2341. if (typeof begin === "number") {
  2342. begin = notranslate ? begin : translatePosition(begin);
  2343. end = notranslate ? end : translatePosition(end);
  2344. end = typeof end == "number" ? end : begin;
  2345. var scrollCalc = parseInt(((input.ownerDocument.defaultView || window).getComputedStyle ? (input.ownerDocument.defaultView || window).getComputedStyle(input, null) : input.currentStyle).fontSize) * end;
  2346. input.scrollLeft = scrollCalc > input.scrollWidth ? scrollCalc : 0;
  2347. input.inputmask.caretPos = {
  2348. begin: begin,
  2349. end: end
  2350. };
  2351. if (input === document.activeElement) {
  2352. if ("selectionStart" in input) {
  2353. input.selectionStart = begin;
  2354. input.selectionEnd = end;
  2355. } else if (window.getSelection) {
  2356. range = document.createRange();
  2357. if (input.firstChild === undefined || input.firstChild === null) {
  2358. var textNode = document.createTextNode("");
  2359. input.appendChild(textNode);
  2360. }
  2361. range.setStart(input.firstChild, begin < input.inputmask._valueGet().length ? begin : input.inputmask._valueGet().length);
  2362. range.setEnd(input.firstChild, end < input.inputmask._valueGet().length ? end : input.inputmask._valueGet().length);
  2363. range.collapse(true);
  2364. var sel = window.getSelection();
  2365. sel.removeAllRanges();
  2366. sel.addRange(range);
  2367. } else if (input.createTextRange) {
  2368. range = input.createTextRange();
  2369. range.collapse(true);
  2370. range.moveEnd("character", end);
  2371. range.moveStart("character", begin);
  2372. range.select();
  2373. }
  2374. renderColorMask(input, {
  2375. begin: begin,
  2376. end: end
  2377. });
  2378. }
  2379. }
  2380. } else {
  2381. if ("selectionStart" in input) {
  2382. begin = input.selectionStart;
  2383. end = input.selectionEnd;
  2384. } else if (window.getSelection) {
  2385. range = window.getSelection().getRangeAt(0);
  2386. if (range.commonAncestorContainer.parentNode === input || range.commonAncestorContainer === input) {
  2387. begin = range.startOffset;
  2388. end = range.endOffset;
  2389. }
  2390. } else if (document.selection && document.selection.createRange) {
  2391. range = document.selection.createRange();
  2392. begin = 0 - range.duplicate().moveStart("character", -input.inputmask._valueGet().length);
  2393. end = begin + range.text.length;
  2394. }
  2395. return {
  2396. begin: notranslate ? begin : translatePosition(begin),
  2397. end: notranslate ? end : translatePosition(end)
  2398. };
  2399. }
  2400. }
  2401. function determineLastRequiredPosition(returnDefinition) {
  2402. var buffer = getMaskTemplate(true, getLastValidPosition(), true, true), bl = buffer.length, pos, lvp = getLastValidPosition(), positions = {}, lvTest = getMaskSet().validPositions[lvp], ndxIntlzr = lvTest !== undefined ? lvTest.locator.slice() : undefined, testPos;
  2403. for (pos = lvp + 1; pos < buffer.length; pos++) {
  2404. testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
  2405. ndxIntlzr = testPos.locator.slice();
  2406. positions[pos] = $.extend(true, {}, testPos);
  2407. }
  2408. var lvTestAlt = lvTest && lvTest.alternation !== undefined ? lvTest.locator[lvTest.alternation] : undefined;
  2409. for (pos = bl - 1; pos > lvp; pos--) {
  2410. testPos = positions[pos];
  2411. if ((testPos.match.optionality || testPos.match.optionalQuantifier && testPos.match.newBlockMarker || lvTestAlt && (lvTestAlt !== positions[pos].locator[lvTest.alternation] && testPos.match.fn != null || testPos.match.fn === null && testPos.locator[lvTest.alternation] && checkAlternationMatch(testPos.locator[lvTest.alternation].toString().split(","), lvTestAlt.toString().split(",")) && getTests(pos)[0].def !== "")) && buffer[pos] === getPlaceholder(pos, testPos.match)) {
  2412. bl--;
  2413. } else break;
  2414. }
  2415. return returnDefinition ? {
  2416. l: bl,
  2417. def: positions[bl] ? positions[bl].match : undefined
  2418. } : bl;
  2419. }
  2420. function clearOptionalTail(buffer) {
  2421. buffer.length = 0;
  2422. var template = getMaskTemplate(true, 0, true, undefined, true), lmnt, validPos;
  2423. while (lmnt = template.shift(), lmnt !== undefined) {
  2424. buffer.push(lmnt);
  2425. }
  2426. return buffer;
  2427. }
  2428. function isComplete(buffer) {
  2429. if ($.isFunction(opts.isComplete)) return opts.isComplete(buffer, opts);
  2430. if (opts.repeat === "*") return undefined;
  2431. var complete = false, lrp = determineLastRequiredPosition(true), aml = seekPrevious(lrp.l);
  2432. if (lrp.def === undefined || lrp.def.newBlockMarker || lrp.def.optionality || lrp.def.optionalQuantifier) {
  2433. complete = true;
  2434. for (var i = 0; i <= aml; i++) {
  2435. var test = getTestTemplate(i).match;
  2436. if (test.fn !== null && getMaskSet().validPositions[i] === undefined && test.optionality !== true && test.optionalQuantifier !== true || test.fn === null && buffer[i] !== getPlaceholder(i, test)) {
  2437. complete = false;
  2438. break;
  2439. }
  2440. }
  2441. }
  2442. return complete;
  2443. }
  2444. function handleRemove(input, k, pos, strict, fromIsValid) {
  2445. if (opts.numericInput || isRTL) {
  2446. if (k === Inputmask.keyCode.BACKSPACE) {
  2447. k = Inputmask.keyCode.DELETE;
  2448. } else if (k === Inputmask.keyCode.DELETE) {
  2449. k = Inputmask.keyCode.BACKSPACE;
  2450. }
  2451. if (isRTL) {
  2452. var pend = pos.end;
  2453. pos.end = pos.begin;
  2454. pos.begin = pend;
  2455. }
  2456. }
  2457. if (k === Inputmask.keyCode.BACKSPACE && pos.end - pos.begin < 1) {
  2458. pos.begin = seekPrevious(pos.begin);
  2459. if (getMaskSet().validPositions[pos.begin] !== undefined && getMaskSet().validPositions[pos.begin].input === opts.groupSeparator) {
  2460. pos.begin--;
  2461. }
  2462. } else if (k === Inputmask.keyCode.DELETE && pos.begin === pos.end) {
  2463. pos.end = isMask(pos.end, true) && getMaskSet().validPositions[pos.end] && getMaskSet().validPositions[pos.end].input !== opts.radixPoint ? pos.end + 1 : seekNext(pos.end) + 1;
  2464. if (getMaskSet().validPositions[pos.begin] !== undefined && getMaskSet().validPositions[pos.begin].input === opts.groupSeparator) {
  2465. pos.end++;
  2466. }
  2467. }
  2468. revalidateMask(pos);
  2469. if (strict !== true && opts.keepStatic !== false || opts.regex !== null) {
  2470. var result = alternate(true);
  2471. if (result) {
  2472. var newPos = result.caret !== undefined ? result.caret : result.pos ? seekNext(result.pos.begin ? result.pos.begin : result.pos) : getLastValidPosition(-1, true);
  2473. if (k !== Inputmask.keyCode.DELETE || pos.begin > newPos) {
  2474. pos.begin == newPos;
  2475. }
  2476. }
  2477. }
  2478. var lvp = getLastValidPosition(pos.begin, true);
  2479. if (lvp < pos.begin || pos.begin === -1) {
  2480. getMaskSet().p = seekNext(lvp);
  2481. } else if (strict !== true) {
  2482. getMaskSet().p = pos.begin;
  2483. if (fromIsValid !== true) {
  2484. while (getMaskSet().p < lvp && getMaskSet().validPositions[getMaskSet().p] === undefined) {
  2485. getMaskSet().p++;
  2486. }
  2487. }
  2488. }
  2489. }
  2490. function initializeColorMask(input) {
  2491. var computedStyle = (input.ownerDocument.defaultView || window).getComputedStyle(input, null);
  2492. function findCaretPos(clientx) {
  2493. var e = document.createElement("span"), caretPos;
  2494. for (var style in computedStyle) {
  2495. if (isNaN(style) && style.indexOf("font") !== -1) {
  2496. e.style[style] = computedStyle[style];
  2497. }
  2498. }
  2499. e.style.textTransform = computedStyle.textTransform;
  2500. e.style.letterSpacing = computedStyle.letterSpacing;
  2501. e.style.position = "absolute";
  2502. e.style.height = "auto";
  2503. e.style.width = "auto";
  2504. e.style.visibility = "hidden";
  2505. e.style.whiteSpace = "nowrap";
  2506. document.body.appendChild(e);
  2507. var inputText = input.inputmask._valueGet(), previousWidth = 0, itl;
  2508. for (caretPos = 0, itl = inputText.length; caretPos <= itl; caretPos++) {
  2509. e.innerHTML += inputText.charAt(caretPos) || "_";
  2510. if (e.offsetWidth >= clientx) {
  2511. var offset1 = clientx - previousWidth;
  2512. var offset2 = e.offsetWidth - clientx;
  2513. e.innerHTML = inputText.charAt(caretPos);
  2514. offset1 -= e.offsetWidth / 3;
  2515. caretPos = offset1 < offset2 ? caretPos - 1 : caretPos;
  2516. break;
  2517. }
  2518. previousWidth = e.offsetWidth;
  2519. }
  2520. document.body.removeChild(e);
  2521. return caretPos;
  2522. }
  2523. var template = document.createElement("div");
  2524. template.style.width = computedStyle.width;
  2525. template.style.textAlign = computedStyle.textAlign;
  2526. colorMask = document.createElement("div");
  2527. input.inputmask.colorMask = colorMask;
  2528. colorMask.className = "im-colormask";
  2529. input.parentNode.insertBefore(colorMask, input);
  2530. input.parentNode.removeChild(input);
  2531. colorMask.appendChild(input);
  2532. colorMask.appendChild(template);
  2533. input.style.left = template.offsetLeft + "px";
  2534. $(colorMask).on("mouseleave", function(e) {
  2535. return EventHandlers.mouseleaveEvent.call(input, [ e ]);
  2536. });
  2537. $(colorMask).on("mouseenter", function(e) {
  2538. return EventHandlers.mouseenterEvent.call(input, [ e ]);
  2539. });
  2540. $(colorMask).on("click", function(e) {
  2541. caret(input, findCaretPos(e.clientX));
  2542. return EventHandlers.clickEvent.call(input, [ e ]);
  2543. });
  2544. }
  2545. Inputmask.prototype.positionColorMask = function(input, template) {
  2546. input.style.left = template.offsetLeft + "px";
  2547. };
  2548. function renderColorMask(input, caretPos, clear) {
  2549. var maskTemplate = [], isStatic = false, test, testPos, ndxIntlzr, pos = 0;
  2550. function setEntry(entry) {
  2551. if (entry === undefined) entry = "";
  2552. if (!isStatic && (test.fn === null || testPos.input === undefined)) {
  2553. isStatic = true;
  2554. maskTemplate.push("<span class='im-static'>" + entry);
  2555. } else if (isStatic && (test.fn !== null && testPos.input !== undefined || test.def === "")) {
  2556. isStatic = false;
  2557. var mtl = maskTemplate.length;
  2558. maskTemplate[mtl - 1] = maskTemplate[mtl - 1] + "</span>";
  2559. maskTemplate.push(entry);
  2560. } else maskTemplate.push(entry);
  2561. }
  2562. function setCaret() {
  2563. if (document.activeElement === input) {
  2564. maskTemplate.splice(caretPos.begin, 0, caretPos.begin === caretPos.end || caretPos.end > getMaskSet().maskLength ? '<mark class="im-caret" style="border-right-width: 1px;border-right-style: solid;">' : '<mark class="im-caret-select">');
  2565. maskTemplate.splice(caretPos.end + 1, 0, "</mark>");
  2566. }
  2567. }
  2568. if (colorMask !== undefined) {
  2569. var buffer = getBuffer();
  2570. if (caretPos === undefined) {
  2571. caretPos = caret(input);
  2572. } else if (caretPos.begin === undefined) {
  2573. caretPos = {
  2574. begin: caretPos,
  2575. end: caretPos
  2576. };
  2577. }
  2578. if (clear !== true) {
  2579. var lvp = getLastValidPosition();
  2580. do {
  2581. if (getMaskSet().validPositions[pos]) {
  2582. testPos = getMaskSet().validPositions[pos];
  2583. test = testPos.match;
  2584. ndxIntlzr = testPos.locator.slice();
  2585. setEntry(buffer[pos]);
  2586. } else {
  2587. testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
  2588. test = testPos.match;
  2589. ndxIntlzr = testPos.locator.slice();
  2590. if (opts.jitMasking === false || pos < lvp || typeof opts.jitMasking === "number" && isFinite(opts.jitMasking) && opts.jitMasking > pos) {
  2591. setEntry(getPlaceholder(pos, test));
  2592. } else isStatic = false;
  2593. }
  2594. pos++;
  2595. } while ((maxLength === undefined || pos < maxLength) && (test.fn !== null || test.def !== "") || lvp > pos || isStatic);
  2596. if (isStatic) setEntry();
  2597. setCaret();
  2598. }
  2599. var template = colorMask.getElementsByTagName("div")[0];
  2600. template.innerHTML = maskTemplate.join("");
  2601. input.inputmask.positionColorMask(input, template);
  2602. }
  2603. }
  2604. function mask(elem) {
  2605. function isElementTypeSupported(input, opts) {
  2606. function patchValueProperty(npt) {
  2607. var valueGet;
  2608. var valueSet;
  2609. function patchValhook(type) {
  2610. if ($.valHooks && ($.valHooks[type] === undefined || $.valHooks[type].inputmaskpatch !== true)) {
  2611. var valhookGet = $.valHooks[type] && $.valHooks[type].get ? $.valHooks[type].get : function(elem) {
  2612. return elem.value;
  2613. };
  2614. var valhookSet = $.valHooks[type] && $.valHooks[type].set ? $.valHooks[type].set : function(elem, value) {
  2615. elem.value = value;
  2616. return elem;
  2617. };
  2618. $.valHooks[type] = {
  2619. get: function get(elem) {
  2620. if (elem.inputmask) {
  2621. if (elem.inputmask.opts.autoUnmask) {
  2622. return elem.inputmask.unmaskedvalue();
  2623. } else {
  2624. var result = valhookGet(elem);
  2625. return getLastValidPosition(undefined, undefined, elem.inputmask.maskset.validPositions) !== -1 || opts.nullable !== true ? result : "";
  2626. }
  2627. } else return valhookGet(elem);
  2628. },
  2629. set: function set(elem, value) {
  2630. var $elem = $(elem), result;
  2631. result = valhookSet(elem, value);
  2632. if (elem.inputmask) {
  2633. $elem.trigger("setvalue", [ value ]);
  2634. }
  2635. return result;
  2636. },
  2637. inputmaskpatch: true
  2638. };
  2639. }
  2640. }
  2641. function getter() {
  2642. if (this.inputmask) {
  2643. return this.inputmask.opts.autoUnmask ? this.inputmask.unmaskedvalue() : getLastValidPosition() !== -1 || opts.nullable !== true ? document.activeElement === this && opts.clearMaskOnLostFocus ? (isRTL ? clearOptionalTail(getBuffer().slice()).reverse() : clearOptionalTail(getBuffer().slice())).join("") : valueGet.call(this) : "";
  2644. } else return valueGet.call(this);
  2645. }
  2646. function setter(value) {
  2647. valueSet.call(this, value);
  2648. if (this.inputmask) {
  2649. $(this).trigger("setvalue", [ value ]);
  2650. }
  2651. }
  2652. function installNativeValueSetFallback(npt) {
  2653. EventRuler.on(npt, "mouseenter", function(event) {
  2654. var $input = $(this), input = this, value = input.inputmask._valueGet();
  2655. if (value !== getBuffer().join("")) {
  2656. $input.trigger("setvalue");
  2657. }
  2658. });
  2659. }
  2660. if (!npt.inputmask.__valueGet) {
  2661. if (opts.noValuePatching !== true) {
  2662. if (Object.getOwnPropertyDescriptor) {
  2663. if (typeof Object.getPrototypeOf !== "function") {
  2664. Object.getPrototypeOf = _typeof("test".__proto__) === "object" ? function(object) {
  2665. return object.__proto__;
  2666. } : function(object) {
  2667. return object.constructor.prototype;
  2668. };
  2669. }
  2670. var valueProperty = Object.getPrototypeOf ? Object.getOwnPropertyDescriptor(Object.getPrototypeOf(npt), "value") : undefined;
  2671. if (valueProperty && valueProperty.get && valueProperty.set) {
  2672. valueGet = valueProperty.get;
  2673. valueSet = valueProperty.set;
  2674. Object.defineProperty(npt, "value", {
  2675. get: getter,
  2676. set: setter,
  2677. configurable: true
  2678. });
  2679. } else if (npt.tagName !== "INPUT") {
  2680. valueGet = function valueGet() {
  2681. return this.textContent;
  2682. };
  2683. valueSet = function valueSet(value) {
  2684. this.textContent = value;
  2685. };
  2686. Object.defineProperty(npt, "value", {
  2687. get: getter,
  2688. set: setter,
  2689. configurable: true
  2690. });
  2691. }
  2692. } else if (document.__lookupGetter__ && npt.__lookupGetter__("value")) {
  2693. valueGet = npt.__lookupGetter__("value");
  2694. valueSet = npt.__lookupSetter__("value");
  2695. npt.__defineGetter__("value", getter);
  2696. npt.__defineSetter__("value", setter);
  2697. }
  2698. npt.inputmask.__valueGet = valueGet;
  2699. npt.inputmask.__valueSet = valueSet;
  2700. }
  2701. npt.inputmask._valueGet = function(overruleRTL) {
  2702. return isRTL && overruleRTL !== true ? valueGet.call(this.el).split("").reverse().join("") : valueGet.call(this.el);
  2703. };
  2704. npt.inputmask._valueSet = function(value, overruleRTL) {
  2705. valueSet.call(this.el, value === null || value === undefined ? "" : overruleRTL !== true && isRTL ? value.split("").reverse().join("") : value);
  2706. };
  2707. if (valueGet === undefined) {
  2708. valueGet = function valueGet() {
  2709. return this.value;
  2710. };
  2711. valueSet = function valueSet(value) {
  2712. this.value = value;
  2713. };
  2714. patchValhook(npt.type);
  2715. installNativeValueSetFallback(npt);
  2716. }
  2717. }
  2718. }
  2719. var elementType = input.getAttribute("type");
  2720. var isSupported = input.tagName === "INPUT" && $.inArray(elementType, opts.supportsInputType) !== -1 || input.isContentEditable || input.tagName === "TEXTAREA";
  2721. if (!isSupported) {
  2722. if (input.tagName === "INPUT") {
  2723. var el = document.createElement("input");
  2724. el.setAttribute("type", elementType);
  2725. isSupported = el.type === "text";
  2726. el = null;
  2727. } else isSupported = "partial";
  2728. }
  2729. if (isSupported !== false) {
  2730. patchValueProperty(input);
  2731. } else input.inputmask = undefined;
  2732. return isSupported;
  2733. }
  2734. EventRuler.off(elem);
  2735. var isSupported = isElementTypeSupported(elem, opts);
  2736. if (isSupported !== false) {
  2737. el = elem;
  2738. $el = $(el);
  2739. originalPlaceholder = el.placeholder;
  2740. maxLength = el !== undefined ? el.maxLength : undefined;
  2741. if (maxLength === -1) maxLength = undefined;
  2742. if (opts.colorMask === true) {
  2743. initializeColorMask(el);
  2744. }
  2745. if (mobile) {
  2746. if ("inputmode" in el) {
  2747. el.inputmode = opts.inputmode;
  2748. el.setAttribute("inputmode", opts.inputmode);
  2749. }
  2750. if (opts.disablePredictiveText === true) {
  2751. if ("autocorrect" in el) {
  2752. el.autocorrect = false;
  2753. } else {
  2754. if (opts.colorMask !== true) {
  2755. initializeColorMask(el);
  2756. }
  2757. el.type = "password";
  2758. }
  2759. }
  2760. }
  2761. if (isSupported === true) {
  2762. el.setAttribute("im-insert", opts.insertMode);
  2763. EventRuler.on(el, "submit", EventHandlers.submitEvent);
  2764. EventRuler.on(el, "reset", EventHandlers.resetEvent);
  2765. EventRuler.on(el, "blur", EventHandlers.blurEvent);
  2766. EventRuler.on(el, "focus", EventHandlers.focusEvent);
  2767. if (opts.colorMask !== true) {
  2768. EventRuler.on(el, "click", EventHandlers.clickEvent);
  2769. EventRuler.on(el, "mouseleave", EventHandlers.mouseleaveEvent);
  2770. EventRuler.on(el, "mouseenter", EventHandlers.mouseenterEvent);
  2771. }
  2772. EventRuler.on(el, "paste", EventHandlers.pasteEvent);
  2773. EventRuler.on(el, "cut", EventHandlers.cutEvent);
  2774. EventRuler.on(el, "complete", opts.oncomplete);
  2775. EventRuler.on(el, "incomplete", opts.onincomplete);
  2776. EventRuler.on(el, "cleared", opts.oncleared);
  2777. if (!mobile && opts.inputEventOnly !== true) {
  2778. EventRuler.on(el, "keydown", EventHandlers.keydownEvent);
  2779. EventRuler.on(el, "keypress", EventHandlers.keypressEvent);
  2780. } else {
  2781. el.removeAttribute("maxLength");
  2782. }
  2783. EventRuler.on(el, "input", EventHandlers.inputFallBackEvent);
  2784. EventRuler.on(el, "beforeinput", EventHandlers.beforeInputEvent);
  2785. }
  2786. EventRuler.on(el, "setvalue", EventHandlers.setValueEvent);
  2787. undoValue = getBufferTemplate().join("");
  2788. if (el.inputmask._valueGet(true) !== "" || opts.clearMaskOnLostFocus === false || document.activeElement === el) {
  2789. var initialValue = $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(inputmask, el.inputmask._valueGet(true), opts) || el.inputmask._valueGet(true) : el.inputmask._valueGet(true);
  2790. if (initialValue !== "") checkVal(el, true, false, initialValue.split(""));
  2791. var buffer = getBuffer().slice();
  2792. undoValue = buffer.join("");
  2793. if (isComplete(buffer) === false) {
  2794. if (opts.clearIncomplete) {
  2795. resetMaskSet();
  2796. }
  2797. }
  2798. if (opts.clearMaskOnLostFocus && document.activeElement !== el) {
  2799. if (getLastValidPosition() === -1) {
  2800. buffer = [];
  2801. } else {
  2802. clearOptionalTail(buffer);
  2803. }
  2804. }
  2805. if (opts.clearMaskOnLostFocus === false || opts.showMaskOnFocus && document.activeElement === el || el.inputmask._valueGet(true) !== "") writeBuffer(el, buffer);
  2806. if (document.activeElement === el) {
  2807. caret(el, seekNext(getLastValidPosition()));
  2808. }
  2809. }
  2810. }
  2811. }
  2812. var valueBuffer;
  2813. if (actionObj !== undefined) {
  2814. switch (actionObj.action) {
  2815. case "isComplete":
  2816. el = actionObj.el;
  2817. return isComplete(getBuffer());
  2818. case "unmaskedvalue":
  2819. if (el === undefined || actionObj.value !== undefined) {
  2820. valueBuffer = actionObj.value;
  2821. valueBuffer = ($.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(inputmask, valueBuffer, opts) || valueBuffer : valueBuffer).split("");
  2822. checkVal.call(this, undefined, false, false, valueBuffer);
  2823. if ($.isFunction(opts.onBeforeWrite)) opts.onBeforeWrite.call(inputmask, undefined, getBuffer(), 0, opts);
  2824. }
  2825. return unmaskedvalue(el);
  2826. case "mask":
  2827. mask(el);
  2828. break;
  2829. case "format":
  2830. valueBuffer = ($.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(inputmask, actionObj.value, opts) || actionObj.value : actionObj.value).split("");
  2831. checkVal.call(this, undefined, true, false, valueBuffer);
  2832. if (actionObj.metadata) {
  2833. return {
  2834. value: isRTL ? getBuffer().slice().reverse().join("") : getBuffer().join(""),
  2835. metadata: maskScope.call(this, {
  2836. action: "getmetadata"
  2837. }, maskset, opts)
  2838. };
  2839. }
  2840. return isRTL ? getBuffer().slice().reverse().join("") : getBuffer().join("");
  2841. case "isValid":
  2842. if (actionObj.value) {
  2843. valueBuffer = actionObj.value.split("");
  2844. checkVal.call(this, undefined, true, true, valueBuffer);
  2845. } else {
  2846. actionObj.value = getBuffer().join("");
  2847. }
  2848. var buffer = getBuffer();
  2849. var rl = determineLastRequiredPosition(), lmib = buffer.length - 1;
  2850. for (;lmib > rl; lmib--) {
  2851. if (isMask(lmib)) break;
  2852. }
  2853. buffer.splice(rl, lmib + 1 - rl);
  2854. return isComplete(buffer) && actionObj.value === getBuffer().join("");
  2855. case "getemptymask":
  2856. return getBufferTemplate().join("");
  2857. case "remove":
  2858. if (el && el.inputmask) {
  2859. $.data(el, "_inputmask_opts", null);
  2860. $el = $(el);
  2861. el.inputmask._valueSet(opts.autoUnmask ? unmaskedvalue(el) : el.inputmask._valueGet(true));
  2862. EventRuler.off(el);
  2863. if (el.inputmask.colorMask) {
  2864. colorMask = el.inputmask.colorMask;
  2865. colorMask.removeChild(el);
  2866. colorMask.parentNode.insertBefore(el, colorMask);
  2867. colorMask.parentNode.removeChild(colorMask);
  2868. }
  2869. var valueProperty;
  2870. if (Object.getOwnPropertyDescriptor && Object.getPrototypeOf) {
  2871. valueProperty = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(el), "value");
  2872. if (valueProperty) {
  2873. if (el.inputmask.__valueGet) {
  2874. Object.defineProperty(el, "value", {
  2875. get: el.inputmask.__valueGet,
  2876. set: el.inputmask.__valueSet,
  2877. configurable: true
  2878. });
  2879. }
  2880. }
  2881. } else if (document.__lookupGetter__ && el.__lookupGetter__("value")) {
  2882. if (el.inputmask.__valueGet) {
  2883. el.__defineGetter__("value", el.inputmask.__valueGet);
  2884. el.__defineSetter__("value", el.inputmask.__valueSet);
  2885. }
  2886. }
  2887. el.inputmask = undefined;
  2888. }
  2889. return el;
  2890. break;
  2891. case "getmetadata":
  2892. if ($.isArray(maskset.metadata)) {
  2893. var maskTarget = getMaskTemplate(true, 0, false).join("");
  2894. $.each(maskset.metadata, function(ndx, mtdt) {
  2895. if (mtdt.mask === maskTarget) {
  2896. maskTarget = mtdt;
  2897. return false;
  2898. }
  2899. });
  2900. return maskTarget;
  2901. }
  2902. return maskset.metadata;
  2903. }
  2904. }
  2905. }
  2906. return Inputmask;
  2907. });
  2908. }, function(module, exports, __webpack_require__) {
  2909. "use strict";
  2910. var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;
  2911. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function(obj) {
  2912. return typeof obj;
  2913. } : function(obj) {
  2914. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  2915. };
  2916. (function(factory) {
  2917. if (true) {
  2918. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [ __webpack_require__(4) ], __WEBPACK_AMD_DEFINE_FACTORY__ = factory,
  2919. __WEBPACK_AMD_DEFINE_RESULT__ = typeof __WEBPACK_AMD_DEFINE_FACTORY__ === "function" ? __WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__) : __WEBPACK_AMD_DEFINE_FACTORY__,
  2920. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  2921. } else {}
  2922. })(function($) {
  2923. return $;
  2924. });
  2925. }, function(module, exports) {
  2926. module.exports = jQuery;
  2927. }, function(module, exports, __webpack_require__) {
  2928. "use strict";
  2929. var __WEBPACK_AMD_DEFINE_RESULT__;
  2930. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function(obj) {
  2931. return typeof obj;
  2932. } : function(obj) {
  2933. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  2934. };
  2935. if (true) !(__WEBPACK_AMD_DEFINE_RESULT__ = function() {
  2936. return typeof window !== "undefined" ? window : new (eval("require('jsdom').JSDOM"))("").window;
  2937. }.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); else {}
  2938. }, function(module, exports, __webpack_require__) {
  2939. "use strict";
  2940. var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;
  2941. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function(obj) {
  2942. return typeof obj;
  2943. } : function(obj) {
  2944. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  2945. };
  2946. (function(factory) {
  2947. if (true) {
  2948. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [ __webpack_require__(2) ], __WEBPACK_AMD_DEFINE_FACTORY__ = factory,
  2949. __WEBPACK_AMD_DEFINE_RESULT__ = typeof __WEBPACK_AMD_DEFINE_FACTORY__ === "function" ? __WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__) : __WEBPACK_AMD_DEFINE_FACTORY__,
  2950. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  2951. } else {}
  2952. })(function(Inputmask) {
  2953. var $ = Inputmask.dependencyLib;
  2954. var formatCode = {
  2955. d: [ "[1-9]|[12][0-9]|3[01]", Date.prototype.setDate, "day", Date.prototype.getDate ],
  2956. dd: [ "0[1-9]|[12][0-9]|3[01]", Date.prototype.setDate, "day", function() {
  2957. return pad(Date.prototype.getDate.call(this), 2);
  2958. } ],
  2959. ddd: [ "" ],
  2960. dddd: [ "" ],
  2961. m: [ "[1-9]|1[012]", Date.prototype.setMonth, "month", function() {
  2962. return Date.prototype.getMonth.call(this) + 1;
  2963. } ],
  2964. mm: [ "0[1-9]|1[012]", Date.prototype.setMonth, "month", function() {
  2965. return pad(Date.prototype.getMonth.call(this) + 1, 2);
  2966. } ],
  2967. mmm: [ "" ],
  2968. mmmm: [ "" ],
  2969. yy: [ "[0-9]{2}", Date.prototype.setFullYear, "year", function() {
  2970. return pad(Date.prototype.getFullYear.call(this), 2);
  2971. } ],
  2972. yyyy: [ "[0-9]{4}", Date.prototype.setFullYear, "year", function() {
  2973. return pad(Date.prototype.getFullYear.call(this), 4);
  2974. } ],
  2975. h: [ "[1-9]|1[0-2]", Date.prototype.setHours, "hours", Date.prototype.getHours ],
  2976. hh: [ "0[1-9]|1[0-2]", Date.prototype.setHours, "hours", function() {
  2977. return pad(Date.prototype.getHours.call(this), 2);
  2978. } ],
  2979. hhh: [ "[0-9]+", Date.prototype.setHours, "hours", Date.prototype.getHours ],
  2980. H: [ "1?[0-9]|2[0-3]", Date.prototype.setHours, "hours", Date.prototype.getHours ],
  2981. HH: [ "[01][0-9]|2[0-3]", Date.prototype.setHours, "hours", function() {
  2982. return pad(Date.prototype.getHours.call(this), 2);
  2983. } ],
  2984. HHH: [ "[0-9]+", Date.prototype.setHours, "hours", Date.prototype.getHours ],
  2985. M: [ "[1-5]?[0-9]", Date.prototype.setMinutes, "minutes", Date.prototype.getMinutes ],
  2986. MM: [ "[0-5][0-9]", Date.prototype.setMinutes, "minutes", function() {
  2987. return pad(Date.prototype.getMinutes.call(this), 2);
  2988. } ],
  2989. s: [ "[1-5]?[0-9]", Date.prototype.setSeconds, "seconds", Date.prototype.getSeconds ],
  2990. ss: [ "[0-5][0-9]", Date.prototype.setSeconds, "seconds", function() {
  2991. return pad(Date.prototype.getSeconds.call(this), 2);
  2992. } ],
  2993. l: [ "[0-9]{3}", Date.prototype.setMilliseconds, "milliseconds", function() {
  2994. return pad(Date.prototype.getMilliseconds.call(this), 3);
  2995. } ],
  2996. L: [ "[0-9]{2}", Date.prototype.setMilliseconds, "milliseconds", function() {
  2997. return pad(Date.prototype.getMilliseconds.call(this), 2);
  2998. } ],
  2999. t: [ "[ap]" ],
  3000. tt: [ "[ap]m" ],
  3001. T: [ "[AP]" ],
  3002. TT: [ "[AP]M" ],
  3003. Z: [ "" ],
  3004. o: [ "" ],
  3005. S: [ "" ]
  3006. }, formatAlias = {
  3007. isoDate: "yyyy-mm-dd",
  3008. isoTime: "HH:MM:ss",
  3009. isoDateTime: "yyyy-mm-dd'T'HH:MM:ss",
  3010. isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
  3011. };
  3012. function getTokenizer(opts) {
  3013. if (!opts.tokenizer) {
  3014. var tokens = [];
  3015. for (var ndx in formatCode) {
  3016. if (tokens.indexOf(ndx[0]) === -1) tokens.push(ndx[0]);
  3017. }
  3018. opts.tokenizer = "(" + tokens.join("+|") + ")+?|.";
  3019. opts.tokenizer = new RegExp(opts.tokenizer, "g");
  3020. }
  3021. return opts.tokenizer;
  3022. }
  3023. function isValidDate(dateParts, currentResult) {
  3024. return !isFinite(dateParts.rawday) || dateParts.day == "29" && !isFinite(dateParts.rawyear) || new Date(dateParts.date.getFullYear(), isFinite(dateParts.rawmonth) ? dateParts.month : dateParts.date.getMonth() + 1, 0).getDate() >= dateParts.day ? currentResult : false;
  3025. }
  3026. function isDateInRange(dateParts, opts) {
  3027. var result = true;
  3028. if (opts.min) {
  3029. if (dateParts["rawyear"]) {
  3030. var rawYear = dateParts["rawyear"].replace(/[^0-9]/g, ""), minYear = opts.min.year.substr(0, rawYear.length);
  3031. result = minYear <= rawYear;
  3032. }
  3033. if (dateParts["year"] === dateParts["rawyear"]) {
  3034. if (opts.min.date.getTime() === opts.min.date.getTime()) {
  3035. result = opts.min.date.getTime() <= dateParts.date.getTime();
  3036. }
  3037. }
  3038. }
  3039. if (result && opts.max && opts.max.date.getTime() === opts.max.date.getTime()) {
  3040. result = opts.max.date.getTime() >= dateParts.date.getTime();
  3041. }
  3042. return result;
  3043. }
  3044. function parse(format, dateObjValue, opts, raw) {
  3045. var mask = "", match;
  3046. while (match = getTokenizer(opts).exec(format)) {
  3047. if (dateObjValue === undefined) {
  3048. if (formatCode[match[0]]) {
  3049. mask += "(" + formatCode[match[0]][0] + ")";
  3050. } else {
  3051. switch (match[0]) {
  3052. case "[":
  3053. mask += "(";
  3054. break;
  3055. case "]":
  3056. mask += ")?";
  3057. break;
  3058. default:
  3059. mask += Inputmask.escapeRegex(match[0]);
  3060. }
  3061. }
  3062. } else {
  3063. if (formatCode[match[0]]) {
  3064. if (raw !== true && formatCode[match[0]][3]) {
  3065. var getFn = formatCode[match[0]][3];
  3066. mask += getFn.call(dateObjValue.date);
  3067. } else if (formatCode[match[0]][2]) mask += dateObjValue["raw" + formatCode[match[0]][2]]; else mask += match[0];
  3068. } else mask += match[0];
  3069. }
  3070. }
  3071. return mask;
  3072. }
  3073. function pad(val, len) {
  3074. val = String(val);
  3075. len = len || 2;
  3076. while (val.length < len) {
  3077. val = "0" + val;
  3078. }
  3079. return val;
  3080. }
  3081. function analyseMask(maskString, format, opts) {
  3082. var dateObj = {
  3083. date: new Date(1, 0, 1)
  3084. }, targetProp, mask = maskString, match, dateOperation, targetValidator;
  3085. function extendProperty(value) {
  3086. var correctedValue = value.replace(/[^0-9]/g, "0");
  3087. if (correctedValue != value) {
  3088. var enteredPart = value.replace(/[^0-9]/g, ""), min = (opts.min && opts.min[targetProp] || value).toString(), max = (opts.max && opts.max[targetProp] || value).toString();
  3089. correctedValue = enteredPart + (enteredPart < min.slice(0, enteredPart.length) ? min.slice(enteredPart.length) : enteredPart > max.slice(0, enteredPart.length) ? max.slice(enteredPart.length) : correctedValue.toString().slice(enteredPart.length));
  3090. }
  3091. return correctedValue;
  3092. }
  3093. function setValue(dateObj, value, opts) {
  3094. dateObj[targetProp] = extendProperty(value);
  3095. dateObj["raw" + targetProp] = value;
  3096. if (dateOperation !== undefined) dateOperation.call(dateObj.date, targetProp == "month" ? parseInt(dateObj[targetProp]) - 1 : dateObj[targetProp]);
  3097. }
  3098. if (typeof mask === "string") {
  3099. while (match = getTokenizer(opts).exec(format)) {
  3100. var value = mask.slice(0, match[0].length);
  3101. if (formatCode.hasOwnProperty(match[0])) {
  3102. targetValidator = formatCode[match[0]][0];
  3103. targetProp = formatCode[match[0]][2];
  3104. dateOperation = formatCode[match[0]][1];
  3105. setValue(dateObj, value, opts);
  3106. }
  3107. mask = mask.slice(value.length);
  3108. }
  3109. return dateObj;
  3110. } else if (mask && (typeof mask === "undefined" ? "undefined" : _typeof(mask)) === "object" && mask.hasOwnProperty("date")) {
  3111. return mask;
  3112. }
  3113. return undefined;
  3114. }
  3115. Inputmask.extendAliases({
  3116. datetime: {
  3117. mask: function mask(opts) {
  3118. formatCode.S = opts.i18n.ordinalSuffix.join("|");
  3119. opts.inputFormat = formatAlias[opts.inputFormat] || opts.inputFormat;
  3120. opts.displayFormat = formatAlias[opts.displayFormat] || opts.displayFormat || opts.inputFormat;
  3121. opts.outputFormat = formatAlias[opts.outputFormat] || opts.outputFormat || opts.inputFormat;
  3122. opts.placeholder = opts.placeholder !== "" ? opts.placeholder : opts.inputFormat.replace(/[\[\]]/, "");
  3123. opts.regex = parse(opts.inputFormat, undefined, opts);
  3124. return null;
  3125. },
  3126. placeholder: "",
  3127. inputFormat: "isoDateTime",
  3128. displayFormat: undefined,
  3129. outputFormat: undefined,
  3130. min: null,
  3131. max: null,
  3132. i18n: {
  3133. dayNames: [ "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ],
  3134. monthNames: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
  3135. ordinalSuffix: [ "st", "nd", "rd", "th" ]
  3136. },
  3137. postValidation: function postValidation(buffer, pos, currentResult, opts) {
  3138. opts.min = analyseMask(opts.min, opts.inputFormat, opts);
  3139. opts.max = analyseMask(opts.max, opts.inputFormat, opts);
  3140. var result = currentResult, dateParts = analyseMask(buffer.join(""), opts.inputFormat, opts);
  3141. if (result && dateParts.date.getTime() === dateParts.date.getTime()) {
  3142. result = isValidDate(dateParts, result);
  3143. result = result && isDateInRange(dateParts, opts);
  3144. }
  3145. if (pos && result && currentResult.pos !== pos) {
  3146. return {
  3147. buffer: parse(opts.inputFormat, dateParts, opts),
  3148. refreshFromBuffer: {
  3149. start: pos,
  3150. end: currentResult.pos
  3151. }
  3152. };
  3153. }
  3154. return result;
  3155. },
  3156. onKeyDown: function onKeyDown(e, buffer, caretPos, opts) {
  3157. var input = this;
  3158. if (e.ctrlKey && e.keyCode === Inputmask.keyCode.RIGHT) {
  3159. var today = new Date(), match, date = "";
  3160. while (match = getTokenizer(opts).exec(opts.inputFormat)) {
  3161. if (match[0].charAt(0) === "d") {
  3162. date += pad(today.getDate(), match[0].length);
  3163. } else if (match[0].charAt(0) === "m") {
  3164. date += pad(today.getMonth() + 1, match[0].length);
  3165. } else if (match[0] === "yyyy") {
  3166. date += today.getFullYear().toString();
  3167. } else if (match[0].charAt(0) === "y") {
  3168. date += pad(today.getYear(), match[0].length);
  3169. }
  3170. }
  3171. input.inputmask._valueSet(date);
  3172. $(input).trigger("setvalue");
  3173. }
  3174. },
  3175. onUnMask: function onUnMask(maskedValue, unmaskedValue, opts) {
  3176. return parse(opts.outputFormat, analyseMask(maskedValue, opts.inputFormat, opts), opts, true);
  3177. },
  3178. casing: function casing(elem, test, pos, validPositions) {
  3179. if (test.nativeDef.indexOf("[ap]") == 0) return elem.toLowerCase();
  3180. if (test.nativeDef.indexOf("[AP]") == 0) return elem.toUpperCase();
  3181. return elem;
  3182. },
  3183. insertMode: false,
  3184. shiftPositions: false
  3185. }
  3186. });
  3187. return Inputmask;
  3188. });
  3189. }, function(module, exports, __webpack_require__) {
  3190. "use strict";
  3191. var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;
  3192. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function(obj) {
  3193. return typeof obj;
  3194. } : function(obj) {
  3195. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  3196. };
  3197. (function(factory) {
  3198. if (true) {
  3199. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [ __webpack_require__(2) ], __WEBPACK_AMD_DEFINE_FACTORY__ = factory,
  3200. __WEBPACK_AMD_DEFINE_RESULT__ = typeof __WEBPACK_AMD_DEFINE_FACTORY__ === "function" ? __WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__) : __WEBPACK_AMD_DEFINE_FACTORY__,
  3201. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  3202. } else {}
  3203. })(function(Inputmask) {
  3204. var $ = Inputmask.dependencyLib;
  3205. function autoEscape(txt, opts) {
  3206. var escapedTxt = "";
  3207. for (var i = 0; i < txt.length; i++) {
  3208. if (Inputmask.prototype.definitions[txt.charAt(i)] || opts.definitions[txt.charAt(i)] || opts.optionalmarker.start === txt.charAt(i) || opts.optionalmarker.end === txt.charAt(i) || opts.quantifiermarker.start === txt.charAt(i) || opts.quantifiermarker.end === txt.charAt(i) || opts.groupmarker.start === txt.charAt(i) || opts.groupmarker.end === txt.charAt(i) || opts.alternatormarker === txt.charAt(i)) {
  3209. escapedTxt += "\\" + txt.charAt(i);
  3210. } else escapedTxt += txt.charAt(i);
  3211. }
  3212. return escapedTxt;
  3213. }
  3214. function alignDigits(buffer, digits, opts) {
  3215. if (digits > 0) {
  3216. var radixPosition = $.inArray(opts.radixPoint, buffer);
  3217. if (radixPosition === -1) {
  3218. buffer.push(opts.radixPoint);
  3219. radixPosition = buffer.length - 1;
  3220. }
  3221. for (var i = 1; i <= digits; i++) {
  3222. buffer[radixPosition + i] = buffer[radixPosition + i] || "0";
  3223. }
  3224. }
  3225. return buffer;
  3226. }
  3227. Inputmask.extendAliases({
  3228. numeric: {
  3229. mask: function mask(opts) {
  3230. if (opts.repeat !== 0 && isNaN(opts.integerDigits)) {
  3231. opts.integerDigits = opts.repeat;
  3232. }
  3233. opts.repeat = 0;
  3234. if (opts.groupSeparator === opts.radixPoint && opts.digits && opts.digits !== "0") {
  3235. if (opts.radixPoint === ".") {
  3236. opts.groupSeparator = ",";
  3237. } else if (opts.radixPoint === ",") {
  3238. opts.groupSeparator = ".";
  3239. } else opts.groupSeparator = "";
  3240. }
  3241. if (opts.groupSeparator === " ") {
  3242. opts.skipOptionalPartCharacter = undefined;
  3243. }
  3244. opts.autoGroup = opts.autoGroup && opts.groupSeparator !== "";
  3245. if (opts.autoGroup) {
  3246. if (typeof opts.groupSize == "string" && isFinite(opts.groupSize)) opts.groupSize = parseInt(opts.groupSize);
  3247. if (isFinite(opts.integerDigits)) {
  3248. var seps = Math.floor(opts.integerDigits / opts.groupSize);
  3249. var mod = opts.integerDigits % opts.groupSize;
  3250. opts.integerDigits = parseInt(opts.integerDigits) + (mod === 0 ? seps - 1 : seps);
  3251. if (opts.integerDigits < 1) {
  3252. opts.integerDigits = "*";
  3253. }
  3254. }
  3255. }
  3256. if (opts.placeholder.length > 1) {
  3257. opts.placeholder = opts.placeholder.charAt(0);
  3258. }
  3259. if (opts.positionCaretOnClick === "radixFocus" && opts.placeholder === "" && opts.integerOptional === false) {
  3260. opts.positionCaretOnClick = "lvp";
  3261. }
  3262. opts.definitions[";"] = opts.definitions["~"];
  3263. opts.definitions[";"].definitionSymbol = "~";
  3264. if (opts.numericInput === true) {
  3265. opts.positionCaretOnClick = opts.positionCaretOnClick === "radixFocus" ? "lvp" : opts.positionCaretOnClick;
  3266. opts.digitsOptional = false;
  3267. if (isNaN(opts.digits)) opts.digits = 2;
  3268. opts.decimalProtect = false;
  3269. }
  3270. var mask = "[+]";
  3271. mask += autoEscape(opts.prefix, opts);
  3272. if (opts.integerOptional === true) {
  3273. mask += "~{1," + opts.integerDigits + "}";
  3274. } else mask += "~{" + opts.integerDigits + "}";
  3275. if (opts.digits !== undefined) {
  3276. var radixDef = opts.decimalProtect ? ":" : opts.radixPoint;
  3277. var dq = opts.digits.toString().split(",");
  3278. if (isFinite(dq[0]) && dq[1] && isFinite(dq[1])) {
  3279. mask += radixDef + ";{" + opts.digits + "}";
  3280. } else if (isNaN(opts.digits) || parseInt(opts.digits) > 0) {
  3281. if (opts.digitsOptional) {
  3282. mask += "[" + radixDef + ";{1," + opts.digits + "}]";
  3283. } else mask += radixDef + ";{" + opts.digits + "}";
  3284. }
  3285. }
  3286. mask += autoEscape(opts.suffix, opts);
  3287. mask += "[-]";
  3288. opts.greedy = false;
  3289. return mask;
  3290. },
  3291. placeholder: "",
  3292. greedy: false,
  3293. digits: "*",
  3294. digitsOptional: true,
  3295. enforceDigitsOnBlur: false,
  3296. radixPoint: ".",
  3297. positionCaretOnClick: "radixFocus",
  3298. groupSize: 3,
  3299. groupSeparator: "",
  3300. autoGroup: false,
  3301. allowMinus: true,
  3302. negationSymbol: {
  3303. front: "-",
  3304. back: ""
  3305. },
  3306. integerDigits: "+",
  3307. integerOptional: true,
  3308. prefix: "",
  3309. suffix: "",
  3310. rightAlign: true,
  3311. decimalProtect: true,
  3312. min: null,
  3313. max: null,
  3314. step: 1,
  3315. insertMode: true,
  3316. autoUnmask: false,
  3317. unmaskAsNumber: false,
  3318. inputType: "text",
  3319. inputmode: "numeric",
  3320. preValidation: function preValidation(buffer, pos, c, isSelection, opts, maskset) {
  3321. if (c === "-" || c === opts.negationSymbol.front) {
  3322. if (opts.allowMinus !== true) return false;
  3323. opts.isNegative = opts.isNegative === undefined ? true : !opts.isNegative;
  3324. if (buffer.join("") === "") return true;
  3325. return {
  3326. caret: maskset.validPositions[pos] ? pos : undefined,
  3327. dopost: true
  3328. };
  3329. }
  3330. if (isSelection === false && c === opts.radixPoint && opts.digits !== undefined && (isNaN(opts.digits) || parseInt(opts.digits) > 0)) {
  3331. var radixPos = $.inArray(opts.radixPoint, buffer);
  3332. if (radixPos !== -1 && maskset.validPositions[radixPos] !== undefined) {
  3333. if (opts.numericInput === true) {
  3334. return pos === radixPos;
  3335. }
  3336. return {
  3337. caret: radixPos + 1
  3338. };
  3339. }
  3340. }
  3341. return true;
  3342. },
  3343. postValidation: function postValidation(buffer, pos, currentResult, opts) {
  3344. function buildPostMask(buffer, opts) {
  3345. var postMask = "";
  3346. postMask += "(" + opts.groupSeparator + "*{" + opts.groupSize + "}){*}";
  3347. if (opts.radixPoint !== "") {
  3348. var radixSplit = buffer.join("").split(opts.radixPoint);
  3349. if (radixSplit[1]) {
  3350. postMask += opts.radixPoint + "*{" + radixSplit[1].match(/^\d*\??\d*/)[0].length + "}";
  3351. }
  3352. }
  3353. return postMask;
  3354. }
  3355. var suffix = opts.suffix.split(""), prefix = opts.prefix.split("");
  3356. if (currentResult.pos === undefined && currentResult.caret !== undefined && currentResult.dopost !== true) return currentResult;
  3357. var caretPos = currentResult.caret !== undefined ? currentResult.caret : currentResult.pos;
  3358. var maskedValue = buffer.slice();
  3359. if (opts.numericInput) {
  3360. caretPos = maskedValue.length - caretPos - 1;
  3361. maskedValue = maskedValue.reverse();
  3362. }
  3363. var charAtPos = maskedValue[caretPos];
  3364. if (charAtPos === opts.groupSeparator) {
  3365. caretPos += 1;
  3366. charAtPos = maskedValue[caretPos];
  3367. }
  3368. if (caretPos === maskedValue.length - opts.suffix.length - 1 && charAtPos === opts.radixPoint) return currentResult;
  3369. if (charAtPos !== undefined) {
  3370. if (charAtPos !== opts.radixPoint && charAtPos !== opts.negationSymbol.front && charAtPos !== opts.negationSymbol.back) {
  3371. maskedValue[caretPos] = "?";
  3372. if (opts.prefix.length > 0 && caretPos >= (opts.isNegative === false ? 1 : 0) && caretPos < opts.prefix.length - 1 + (opts.isNegative === false ? 1 : 0)) {
  3373. prefix[caretPos - (opts.isNegative === false ? 1 : 0)] = "?";
  3374. } else if (opts.suffix.length > 0 && caretPos >= maskedValue.length - opts.suffix.length - (opts.isNegative === false ? 1 : 0)) {
  3375. suffix[caretPos - (maskedValue.length - opts.suffix.length - (opts.isNegative === false ? 1 : 0))] = "?";
  3376. }
  3377. }
  3378. }
  3379. prefix = prefix.join("");
  3380. suffix = suffix.join("");
  3381. var processValue = maskedValue.join("").replace(prefix, "");
  3382. processValue = processValue.replace(suffix, "");
  3383. processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
  3384. processValue = processValue.replace(new RegExp("[-" + Inputmask.escapeRegex(opts.negationSymbol.front) + "]", "g"), "");
  3385. processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.negationSymbol.back) + "$"), "");
  3386. if (isNaN(opts.placeholder)) {
  3387. processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.placeholder), "g"), "");
  3388. }
  3389. if (processValue.length > 1 && processValue.indexOf(opts.radixPoint) !== 1) {
  3390. if (charAtPos === "0") {
  3391. processValue = processValue.replace(/^\?/g, "");
  3392. }
  3393. processValue = processValue.replace(/^0/g, "");
  3394. }
  3395. if (processValue.charAt(0) === opts.radixPoint && opts.radixPoint !== "" && opts.numericInput !== true) {
  3396. processValue = "0" + processValue;
  3397. }
  3398. if (processValue !== "") {
  3399. processValue = processValue.split("");
  3400. if ((!opts.digitsOptional || opts.enforceDigitsOnBlur && currentResult.event === "blur") && isFinite(opts.digits)) {
  3401. var radixPosition = $.inArray(opts.radixPoint, processValue);
  3402. var rpb = $.inArray(opts.radixPoint, maskedValue);
  3403. if (radixPosition === -1) {
  3404. processValue.push(opts.radixPoint);
  3405. radixPosition = processValue.length - 1;
  3406. }
  3407. for (var i = 1; i <= opts.digits; i++) {
  3408. if ((!opts.digitsOptional || opts.enforceDigitsOnBlur && currentResult.event === "blur") && (processValue[radixPosition + i] === undefined || processValue[radixPosition + i] === opts.placeholder.charAt(0))) {
  3409. processValue[radixPosition + i] = currentResult.placeholder || opts.placeholder.charAt(0);
  3410. } else if (rpb !== -1 && maskedValue[rpb + i] !== undefined) {
  3411. processValue[radixPosition + i] = processValue[radixPosition + i] || maskedValue[rpb + i];
  3412. }
  3413. }
  3414. }
  3415. if (opts.autoGroup === true && opts.groupSeparator !== "" && (charAtPos !== opts.radixPoint || currentResult.pos !== undefined || currentResult.dopost)) {
  3416. var addRadix = processValue[processValue.length - 1] === opts.radixPoint && currentResult.c === opts.radixPoint;
  3417. processValue = Inputmask(buildPostMask(processValue, opts), {
  3418. numericInput: true,
  3419. jitMasking: true,
  3420. definitions: {
  3421. "*": {
  3422. validator: "[0-9?]",
  3423. cardinality: 1
  3424. }
  3425. }
  3426. }).format(processValue.join(""));
  3427. if (addRadix) processValue += opts.radixPoint;
  3428. if (processValue.charAt(0) === opts.groupSeparator) {
  3429. processValue.substr(1);
  3430. }
  3431. } else processValue = processValue.join("");
  3432. }
  3433. if (opts.isNegative && currentResult.event === "blur") {
  3434. opts.isNegative = processValue !== "0";
  3435. }
  3436. processValue = prefix + processValue;
  3437. processValue += suffix;
  3438. if (opts.isNegative) {
  3439. processValue = opts.negationSymbol.front + processValue;
  3440. processValue += opts.negationSymbol.back;
  3441. }
  3442. processValue = processValue.split("");
  3443. if (charAtPos !== undefined) {
  3444. if (charAtPos !== opts.radixPoint && charAtPos !== opts.negationSymbol.front && charAtPos !== opts.negationSymbol.back) {
  3445. caretPos = $.inArray("?", processValue);
  3446. if (caretPos > -1) {
  3447. processValue[caretPos] = charAtPos;
  3448. } else caretPos = currentResult.caret || 0;
  3449. } else if (charAtPos === opts.radixPoint || charAtPos === opts.negationSymbol.front || charAtPos === opts.negationSymbol.back) {
  3450. var newCaretPos = $.inArray(charAtPos, processValue);
  3451. if (newCaretPos !== -1) caretPos = newCaretPos;
  3452. }
  3453. }
  3454. if (opts.numericInput) {
  3455. caretPos = processValue.length - caretPos - 1;
  3456. processValue = processValue.reverse();
  3457. }
  3458. var rslt = {
  3459. caret: (charAtPos === undefined || currentResult.pos !== undefined) && caretPos !== undefined ? caretPos + (opts.numericInput ? -1 : 1) : caretPos,
  3460. buffer: processValue,
  3461. refreshFromBuffer: currentResult.dopost || buffer.join("") !== processValue.join("")
  3462. };
  3463. return rslt.refreshFromBuffer ? rslt : currentResult;
  3464. },
  3465. onBeforeWrite: function onBeforeWrite(e, buffer, caretPos, opts) {
  3466. function parseMinMaxOptions(opts) {
  3467. if (opts.parseMinMaxOptions === undefined) {
  3468. if (opts.min !== null) {
  3469. opts.min = opts.min.toString().replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
  3470. if (opts.radixPoint === ",") opts.min = opts.min.replace(opts.radixPoint, ".");
  3471. opts.min = isFinite(opts.min) ? parseFloat(opts.min) : NaN;
  3472. if (isNaN(opts.min)) opts.min = Number.MIN_VALUE;
  3473. }
  3474. if (opts.max !== null) {
  3475. opts.max = opts.max.toString().replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
  3476. if (opts.radixPoint === ",") opts.max = opts.max.replace(opts.radixPoint, ".");
  3477. opts.max = isFinite(opts.max) ? parseFloat(opts.max) : NaN;
  3478. if (isNaN(opts.max)) opts.max = Number.MAX_VALUE;
  3479. }
  3480. opts.parseMinMaxOptions = "done";
  3481. }
  3482. }
  3483. if (e) {
  3484. switch (e.type) {
  3485. case "keydown":
  3486. return opts.postValidation(buffer, caretPos, {
  3487. caret: caretPos,
  3488. dopost: true
  3489. }, opts);
  3490. case "blur":
  3491. case "checkval":
  3492. var unmasked;
  3493. parseMinMaxOptions(opts);
  3494. if (opts.min !== null || opts.max !== null) {
  3495. unmasked = opts.onUnMask(buffer.join(""), undefined, $.extend({}, opts, {
  3496. unmaskAsNumber: true
  3497. }));
  3498. if (opts.min !== null && unmasked < opts.min) {
  3499. opts.isNegative = opts.min < 0;
  3500. return opts.postValidation(opts.min.toString().replace(".", opts.radixPoint).split(""), caretPos, {
  3501. caret: caretPos,
  3502. dopost: true,
  3503. placeholder: "0"
  3504. }, opts);
  3505. } else if (opts.max !== null && unmasked > opts.max) {
  3506. opts.isNegative = opts.max < 0;
  3507. return opts.postValidation(opts.max.toString().replace(".", opts.radixPoint).split(""), caretPos, {
  3508. caret: caretPos,
  3509. dopost: true,
  3510. placeholder: "0"
  3511. }, opts);
  3512. }
  3513. }
  3514. return opts.postValidation(buffer, caretPos, {
  3515. caret: caretPos,
  3516. placeholder: "0",
  3517. event: "blur"
  3518. }, opts);
  3519. case "_checkval":
  3520. return {
  3521. caret: caretPos
  3522. };
  3523. default:
  3524. break;
  3525. }
  3526. }
  3527. },
  3528. regex: {
  3529. integerPart: function integerPart(opts, emptyCheck) {
  3530. return emptyCheck ? new RegExp("[" + Inputmask.escapeRegex(opts.negationSymbol.front) + "+]?") : new RegExp("[" + Inputmask.escapeRegex(opts.negationSymbol.front) + "+]?\\d+");
  3531. },
  3532. integerNPart: function integerNPart(opts) {
  3533. return new RegExp("[\\d" + Inputmask.escapeRegex(opts.groupSeparator) + Inputmask.escapeRegex(opts.placeholder.charAt(0)) + "]+");
  3534. }
  3535. },
  3536. definitions: {
  3537. "~": {
  3538. validator: function validator(chrs, maskset, pos, strict, opts, isSelection) {
  3539. var isValid, l;
  3540. if (chrs === "k" || chrs === "m") {
  3541. isValid = {
  3542. insert: [],
  3543. c: 0
  3544. };
  3545. for (var i = 0, l = chrs === "k" ? 2 : 5; i < l; i++) {
  3546. isValid.insert.push({
  3547. pos: pos + i,
  3548. c: 0
  3549. });
  3550. }
  3551. isValid.pos = pos + l;
  3552. return isValid;
  3553. }
  3554. isValid = strict ? new RegExp("[0-9" + Inputmask.escapeRegex(opts.groupSeparator) + "]").test(chrs) : new RegExp("[0-9]").test(chrs);
  3555. if (isValid === true) {
  3556. if (opts.numericInput !== true && maskset.validPositions[pos] !== undefined && maskset.validPositions[pos].match.def === "~" && !isSelection) {
  3557. var processValue = maskset.buffer.join("");
  3558. processValue = processValue.replace(new RegExp("[-" + Inputmask.escapeRegex(opts.negationSymbol.front) + "]", "g"), "");
  3559. processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.negationSymbol.back) + "$"), "");
  3560. var pvRadixSplit = processValue.split(opts.radixPoint);
  3561. if (pvRadixSplit.length > 1) {
  3562. pvRadixSplit[1] = pvRadixSplit[1].replace(/0/g, opts.placeholder.charAt(0));
  3563. }
  3564. if (pvRadixSplit[0] === "0") {
  3565. pvRadixSplit[0] = pvRadixSplit[0].replace(/0/g, opts.placeholder.charAt(0));
  3566. }
  3567. processValue = pvRadixSplit[0] + opts.radixPoint + pvRadixSplit[1] || "";
  3568. var bufferTemplate = maskset._buffer.join("");
  3569. if (processValue === opts.radixPoint) {
  3570. processValue = bufferTemplate;
  3571. }
  3572. while (processValue.match(Inputmask.escapeRegex(bufferTemplate) + "$") === null) {
  3573. bufferTemplate = bufferTemplate.slice(1);
  3574. }
  3575. processValue = processValue.replace(bufferTemplate, "");
  3576. processValue = processValue.split("");
  3577. if (processValue[pos] === undefined) {
  3578. isValid = {
  3579. pos: pos,
  3580. remove: pos
  3581. };
  3582. } else {
  3583. isValid = {
  3584. pos: pos
  3585. };
  3586. }
  3587. }
  3588. } else if (!strict && chrs === opts.radixPoint && maskset.validPositions[pos - 1] === undefined) {
  3589. isValid = {
  3590. insert: {
  3591. pos: pos,
  3592. c: 0
  3593. },
  3594. pos: pos + 1
  3595. };
  3596. }
  3597. return isValid;
  3598. },
  3599. cardinality: 1
  3600. },
  3601. "+": {
  3602. validator: function validator(chrs, maskset, pos, strict, opts) {
  3603. return opts.allowMinus && (chrs === "-" || chrs === opts.negationSymbol.front);
  3604. },
  3605. cardinality: 1,
  3606. placeholder: ""
  3607. },
  3608. "-": {
  3609. validator: function validator(chrs, maskset, pos, strict, opts) {
  3610. return opts.allowMinus && chrs === opts.negationSymbol.back;
  3611. },
  3612. cardinality: 1,
  3613. placeholder: ""
  3614. },
  3615. ":": {
  3616. validator: function validator(chrs, maskset, pos, strict, opts) {
  3617. var radix = "[" + Inputmask.escapeRegex(opts.radixPoint) + "]";
  3618. var isValid = new RegExp(radix).test(chrs);
  3619. if (isValid && maskset.validPositions[pos] && maskset.validPositions[pos].match.placeholder === opts.radixPoint) {
  3620. isValid = {
  3621. caret: pos + 1
  3622. };
  3623. }
  3624. return isValid;
  3625. },
  3626. cardinality: 1,
  3627. placeholder: function placeholder(opts) {
  3628. return opts.radixPoint;
  3629. }
  3630. }
  3631. },
  3632. onUnMask: function onUnMask(maskedValue, unmaskedValue, opts) {
  3633. if (unmaskedValue === "" && opts.nullable === true) {
  3634. return unmaskedValue;
  3635. }
  3636. var processValue = maskedValue.replace(opts.prefix, "");
  3637. processValue = processValue.replace(opts.suffix, "");
  3638. processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
  3639. if (opts.placeholder.charAt(0) !== "") {
  3640. processValue = processValue.replace(new RegExp(opts.placeholder.charAt(0), "g"), "0");
  3641. }
  3642. if (opts.unmaskAsNumber) {
  3643. if (opts.radixPoint !== "" && processValue.indexOf(opts.radixPoint) !== -1) processValue = processValue.replace(Inputmask.escapeRegex.call(this, opts.radixPoint), ".");
  3644. processValue = processValue.replace(new RegExp("^" + Inputmask.escapeRegex(opts.negationSymbol.front)), "-");
  3645. processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.negationSymbol.back) + "$"), "");
  3646. return Number(processValue);
  3647. }
  3648. return processValue;
  3649. },
  3650. isComplete: function isComplete(buffer, opts) {
  3651. var maskedValue = (opts.numericInput ? buffer.slice().reverse() : buffer).join("");
  3652. maskedValue = maskedValue.replace(new RegExp("^" + Inputmask.escapeRegex(opts.negationSymbol.front)), "-");
  3653. maskedValue = maskedValue.replace(new RegExp(Inputmask.escapeRegex(opts.negationSymbol.back) + "$"), "");
  3654. maskedValue = maskedValue.replace(opts.prefix, "");
  3655. maskedValue = maskedValue.replace(opts.suffix, "");
  3656. maskedValue = maskedValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator) + "([0-9]{3})", "g"), "$1");
  3657. if (opts.radixPoint === ",") maskedValue = maskedValue.replace(Inputmask.escapeRegex(opts.radixPoint), ".");
  3658. return isFinite(maskedValue);
  3659. },
  3660. onBeforeMask: function onBeforeMask(initialValue, opts) {
  3661. opts.isNegative = undefined;
  3662. var radixPoint = opts.radixPoint || ",";
  3663. if ((typeof initialValue == "number" || opts.inputType === "number") && radixPoint !== "") {
  3664. initialValue = initialValue.toString().replace(".", radixPoint);
  3665. }
  3666. var valueParts = initialValue.split(radixPoint), integerPart = valueParts[0].replace(/[^\-0-9]/g, ""), decimalPart = valueParts.length > 1 ? valueParts[1].replace(/[^0-9]/g, "") : "";
  3667. initialValue = integerPart + (decimalPart !== "" ? radixPoint + decimalPart : decimalPart);
  3668. var digits = 0;
  3669. if (radixPoint !== "") {
  3670. digits = decimalPart.length;
  3671. if (decimalPart !== "") {
  3672. var digitsFactor = Math.pow(10, digits || 1);
  3673. if (isFinite(opts.digits)) {
  3674. digits = parseInt(opts.digits);
  3675. digitsFactor = Math.pow(10, digits);
  3676. }
  3677. initialValue = initialValue.replace(Inputmask.escapeRegex(radixPoint), ".");
  3678. if (isFinite(initialValue)) initialValue = Math.round(parseFloat(initialValue) * digitsFactor) / digitsFactor;
  3679. initialValue = initialValue.toString().replace(".", radixPoint);
  3680. }
  3681. }
  3682. if (opts.digits === 0 && initialValue.indexOf(Inputmask.escapeRegex(radixPoint)) !== -1) {
  3683. initialValue = initialValue.substring(0, initialValue.indexOf(Inputmask.escapeRegex(radixPoint)));
  3684. }
  3685. return alignDigits(initialValue.toString().split(""), digits, opts).join("");
  3686. },
  3687. onKeyDown: function onKeyDown(e, buffer, caretPos, opts) {
  3688. var $input = $(this);
  3689. if (e.ctrlKey) {
  3690. switch (e.keyCode) {
  3691. case Inputmask.keyCode.UP:
  3692. $input.val(parseFloat(this.inputmask.unmaskedvalue()) + parseInt(opts.step));
  3693. $input.trigger("setvalue");
  3694. break;
  3695. case Inputmask.keyCode.DOWN:
  3696. $input.val(parseFloat(this.inputmask.unmaskedvalue()) - parseInt(opts.step));
  3697. $input.trigger("setvalue");
  3698. break;
  3699. }
  3700. }
  3701. }
  3702. },
  3703. currency: {
  3704. prefix: "$ ",
  3705. groupSeparator: ",",
  3706. alias: "numeric",
  3707. placeholder: "0",
  3708. autoGroup: true,
  3709. digits: 2,
  3710. digitsOptional: false,
  3711. clearMaskOnLostFocus: false
  3712. },
  3713. decimal: {
  3714. alias: "numeric"
  3715. },
  3716. integer: {
  3717. alias: "numeric",
  3718. digits: 0,
  3719. radixPoint: ""
  3720. },
  3721. percentage: {
  3722. alias: "numeric",
  3723. digits: 2,
  3724. digitsOptional: true,
  3725. radixPoint: ".",
  3726. placeholder: "0",
  3727. autoGroup: false,
  3728. min: 0,
  3729. max: 100,
  3730. suffix: " %",
  3731. allowMinus: false
  3732. }
  3733. });
  3734. return Inputmask;
  3735. });
  3736. }, function(module, exports, __webpack_require__) {
  3737. "use strict";
  3738. var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;
  3739. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function(obj) {
  3740. return typeof obj;
  3741. } : function(obj) {
  3742. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  3743. };
  3744. (function(factory) {
  3745. if (true) {
  3746. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [ __webpack_require__(4), __webpack_require__(2) ],
  3747. __WEBPACK_AMD_DEFINE_FACTORY__ = factory, __WEBPACK_AMD_DEFINE_RESULT__ = typeof __WEBPACK_AMD_DEFINE_FACTORY__ === "function" ? __WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__) : __WEBPACK_AMD_DEFINE_FACTORY__,
  3748. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  3749. } else {}
  3750. })(function($, Inputmask) {
  3751. if ($.fn.inputmask === undefined) {
  3752. $.fn.inputmask = function(fn, options) {
  3753. var nptmask, input = this[0];
  3754. if (options === undefined) options = {};
  3755. if (typeof fn === "string") {
  3756. switch (fn) {
  3757. case "unmaskedvalue":
  3758. return input && input.inputmask ? input.inputmask.unmaskedvalue() : $(input).val();
  3759. case "remove":
  3760. return this.each(function() {
  3761. if (this.inputmask) this.inputmask.remove();
  3762. });
  3763. case "getemptymask":
  3764. return input && input.inputmask ? input.inputmask.getemptymask() : "";
  3765. case "hasMaskedValue":
  3766. return input && input.inputmask ? input.inputmask.hasMaskedValue() : false;
  3767. case "isComplete":
  3768. return input && input.inputmask ? input.inputmask.isComplete() : true;
  3769. case "getmetadata":
  3770. return input && input.inputmask ? input.inputmask.getmetadata() : undefined;
  3771. case "setvalue":
  3772. Inputmask.setValue(input, options);
  3773. break;
  3774. case "option":
  3775. if (typeof options === "string") {
  3776. if (input && input.inputmask !== undefined) {
  3777. return input.inputmask.option(options);
  3778. }
  3779. } else {
  3780. return this.each(function() {
  3781. if (this.inputmask !== undefined) {
  3782. return this.inputmask.option(options);
  3783. }
  3784. });
  3785. }
  3786. break;
  3787. default:
  3788. options.alias = fn;
  3789. nptmask = new Inputmask(options);
  3790. return this.each(function() {
  3791. nptmask.mask(this);
  3792. });
  3793. }
  3794. } else if (Array.isArray(fn)) {
  3795. options.alias = fn;
  3796. nptmask = new Inputmask(options);
  3797. return this.each(function() {
  3798. nptmask.mask(this);
  3799. });
  3800. } else if ((typeof fn === "undefined" ? "undefined" : _typeof(fn)) == "object") {
  3801. nptmask = new Inputmask(fn);
  3802. if (fn.mask === undefined && fn.alias === undefined) {
  3803. return this.each(function() {
  3804. if (this.inputmask !== undefined) {
  3805. return this.inputmask.option(fn);
  3806. } else nptmask.mask(this);
  3807. });
  3808. } else {
  3809. return this.each(function() {
  3810. nptmask.mask(this);
  3811. });
  3812. }
  3813. } else if (fn === undefined) {
  3814. return this.each(function() {
  3815. nptmask = new Inputmask(options);
  3816. nptmask.mask(this);
  3817. });
  3818. }
  3819. };
  3820. }
  3821. return $.fn.inputmask;
  3822. });
  3823. } ]);