inputmask.js 91 KB

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