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