inputmask.js 110 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557
  1. /*!
  2. * inputmask.js
  3. * https://github.com/RobinHerbots/jquery.inputmask
  4. * Copyright (c) 2010 - 2017 Robin Herbots
  5. * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. * Version: 3.3.5-2
  7. */
  8. !function(factory) {
  9. "function" == typeof define && define.amd ? define("inputmask", [ "inputmask.dependencyLib" ], factory) : "object" == typeof exports ? module.exports = factory(require("./inputmask.dependencyLib")) : factory(window.dependencyLib || jQuery);
  10. }(function($) {
  11. function Inputmask(alias, options) {
  12. return this instanceof Inputmask ? ($.isPlainObject(alias) ? options = alias : (options = options || {},
  13. options.alias = alias), this.el = void 0, this.opts = $.extend(!0, {}, this.defaults, options),
  14. this.maskset = void 0, this.noMasksCache = options && void 0 !== options.definitions,
  15. this.userOptions = options || {}, this.events = {}, this.dataAttribute = "data-inputmask",
  16. this.isRTL = this.opts.numericInput, void resolveAlias(this.opts.alias, options, this.opts)) : new Inputmask(alias, options);
  17. }
  18. function resolveAlias(aliasStr, options, opts) {
  19. var aliasDefinition = opts.aliases[aliasStr];
  20. return aliasDefinition ? (aliasDefinition.alias && resolveAlias(aliasDefinition.alias, void 0, opts),
  21. $.extend(!0, opts, aliasDefinition), $.extend(!0, opts, options), !0) : (null === opts.mask && (opts.mask = aliasStr),
  22. !1);
  23. }
  24. function generateMaskSet(opts, nocache) {
  25. function generateMask(mask, metadata, opts) {
  26. if (null !== mask && "" !== mask) {
  27. if (1 === mask.length && opts.greedy === !1 && 0 !== opts.repeat && (opts.placeholder = ""),
  28. opts.repeat > 0 || "*" === opts.repeat || "+" === opts.repeat) {
  29. var repeatStart = "*" === opts.repeat ? 0 : "+" === opts.repeat ? 1 : opts.repeat;
  30. mask = opts.groupmarker.start + mask + opts.groupmarker.end + opts.quantifiermarker.start + repeatStart + "," + opts.repeat + opts.quantifiermarker.end;
  31. }
  32. var masksetDefinition;
  33. return void 0 === Inputmask.prototype.masksCache[mask] || nocache === !0 ? (masksetDefinition = {
  34. mask: mask,
  35. maskToken: Inputmask.prototype.analyseMask(mask, opts),
  36. validPositions: {},
  37. _buffer: void 0,
  38. buffer: void 0,
  39. tests: {},
  40. metadata: metadata,
  41. maskLength: void 0
  42. }, nocache !== !0 && (Inputmask.prototype.masksCache[opts.numericInput ? mask.split("").reverse().join("") : mask] = masksetDefinition,
  43. masksetDefinition = $.extend(!0, {}, Inputmask.prototype.masksCache[opts.numericInput ? mask.split("").reverse().join("") : mask]))) : masksetDefinition = $.extend(!0, {}, Inputmask.prototype.masksCache[opts.numericInput ? mask.split("").reverse().join("") : mask]),
  44. masksetDefinition;
  45. }
  46. }
  47. var ms;
  48. if ($.isFunction(opts.mask) && (opts.mask = opts.mask(opts)), $.isArray(opts.mask)) {
  49. if (opts.mask.length > 1) {
  50. opts.keepStatic = null === opts.keepStatic || opts.keepStatic;
  51. var altMask = opts.groupmarker.start;
  52. return $.each(opts.numericInput ? opts.mask.reverse() : opts.mask, function(ndx, msk) {
  53. altMask.length > 1 && (altMask += opts.groupmarker.end + opts.alternatormarker + opts.groupmarker.start),
  54. altMask += void 0 === msk.mask || $.isFunction(msk.mask) ? msk : msk.mask;
  55. }), altMask += opts.groupmarker.end, generateMask(altMask, opts.mask, opts);
  56. }
  57. opts.mask = opts.mask.pop();
  58. }
  59. return opts.mask && (ms = void 0 === opts.mask.mask || $.isFunction(opts.mask.mask) ? generateMask(opts.mask, opts.mask, opts) : generateMask(opts.mask.mask, opts.mask, opts)),
  60. ms;
  61. }
  62. function maskScope(actionObj, maskset, opts) {
  63. function getMaskTemplate(baseOnInput, minimalPos, includeMode) {
  64. minimalPos = minimalPos || 0;
  65. var ndxIntlzr, test, testPos, maskTemplate = [], pos = 0, lvp = getLastValidPosition();
  66. maxLength = void 0 !== el ? el.maxLength : void 0, maxLength === -1 && (maxLength = void 0);
  67. do baseOnInput === !0 && getMaskSet().validPositions[pos] ? (testPos = getMaskSet().validPositions[pos],
  68. test = testPos.match, ndxIntlzr = testPos.locator.slice(), maskTemplate.push(includeMode === !0 ? testPos.input : includeMode === !1 ? test.nativeDef : getPlaceholder(pos, test))) : (testPos = getTestTemplate(pos, ndxIntlzr, pos - 1),
  69. test = testPos.match, ndxIntlzr = testPos.locator.slice(), (opts.jitMasking === !1 || pos < lvp || "number" == typeof opts.jitMasking && isFinite(opts.jitMasking) && opts.jitMasking > pos) && maskTemplate.push(includeMode === !1 ? test.nativeDef : getPlaceholder(pos, test))),
  70. pos++; while ((void 0 === maxLength || pos < maxLength) && (null !== test.fn || "" !== test.def) || minimalPos > pos);
  71. return "" === maskTemplate[maskTemplate.length - 1] && maskTemplate.pop(), getMaskSet().maskLength = pos + 1,
  72. maskTemplate;
  73. }
  74. function getMaskSet() {
  75. return maskset;
  76. }
  77. function resetMaskSet(soft) {
  78. var maskset = getMaskSet();
  79. maskset.buffer = void 0, soft !== !0 && (maskset._buffer = void 0, maskset.validPositions = {},
  80. maskset.p = 0);
  81. }
  82. function getLastValidPosition(closestTo, strict, validPositions) {
  83. var before = -1, after = -1, valids = validPositions || getMaskSet().validPositions;
  84. void 0 === closestTo && (closestTo = -1);
  85. for (var posNdx in valids) {
  86. var psNdx = parseInt(posNdx);
  87. valids[psNdx] && (strict || valids[psNdx].generatedInput !== !0) && (psNdx <= closestTo && (before = psNdx),
  88. psNdx >= closestTo && (after = psNdx));
  89. }
  90. return before !== -1 && closestTo - before > 1 || after < closestTo ? before : after;
  91. }
  92. function stripValidPositions(start, end, nocheck, strict) {
  93. function IsEnclosedStatic(pos) {
  94. var posMatch = getMaskSet().validPositions[pos];
  95. if (void 0 !== posMatch && null === posMatch.match.fn) {
  96. var prevMatch = getMaskSet().validPositions[pos - 1], nextMatch = getMaskSet().validPositions[pos + 1];
  97. return void 0 !== prevMatch && void 0 !== nextMatch;
  98. }
  99. return !1;
  100. }
  101. var i, startPos = start, positionsClone = $.extend(!0, {}, getMaskSet().validPositions), needsValidation = !1;
  102. for (getMaskSet().p = start, i = end - 1; i >= startPos; i--) void 0 !== getMaskSet().validPositions[i] && (nocheck !== !0 && (!getMaskSet().validPositions[i].match.optionality && IsEnclosedStatic(i) || opts.canClearPosition(getMaskSet(), i, getLastValidPosition(), strict, opts) === !1) || delete getMaskSet().validPositions[i]);
  103. for (resetMaskSet(!0), i = startPos + 1; i <= getLastValidPosition(); ) {
  104. for (;void 0 !== getMaskSet().validPositions[startPos]; ) startPos++;
  105. if (i < startPos && (i = startPos + 1), void 0 === getMaskSet().validPositions[i] && isMask(i)) i++; else {
  106. var t = getTestTemplate(i);
  107. needsValidation === !1 && positionsClone[startPos] && positionsClone[startPos].match.def === t.match.def ? (getMaskSet().validPositions[startPos] = $.extend(!0, {}, positionsClone[startPos]),
  108. getMaskSet().validPositions[startPos].input = t.input, delete getMaskSet().validPositions[i],
  109. i++) : positionCanMatchDefinition(startPos, t.match.def) ? isValid(startPos, t.input || getPlaceholder(i), !0) !== !1 && (delete getMaskSet().validPositions[i],
  110. i++, needsValidation = !0) : isMask(i) || (i++, startPos--), startPos++;
  111. }
  112. }
  113. resetMaskSet(!0);
  114. }
  115. function determineTestTemplate(tests, guessNextBest) {
  116. for (var testPos, testPositions = tests, lvp = getLastValidPosition(), lvTest = getMaskSet().validPositions[lvp] || getTests(0)[0], lvTestAltArr = void 0 !== lvTest.alternation ? lvTest.locator[lvTest.alternation].toString().split(",") : [], ndx = 0; ndx < testPositions.length && (testPos = testPositions[ndx],
  117. !(testPos.match && (opts.greedy && testPos.match.optionalQuantifier !== !0 || (testPos.match.optionality === !1 || testPos.match.newBlockMarker === !1) && testPos.match.optionalQuantifier !== !0) && (void 0 === lvTest.alternation || lvTest.alternation !== testPos.alternation || void 0 !== testPos.locator[lvTest.alternation] && checkAlternationMatch(testPos.locator[lvTest.alternation].toString().split(","), lvTestAltArr))) || guessNextBest === !0 && (null !== testPos.match.fn || /[0-9a-bA-Z]/.test(testPos.match.def))); ndx++) ;
  118. return testPos;
  119. }
  120. function getTestTemplate(pos, ndxIntlzr, tstPs) {
  121. return getMaskSet().validPositions[pos] || determineTestTemplate(getTests(pos, ndxIntlzr ? ndxIntlzr.slice() : ndxIntlzr, tstPs));
  122. }
  123. function getTest(pos) {
  124. return getMaskSet().validPositions[pos] ? getMaskSet().validPositions[pos] : getTests(pos)[0];
  125. }
  126. function positionCanMatchDefinition(pos, def) {
  127. for (var valid = !1, tests = getTests(pos), tndx = 0; tndx < tests.length; tndx++) if (tests[tndx].match && tests[tndx].match.def === def) {
  128. valid = !0;
  129. break;
  130. }
  131. return valid;
  132. }
  133. function getTests(pos, ndxIntlzr, tstPs) {
  134. function resolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) {
  135. function handleMatch(match, loopNdx, quantifierRecurse) {
  136. function isFirstMatch(latestMatch, tokenGroup) {
  137. var firstMatch = 0 === $.inArray(latestMatch, tokenGroup.matches);
  138. return firstMatch || $.each(tokenGroup.matches, function(ndx, match) {
  139. if (match.isQuantifier === !0 && (firstMatch = isFirstMatch(latestMatch, tokenGroup.matches[ndx - 1]))) return !1;
  140. }), firstMatch;
  141. }
  142. function resolveNdxInitializer(pos, alternateNdx, targetAlternation) {
  143. var bestMatch, indexPos;
  144. return (getMaskSet().tests[pos] || getMaskSet().validPositions[pos]) && $.each(getMaskSet().tests[pos] || [ getMaskSet().validPositions[pos] ], function(ndx, lmnt) {
  145. var alternation = void 0 !== targetAlternation ? targetAlternation : lmnt.alternation, ndxPos = void 0 !== lmnt.locator[alternation] ? lmnt.locator[alternation].toString().indexOf(alternateNdx) : -1;
  146. (void 0 === indexPos || ndxPos < indexPos) && ndxPos !== -1 && (bestMatch = lmnt,
  147. indexPos = ndxPos);
  148. }), bestMatch ? bestMatch.locator.slice((void 0 !== targetAlternation ? targetAlternation : bestMatch.alternation) + 1) : void 0 !== targetAlternation ? resolveNdxInitializer(pos, alternateNdx) : void 0;
  149. }
  150. function staticCanMatchDefinition(source, target) {
  151. return null === source.match.fn && null !== target.match.fn && target.match.fn.test(source.match.def, getMaskSet(), pos, !1, opts, !1);
  152. }
  153. if (testPos > 1e4) 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;
  154. if (testPos === pos && void 0 === match.matches) return matches.push({
  155. match: match,
  156. locator: loopNdx.reverse(),
  157. cd: cacheDependency
  158. }), !0;
  159. if (void 0 !== match.matches) {
  160. if (match.isGroup && quantifierRecurse !== match) {
  161. if (match = handleMatch(maskToken.matches[$.inArray(match, maskToken.matches) + 1], loopNdx)) return !0;
  162. } else if (match.isOptional) {
  163. var optionalToken = match;
  164. if (match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse)) {
  165. if (latestMatch = matches[matches.length - 1].match, !isFirstMatch(latestMatch, optionalToken)) return !0;
  166. insertStop = !0, testPos = pos;
  167. }
  168. } else if (match.isAlternator) {
  169. var maltMatches, alternateToken = match, malternateMatches = [], currentMatches = matches.slice(), loopNdxCnt = loopNdx.length, altIndex = ndxInitializer.length > 0 ? ndxInitializer.shift() : -1;
  170. if (altIndex === -1 || "string" == typeof altIndex) {
  171. var amndx, currentPos = testPos, ndxInitializerClone = ndxInitializer.slice(), altIndexArr = [];
  172. if ("string" == typeof altIndex) altIndexArr = altIndex.split(","); else for (amndx = 0; amndx < alternateToken.matches.length; amndx++) altIndexArr.push(amndx);
  173. for (var ndx = 0; ndx < altIndexArr.length; ndx++) {
  174. if (amndx = parseInt(altIndexArr[ndx]), matches = [], ndxInitializer = resolveNdxInitializer(testPos, amndx, loopNdxCnt) || ndxInitializerClone.slice(),
  175. match = handleMatch(alternateToken.matches[amndx] || maskToken.matches[amndx], [ amndx ].concat(loopNdx), quantifierRecurse) || match,
  176. match !== !0 && void 0 !== match && altIndexArr[altIndexArr.length - 1] < alternateToken.matches.length) {
  177. var ntndx = $.inArray(match, maskToken.matches) + 1;
  178. maskToken.matches.length > ntndx && (match = handleMatch(maskToken.matches[ntndx], [ ntndx ].concat(loopNdx.slice(1, loopNdx.length)), quantifierRecurse),
  179. match && (altIndexArr.push(ntndx.toString()), $.each(matches, function(ndx, lmnt) {
  180. lmnt.alternation = loopNdx.length - 1;
  181. })));
  182. }
  183. maltMatches = matches.slice(), testPos = currentPos, matches = [];
  184. for (var ndx1 = 0; ndx1 < maltMatches.length; ndx1++) {
  185. var altMatch = maltMatches[ndx1], hasMatch = !1;
  186. altMatch.alternation = altMatch.alternation || loopNdxCnt;
  187. for (var ndx2 = 0; ndx2 < malternateMatches.length; ndx2++) {
  188. var altMatch2 = malternateMatches[ndx2];
  189. if (("string" != typeof altIndex || $.inArray(altMatch.locator[altMatch.alternation].toString(), altIndexArr) !== -1) && (altMatch.match.def === altMatch2.match.def || staticCanMatchDefinition(altMatch, altMatch2))) {
  190. hasMatch = altMatch.match.nativeDef === altMatch2.match.nativeDef, altMatch.alternation == altMatch2.alternation && altMatch2.locator[altMatch2.alternation].toString().indexOf(altMatch.locator[altMatch.alternation]) === -1 && (altMatch2.locator[altMatch2.alternation] = altMatch2.locator[altMatch2.alternation] + "," + altMatch.locator[altMatch.alternation],
  191. altMatch2.alternation = altMatch.alternation, null == altMatch.match.fn && (altMatch2.na = altMatch2.na || altMatch.locator[altMatch.alternation].toString(),
  192. altMatch2.na.indexOf(altMatch.locator[altMatch.alternation]) === -1 && (altMatch2.na = altMatch2.na + "," + altMatch.locator[altMatch.alternation])));
  193. break;
  194. }
  195. }
  196. hasMatch || malternateMatches.push(altMatch);
  197. }
  198. }
  199. "string" == typeof altIndex && (malternateMatches = $.map(malternateMatches, function(lmnt, ndx) {
  200. if (isFinite(ndx)) {
  201. var mamatch, alternation = lmnt.alternation, altLocArr = lmnt.locator[alternation].toString().split(",");
  202. lmnt.locator[alternation] = void 0, lmnt.alternation = void 0;
  203. for (var alndx = 0; alndx < altLocArr.length; alndx++) mamatch = $.inArray(altLocArr[alndx], altIndexArr) !== -1,
  204. mamatch && (void 0 !== lmnt.locator[alternation] ? (lmnt.locator[alternation] += ",",
  205. lmnt.locator[alternation] += altLocArr[alndx]) : lmnt.locator[alternation] = parseInt(altLocArr[alndx]),
  206. lmnt.alternation = alternation);
  207. if (void 0 !== lmnt.locator[alternation]) return lmnt;
  208. }
  209. })), matches = currentMatches.concat(malternateMatches), testPos = pos, insertStop = matches.length > 0,
  210. ndxInitializer = ndxInitializerClone.slice();
  211. } else match = handleMatch(alternateToken.matches[altIndex] || maskToken.matches[altIndex], [ altIndex ].concat(loopNdx), quantifierRecurse);
  212. if (match) return !0;
  213. } else if (match.isQuantifier && quantifierRecurse !== maskToken.matches[$.inArray(match, maskToken.matches) - 1]) for (var qt = match, qndx = ndxInitializer.length > 0 ? ndxInitializer.shift() : 0; qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max) && testPos <= pos; qndx++) {
  214. var tokenGroup = maskToken.matches[$.inArray(qt, maskToken.matches) - 1];
  215. if (match = handleMatch(tokenGroup, [ qndx ].concat(loopNdx), tokenGroup)) {
  216. if (latestMatch = matches[matches.length - 1].match, latestMatch.optionalQuantifier = qndx > qt.quantifier.min - 1,
  217. isFirstMatch(latestMatch, tokenGroup)) {
  218. if (qndx > qt.quantifier.min - 1) {
  219. insertStop = !0, testPos = pos;
  220. break;
  221. }
  222. return !0;
  223. }
  224. return !0;
  225. }
  226. } else if (match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse)) return !0;
  227. } else testPos++;
  228. }
  229. for (var tndx = ndxInitializer.length > 0 ? ndxInitializer.shift() : 0; tndx < maskToken.matches.length; tndx++) if (maskToken.matches[tndx].isQuantifier !== !0) {
  230. var match = handleMatch(maskToken.matches[tndx], [ tndx ].concat(loopNdx), quantifierRecurse);
  231. if (match && testPos === pos) return match;
  232. if (testPos > pos) break;
  233. }
  234. }
  235. function mergeLocators(tests) {
  236. var locator = [];
  237. return $.isArray(tests) || (tests = [ tests ]), tests.length > 0 && (void 0 === tests[0].alternation ? (locator = determineTestTemplate(tests.slice()).locator.slice(),
  238. 0 === locator.length && (locator = tests[0].locator.slice())) : $.each(tests, function(ndx, tst) {
  239. if ("" !== tst.def) if (0 === locator.length) locator = tst.locator.slice(); else for (var i = 0; i < locator.length; i++) tst.locator[i] && locator[i].toString().indexOf(tst.locator[i]) === -1 && (locator[i] += "," + tst.locator[i]);
  240. })), locator;
  241. }
  242. function filterTests(tests) {
  243. return opts.keepStatic && pos > 0 && tests.length > 1 + ("" === tests[tests.length - 1].match.def ? 1 : 0) && tests[0].match.optionality !== !0 && tests[0].match.optionalQuantifier !== !0 && null === tests[0].match.fn && !/[0-9a-bA-Z]/.test(tests[0].match.def) ? [ determineTestTemplate(tests) ] : tests;
  244. }
  245. var latestMatch, maskTokens = getMaskSet().maskToken, testPos = ndxIntlzr ? tstPs : 0, ndxInitializer = ndxIntlzr ? ndxIntlzr.slice() : [ 0 ], matches = [], insertStop = !1, cacheDependency = ndxIntlzr ? ndxIntlzr.join("") : "";
  246. if (pos > -1) {
  247. if (void 0 === ndxIntlzr) {
  248. for (var test, previousPos = pos - 1; void 0 === (test = getMaskSet().validPositions[previousPos] || getMaskSet().tests[previousPos]) && previousPos > -1; ) previousPos--;
  249. void 0 !== test && previousPos > -1 && (ndxInitializer = mergeLocators(test), cacheDependency = ndxInitializer.join(""),
  250. testPos = previousPos);
  251. }
  252. if (getMaskSet().tests[pos] && getMaskSet().tests[pos][0].cd === cacheDependency) return filterTests(getMaskSet().tests[pos]);
  253. for (var mtndx = ndxInitializer.shift(); mtndx < maskTokens.length; mtndx++) {
  254. var match = resolveTestFromToken(maskTokens[mtndx], ndxInitializer, [ mtndx ]);
  255. if (match && testPos === pos || testPos > pos) break;
  256. }
  257. }
  258. return (0 === matches.length || insertStop) && matches.push({
  259. match: {
  260. fn: null,
  261. cardinality: 0,
  262. optionality: !0,
  263. casing: null,
  264. def: "",
  265. placeholder: ""
  266. },
  267. locator: [],
  268. cd: cacheDependency
  269. }), void 0 !== ndxIntlzr && getMaskSet().tests[pos] ? filterTests($.extend(!0, [], matches)) : (getMaskSet().tests[pos] = $.extend(!0, [], matches),
  270. filterTests(getMaskSet().tests[pos]));
  271. }
  272. function getBufferTemplate() {
  273. return void 0 === getMaskSet()._buffer && (getMaskSet()._buffer = getMaskTemplate(!1, 1),
  274. void 0 === getMaskSet().buffer && getMaskSet()._buffer.slice()), getMaskSet()._buffer;
  275. }
  276. function getBuffer(noCache) {
  277. return void 0 !== getMaskSet().buffer && noCache !== !0 || (getMaskSet().buffer = getMaskTemplate(!0, getLastValidPosition(), !0)),
  278. getMaskSet().buffer;
  279. }
  280. function refreshFromBuffer(start, end, buffer) {
  281. var i;
  282. if (start === !0) resetMaskSet(), start = 0, end = buffer.length; else for (i = start; i < end; i++) delete getMaskSet().validPositions[i];
  283. for (i = start; i < end; i++) resetMaskSet(!0), buffer[i] !== opts.skipOptionalPartCharacter && isValid(i, buffer[i], !0, !0);
  284. }
  285. function casing(elem, test, pos) {
  286. switch (opts.casing || test.casing) {
  287. case "upper":
  288. elem = elem.toUpperCase();
  289. break;
  290. case "lower":
  291. elem = elem.toLowerCase();
  292. break;
  293. case "title":
  294. var posBefore = getMaskSet().validPositions[pos - 1];
  295. elem = 0 === pos || posBefore && posBefore.input === String.fromCharCode(Inputmask.keyCode.SPACE) ? elem.toUpperCase() : elem.toLowerCase();
  296. }
  297. return elem;
  298. }
  299. function checkAlternationMatch(altArr1, altArr2) {
  300. for (var altArrC = opts.greedy ? altArr2 : altArr2.slice(0, 1), isMatch = !1, alndx = 0; alndx < altArr1.length; alndx++) if ($.inArray(altArr1[alndx], altArrC) !== -1) {
  301. isMatch = !0;
  302. break;
  303. }
  304. return isMatch;
  305. }
  306. function isValid(pos, c, strict, fromSetValid, fromAlternate) {
  307. function isSelection(posObj) {
  308. var selection = isRTL ? posObj.begin - posObj.end > 1 || posObj.begin - posObj.end === 1 && opts.insertMode : posObj.end - posObj.begin > 1 || posObj.end - posObj.begin === 1 && opts.insertMode;
  309. return selection && 0 === posObj.begin && posObj.end === getMaskSet().maskLength ? "full" : selection;
  310. }
  311. function _isValid(position, c, strict) {
  312. var rslt = !1;
  313. return $.each(getTests(position), function(ndx, tst) {
  314. for (var test = tst.match, loopend = c ? 1 : 0, chrs = "", i = test.cardinality; i > loopend; i--) chrs += getBufferElement(position - (i - 1));
  315. if (c && (chrs += c), getBuffer(!0), rslt = null != test.fn ? test.fn.test(chrs, getMaskSet(), position, strict, opts, isSelection(pos)) : (c === test.def || c === opts.skipOptionalPartCharacter) && "" !== test.def && {
  316. c: test.placeholder || test.def,
  317. pos: position
  318. }, rslt !== !1) {
  319. var elem = void 0 !== rslt.c ? rslt.c : c;
  320. elem = elem === opts.skipOptionalPartCharacter && null === test.fn ? test.placeholder || test.def : elem;
  321. var validatedPos = position, possibleModifiedBuffer = getBuffer();
  322. if (void 0 !== rslt.remove && ($.isArray(rslt.remove) || (rslt.remove = [ rslt.remove ]),
  323. $.each(rslt.remove.sort(function(a, b) {
  324. return b - a;
  325. }), function(ndx, lmnt) {
  326. stripValidPositions(lmnt, lmnt + 1, !0);
  327. })), void 0 !== rslt.insert && ($.isArray(rslt.insert) || (rslt.insert = [ rslt.insert ]),
  328. $.each(rslt.insert.sort(function(a, b) {
  329. return a - b;
  330. }), function(ndx, lmnt) {
  331. isValid(lmnt.pos, lmnt.c, !0, fromSetValid);
  332. })), rslt.refreshFromBuffer) {
  333. var refresh = rslt.refreshFromBuffer;
  334. if (strict = !0, refreshFromBuffer(refresh === !0 ? refresh : refresh.start, refresh.end, possibleModifiedBuffer),
  335. void 0 === rslt.pos && void 0 === rslt.c) return rslt.pos = getLastValidPosition(),
  336. !1;
  337. if (validatedPos = void 0 !== rslt.pos ? rslt.pos : position, validatedPos !== position) return rslt = $.extend(rslt, isValid(validatedPos, elem, !0, fromSetValid)),
  338. !1;
  339. } else if (rslt !== !0 && void 0 !== rslt.pos && rslt.pos !== position && (validatedPos = rslt.pos,
  340. refreshFromBuffer(position, validatedPos, getBuffer().slice()), validatedPos !== position)) return rslt = $.extend(rslt, isValid(validatedPos, elem, !0)),
  341. !1;
  342. return (rslt === !0 || void 0 !== rslt.pos || void 0 !== rslt.c) && (ndx > 0 && resetMaskSet(!0),
  343. setValidPosition(validatedPos, $.extend({}, tst, {
  344. input: casing(elem, test, validatedPos)
  345. }), fromSetValid, isSelection(pos)) || (rslt = !1), !1);
  346. }
  347. }), rslt;
  348. }
  349. function alternate(pos, c, strict) {
  350. var lastAlt, alternation, altPos, prevAltPos, i, validPos, altNdxs, decisionPos, validPsClone = $.extend(!0, {}, getMaskSet().validPositions), isValidRslt = !1, lAltPos = getLastValidPosition();
  351. for (prevAltPos = getMaskSet().validPositions[lAltPos]; lAltPos >= 0; lAltPos--) if (altPos = getMaskSet().validPositions[lAltPos],
  352. altPos && void 0 !== altPos.alternation) {
  353. if (lastAlt = lAltPos, alternation = getMaskSet().validPositions[lastAlt].alternation,
  354. prevAltPos.locator[altPos.alternation] !== altPos.locator[altPos.alternation]) break;
  355. prevAltPos = altPos;
  356. }
  357. if (void 0 !== alternation) {
  358. decisionPos = parseInt(lastAlt);
  359. var decisionTaker = void 0 !== prevAltPos.locator[prevAltPos.alternation || alternation] ? prevAltPos.locator[prevAltPos.alternation || alternation] : altNdxs[0];
  360. decisionTaker.length > 0 && (decisionTaker = decisionTaker.split(",")[0]);
  361. var possibilityPos = getMaskSet().validPositions[decisionPos], prevPos = getMaskSet().validPositions[decisionPos - 1];
  362. $.each(getTests(decisionPos, prevPos ? prevPos.locator : void 0, decisionPos - 1), function(ndx, test) {
  363. altNdxs = test.locator[alternation] ? test.locator[alternation].toString().split(",") : [];
  364. for (var mndx = 0; mndx < altNdxs.length; mndx++) {
  365. var validInputs = [], staticInputsBeforePos = 0, staticInputsBeforePosAlternate = 0, verifyValidInput = !1;
  366. if (decisionTaker < altNdxs[mndx] && (void 0 === test.na || $.inArray(altNdxs[mndx], test.na.split(",")) === -1)) {
  367. getMaskSet().validPositions[decisionPos] = $.extend(!0, {}, test);
  368. var possibilities = getMaskSet().validPositions[decisionPos].locator;
  369. for (getMaskSet().validPositions[decisionPos].locator[alternation] = parseInt(altNdxs[mndx]),
  370. null == test.match.fn ? (possibilityPos.input !== test.match.def && (verifyValidInput = !0,
  371. possibilityPos.generatedInput !== !0 && validInputs.push(possibilityPos.input)),
  372. staticInputsBeforePosAlternate++, getMaskSet().validPositions[decisionPos].generatedInput = !/[0-9a-bA-Z]/.test(test.match.def),
  373. getMaskSet().validPositions[decisionPos].input = test.match.def) : getMaskSet().validPositions[decisionPos].input = possibilityPos.input,
  374. i = decisionPos + 1; i < getLastValidPosition(void 0, !0) + 1; i++) validPos = getMaskSet().validPositions[i],
  375. validPos && validPos.generatedInput !== !0 && /[0-9a-bA-Z]/.test(validPos.input) ? validInputs.push(validPos.input) : i < pos && staticInputsBeforePos++,
  376. delete getMaskSet().validPositions[i];
  377. for (verifyValidInput && validInputs[0] === test.match.def && validInputs.shift(),
  378. resetMaskSet(!0), isValidRslt = !0; validInputs.length > 0; ) {
  379. var input = validInputs.shift();
  380. if (input !== opts.skipOptionalPartCharacter && !(isValidRslt = isValid(getLastValidPosition(void 0, !0) + 1, input, !1, fromSetValid, !0))) break;
  381. }
  382. if (isValidRslt) {
  383. getMaskSet().validPositions[decisionPos].locator = possibilities;
  384. var targetLvp = getLastValidPosition(pos) + 1;
  385. for (i = decisionPos + 1; i < getLastValidPosition() + 1; i++) validPos = getMaskSet().validPositions[i],
  386. (void 0 === validPos || null == validPos.match.fn) && i < pos + (staticInputsBeforePosAlternate - staticInputsBeforePos) && staticInputsBeforePosAlternate++;
  387. pos += staticInputsBeforePosAlternate - staticInputsBeforePos, isValidRslt = isValid(pos > targetLvp ? targetLvp : pos, c, strict, fromSetValid, !0);
  388. }
  389. if (isValidRslt) return !1;
  390. resetMaskSet(), getMaskSet().validPositions = $.extend(!0, {}, validPsClone);
  391. }
  392. }
  393. });
  394. }
  395. return isValidRslt;
  396. }
  397. function trackbackAlternations(originalPos, newPos) {
  398. var vp = getMaskSet().validPositions[newPos];
  399. if (vp) for (var targetLocator = vp.locator, tll = targetLocator.length, ps = originalPos; ps < newPos; ps++) if (void 0 === getMaskSet().validPositions[ps] && !isMask(ps, !0)) {
  400. var tests = getTests(ps), bestMatch = tests[0], equality = -1;
  401. $.each(tests, function(ndx, tst) {
  402. for (var i = 0; i < tll && (void 0 !== tst.locator[i] && checkAlternationMatch(tst.locator[i].toString().split(","), targetLocator[i].toString().split(","))); i++) equality < i && (equality = i,
  403. bestMatch = tst);
  404. }), setValidPosition(ps, $.extend({}, bestMatch, {
  405. input: bestMatch.match.placeholder || bestMatch.match.def
  406. }), !0);
  407. }
  408. }
  409. function setValidPosition(pos, validTest, fromSetValid, isSelection) {
  410. if (isSelection || opts.insertMode && void 0 !== getMaskSet().validPositions[pos] && void 0 === fromSetValid) {
  411. var i, positionsClone = $.extend(!0, {}, getMaskSet().validPositions), lvp = getLastValidPosition(void 0, !0);
  412. for (i = pos; i <= lvp; i++) delete getMaskSet().validPositions[i];
  413. getMaskSet().validPositions[pos] = $.extend(!0, {}, validTest);
  414. var j, valid = !0, vps = getMaskSet().validPositions, needsValidation = !1, initialLength = getMaskSet().maskLength;
  415. for (i = j = pos; i <= lvp; i++) {
  416. var t = positionsClone[i];
  417. if (void 0 !== t) for (var posMatch = j; posMatch < getMaskSet().maskLength && (null === t.match.fn && vps[i] && (vps[i].match.optionalQuantifier === !0 || vps[i].match.optionality === !0) || null != t.match.fn); ) {
  418. if (posMatch++, needsValidation === !1 && positionsClone[posMatch] && positionsClone[posMatch].match.def === t.match.def) getMaskSet().validPositions[posMatch] = $.extend(!0, {}, positionsClone[posMatch]),
  419. getMaskSet().validPositions[posMatch].input = t.input, fillMissingNonMask(posMatch),
  420. j = posMatch, valid = !0; else if (positionCanMatchDefinition(posMatch, t.match.def)) {
  421. var result = isValid(posMatch, t.input, !0, !0);
  422. valid = result !== !1, j = result.caret || result.insert ? getLastValidPosition() : posMatch,
  423. needsValidation = !0;
  424. } else valid = t.generatedInput === !0;
  425. if (getMaskSet().maskLength < initialLength && (getMaskSet().maskLength = initialLength),
  426. valid) break;
  427. }
  428. if (!valid) break;
  429. }
  430. if (!valid) return getMaskSet().validPositions = $.extend(!0, {}, positionsClone),
  431. resetMaskSet(!0), !1;
  432. } else getMaskSet().validPositions[pos] = $.extend(!0, {}, validTest);
  433. return resetMaskSet(!0), !0;
  434. }
  435. function fillMissingNonMask(maskPos) {
  436. for (var pndx = maskPos - 1; pndx > -1 && !getMaskSet().validPositions[pndx]; pndx--) ;
  437. var testTemplate, testsFromPos;
  438. for (pndx++; pndx < maskPos; pndx++) void 0 === getMaskSet().validPositions[pndx] && (opts.jitMasking === !1 || opts.jitMasking > pndx) && (testsFromPos = getTests(pndx, getTestTemplate(pndx - 1).locator, pndx - 1).slice(),
  439. "" === testsFromPos[testsFromPos.length - 1].match.def && testsFromPos.pop(), testTemplate = determineTestTemplate(testsFromPos),
  440. testTemplate && (testTemplate.match.def === opts.radixPointDefinitionSymbol || !isMask(pndx, !0) || $.inArray(opts.radixPoint, getBuffer()) < pndx && testTemplate.match.fn && testTemplate.match.fn.test(getPlaceholder(pndx), getMaskSet(), pndx, !1, opts)) && (result = _isValid(pndx, testTemplate.match.placeholder || (null == testTemplate.match.fn ? testTemplate.match.def : "" !== getPlaceholder(pndx) ? getPlaceholder(pndx) : getBuffer()[pndx]), !0),
  441. result !== !1 && (getMaskSet().validPositions[result.pos || pndx].generatedInput = !0)));
  442. }
  443. strict = strict === !0;
  444. var maskPos = pos;
  445. void 0 !== pos.begin && (maskPos = isRTL && !isSelection(pos) ? pos.end : pos.begin);
  446. var result = !1, positionsClone = $.extend(!0, {}, getMaskSet().validPositions);
  447. if (fillMissingNonMask(maskPos), isSelection(pos) && (handleRemove(void 0, Inputmask.keyCode.DELETE, pos),
  448. maskPos = getMaskSet().p), maskPos < getMaskSet().maskLength && (result = _isValid(maskPos, c, strict),
  449. (!strict || fromSetValid === !0) && result === !1)) {
  450. var currentPosValid = getMaskSet().validPositions[maskPos];
  451. if (!currentPosValid || null !== currentPosValid.match.fn || currentPosValid.match.def !== c && c !== opts.skipOptionalPartCharacter) {
  452. if ((opts.insertMode || void 0 === getMaskSet().validPositions[seekNext(maskPos)]) && !isMask(maskPos, !0)) {
  453. var testsFromPos = getTests(maskPos).slice();
  454. "" === testsFromPos[testsFromPos.length - 1].match.def && testsFromPos.pop();
  455. var staticChar = determineTestTemplate(testsFromPos, !0);
  456. staticChar && null === staticChar.match.fn && (staticChar = staticChar.match.placeholder || staticChar.match.def,
  457. _isValid(maskPos, staticChar, strict), getMaskSet().validPositions[maskPos].generatedInput = !0);
  458. for (var nPos = maskPos + 1, snPos = seekNext(maskPos); nPos <= snPos; nPos++) if (result = _isValid(nPos, c, strict),
  459. result !== !1) {
  460. trackbackAlternations(maskPos, void 0 !== result.pos ? result.pos : nPos), maskPos = nPos;
  461. break;
  462. }
  463. }
  464. } else result = {
  465. caret: seekNext(maskPos)
  466. };
  467. }
  468. return result === !1 && opts.keepStatic && !strict && fromAlternate !== !0 && (result = alternate(maskPos, c, strict)),
  469. result === !0 && (result = {
  470. pos: maskPos
  471. }), $.isFunction(opts.postValidation) && result !== !1 && !strict && fromSetValid !== !0 && (result = !!opts.postValidation(getBuffer(!0), result, opts) && result),
  472. void 0 === result.pos && (result.pos = maskPos), result === !1 && (resetMaskSet(!0),
  473. getMaskSet().validPositions = $.extend(!0, {}, positionsClone)), result;
  474. }
  475. function isMask(pos, strict) {
  476. var test;
  477. if (strict ? (test = getTestTemplate(pos).match, "" === test.def && (test = getTest(pos).match)) : test = getTest(pos).match,
  478. null != test.fn) return test.fn;
  479. if (strict !== !0 && pos > -1) {
  480. var tests = getTests(pos);
  481. return tests.length > 1 + ("" === tests[tests.length - 1].match.def ? 1 : 0);
  482. }
  483. return !1;
  484. }
  485. function seekNext(pos, newBlock) {
  486. var maskL = getMaskSet().maskLength;
  487. if (pos >= maskL) return maskL;
  488. for (var position = pos; ++position < maskL && (newBlock === !0 && (getTest(position).match.newBlockMarker !== !0 || !isMask(position)) || newBlock !== !0 && !isMask(position)); ) ;
  489. return position;
  490. }
  491. function seekPrevious(pos, newBlock) {
  492. var tests, position = pos;
  493. if (position <= 0) return 0;
  494. for (;--position > 0 && (newBlock === !0 && getTest(position).match.newBlockMarker !== !0 || newBlock !== !0 && !isMask(position) && (tests = getTests(position),
  495. tests.length < 2 || 2 === tests.length && "" === tests[1].match.def)); ) ;
  496. return position;
  497. }
  498. function getBufferElement(position) {
  499. return void 0 === getMaskSet().validPositions[position] ? getPlaceholder(position) : getMaskSet().validPositions[position].input;
  500. }
  501. function writeBuffer(input, buffer, caretPos, event, triggerInputEvent) {
  502. if (event && $.isFunction(opts.onBeforeWrite)) {
  503. var result = opts.onBeforeWrite(event, buffer, caretPos, opts);
  504. if (result) {
  505. if (result.refreshFromBuffer) {
  506. var refresh = result.refreshFromBuffer;
  507. refreshFromBuffer(refresh === !0 ? refresh : refresh.start, refresh.end, result.buffer || buffer),
  508. buffer = getBuffer(!0);
  509. }
  510. void 0 !== caretPos && (caretPos = void 0 !== result.caret ? result.caret : caretPos);
  511. }
  512. }
  513. input.inputmask._valueSet(buffer.join("")), void 0 === caretPos || void 0 !== event && "blur" === event.type ? renderColorMask(input, buffer, caretPos) : caret(input, caretPos),
  514. triggerInputEvent === !0 && (skipInputEvent = !0, $(input).trigger("input"));
  515. }
  516. function getPlaceholder(pos, test) {
  517. if (test = test || getTest(pos).match, void 0 !== test.placeholder) return test.placeholder;
  518. if (null === test.fn) {
  519. if (pos > -1 && void 0 === getMaskSet().validPositions[pos]) {
  520. var prevTest, tests = getTests(pos), staticAlternations = [];
  521. if (tests.length > 1 + ("" === tests[tests.length - 1].match.def ? 1 : 0)) for (var i = 0; i < tests.length; i++) if (tests[i].match.optionality !== !0 && tests[i].match.optionalQuantifier !== !0 && (null === tests[i].match.fn || void 0 === prevTest || tests[i].match.fn.test(prevTest.match.def, getMaskSet(), pos, !0, opts) !== !1) && (staticAlternations.push(tests[i]),
  522. null === tests[i].match.fn && (prevTest = tests[i]), staticAlternations.length > 1 && /[0-9a-bA-Z]/.test(staticAlternations[0].match.def))) return opts.placeholder.charAt(pos % opts.placeholder.length);
  523. }
  524. return test.def;
  525. }
  526. return opts.placeholder.charAt(pos % opts.placeholder.length);
  527. }
  528. function checkVal(input, writeOut, strict, nptvl, initiatingEvent, stickyCaret) {
  529. function isTemplateMatch() {
  530. var isMatch = !1, charCodeNdx = getBufferTemplate().slice(initialNdx, seekNext(initialNdx)).join("").indexOf(charCodes);
  531. if (charCodeNdx !== -1 && !isMask(initialNdx)) {
  532. isMatch = !0;
  533. for (var bufferTemplateArr = getBufferTemplate().slice(initialNdx, initialNdx + charCodeNdx), i = 0; i < bufferTemplateArr.length; i++) if (" " !== bufferTemplateArr[i]) {
  534. isMatch = !1;
  535. break;
  536. }
  537. }
  538. return isMatch;
  539. }
  540. var inputValue = nptvl.slice(), charCodes = "", initialNdx = 0, result = void 0;
  541. if (resetMaskSet(), getMaskSet().p = seekNext(-1), !strict) if (opts.autoUnmask !== !0) {
  542. var staticInput = getBufferTemplate().slice(0, seekNext(-1)).join(""), matches = inputValue.join("").match(new RegExp("^" + Inputmask.escapeRegex(staticInput), "g"));
  543. matches && matches.length > 0 && (inputValue.splice(0, matches.length * staticInput.length),
  544. initialNdx = seekNext(initialNdx));
  545. } else initialNdx = seekNext(initialNdx);
  546. if ($.each(inputValue, function(ndx, charCode) {
  547. if (void 0 !== charCode) {
  548. var keypress = new $.Event("keypress");
  549. keypress.which = charCode.charCodeAt(0), charCodes += charCode;
  550. var lvp = getLastValidPosition(void 0, !0), lvTest = getMaskSet().validPositions[lvp], nextTest = getTestTemplate(lvp + 1, lvTest ? lvTest.locator.slice() : void 0, lvp);
  551. if (!isTemplateMatch() || strict || opts.autoUnmask) {
  552. var pos = strict ? ndx : null == nextTest.match.fn && nextTest.match.optionality && lvp + 1 < getMaskSet().p ? lvp + 1 : getMaskSet().p;
  553. result = EventHandlers.keypressEvent.call(input, keypress, !0, !1, strict, pos),
  554. initialNdx = pos + 1, charCodes = "";
  555. } else result = EventHandlers.keypressEvent.call(input, keypress, !0, !1, !0, lvp + 1);
  556. if (!strict && $.isFunction(opts.onBeforeWrite) && (result = opts.onBeforeWrite(keypress, getBuffer(), result.forwardPosition, opts),
  557. result && result.refreshFromBuffer)) {
  558. var refresh = result.refreshFromBuffer;
  559. refreshFromBuffer(refresh === !0 ? refresh : refresh.start, refresh.end, result.buffer),
  560. resetMaskSet(!0), result.caret && (getMaskSet().p = result.caret);
  561. }
  562. }
  563. }), writeOut) {
  564. var caretPos = void 0, lvp = getLastValidPosition();
  565. document.activeElement === input && (initiatingEvent || result) && (caretPos = caret(input).begin,
  566. initiatingEvent && result === !1 && (caretPos = seekNext(getLastValidPosition(caretPos))),
  567. result && stickyCaret !== !0 && (caretPos < lvp + 1 || lvp === -1) && (caretPos = opts.numericInput && void 0 === result.caret ? seekPrevious(result.forwardPosition) : result.forwardPosition)),
  568. writeBuffer(input, getBuffer(), caretPos, initiatingEvent || new $.Event("checkval"));
  569. }
  570. }
  571. function unmaskedvalue(input) {
  572. if (input && void 0 === input.inputmask) return input.value;
  573. var umValue = [], vps = getMaskSet().validPositions;
  574. for (var pndx in vps) vps[pndx].match && null != vps[pndx].match.fn && umValue.push(vps[pndx].input);
  575. var unmaskedValue = 0 === umValue.length ? "" : (isRTL ? umValue.reverse() : umValue).join("");
  576. if ($.isFunction(opts.onUnMask)) {
  577. var bufferValue = (isRTL ? getBuffer().slice().reverse() : getBuffer()).join("");
  578. unmaskedValue = opts.onUnMask(bufferValue, unmaskedValue, opts) || unmaskedValue;
  579. }
  580. return unmaskedValue;
  581. }
  582. function caret(input, begin, end, notranslate) {
  583. function translatePosition(pos) {
  584. if (notranslate !== !0 && isRTL && "number" == typeof pos && (!opts.greedy || "" !== opts.placeholder)) {
  585. var bffrLght = getBuffer().join("").length;
  586. pos = bffrLght - pos;
  587. }
  588. return pos;
  589. }
  590. var range;
  591. if ("number" != typeof begin) return input.setSelectionRange ? (begin = input.selectionStart,
  592. end = input.selectionEnd) : window.getSelection ? (range = window.getSelection().getRangeAt(0),
  593. range.commonAncestorContainer.parentNode !== input && range.commonAncestorContainer !== input || (begin = range.startOffset,
  594. end = range.endOffset)) : document.selection && document.selection.createRange && (range = document.selection.createRange(),
  595. begin = 0 - range.duplicate().moveStart("character", -input.inputmask._valueGet().length),
  596. end = begin + range.text.length), {
  597. begin: translatePosition(begin),
  598. end: translatePosition(end)
  599. };
  600. begin = translatePosition(begin), end = translatePosition(end), end = "number" == typeof end ? end : begin;
  601. var scrollCalc = parseInt(((input.ownerDocument.defaultView || window).getComputedStyle ? (input.ownerDocument.defaultView || window).getComputedStyle(input, null) : input.currentStyle).fontSize) * end;
  602. if (input.scrollLeft = scrollCalc > input.scrollWidth ? scrollCalc : 0, mobile || opts.insertMode !== !1 || begin !== end || end++,
  603. input.setSelectionRange) input.selectionStart = begin, input.selectionEnd = end; else if (window.getSelection) {
  604. if (range = document.createRange(), void 0 === input.firstChild || null === input.firstChild) {
  605. var textNode = document.createTextNode("");
  606. input.appendChild(textNode);
  607. }
  608. range.setStart(input.firstChild, begin < input.inputmask._valueGet().length ? begin : input.inputmask._valueGet().length),
  609. range.setEnd(input.firstChild, end < input.inputmask._valueGet().length ? end : input.inputmask._valueGet().length),
  610. range.collapse(!0);
  611. var sel = window.getSelection();
  612. sel.removeAllRanges(), sel.addRange(range);
  613. } else input.createTextRange && (range = input.createTextRange(), range.collapse(!0),
  614. range.moveEnd("character", end), range.moveStart("character", begin), range.select());
  615. renderColorMask(input, void 0, {
  616. begin: begin,
  617. end: end
  618. });
  619. }
  620. function determineLastRequiredPosition(returnDefinition) {
  621. var pos, testPos, buffer = getBuffer(), bl = buffer.length, lvp = getLastValidPosition(), positions = {}, lvTest = getMaskSet().validPositions[lvp], ndxIntlzr = void 0 !== lvTest ? lvTest.locator.slice() : void 0;
  622. for (pos = lvp + 1; pos < buffer.length; pos++) testPos = getTestTemplate(pos, ndxIntlzr, pos - 1),
  623. ndxIntlzr = testPos.locator.slice(), positions[pos] = $.extend(!0, {}, testPos);
  624. var lvTestAlt = lvTest && void 0 !== lvTest.alternation ? lvTest.locator[lvTest.alternation] : void 0;
  625. for (pos = bl - 1; pos > lvp && (testPos = positions[pos], (testPos.match.optionality || testPos.match.optionalQuantifier || lvTestAlt && (lvTestAlt !== positions[pos].locator[lvTest.alternation] && null != testPos.match.fn || null === testPos.match.fn && testPos.locator[lvTest.alternation] && checkAlternationMatch(testPos.locator[lvTest.alternation].toString().split(","), lvTestAlt.toString().split(",")) && "" !== getTests(pos)[0].def)) && buffer[pos] === getPlaceholder(pos, testPos.match)); pos--) bl--;
  626. return returnDefinition ? {
  627. l: bl,
  628. def: positions[bl] ? positions[bl].match : void 0
  629. } : bl;
  630. }
  631. function clearOptionalTail(buffer) {
  632. for (var validPos, rl = determineLastRequiredPosition(), bl = buffer.length; rl < bl && !isMask(rl + 1) && (validPos = getTest(rl + 1)) && validPos.match.optionality !== !0 && validPos.match.optionalQuantifier !== !0; ) rl++;
  633. for (;(validPos = getTest(rl - 1)) && validPos.match.optionality && validPos.input === opts.skipOptionalPartCharacter; ) rl--;
  634. return buffer.splice(rl), buffer;
  635. }
  636. function isComplete(buffer) {
  637. if ($.isFunction(opts.isComplete)) return opts.isComplete(buffer, opts);
  638. if ("*" !== opts.repeat) {
  639. var complete = !1, lrp = determineLastRequiredPosition(!0), aml = seekPrevious(lrp.l);
  640. if (void 0 === lrp.def || lrp.def.newBlockMarker || lrp.def.optionality || lrp.def.optionalQuantifier) {
  641. complete = !0;
  642. for (var i = 0; i <= aml; i++) {
  643. var test = getTestTemplate(i).match;
  644. if (null !== test.fn && void 0 === getMaskSet().validPositions[i] && test.optionality !== !0 && test.optionalQuantifier !== !0 || null === test.fn && buffer[i] !== getPlaceholder(i, test)) {
  645. complete = !1;
  646. break;
  647. }
  648. }
  649. }
  650. return complete;
  651. }
  652. }
  653. function handleRemove(input, k, pos, strict) {
  654. function generalize() {
  655. if (opts.keepStatic) {
  656. for (var validInputs = [], lastAlt = getLastValidPosition(-1, !0), positionsClone = $.extend(!0, {}, getMaskSet().validPositions), prevAltPos = getMaskSet().validPositions[lastAlt]; lastAlt >= 0; lastAlt--) {
  657. var altPos = getMaskSet().validPositions[lastAlt];
  658. if (altPos) {
  659. if (altPos.generatedInput !== !0 && /[0-9a-bA-Z]/.test(altPos.input) && validInputs.push(altPos.input),
  660. delete getMaskSet().validPositions[lastAlt], void 0 !== altPos.alternation && altPos.locator[altPos.alternation] !== prevAltPos.locator[altPos.alternation]) break;
  661. prevAltPos = altPos;
  662. }
  663. }
  664. if (lastAlt > -1) for (getMaskSet().p = seekNext(getLastValidPosition(-1, !0)); validInputs.length > 0; ) {
  665. var keypress = new $.Event("keypress");
  666. keypress.which = validInputs.pop().charCodeAt(0), EventHandlers.keypressEvent.call(input, keypress, !0, !1, !1, getMaskSet().p);
  667. } else getMaskSet().validPositions = $.extend(!0, {}, positionsClone);
  668. }
  669. }
  670. if ((opts.numericInput || isRTL) && (k === Inputmask.keyCode.BACKSPACE ? k = Inputmask.keyCode.DELETE : k === Inputmask.keyCode.DELETE && (k = Inputmask.keyCode.BACKSPACE),
  671. isRTL)) {
  672. var pend = pos.end;
  673. pos.end = pos.begin, pos.begin = pend;
  674. }
  675. k === Inputmask.keyCode.BACKSPACE && (pos.end - pos.begin < 1 || opts.insertMode === !1) ? (pos.begin = seekPrevious(pos.begin),
  676. void 0 === getMaskSet().validPositions[pos.begin] || getMaskSet().validPositions[pos.begin].input !== opts.groupSeparator && getMaskSet().validPositions[pos.begin].input !== opts.radixPoint || pos.begin--) : k === Inputmask.keyCode.DELETE && pos.begin === pos.end && (pos.end = isMask(pos.end, !0) ? pos.end + 1 : seekNext(pos.end) + 1,
  677. void 0 === getMaskSet().validPositions[pos.begin] || getMaskSet().validPositions[pos.begin].input !== opts.groupSeparator && getMaskSet().validPositions[pos.begin].input !== opts.radixPoint || pos.end++),
  678. stripValidPositions(pos.begin, pos.end, !1, strict), strict !== !0 && generalize();
  679. var lvp = getLastValidPosition(pos.begin, !0);
  680. lvp < pos.begin ? getMaskSet().p = seekNext(lvp) : strict !== !0 && (getMaskSet().p = pos.begin);
  681. }
  682. function initializeColorMask(input) {
  683. function findCaretPos(clientx) {
  684. var caretPos, e = document.createElement("span");
  685. for (var style in computedStyle) isNaN(style) && style.indexOf("font") !== -1 && (e.style[style] = computedStyle[style]);
  686. e.style.textTransform = computedStyle.textTransform, e.style.letterSpacing = computedStyle.letterSpacing,
  687. e.style.position = "absolute", e.style.height = "auto", e.style.width = "auto",
  688. e.style.visibility = "hidden", e.style.whiteSpace = "nowrap", document.body.appendChild(e);
  689. var itl, inputText = input.inputmask._valueGet(), previousWidth = 0;
  690. for (caretPos = 0, itl = inputText.length; caretPos <= itl; caretPos++) {
  691. if (e.innerHTML += inputText.charAt(caretPos) || "_", e.offsetWidth >= clientx) {
  692. var offset1 = clientx - previousWidth, offset2 = e.offsetWidth - clientx;
  693. e.innerHTML = inputText.charAt(caretPos), offset1 -= e.offsetWidth / 3, caretPos = offset1 < offset2 ? caretPos - 1 : caretPos;
  694. break;
  695. }
  696. previousWidth = e.offsetWidth;
  697. }
  698. return document.body.removeChild(e), caretPos;
  699. }
  700. function position() {
  701. colorMask.style.position = "absolute", colorMask.style.top = offset.top + "px",
  702. colorMask.style.left = offset.left + "px", colorMask.style.width = parseInt(input.offsetWidth) - parseInt(computedStyle.paddingLeft) - parseInt(computedStyle.paddingRight) - parseInt(computedStyle.borderLeftWidth) - parseInt(computedStyle.borderRightWidth) + "px",
  703. colorMask.style.height = parseInt(input.offsetHeight) - parseInt(computedStyle.paddingTop) - parseInt(computedStyle.paddingBottom) - parseInt(computedStyle.borderTopWidth) - parseInt(computedStyle.borderBottomWidth) + "px",
  704. colorMask.style.lineHeight = colorMask.style.height, colorMask.style.zIndex = isNaN(computedStyle.zIndex) ? -1 : computedStyle.zIndex - 1,
  705. colorMask.style.webkitAppearance = "textfield", colorMask.style.mozAppearance = "textfield",
  706. colorMask.style.Appearance = "textfield";
  707. }
  708. var offset = $(input).position(), computedStyle = (input.ownerDocument.defaultView || window).getComputedStyle(input, null);
  709. input.parentNode;
  710. colorMask = document.createElement("div"), document.body.appendChild(colorMask);
  711. for (var style in computedStyle) isNaN(style) && "cssText" !== style && style.indexOf("webkit") == -1 && (colorMask.style[style] = computedStyle[style]);
  712. input.style.backgroundColor = "transparent", input.style.color = "transparent",
  713. input.style.webkitAppearance = "caret", input.style.mozAppearance = "caret", input.style.Appearance = "caret",
  714. position(), $(window).on("resize", function(e) {
  715. offset = $(input).position(), computedStyle = (input.ownerDocument.defaultView || window).getComputedStyle(input, null),
  716. position();
  717. }), $(input).on("click", function(e) {
  718. return caret(input, findCaretPos(e.clientX)), EventHandlers.clickEvent.call(this, [ e ]);
  719. }), $(input).on("keydown", function(e) {
  720. e.shiftKey || opts.insertMode === !1 || setTimeout(function() {
  721. renderColorMask(input);
  722. }, 0);
  723. });
  724. }
  725. function renderColorMask(input, buffer, caretPos) {
  726. function handleStatic() {
  727. static || null !== test.fn && void 0 !== testPos.input ? static && null !== test.fn && void 0 !== testPos.input && (static = !1,
  728. maskTemplate += "</span>") : (static = !0, maskTemplate += "<span class='im-static''>");
  729. }
  730. if (void 0 !== colorMask) {
  731. buffer = buffer || getBuffer(), void 0 === caretPos ? caretPos = caret(input) : void 0 === caretPos.begin && (caretPos = {
  732. begin: caretPos,
  733. end: caretPos
  734. });
  735. var maskTemplate = "", static = !1;
  736. if ("" != buffer) {
  737. var ndxIntlzr, test, testPos, pos = 0, lvp = getLastValidPosition();
  738. do pos === caretPos.begin && document.activeElement === input && (maskTemplate += "<span class='im-caret' style='border-right-width: 1px;border-right-style: solid;'></span>"),
  739. getMaskSet().validPositions[pos] ? (testPos = getMaskSet().validPositions[pos],
  740. test = testPos.match, ndxIntlzr = testPos.locator.slice(), handleStatic(), maskTemplate += testPos.input) : (testPos = getTestTemplate(pos, ndxIntlzr, pos - 1),
  741. test = testPos.match, ndxIntlzr = testPos.locator.slice(), (opts.jitMasking === !1 || pos < lvp || "number" == typeof opts.jitMasking && isFinite(opts.jitMasking) && opts.jitMasking > pos) && (handleStatic(),
  742. maskTemplate += getPlaceholder(pos, test))), pos++; while ((void 0 === maxLength || pos < maxLength) && (null !== test.fn || "" !== test.def) || lvp > pos);
  743. }
  744. colorMask.innerHTML = maskTemplate;
  745. }
  746. }
  747. function mask(elem) {
  748. function isElementTypeSupported(input, opts) {
  749. function patchValueProperty(npt) {
  750. function patchValhook(type) {
  751. if ($.valHooks && (void 0 === $.valHooks[type] || $.valHooks[type].inputmaskpatch !== !0)) {
  752. var valhookGet = $.valHooks[type] && $.valHooks[type].get ? $.valHooks[type].get : function(elem) {
  753. return elem.value;
  754. }, valhookSet = $.valHooks[type] && $.valHooks[type].set ? $.valHooks[type].set : function(elem, value) {
  755. return elem.value = value, elem;
  756. };
  757. $.valHooks[type] = {
  758. get: function(elem) {
  759. if (elem.inputmask) {
  760. if (elem.inputmask.opts.autoUnmask) return elem.inputmask.unmaskedvalue();
  761. var result = valhookGet(elem);
  762. return getLastValidPosition(void 0, void 0, elem.inputmask.maskset.validPositions) !== -1 || opts.nullable !== !0 ? result : "";
  763. }
  764. return valhookGet(elem);
  765. },
  766. set: function(elem, value) {
  767. var result, $elem = $(elem);
  768. return result = valhookSet(elem, value), elem.inputmask && $elem.trigger("setvalue"),
  769. result;
  770. },
  771. inputmaskpatch: !0
  772. };
  773. }
  774. }
  775. function getter() {
  776. return this.inputmask ? this.inputmask.opts.autoUnmask ? this.inputmask.unmaskedvalue() : getLastValidPosition() !== -1 || opts.nullable !== !0 ? document.activeElement === this && opts.clearMaskOnLostFocus ? (isRTL ? clearOptionalTail(getBuffer().slice()).reverse() : clearOptionalTail(getBuffer().slice())).join("") : valueGet.call(this) : "" : valueGet.call(this);
  777. }
  778. function setter(value) {
  779. valueSet.call(this, value), this.inputmask && $(this).trigger("setvalue");
  780. }
  781. function installNativeValueSetFallback(npt) {
  782. EventRuler.on(npt, "mouseenter", function(event) {
  783. var $input = $(this), input = this, value = input.inputmask._valueGet();
  784. value !== getBuffer().join("") && $input.trigger("setvalue");
  785. });
  786. }
  787. var valueGet, valueSet;
  788. if (!npt.inputmask.__valueGet) {
  789. if (opts.noValuePatching !== !0) {
  790. if (Object.getOwnPropertyDescriptor) {
  791. "function" != typeof Object.getPrototypeOf && (Object.getPrototypeOf = "object" == typeof "test".__proto__ ? function(object) {
  792. return object.__proto__;
  793. } : function(object) {
  794. return object.constructor.prototype;
  795. });
  796. var valueProperty = Object.getPrototypeOf ? Object.getOwnPropertyDescriptor(Object.getPrototypeOf(npt), "value") : void 0;
  797. valueProperty && valueProperty.get && valueProperty.set ? (valueGet = valueProperty.get,
  798. valueSet = valueProperty.set, Object.defineProperty(npt, "value", {
  799. get: getter,
  800. set: setter,
  801. configurable: !0
  802. })) : "INPUT" !== npt.tagName && (valueGet = function() {
  803. return this.textContent;
  804. }, valueSet = function(value) {
  805. this.textContent = value;
  806. }, Object.defineProperty(npt, "value", {
  807. get: getter,
  808. set: setter,
  809. configurable: !0
  810. }));
  811. } else document.__lookupGetter__ && npt.__lookupGetter__("value") && (valueGet = npt.__lookupGetter__("value"),
  812. valueSet = npt.__lookupSetter__("value"), npt.__defineGetter__("value", getter),
  813. npt.__defineSetter__("value", setter));
  814. npt.inputmask.__valueGet = valueGet, npt.inputmask.__valueSet = valueSet;
  815. }
  816. npt.inputmask._valueGet = function(overruleRTL) {
  817. return isRTL && overruleRTL !== !0 ? valueGet.call(this.el).split("").reverse().join("") : valueGet.call(this.el);
  818. }, npt.inputmask._valueSet = function(value, overruleRTL) {
  819. valueSet.call(this.el, null === value || void 0 === value ? "" : overruleRTL !== !0 && isRTL ? value.split("").reverse().join("") : value);
  820. }, void 0 === valueGet && (valueGet = function() {
  821. return this.value;
  822. }, valueSet = function(value) {
  823. this.value = value;
  824. }, patchValhook(npt.type), installNativeValueSetFallback(npt));
  825. }
  826. }
  827. var elementType = input.getAttribute("type"), isSupported = "INPUT" === input.tagName && $.inArray(elementType, opts.supportsInputType) !== -1 || input.isContentEditable || "TEXTAREA" === input.tagName;
  828. if (!isSupported) if ("INPUT" === input.tagName) {
  829. var el = document.createElement("input");
  830. el.setAttribute("type", elementType), isSupported = "text" === el.type, el = null;
  831. } else isSupported = "partial";
  832. return isSupported !== !1 && patchValueProperty(input), isSupported;
  833. }
  834. var isSupported = isElementTypeSupported(elem, opts);
  835. if (isSupported !== !1 && (el = elem, $el = $(el), ("rtl" === el.dir || opts.rightAlign) && (el.style.textAlign = "right"),
  836. ("rtl" === el.dir || opts.numericInput) && (el.dir = "ltr", el.removeAttribute("dir"),
  837. el.inputmask.isRTL = !0, isRTL = !0), opts.colorMask === !0 && initializeColorMask(el),
  838. android && (el.hasOwnProperty("inputmode") && (el.inputmode = opts.inputmode, el.setAttribute("inputmode", opts.inputmode)),
  839. "rtfm" === opts.androidHack && (opts.colorMask !== !0 && initializeColorMask(el),
  840. el.type = "password")), EventRuler.off(el), isSupported === !0 && (EventRuler.on(el, "submit", EventHandlers.submitEvent),
  841. EventRuler.on(el, "reset", EventHandlers.resetEvent), EventRuler.on(el, "mouseenter", EventHandlers.mouseenterEvent),
  842. EventRuler.on(el, "blur", EventHandlers.blurEvent), EventRuler.on(el, "focus", EventHandlers.focusEvent),
  843. EventRuler.on(el, "mouseleave", EventHandlers.mouseleaveEvent), opts.colorMask !== !0 && EventRuler.on(el, "click", EventHandlers.clickEvent),
  844. EventRuler.on(el, "dblclick", EventHandlers.dblclickEvent), EventRuler.on(el, "paste", EventHandlers.pasteEvent),
  845. EventRuler.on(el, "dragdrop", EventHandlers.pasteEvent), EventRuler.on(el, "drop", EventHandlers.pasteEvent),
  846. EventRuler.on(el, "cut", EventHandlers.cutEvent), EventRuler.on(el, "complete", opts.oncomplete),
  847. EventRuler.on(el, "incomplete", opts.onincomplete), EventRuler.on(el, "cleared", opts.oncleared),
  848. opts.inputEventOnly !== !0 && (EventRuler.on(el, "keydown", EventHandlers.keydownEvent),
  849. EventRuler.on(el, "keypress", EventHandlers.keypressEvent)), EventRuler.on(el, "compositionstart", $.noop),
  850. EventRuler.on(el, "compositionupdate", $.noop), EventRuler.on(el, "compositionend", $.noop),
  851. EventRuler.on(el, "keyup", $.noop), EventRuler.on(el, "input", EventHandlers.inputFallBackEvent)),
  852. EventRuler.on(el, "setvalue", EventHandlers.setValueEvent), getBufferTemplate(),
  853. "" !== el.inputmask._valueGet() || opts.clearMaskOnLostFocus === !1 || document.activeElement === el)) {
  854. var initialValue = $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask(el.inputmask._valueGet(), opts) || el.inputmask._valueGet() : el.inputmask._valueGet();
  855. checkVal(el, !0, !1, initialValue.split(""));
  856. var buffer = getBuffer().slice();
  857. undoValue = buffer.join(""), isComplete(buffer) === !1 && opts.clearIncomplete && resetMaskSet(),
  858. opts.clearMaskOnLostFocus && document.activeElement !== el && (getLastValidPosition() === -1 ? buffer = [] : clearOptionalTail(buffer)),
  859. writeBuffer(el, buffer), document.activeElement === el && caret(el, seekNext(getLastValidPosition()));
  860. }
  861. }
  862. maskset = maskset || this.maskset, opts = opts || this.opts;
  863. var undoValue, $el, maxLength, colorMask, valueBuffer, el = this.el, isRTL = this.isRTL, skipKeyPressEvent = !1, skipInputEvent = !1, ignorable = !1, mouseEnter = !1, EventRuler = {
  864. on: function(input, eventName, eventHandler) {
  865. var ev = function(e) {
  866. if (void 0 === this.inputmask && "FORM" !== this.nodeName) {
  867. var imOpts = $.data(this, "_inputmask_opts");
  868. imOpts ? new Inputmask(imOpts).mask(this) : EventRuler.off(this);
  869. } else {
  870. if ("setvalue" === e.type || "FORM" === this.nodeName || !(this.disabled || this.readOnly && !("keydown" === e.type && e.ctrlKey && 67 === e.keyCode || opts.tabThrough === !1 && e.keyCode === Inputmask.keyCode.TAB))) {
  871. switch (e.type) {
  872. case "input":
  873. if (skipInputEvent === !0) return skipInputEvent = !1, e.preventDefault();
  874. break;
  875. case "keydown":
  876. skipKeyPressEvent = !1, skipInputEvent = !1;
  877. break;
  878. case "keypress":
  879. if (skipKeyPressEvent === !0) return e.preventDefault();
  880. skipKeyPressEvent = !0;
  881. break;
  882. case "click":
  883. if (iemobile || iphone) {
  884. var that = this, args = arguments;
  885. return setTimeout(function() {
  886. eventHandler.apply(that, args);
  887. }, 0), !1;
  888. }
  889. }
  890. var returnVal = eventHandler.apply(this, arguments);
  891. return returnVal === !1 && (e.preventDefault(), e.stopPropagation()), returnVal;
  892. }
  893. e.preventDefault();
  894. }
  895. };
  896. input.inputmask.events[eventName] = input.inputmask.events[eventName] || [], input.inputmask.events[eventName].push(ev),
  897. $.inArray(eventName, [ "submit", "reset" ]) !== -1 ? null != input.form && $(input.form).on(eventName, ev) : $(input).on(eventName, ev);
  898. },
  899. off: function(input, event) {
  900. if (input.inputmask && input.inputmask.events) {
  901. var events;
  902. event ? (events = [], events[event] = input.inputmask.events[event]) : events = input.inputmask.events,
  903. $.each(events, function(eventName, evArr) {
  904. for (;evArr.length > 0; ) {
  905. var ev = evArr.pop();
  906. $.inArray(eventName, [ "submit", "reset" ]) !== -1 ? null != input.form && $(input.form).off(eventName, ev) : $(input).off(eventName, ev);
  907. }
  908. delete input.inputmask.events[eventName];
  909. });
  910. }
  911. }
  912. }, EventHandlers = {
  913. keydownEvent: function(e) {
  914. function isInputEventSupported(eventName) {
  915. var el = document.createElement("input"), evName = "on" + eventName, isSupported = evName in el;
  916. return isSupported || (el.setAttribute(evName, "return;"), isSupported = "function" == typeof el[evName]),
  917. el = null, isSupported;
  918. }
  919. var input = this, $input = $(input), k = e.keyCode, pos = caret(input);
  920. if (k === Inputmask.keyCode.BACKSPACE || k === Inputmask.keyCode.DELETE || iphone && k === Inputmask.keyCode.BACKSPACE_SAFARI || e.ctrlKey && k === Inputmask.keyCode.X && !isInputEventSupported("cut")) e.preventDefault(),
  921. handleRemove(input, k, pos), writeBuffer(input, getBuffer(!0), getMaskSet().p, e, input.inputmask._valueGet() !== getBuffer().join("")),
  922. input.inputmask._valueGet() === getBufferTemplate().join("") ? $input.trigger("cleared") : isComplete(getBuffer()) === !0 && $input.trigger("complete"); else if (k === Inputmask.keyCode.END || k === Inputmask.keyCode.PAGE_DOWN) {
  923. e.preventDefault();
  924. var caretPos = seekNext(getLastValidPosition());
  925. opts.insertMode || caretPos !== getMaskSet().maskLength || e.shiftKey || caretPos--,
  926. caret(input, e.shiftKey ? pos.begin : caretPos, caretPos, !0);
  927. } else k === Inputmask.keyCode.HOME && !e.shiftKey || k === Inputmask.keyCode.PAGE_UP ? (e.preventDefault(),
  928. caret(input, 0, e.shiftKey ? pos.begin : 0, !0)) : (opts.undoOnEscape && k === Inputmask.keyCode.ESCAPE || 90 === k && e.ctrlKey) && e.altKey !== !0 ? (checkVal(input, !0, !1, undoValue.split("")),
  929. $input.trigger("click")) : k !== Inputmask.keyCode.INSERT || e.shiftKey || e.ctrlKey ? opts.tabThrough === !0 && k === Inputmask.keyCode.TAB ? (e.shiftKey === !0 ? (null === getTest(pos.begin).match.fn && (pos.begin = seekNext(pos.begin)),
  930. pos.end = seekPrevious(pos.begin, !0), pos.begin = seekPrevious(pos.end, !0)) : (pos.begin = seekNext(pos.begin, !0),
  931. pos.end = seekNext(pos.begin, !0), pos.end < getMaskSet().maskLength && pos.end--),
  932. pos.begin < getMaskSet().maskLength && (e.preventDefault(), caret(input, pos.begin, pos.end))) : e.shiftKey || opts.insertMode === !1 && (k === Inputmask.keyCode.RIGHT ? setTimeout(function() {
  933. var caretPos = caret(input);
  934. caret(input, caretPos.begin);
  935. }, 0) : k === Inputmask.keyCode.LEFT && setTimeout(function() {
  936. var caretPos = caret(input);
  937. caret(input, isRTL ? caretPos.begin + 1 : caretPos.begin - 1);
  938. }, 0)) : (opts.insertMode = !opts.insertMode, caret(input, opts.insertMode || pos.begin !== getMaskSet().maskLength ? pos.begin : pos.begin - 1));
  939. opts.onKeyDown.call(this, e, getBuffer(), caret(input).begin, opts), ignorable = $.inArray(k, opts.ignorables) !== -1;
  940. },
  941. keypressEvent: function(e, checkval, writeOut, strict, ndx) {
  942. var input = this, $input = $(input), k = e.which || e.charCode || e.keyCode;
  943. if (!(checkval === !0 || e.ctrlKey && e.altKey) && (e.ctrlKey || e.metaKey || ignorable)) return k === Inputmask.keyCode.ENTER && undoValue !== getBuffer().join("") && (undoValue = getBuffer().join(""),
  944. setTimeout(function() {
  945. $input.trigger("change");
  946. }, 0)), !0;
  947. if (k) {
  948. 46 === k && e.shiftKey === !1 && "," === opts.radixPoint && (k = 44);
  949. var forwardPosition, pos = checkval ? {
  950. begin: ndx,
  951. end: ndx
  952. } : caret(input), c = String.fromCharCode(k);
  953. getMaskSet().writeOutBuffer = !0;
  954. var valResult = isValid(pos, c, strict);
  955. if (valResult !== !1 && (resetMaskSet(!0), forwardPosition = void 0 !== valResult.caret ? valResult.caret : checkval ? valResult.pos + 1 : seekNext(valResult.pos),
  956. getMaskSet().p = forwardPosition), writeOut !== !1) {
  957. var self = this;
  958. if (setTimeout(function() {
  959. opts.onKeyValidation.call(self, k, valResult, opts);
  960. }, 0), getMaskSet().writeOutBuffer && valResult !== !1) {
  961. var buffer = getBuffer();
  962. writeBuffer(input, buffer, opts.numericInput && void 0 === valResult.caret ? seekPrevious(forwardPosition) : forwardPosition, e, checkval !== !0),
  963. checkval !== !0 && setTimeout(function() {
  964. isComplete(buffer) === !0 && $input.trigger("complete");
  965. }, 0);
  966. }
  967. }
  968. if (e.preventDefault(), checkval) return valResult.forwardPosition = forwardPosition,
  969. valResult;
  970. }
  971. },
  972. pasteEvent: function(e) {
  973. var tempValue, input = this, ev = e.originalEvent || e, $input = $(input), inputValue = input.inputmask._valueGet(!0), caretPos = caret(input);
  974. isRTL && (tempValue = caretPos.end, caretPos.end = caretPos.begin, caretPos.begin = tempValue);
  975. var valueBeforeCaret = inputValue.substr(0, caretPos.begin), valueAfterCaret = inputValue.substr(caretPos.end, inputValue.length);
  976. if (valueBeforeCaret === (isRTL ? getBufferTemplate().reverse() : getBufferTemplate()).slice(0, caretPos.begin).join("") && (valueBeforeCaret = ""),
  977. valueAfterCaret === (isRTL ? getBufferTemplate().reverse() : getBufferTemplate()).slice(caretPos.end).join("") && (valueAfterCaret = ""),
  978. isRTL && (tempValue = valueBeforeCaret, valueBeforeCaret = valueAfterCaret, valueAfterCaret = tempValue),
  979. window.clipboardData && window.clipboardData.getData) inputValue = valueBeforeCaret + window.clipboardData.getData("Text") + valueAfterCaret; else {
  980. if (!ev.clipboardData || !ev.clipboardData.getData) return !0;
  981. inputValue = valueBeforeCaret + ev.clipboardData.getData("text/plain") + valueAfterCaret;
  982. }
  983. var pasteValue = inputValue;
  984. if ($.isFunction(opts.onBeforePaste)) {
  985. if (pasteValue = opts.onBeforePaste(inputValue, opts), pasteValue === !1) return e.preventDefault();
  986. pasteValue || (pasteValue = inputValue);
  987. }
  988. return checkVal(input, !1, !1, isRTL ? pasteValue.split("").reverse() : pasteValue.toString().split("")),
  989. writeBuffer(input, getBuffer(), seekNext(getLastValidPosition()), e, undoValue !== getBuffer().join("")),
  990. isComplete(getBuffer()) === !0 && $input.trigger("complete"), e.preventDefault();
  991. },
  992. inputFallBackEvent: function(e) {
  993. var input = this, inputValue = input.inputmask._valueGet();
  994. if (getBuffer().join("") !== inputValue) {
  995. var caretPos = caret(input);
  996. if (inputValue = inputValue.replace(new RegExp("(" + Inputmask.escapeRegex(getBufferTemplate().join("")) + ")*"), ""),
  997. iemobile) {
  998. var inputChar = inputValue.replace(getBuffer().join(""), "");
  999. if (1 === inputChar.length) {
  1000. var keypress = new $.Event("keypress");
  1001. return keypress.which = inputChar.charCodeAt(0), EventHandlers.keypressEvent.call(input, keypress, !0, !0, !1, getMaskSet().validPositions[caretPos.begin - 1] ? caretPos.begin : caretPos.begin - 1),
  1002. !1;
  1003. }
  1004. }
  1005. if (caretPos.begin > inputValue.length && (caret(input, inputValue.length), caretPos = caret(input)),
  1006. getBuffer().length - inputValue.length !== 1 || inputValue.charAt(caretPos.begin) === getBuffer()[caretPos.begin] || inputValue.charAt(caretPos.begin + 1) === getBuffer()[caretPos.begin] || isMask(caretPos.begin)) {
  1007. for (var lvp = getLastValidPosition() + 1, bufferTemplate = getBufferTemplate().join(""); null === inputValue.match(Inputmask.escapeRegex(bufferTemplate) + "$"); ) bufferTemplate = bufferTemplate.slice(1);
  1008. inputValue = inputValue.replace(bufferTemplate, ""), inputValue = inputValue.split(""),
  1009. checkVal(input, !0, !1, inputValue, e, caretPos.begin < lvp), isComplete(getBuffer()) === !0 && $(input).trigger("complete");
  1010. } else e.keyCode = Inputmask.keyCode.BACKSPACE, EventHandlers.keydownEvent.call(input, e);
  1011. e.preventDefault();
  1012. }
  1013. },
  1014. setValueEvent: function(e) {
  1015. var input = this, value = input.inputmask._valueGet();
  1016. checkVal(input, !0, !1, ($.isFunction(opts.onBeforeMask) ? opts.onBeforeMask(value, opts) || value : value).split("")),
  1017. undoValue = getBuffer().join(""), (opts.clearMaskOnLostFocus || opts.clearIncomplete) && input.inputmask._valueGet() === getBufferTemplate().join("") && input.inputmask._valueSet("");
  1018. },
  1019. focusEvent: function(e) {
  1020. var input = this, nptValue = input.inputmask._valueGet();
  1021. opts.showMaskOnFocus && (!opts.showMaskOnHover || opts.showMaskOnHover && "" === nptValue) && (input.inputmask._valueGet() !== getBuffer().join("") ? writeBuffer(input, getBuffer(), seekNext(getLastValidPosition())) : mouseEnter === !1 && caret(input, seekNext(getLastValidPosition()))),
  1022. opts.positionCaretOnTab === !0 && EventHandlers.clickEvent.apply(input, [ e, !0 ]),
  1023. undoValue = getBuffer().join("");
  1024. },
  1025. mouseleaveEvent: function(e) {
  1026. var input = this;
  1027. if (mouseEnter = !1, opts.clearMaskOnLostFocus && document.activeElement !== input) {
  1028. var buffer = getBuffer().slice(), nptValue = input.inputmask._valueGet();
  1029. nptValue !== input.getAttribute("placeholder") && "" !== nptValue && (getLastValidPosition() === -1 && nptValue === getBufferTemplate().join("") ? buffer = [] : clearOptionalTail(buffer),
  1030. writeBuffer(input, buffer));
  1031. }
  1032. },
  1033. clickEvent: function(e, tabbed) {
  1034. function doRadixFocus(clickPos) {
  1035. if ("" !== opts.radixPoint) {
  1036. var vps = getMaskSet().validPositions;
  1037. if (void 0 === vps[clickPos] || vps[clickPos].input === getPlaceholder(clickPos)) {
  1038. if (clickPos < seekNext(-1)) return !0;
  1039. var radixPos = $.inArray(opts.radixPoint, getBuffer());
  1040. if (radixPos !== -1) {
  1041. for (var vp in vps) if (radixPos < vp && vps[vp].input !== getPlaceholder(vp)) return !1;
  1042. return !0;
  1043. }
  1044. }
  1045. }
  1046. return !1;
  1047. }
  1048. var input = this;
  1049. setTimeout(function() {
  1050. if (document.activeElement === input) {
  1051. var selectedCaret = caret(input);
  1052. if (tabbed && (selectedCaret.begin = selectedCaret.end), selectedCaret.begin === selectedCaret.end) switch (opts.positionCaretOnClick) {
  1053. case "none":
  1054. break;
  1055. case "radixFocus":
  1056. if (doRadixFocus(selectedCaret.begin)) {
  1057. var radixPos = $.inArray(opts.radixPoint, getBuffer().join(""));
  1058. caret(input, opts.numericInput ? seekNext(radixPos) : radixPos);
  1059. break;
  1060. }
  1061. default:
  1062. var clickPosition = selectedCaret.begin, lvclickPosition = getLastValidPosition(clickPosition, !0), lastPosition = seekNext(lvclickPosition);
  1063. if (clickPosition < lastPosition) caret(input, isMask(clickPosition) || isMask(clickPosition - 1) ? clickPosition : seekNext(clickPosition)); else {
  1064. var placeholder = getPlaceholder(lastPosition);
  1065. ("" !== placeholder && getBuffer()[lastPosition] !== placeholder && getTest(lastPosition).match.optionalQuantifier !== !0 || !isMask(lastPosition) && getTest(lastPosition).match.def === placeholder) && (lastPosition = seekNext(lastPosition)),
  1066. caret(input, lastPosition);
  1067. }
  1068. }
  1069. }
  1070. }, 0);
  1071. },
  1072. dblclickEvent: function(e) {
  1073. var input = this;
  1074. setTimeout(function() {
  1075. caret(input, 0, seekNext(getLastValidPosition()));
  1076. }, 0);
  1077. },
  1078. cutEvent: function(e) {
  1079. var input = this, $input = $(input), pos = caret(input), ev = e.originalEvent || e, clipboardData = window.clipboardData || ev.clipboardData, clipData = isRTL ? getBuffer().slice(pos.end, pos.begin) : getBuffer().slice(pos.begin, pos.end);
  1080. clipboardData.setData("text", isRTL ? clipData.reverse().join("") : clipData.join("")),
  1081. document.execCommand && document.execCommand("copy"), handleRemove(input, Inputmask.keyCode.DELETE, pos),
  1082. writeBuffer(input, getBuffer(), getMaskSet().p, e, undoValue !== getBuffer().join("")),
  1083. input.inputmask._valueGet() === getBufferTemplate().join("") && $input.trigger("cleared");
  1084. },
  1085. blurEvent: function(e) {
  1086. var $input = $(this), input = this;
  1087. if (input.inputmask) {
  1088. var nptValue = input.inputmask._valueGet(), buffer = getBuffer().slice();
  1089. undoValue !== buffer.join("") && setTimeout(function() {
  1090. $input.trigger("change"), undoValue = buffer.join("");
  1091. }, 0), "" !== nptValue && (opts.clearMaskOnLostFocus && (getLastValidPosition() === -1 && nptValue === getBufferTemplate().join("") ? buffer = [] : clearOptionalTail(buffer)),
  1092. isComplete(buffer) === !1 && (setTimeout(function() {
  1093. $input.trigger("incomplete");
  1094. }, 0), opts.clearIncomplete && (resetMaskSet(), buffer = opts.clearMaskOnLostFocus ? [] : getBufferTemplate().slice())),
  1095. writeBuffer(input, buffer, void 0, e));
  1096. }
  1097. },
  1098. mouseenterEvent: function(e) {
  1099. var input = this;
  1100. mouseEnter = !0, document.activeElement !== input && opts.showMaskOnHover && input.inputmask._valueGet() !== getBuffer().join("") && writeBuffer(input, getBuffer());
  1101. },
  1102. submitEvent: function(e) {
  1103. undoValue !== getBuffer().join("") && $el.trigger("change"), opts.clearMaskOnLostFocus && getLastValidPosition() === -1 && el.inputmask._valueGet && el.inputmask._valueGet() === getBufferTemplate().join("") && el.inputmask._valueSet(""),
  1104. opts.removeMaskOnSubmit && (el.inputmask._valueSet(el.inputmask.unmaskedvalue(), !0),
  1105. setTimeout(function() {
  1106. writeBuffer(el, getBuffer());
  1107. }, 0));
  1108. },
  1109. resetEvent: function(e) {
  1110. setTimeout(function() {
  1111. $el.trigger("setvalue");
  1112. }, 0);
  1113. }
  1114. };
  1115. if (void 0 !== actionObj) switch (actionObj.action) {
  1116. case "isComplete":
  1117. return el = actionObj.el, isComplete(getBuffer());
  1118. case "unmaskedvalue":
  1119. return void 0 !== el && void 0 === actionObj.value || (valueBuffer = actionObj.value,
  1120. valueBuffer = ($.isFunction(opts.onBeforeMask) ? opts.onBeforeMask(valueBuffer, opts) || valueBuffer : valueBuffer).split(""),
  1121. checkVal(void 0, !1, !1, isRTL ? valueBuffer.reverse() : valueBuffer), $.isFunction(opts.onBeforeWrite) && opts.onBeforeWrite(void 0, getBuffer(), 0, opts)),
  1122. unmaskedvalue(el);
  1123. case "mask":
  1124. mask(el);
  1125. break;
  1126. case "format":
  1127. return valueBuffer = ($.isFunction(opts.onBeforeMask) ? opts.onBeforeMask(actionObj.value, opts) || actionObj.value : actionObj.value).split(""),
  1128. checkVal(void 0, !1, !1, isRTL ? valueBuffer.reverse() : valueBuffer), $.isFunction(opts.onBeforeWrite) && opts.onBeforeWrite(void 0, getBuffer(), 0, opts),
  1129. actionObj.metadata ? {
  1130. value: isRTL ? getBuffer().slice().reverse().join("") : getBuffer().join(""),
  1131. metadata: maskScope.call(this, {
  1132. action: "getmetadata"
  1133. }, maskset, opts)
  1134. } : isRTL ? getBuffer().slice().reverse().join("") : getBuffer().join("");
  1135. case "isValid":
  1136. actionObj.value ? (valueBuffer = actionObj.value.split(""), checkVal(void 0, !1, !0, isRTL ? valueBuffer.reverse() : valueBuffer)) : actionObj.value = getBuffer().join("");
  1137. for (var buffer = getBuffer(), rl = determineLastRequiredPosition(), lmib = buffer.length - 1; lmib > rl && !isMask(lmib); lmib--) ;
  1138. return buffer.splice(rl, lmib + 1 - rl), isComplete(buffer) && actionObj.value === getBuffer().join("");
  1139. case "getemptymask":
  1140. return getBufferTemplate().join("");
  1141. case "remove":
  1142. if (el) {
  1143. $el = $(el), el.inputmask._valueSet(unmaskedvalue(el)), EventRuler.off(el);
  1144. var valueProperty;
  1145. Object.getOwnPropertyDescriptor && Object.getPrototypeOf ? (valueProperty = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(el), "value"),
  1146. valueProperty && el.inputmask.__valueGet && Object.defineProperty(el, "value", {
  1147. get: el.inputmask.__valueGet,
  1148. set: el.inputmask.__valueSet,
  1149. configurable: !0
  1150. })) : document.__lookupGetter__ && el.__lookupGetter__("value") && el.inputmask.__valueGet && (el.__defineGetter__("value", el.inputmask.__valueGet),
  1151. el.__defineSetter__("value", el.inputmask.__valueSet)), el.inputmask = void 0;
  1152. }
  1153. return el;
  1154. case "getmetadata":
  1155. if ($.isArray(maskset.metadata)) {
  1156. var maskTarget = getMaskTemplate(!0, 0, !1).join("");
  1157. return $.each(maskset.metadata, function(ndx, mtdt) {
  1158. if (mtdt.mask === maskTarget) return maskTarget = mtdt, !1;
  1159. }), maskTarget;
  1160. }
  1161. return maskset.metadata;
  1162. }
  1163. }
  1164. var ua = navigator.userAgent, mobile = /mobile/i.test(ua), iemobile = /iemobile/i.test(ua), iphone = /iphone/i.test(ua) && !iemobile, android = /android/i.test(ua) && !iemobile;
  1165. return Inputmask.prototype = {
  1166. defaults: {
  1167. placeholder: "_",
  1168. optionalmarker: {
  1169. start: "[",
  1170. end: "]"
  1171. },
  1172. quantifiermarker: {
  1173. start: "{",
  1174. end: "}"
  1175. },
  1176. groupmarker: {
  1177. start: "(",
  1178. end: ")"
  1179. },
  1180. alternatormarker: "|",
  1181. escapeChar: "\\",
  1182. mask: null,
  1183. oncomplete: $.noop,
  1184. onincomplete: $.noop,
  1185. oncleared: $.noop,
  1186. repeat: 0,
  1187. greedy: !0,
  1188. autoUnmask: !1,
  1189. removeMaskOnSubmit: !1,
  1190. clearMaskOnLostFocus: !0,
  1191. insertMode: !0,
  1192. clearIncomplete: !1,
  1193. aliases: {},
  1194. alias: null,
  1195. onKeyDown: $.noop,
  1196. onBeforeMask: null,
  1197. onBeforePaste: function(pastedValue, opts) {
  1198. return $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask(pastedValue, opts) : pastedValue;
  1199. },
  1200. onBeforeWrite: null,
  1201. onUnMask: null,
  1202. showMaskOnFocus: !0,
  1203. showMaskOnHover: !0,
  1204. onKeyValidation: $.noop,
  1205. skipOptionalPartCharacter: " ",
  1206. numericInput: !1,
  1207. rightAlign: !1,
  1208. undoOnEscape: !0,
  1209. radixPoint: "",
  1210. radixPointDefinitionSymbol: void 0,
  1211. groupSeparator: "",
  1212. keepStatic: null,
  1213. positionCaretOnTab: !0,
  1214. tabThrough: !1,
  1215. supportsInputType: [ "text", "tel", "password" ],
  1216. definitions: {
  1217. "9": {
  1218. validator: "[0-9]",
  1219. cardinality: 1,
  1220. definitionSymbol: "*"
  1221. },
  1222. a: {
  1223. validator: "[A-Za-z\u0410-\u044f\u0401\u0451\xc0-\xff\xb5]",
  1224. cardinality: 1,
  1225. definitionSymbol: "*"
  1226. },
  1227. "*": {
  1228. validator: "[0-9A-Za-z\u0410-\u044f\u0401\u0451\xc0-\xff\xb5]",
  1229. cardinality: 1
  1230. }
  1231. },
  1232. 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 ],
  1233. isComplete: null,
  1234. canClearPosition: $.noop,
  1235. postValidation: null,
  1236. staticDefinitionSymbol: void 0,
  1237. jitMasking: !1,
  1238. nullable: !0,
  1239. inputEventOnly: !1,
  1240. noValuePatching: !1,
  1241. positionCaretOnClick: "lvp",
  1242. casing: null,
  1243. inputmode: "verbatim",
  1244. colorMask: !1,
  1245. androidHack: !1
  1246. },
  1247. masksCache: {},
  1248. mask: function(elems) {
  1249. function importAttributeOptions(npt, opts, userOptions, dataAttribute) {
  1250. function importOption(option, optionData) {
  1251. optionData = void 0 !== optionData ? optionData : npt.getAttribute(dataAttribute + "-" + option),
  1252. null !== optionData && ("string" == typeof optionData && (0 === option.indexOf("on") ? optionData = window[optionData] : "false" === optionData ? optionData = !1 : "true" === optionData && (optionData = !0)),
  1253. userOptions[option] = optionData);
  1254. }
  1255. var option, dataoptions, optionData, p, attrOptions = npt.getAttribute(dataAttribute);
  1256. if (attrOptions && "" !== attrOptions && (attrOptions = attrOptions.replace(new RegExp("'", "g"), '"'),
  1257. dataoptions = JSON.parse("{" + attrOptions + "}")), dataoptions) {
  1258. optionData = void 0;
  1259. for (p in dataoptions) if ("alias" === p.toLowerCase()) {
  1260. optionData = dataoptions[p];
  1261. break;
  1262. }
  1263. }
  1264. importOption("alias", optionData), userOptions.alias && resolveAlias(userOptions.alias, userOptions, opts);
  1265. for (option in opts) {
  1266. if (dataoptions) {
  1267. optionData = void 0;
  1268. for (p in dataoptions) if (p.toLowerCase() === option.toLowerCase()) {
  1269. optionData = dataoptions[p];
  1270. break;
  1271. }
  1272. }
  1273. importOption(option, optionData);
  1274. }
  1275. return $.extend(!0, opts, userOptions), opts;
  1276. }
  1277. var that = this;
  1278. return "string" == typeof elems && (elems = document.getElementById(elems) || document.querySelectorAll(elems)),
  1279. elems = elems.nodeName ? [ elems ] : elems, $.each(elems, function(ndx, el) {
  1280. var scopedOpts = $.extend(!0, {}, that.opts);
  1281. importAttributeOptions(el, scopedOpts, $.extend(!0, {}, that.userOptions), that.dataAttribute);
  1282. var maskset = generateMaskSet(scopedOpts, that.noMasksCache);
  1283. void 0 !== maskset && (void 0 !== el.inputmask && el.inputmask.remove(), el.inputmask = new Inputmask(),
  1284. el.inputmask.opts = scopedOpts, el.inputmask.noMasksCache = that.noMasksCache, el.inputmask.userOptions = $.extend(!0, {}, that.userOptions),
  1285. el.inputmask.el = el, el.inputmask.maskset = maskset, $.data(el, "_inputmask_opts", scopedOpts),
  1286. maskScope.call(el.inputmask, {
  1287. action: "mask"
  1288. }));
  1289. }), elems && elems[0] ? elems[0].inputmask || this : this;
  1290. },
  1291. option: function(options, noremask) {
  1292. return "string" == typeof options ? this.opts[options] : "object" == typeof options ? ($.extend(this.userOptions, options),
  1293. this.el && noremask !== !0 && this.mask(this.el), this) : void 0;
  1294. },
  1295. unmaskedvalue: function(value) {
  1296. return this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache),
  1297. maskScope.call(this, {
  1298. action: "unmaskedvalue",
  1299. value: value
  1300. });
  1301. },
  1302. remove: function() {
  1303. return maskScope.call(this, {
  1304. action: "remove"
  1305. });
  1306. },
  1307. getemptymask: function() {
  1308. return this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache),
  1309. maskScope.call(this, {
  1310. action: "getemptymask"
  1311. });
  1312. },
  1313. hasMaskedValue: function() {
  1314. return !this.opts.autoUnmask;
  1315. },
  1316. isComplete: function() {
  1317. return this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache),
  1318. maskScope.call(this, {
  1319. action: "isComplete"
  1320. });
  1321. },
  1322. getmetadata: function() {
  1323. return this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache),
  1324. maskScope.call(this, {
  1325. action: "getmetadata"
  1326. });
  1327. },
  1328. isValid: function(value) {
  1329. return this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache),
  1330. maskScope.call(this, {
  1331. action: "isValid",
  1332. value: value
  1333. });
  1334. },
  1335. format: function(value, metadata) {
  1336. return this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache),
  1337. maskScope.call(this, {
  1338. action: "format",
  1339. value: value,
  1340. metadata: metadata
  1341. });
  1342. },
  1343. analyseMask: function(mask, opts) {
  1344. function MaskToken(isGroup, isOptional, isQuantifier, isAlternator) {
  1345. this.matches = [], this.openGroup = isGroup || !1, this.isGroup = isGroup || !1,
  1346. this.isOptional = isOptional || !1, this.isQuantifier = isQuantifier || !1, this.isAlternator = isAlternator || !1,
  1347. this.quantifier = {
  1348. min: 1,
  1349. max: 1
  1350. };
  1351. }
  1352. function insertTestDefinition(mtoken, element, position) {
  1353. var maskdef = opts.definitions[element];
  1354. position = void 0 !== position ? position : mtoken.matches.length;
  1355. var prevMatch = mtoken.matches[position - 1];
  1356. if (maskdef && !escaped) {
  1357. maskdef.placeholder = $.isFunction(maskdef.placeholder) ? maskdef.placeholder(opts) : maskdef.placeholder;
  1358. for (var prevalidators = maskdef.prevalidator, prevalidatorsL = prevalidators ? prevalidators.length : 0, i = 1; i < maskdef.cardinality; i++) {
  1359. var prevalidator = prevalidatorsL >= i ? prevalidators[i - 1] : [], validator = prevalidator.validator, cardinality = prevalidator.cardinality;
  1360. mtoken.matches.splice(position++, 0, {
  1361. fn: validator ? "string" == typeof validator ? new RegExp(validator) : new function() {
  1362. this.test = validator;
  1363. }() : new RegExp("."),
  1364. cardinality: cardinality ? cardinality : 1,
  1365. optionality: mtoken.isOptional,
  1366. newBlockMarker: void 0 === prevMatch || prevMatch.def !== (maskdef.definitionSymbol || element),
  1367. casing: maskdef.casing,
  1368. def: maskdef.definitionSymbol || element,
  1369. placeholder: maskdef.placeholder,
  1370. nativeDef: element
  1371. }), prevMatch = mtoken.matches[position - 1];
  1372. }
  1373. mtoken.matches.splice(position++, 0, {
  1374. fn: maskdef.validator ? "string" == typeof maskdef.validator ? new RegExp(maskdef.validator) : new function() {
  1375. this.test = maskdef.validator;
  1376. }() : new RegExp("."),
  1377. cardinality: maskdef.cardinality,
  1378. optionality: mtoken.isOptional,
  1379. newBlockMarker: void 0 === prevMatch || prevMatch.def !== (maskdef.definitionSymbol || element),
  1380. casing: maskdef.casing,
  1381. def: maskdef.definitionSymbol || element,
  1382. placeholder: maskdef.placeholder,
  1383. nativeDef: element
  1384. });
  1385. } else mtoken.matches.splice(position++, 0, {
  1386. fn: null,
  1387. cardinality: 0,
  1388. optionality: mtoken.isOptional,
  1389. newBlockMarker: void 0 === prevMatch || prevMatch.def !== element,
  1390. casing: null,
  1391. def: opts.staticDefinitionSymbol || element,
  1392. placeholder: void 0 !== opts.staticDefinitionSymbol ? element : void 0,
  1393. nativeDef: element
  1394. }), escaped = !1;
  1395. }
  1396. function verifyGroupMarker(maskToken) {
  1397. maskToken && maskToken.matches && $.each(maskToken.matches, function(ndx, token) {
  1398. var nextToken = maskToken.matches[ndx + 1];
  1399. (void 0 === nextToken || void 0 === nextToken.matches || nextToken.isQuantifier === !1) && token && token.isGroup && (token.isGroup = !1,
  1400. insertTestDefinition(token, opts.groupmarker.start, 0), token.openGroup !== !0 && insertTestDefinition(token, opts.groupmarker.end)),
  1401. verifyGroupMarker(token);
  1402. });
  1403. }
  1404. function defaultCase() {
  1405. if (openenings.length > 0) {
  1406. if (currentOpeningToken = openenings[openenings.length - 1], insertTestDefinition(currentOpeningToken, m),
  1407. currentOpeningToken.isAlternator) {
  1408. alternator = openenings.pop();
  1409. for (var mndx = 0; mndx < alternator.matches.length; mndx++) alternator.matches[mndx].isGroup = !1;
  1410. openenings.length > 0 ? (currentOpeningToken = openenings[openenings.length - 1],
  1411. currentOpeningToken.matches.push(alternator)) : currentToken.matches.push(alternator);
  1412. }
  1413. } else insertTestDefinition(currentToken, m);
  1414. }
  1415. function reverseTokens(maskToken) {
  1416. function reverseStatic(st) {
  1417. return st === opts.optionalmarker.start ? st = opts.optionalmarker.end : st === opts.optionalmarker.end ? st = opts.optionalmarker.start : st === opts.groupmarker.start ? st = opts.groupmarker.end : st === opts.groupmarker.end && (st = opts.groupmarker.start),
  1418. st;
  1419. }
  1420. maskToken.matches = maskToken.matches.reverse();
  1421. for (var match in maskToken.matches) {
  1422. var intMatch = parseInt(match);
  1423. if (maskToken.matches[match].isQuantifier && maskToken.matches[intMatch + 1] && maskToken.matches[intMatch + 1].isGroup) {
  1424. var qt = maskToken.matches[match];
  1425. maskToken.matches.splice(match, 1), maskToken.matches.splice(intMatch + 1, 0, qt);
  1426. }
  1427. void 0 !== maskToken.matches[match].matches ? maskToken.matches[match] = reverseTokens(maskToken.matches[match]) : maskToken.matches[match] = reverseStatic(maskToken.matches[match]);
  1428. }
  1429. return maskToken;
  1430. }
  1431. for (var match, m, openingToken, currentOpeningToken, alternator, lastMatch, groupToken, tokenizer = /(?:[?*+]|\{[0-9\+\*]+(?:,[0-9\+\*]*)?\})|[^.?*+^${[]()|\\]+|./g, escaped = !1, currentToken = new MaskToken(), openenings = [], maskTokens = []; match = tokenizer.exec(mask); ) if (m = match[0],
  1432. escaped) defaultCase(); else switch (m.charAt(0)) {
  1433. case opts.escapeChar:
  1434. escaped = !0;
  1435. break;
  1436. case opts.optionalmarker.end:
  1437. case opts.groupmarker.end:
  1438. if (openingToken = openenings.pop(), openingToken.openGroup = !1, void 0 !== openingToken) if (openenings.length > 0) {
  1439. if (currentOpeningToken = openenings[openenings.length - 1], currentOpeningToken.matches.push(openingToken),
  1440. currentOpeningToken.isAlternator) {
  1441. alternator = openenings.pop();
  1442. for (var mndx = 0; mndx < alternator.matches.length; mndx++) alternator.matches[mndx].isGroup = !1;
  1443. openenings.length > 0 ? (currentOpeningToken = openenings[openenings.length - 1],
  1444. currentOpeningToken.matches.push(alternator)) : currentToken.matches.push(alternator);
  1445. }
  1446. } else currentToken.matches.push(openingToken); else defaultCase();
  1447. break;
  1448. case opts.optionalmarker.start:
  1449. openenings.push(new MaskToken((!1), (!0)));
  1450. break;
  1451. case opts.groupmarker.start:
  1452. openenings.push(new MaskToken((!0)));
  1453. break;
  1454. case opts.quantifiermarker.start:
  1455. var quantifier = new MaskToken((!1), (!1), (!0));
  1456. m = m.replace(/[{}]/g, "");
  1457. var mq = m.split(","), mq0 = isNaN(mq[0]) ? mq[0] : parseInt(mq[0]), mq1 = 1 === mq.length ? mq0 : isNaN(mq[1]) ? mq[1] : parseInt(mq[1]);
  1458. if ("*" !== mq1 && "+" !== mq1 || (mq0 = "*" === mq1 ? 0 : 1), quantifier.quantifier = {
  1459. min: mq0,
  1460. max: mq1
  1461. }, openenings.length > 0) {
  1462. var matches = openenings[openenings.length - 1].matches;
  1463. match = matches.pop(), match.isGroup || (groupToken = new MaskToken((!0)), groupToken.matches.push(match),
  1464. match = groupToken), matches.push(match), matches.push(quantifier);
  1465. } else match = currentToken.matches.pop(), match.isGroup || (groupToken = new MaskToken((!0)),
  1466. groupToken.matches.push(match), match = groupToken), currentToken.matches.push(match),
  1467. currentToken.matches.push(quantifier);
  1468. break;
  1469. case opts.alternatormarker:
  1470. openenings.length > 0 ? (currentOpeningToken = openenings[openenings.length - 1],
  1471. lastMatch = currentOpeningToken.matches.pop()) : lastMatch = currentToken.matches.pop(),
  1472. lastMatch.isAlternator ? openenings.push(lastMatch) : (alternator = new MaskToken((!1), (!1), (!1), (!0)),
  1473. alternator.matches.push(lastMatch), openenings.push(alternator));
  1474. break;
  1475. default:
  1476. defaultCase();
  1477. }
  1478. for (;openenings.length > 0; ) openingToken = openenings.pop(), currentToken.matches.push(openingToken);
  1479. return currentToken.matches.length > 0 && (verifyGroupMarker(currentToken), maskTokens.push(currentToken)),
  1480. opts.numericInput && reverseTokens(maskTokens[0]), maskTokens;
  1481. }
  1482. }, Inputmask.extendDefaults = function(options) {
  1483. $.extend(!0, Inputmask.prototype.defaults, options);
  1484. }, Inputmask.extendDefinitions = function(definition) {
  1485. $.extend(!0, Inputmask.prototype.defaults.definitions, definition);
  1486. }, Inputmask.extendAliases = function(alias) {
  1487. $.extend(!0, Inputmask.prototype.defaults.aliases, alias);
  1488. }, Inputmask.format = function(value, options, metadata) {
  1489. return Inputmask(options).format(value, metadata);
  1490. }, Inputmask.unmask = function(value, options) {
  1491. return Inputmask(options).unmaskedvalue(value);
  1492. }, Inputmask.isValid = function(value, options) {
  1493. return Inputmask(options).isValid(value);
  1494. }, Inputmask.remove = function(elems) {
  1495. $.each(elems, function(ndx, el) {
  1496. el.inputmask && el.inputmask.remove();
  1497. });
  1498. }, Inputmask.escapeRegex = function(str) {
  1499. var specials = [ "/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\", "$", "^" ];
  1500. return str.replace(new RegExp("(\\" + specials.join("|\\") + ")", "gim"), "\\$1");
  1501. }, Inputmask.keyCode = {
  1502. ALT: 18,
  1503. BACKSPACE: 8,
  1504. BACKSPACE_SAFARI: 127,
  1505. CAPS_LOCK: 20,
  1506. COMMA: 188,
  1507. COMMAND: 91,
  1508. COMMAND_LEFT: 91,
  1509. COMMAND_RIGHT: 93,
  1510. CONTROL: 17,
  1511. DELETE: 46,
  1512. DOWN: 40,
  1513. END: 35,
  1514. ENTER: 13,
  1515. ESCAPE: 27,
  1516. HOME: 36,
  1517. INSERT: 45,
  1518. LEFT: 37,
  1519. MENU: 93,
  1520. NUMPAD_ADD: 107,
  1521. NUMPAD_DECIMAL: 110,
  1522. NUMPAD_DIVIDE: 111,
  1523. NUMPAD_ENTER: 108,
  1524. NUMPAD_MULTIPLY: 106,
  1525. NUMPAD_SUBTRACT: 109,
  1526. PAGE_DOWN: 34,
  1527. PAGE_UP: 33,
  1528. PERIOD: 190,
  1529. RIGHT: 39,
  1530. SHIFT: 16,
  1531. SPACE: 32,
  1532. TAB: 9,
  1533. UP: 38,
  1534. WINDOWS: 91,
  1535. X: 88
  1536. }, window.Inputmask = Inputmask, Inputmask;
  1537. });