inputmask.js 86 KB

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