inputmask.js 111 KB

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