inputmask.js 111 KB

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