inputmask.js 91 KB

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