inputmask.js 97 KB

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