inputmask.js 90 KB

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