inputmask.js 117 KB

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