inputmask.js 107 KB

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