inputmask.js 111 KB

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