inputmask.js 101 KB

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