inputmask.js 90 KB

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