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