inputmask.js 100 KB

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