inputmask.js 110 KB

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