inputmask.js 107 KB

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