inputmask.js 108 KB

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