inputmask.js 91 KB

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