inputmask.js 98 KB

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