inputmask.js 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684
  1. /*
  2. * Input Mask Core
  3. * http://github.com/RobinHerbots/jquery.inputmask
  4. * Copyright (c) 2010 - Robin Herbots
  5. * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. * Version: 0.0.0-dev
  7. */
  8. (function(factory) {
  9. if (typeof define === "function" && define.amd) {
  10. define(["inputmask.dependencyLib"], factory);
  11. } else if (typeof exports === "object") {
  12. module.exports = factory(require("./inputmask.dependencyLib"));
  13. } else {
  14. factory(window.dependencyLib || jQuery);
  15. }
  16. }
  17. (function($) {
  18. function Inputmask(alias, options) {
  19. //allow instanciating without new
  20. if (!(this instanceof Inputmask)) {
  21. return new Inputmask(alias, options);
  22. }
  23. if (typeof alias === "object") {
  24. options = alias;
  25. } else {
  26. options = options || {};
  27. options.alias = alias;
  28. }
  29. this.el = undefined;
  30. //init options
  31. this.opts = $.extend(true, {}, this.defaults, options);
  32. this.noMasksCache = options && options.definitions !== undefined;
  33. this.userOptions = options || {}; //user passed options
  34. resolveAlias(this.opts.alias, options, this.opts);
  35. }
  36. Inputmask.prototype = {
  37. //options default
  38. defaults: {
  39. placeholder: "_",
  40. optionalmarker: {
  41. start: "[",
  42. end: "]"
  43. },
  44. quantifiermarker: {
  45. start: "{",
  46. end: "}"
  47. },
  48. groupmarker: {
  49. start: "(",
  50. end: ")"
  51. },
  52. alternatormarker: "|",
  53. escapeChar: "\\",
  54. mask: null, //needs tobe null instead of undefined as the extend method does not consider props with the undefined value
  55. oncomplete: $.noop, //executes when the mask is complete
  56. onincomplete: $.noop, //executes when the mask is incomplete and focus is lost
  57. oncleared: $.noop, //executes when the mask is cleared
  58. repeat: 0, //repetitions of the mask: * ~ forever, otherwise specify an integer
  59. greedy: true, //true: allocated buffer for the mask and repetitions - false: allocate only if needed
  60. autoUnmask: false, //automatically unmask when retrieving the value with $.fn.val or value if the browser supports __lookupGetter__ or getOwnPropertyDescriptor
  61. removeMaskOnSubmit: false, //remove the mask before submitting the form.
  62. clearMaskOnLostFocus: true,
  63. insertMode: true, //insert the input or overwrite the input
  64. clearIncomplete: false, //clear the incomplete input on blur
  65. aliases: {}, //aliases definitions => see jquery.inputmask.extensions.js
  66. alias: null,
  67. onKeyDown: $.noop, //callback to implement autocomplete on certain keys for example. args => event, buffer, caretPos, opts
  68. onBeforeMask: null, //executes before masking the initial value to allow preprocessing of the initial value. args => initialValue, opts => return processedValue
  69. onBeforePaste: function(pastedValue, opts) {
  70. return $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask(pastedValue, opts) : pastedValue;
  71. }, //executes before masking the pasted value to allow preprocessing of the pasted value. args => pastedValue, opts => return processedValue
  72. onBeforeWrite: null, //executes before writing to the masked element. args => event, opts
  73. onUnMask: null, //executes after unmasking to allow postprocessing of the unmaskedvalue. args => maskedValue, unmaskedValue, opts
  74. showMaskOnFocus: true, //show the mask-placeholder when the input has focus
  75. showMaskOnHover: true, //show the mask-placeholder when hovering the empty input
  76. onKeyValidation: $.noop, //executes on every key-press with the result of isValid. Params: result, opts
  77. skipOptionalPartCharacter: " ", //a character which can be used to skip an optional part of a mask
  78. showTooltip: false, //show the activemask as tooltip
  79. numericInput: false, //numericInput input direction style (input shifts to the left while holding the caret position)
  80. rightAlign: false, //align to the right
  81. undoOnEscape: true, //pressing escape reverts the value to the value before focus
  82. //numeric basic properties
  83. radixPoint: "", //".", // | ","
  84. groupSeparator: "", //",", // | "."
  85. radixFocus: false, //position caret to radixpoint on initial click
  86. //numeric basic properties
  87. nojumps: false, //do not jump over fixed parts in the mask
  88. nojumpsThreshold: 0, //start nojumps as of
  89. keepStatic: null, //try to keep the mask static while typing. Decisions to alter the mask will be posponed if possible - null see auto selection for multi masks
  90. positionCaretOnTab: false, //when enabled the caret position is set after the latest valid position on TAB
  91. tabThrough: false, //allows for tabbing through the different parts of the masked field
  92. supportsInputType: [], //allow extra inputtypes for masking, ex. number can be allowed for numeric alias without pre-/suffix and standard radixpoint, groupSeparator
  93. definitions: {
  94. "9": {
  95. validator: "[0-9]",
  96. cardinality: 1,
  97. definitionSymbol: "*"
  98. },
  99. "a": {
  100. validator: "[A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]",
  101. cardinality: 1,
  102. definitionSymbol: "*"
  103. },
  104. "*": {
  105. validator: "[0-9A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]",
  106. cardinality: 1
  107. }
  108. },
  109. //specify keyCodes which should not be considered in the keypress event, otherwise the preventDefault will stop their default behavior especially in FF
  110. 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],
  111. isComplete: null, //override for isComplete - args => buffer, opts - return true || false
  112. canClearPosition: $.noop, //hook to alter the clear behavior in the stripValidPositions args => maskset, position, lastValidPosition, opts => return true|false
  113. postValidation: null //hook to postValidate the result from isValid. Usefull for validating the entry as a whole. args => buffer, opts => return true/false
  114. },
  115. masksCache: {},
  116. mask: function(el) {
  117. var scopedOpts = $.extend(true, {}, this.opts);
  118. importAttributeOptions(el, scopedOpts, $.extend(true, {}, this.userOptions));
  119. var maskset = generateMaskSet(scopedOpts, this.noMasksCache);
  120. if (maskset !== undefined) {
  121. if (el.inputmask !== undefined) {
  122. el.inputmask.remove();
  123. }
  124. //store inputmask instance on the input with element reference
  125. el.inputmask = new Inputmask();
  126. el.inputmask.opts = scopedOpts;
  127. el.inputmask.noMasksCache = this.noMasksCache;
  128. el.inputmask.userOptions = $.extend(true, {}, this.userOptions);
  129. el.inputmask.el = el;
  130. el.inputmask.maskset = maskset;
  131. el.inputmask.isRTL = false;
  132. $.data(el, "_inputmask_opts", scopedOpts);
  133. maskScope({
  134. "action": "mask",
  135. "el": el
  136. }, maskset, el.inputmask.opts);
  137. }
  138. return el;
  139. },
  140. option: function(options) { //set extra options || retrieve value of a current option
  141. if (typeof options === "string") {
  142. return this.opts[options];
  143. } else if (typeof options === "object") {
  144. $.extend(this.opts, options);
  145. $.extend(this.userOptions, options); //user passed options
  146. return this;
  147. }
  148. },
  149. unmaskedvalue: function(value) {
  150. return maskScope({
  151. "action": "unmaskedvalue",
  152. "el": this.el,
  153. "value": value
  154. }, this.el && this.el.inputmask ? this.el.inputmask.maskset : generateMaskSet(this.opts, this.noMasksCache), this.opts);
  155. },
  156. remove: function() {
  157. if (this.el) {
  158. maskScope({
  159. "action": "remove",
  160. "el": this.el
  161. });
  162. this.el.inputmask = undefined; //delete ~ undefined
  163. return this.el;
  164. }
  165. },
  166. getemptymask: function() { //return the default (empty) mask value, usefull for setting the default value in validation
  167. if (this.el) {
  168. return maskScope({
  169. "action": "getemptymask",
  170. "el": this.el
  171. });
  172. }
  173. },
  174. hasMaskedValue: function() { //check wheter the returned value is masked or not; currently only works reliable when using jquery.val fn to retrieve the value
  175. return !this.opts.autoUnmask;
  176. },
  177. isComplete: function() {
  178. if (this.el) {
  179. return maskScope({
  180. "action": "isComplete",
  181. "buffer": this.el.inputmask._valueGet().split(""),
  182. "el": this.el
  183. });
  184. }
  185. },
  186. getmetadata: function() { //return mask metadata if exists
  187. if (this.el) {
  188. return maskScope({
  189. "action": "getmetadata",
  190. "el": this.el
  191. });
  192. }
  193. },
  194. isValid: function(value) {
  195. return maskScope({
  196. "action": "isValid",
  197. "value": value
  198. }, generateMaskSet(this.opts, this.noMasksCache), this.opts);
  199. },
  200. format: function(value, metadata) {
  201. return maskScope({
  202. "action": "format",
  203. "value": value,
  204. "metadata": metadata //true/false getmetadata
  205. }, generateMaskSet(this.opts, this.noMasksCache), this.opts);
  206. }
  207. };
  208. //apply defaults, definitions, aliases
  209. Inputmask.extendDefaults = function(options) {
  210. $.extend(Inputmask.prototype.defaults, options);
  211. };
  212. Inputmask.extendDefinitions = function(definition) {
  213. $.extend(Inputmask.prototype.defaults.definitions, definition);
  214. };
  215. Inputmask.extendAliases = function(alias) {
  216. $.extend(Inputmask.prototype.defaults.aliases, alias);
  217. };
  218. //static fn on inputmask
  219. Inputmask.format = function(value, options, metadata) {
  220. return Inputmask(options).format(value, metadata);
  221. };
  222. Inputmask.unmask = function(value, options) {
  223. return Inputmask(options).unmaskedvalue(value);
  224. };
  225. Inputmask.isValid = function(value, options) {
  226. return Inputmask(options).isValid(value);
  227. };
  228. Inputmask.escapeRegex = function(str) {
  229. var specials = ["/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\", "$", "^"];
  230. return str.replace(new RegExp("(\\" + specials.join("|\\") + ")", "gim"), "\\$1");
  231. };
  232. Inputmask.keyCode = {
  233. ALT: 18,
  234. BACKSPACE: 8,
  235. CAPS_LOCK: 20,
  236. COMMA: 188,
  237. COMMAND: 91,
  238. COMMAND_LEFT: 91,
  239. COMMAND_RIGHT: 93,
  240. CONTROL: 17,
  241. DELETE: 46,
  242. DOWN: 40,
  243. END: 35,
  244. ENTER: 13,
  245. ESCAPE: 27,
  246. HOME: 36,
  247. INSERT: 45,
  248. LEFT: 37,
  249. MENU: 93,
  250. NUMPAD_ADD: 107,
  251. NUMPAD_DECIMAL: 110,
  252. NUMPAD_DIVIDE: 111,
  253. NUMPAD_ENTER: 108,
  254. NUMPAD_MULTIPLY: 106,
  255. NUMPAD_SUBTRACT: 109,
  256. PAGE_DOWN: 34,
  257. PAGE_UP: 33,
  258. PERIOD: 190,
  259. RIGHT: 39,
  260. SHIFT: 16,
  261. SPACE: 32,
  262. TAB: 9,
  263. UP: 38,
  264. WINDOWS: 91
  265. };
  266. //helper functions
  267. function isInputEventSupported(eventName) {
  268. var el = document.createElement("input"),
  269. evName = "on" + eventName,
  270. isSupported = (evName in el);
  271. if (!isSupported) {
  272. el.setAttribute(evName, "return;");
  273. isSupported = typeof el[evName] == "function";
  274. }
  275. el = null;
  276. return isSupported;
  277. }
  278. function isInputTypeSupported(inputType) {
  279. var isSupported = inputType === "text" || inputType === "tel" || inputType === "password";
  280. if (!isSupported) {
  281. var el = document.createElement("input");
  282. el.setAttribute("type", inputType);
  283. isSupported = el.type === "text"; //apply mask only if the type is not natively supported
  284. el = null;
  285. }
  286. return isSupported;
  287. }
  288. function resolveAlias(aliasStr, options, opts) {
  289. var aliasDefinition = opts.aliases[aliasStr];
  290. if (aliasDefinition) {
  291. if (aliasDefinition.alias) resolveAlias(aliasDefinition.alias, undefined, opts); //alias is another alias
  292. $.extend(true, opts, aliasDefinition); //merge alias definition in the options
  293. $.extend(true, opts, options); //reapply extra given options
  294. return true;
  295. } else //alias not found - try as mask
  296. if (opts.mask === null) {
  297. opts.mask = aliasStr;
  298. }
  299. return false;
  300. }
  301. function importAttributeOptions(npt, opts, userOptions) {
  302. var attrOptions = npt.getAttribute("data-inputmask");
  303. function importOption(option) {
  304. var optionData = npt.getAttribute("data-inputmask-" + option.toLowerCase());
  305. if (optionData !== null) {
  306. optionData = typeof optionData == "boolean" ? optionData : optionData.toString();
  307. /*eslint-disable no-eval */
  308. if (typeof optionData === "string" && option.indexOf("on") === 0) {
  309. optionData = eval("(" + optionData + ")");
  310. }
  311. /*eslint-enable no-eval */
  312. if (option === "mask" && optionData.indexOf("[") === 0) {
  313. userOptions[option] = optionData.replace(/[\s[\]]/g, "").split(",");
  314. userOptions[option][0] = userOptions[option][0].replace("'", "");
  315. userOptions[option][userOptions[option].length - 1] = userOptions[option][userOptions[option].length - 1].replace("'", "");
  316. } else userOptions[option] = optionData;
  317. }
  318. }
  319. if (attrOptions && attrOptions !== "") {
  320. try {
  321. attrOptions = attrOptions.replace(new RegExp("'", "g"), '"');
  322. var dataoptions = $.parseJSON("{" + attrOptions + "}");
  323. $.extend(true, userOptions, dataoptions);
  324. } catch (ex) {
  325. } //need a more relax parseJSON
  326. }
  327. for (var option in opts) {
  328. importOption(option);
  329. }
  330. if (userOptions.alias) {
  331. resolveAlias(userOptions.alias, userOptions, opts);
  332. for (option in opts) {
  333. importOption(option);
  334. }
  335. }
  336. $.extend(true, opts, userOptions);
  337. return opts;
  338. }
  339. function generateMaskSet(opts, nocache) {
  340. var ms;
  341. function analyseMask(mask) {
  342. var tokenizer = /(?:[?*+]|\{[0-9\+\*]+(?:,[0-9\+\*]*)?\})|[^.?*+^${[]()|\\]+|./g,
  343. escaped = false,
  344. currentToken = new MaskToken(),
  345. match,
  346. m,
  347. openenings = [],
  348. maskTokens = [],
  349. openingToken,
  350. currentOpeningToken,
  351. alternator,
  352. lastMatch,
  353. groupToken;
  354. function MaskToken(isGroup, isOptional, isQuantifier, isAlternator) {
  355. this.matches = [];
  356. this.isGroup = isGroup || false;
  357. this.isOptional = isOptional || false;
  358. this.isQuantifier = isQuantifier || false;
  359. this.isAlternator = isAlternator || false;
  360. this.quantifier = {
  361. min: 1,
  362. max: 1
  363. };
  364. }
  365. //test definition => {fn: RegExp/function, cardinality: int, optionality: bool, newBlockMarker: bool, casing: null/upper/lower, def: definitionSymbol, placeholder: placeholder, mask: real maskDefinition}
  366. function insertTestDefinition(mtoken, element, position) {
  367. var maskdef = opts.definitions[element];
  368. position = position !== undefined ? position : mtoken.matches.length;
  369. var prevMatch = mtoken.matches[position - 1];
  370. if (maskdef && !escaped) {
  371. maskdef.placeholder = $.isFunction(maskdef.placeholder) ? maskdef.placeholder.call(this, opts) : maskdef.placeholder;
  372. var prevalidators = maskdef.prevalidator,
  373. prevalidatorsL = prevalidators ? prevalidators.length : 0;
  374. //handle prevalidators
  375. for (var i = 1; i < maskdef.cardinality; i++) {
  376. var prevalidator = prevalidatorsL >= i ? prevalidators[i - 1] : [],
  377. validator = prevalidator.validator,
  378. cardinality = prevalidator.cardinality;
  379. mtoken.matches.splice(position++, 0, {
  380. fn: validator ? typeof validator === "string" ? new RegExp(validator) : new function() {
  381. this.test = validator;
  382. } : new RegExp("."),
  383. cardinality: cardinality ? cardinality : 1,
  384. optionality: mtoken.isOptional,
  385. newBlockMarker: prevMatch === undefined || prevMatch.def !== (maskdef.definitionSymbol || element),
  386. casing: maskdef.casing,
  387. def: maskdef.definitionSymbol || element,
  388. placeholder: maskdef.placeholder,
  389. mask: element
  390. });
  391. prevMatch = mtoken.matches[position - 1];
  392. }
  393. mtoken.matches.splice(position++, 0, {
  394. fn: maskdef.validator ? typeof maskdef.validator == "string" ? new RegExp(maskdef.validator) : new function() {
  395. this.test = maskdef.validator;
  396. } : new RegExp("."),
  397. cardinality: maskdef.cardinality,
  398. optionality: mtoken.isOptional,
  399. newBlockMarker: prevMatch === undefined || prevMatch.def !== (maskdef.definitionSymbol || element),
  400. casing: maskdef.casing,
  401. def: maskdef.definitionSymbol || element,
  402. placeholder: maskdef.placeholder,
  403. mask: element
  404. });
  405. } else {
  406. mtoken.matches.splice(position++, 0, {
  407. fn: null,
  408. cardinality: 0,
  409. optionality: mtoken.isOptional,
  410. newBlockMarker: prevMatch === undefined || prevMatch.def !== element,
  411. casing: null,
  412. def: element,
  413. placeholder: undefined,
  414. mask: element
  415. });
  416. escaped = false;
  417. }
  418. }
  419. function verifyGroupMarker(lastMatch, isOpenGroup) {
  420. if (lastMatch.isGroup) { //this is not a group but a normal mask => convert
  421. lastMatch.isGroup = false;
  422. insertTestDefinition(lastMatch, opts.groupmarker.start, 0);
  423. if (isOpenGroup !== true) {
  424. insertTestDefinition(lastMatch, opts.groupmarker.end);
  425. }
  426. }
  427. }
  428. function maskCurrentToken(m, currentToken, lastMatch, extraCondition) {
  429. if (currentToken.matches.length > 0 && (extraCondition === undefined || extraCondition)) {
  430. lastMatch = currentToken.matches[currentToken.matches.length - 1];
  431. verifyGroupMarker(lastMatch);
  432. }
  433. insertTestDefinition(currentToken, m);
  434. }
  435. function defaultCase() {
  436. if (openenings.length > 0) {
  437. currentOpeningToken = openenings[openenings.length - 1];
  438. maskCurrentToken(m, currentOpeningToken, lastMatch, !currentOpeningToken.isAlternator);
  439. if (currentOpeningToken.isAlternator) { //handle alternator a | b case
  440. alternator = openenings.pop();
  441. for (var mndx = 0; mndx < alternator.matches.length; mndx++) {
  442. alternator.matches[mndx].isGroup = false; //don't mark alternate groups as group
  443. }
  444. if (openenings.length > 0) {
  445. currentOpeningToken = openenings[openenings.length - 1];
  446. currentOpeningToken.matches.push(alternator);
  447. } else {
  448. currentToken.matches.push(alternator);
  449. }
  450. }
  451. } else {
  452. maskCurrentToken(m, currentToken, lastMatch);
  453. }
  454. }
  455. function reverseTokens(maskToken) {
  456. function reverseStatic(st) {
  457. if (st === opts.optionalmarker.start) st = opts.optionalmarker.end;
  458. else if (st === opts.optionalmarker.end) st = opts.optionalmarker.start;
  459. else if (st === opts.groupmarker.start) st = opts.groupmarker.end;
  460. else if (st === opts.groupmarker.end) st = opts.groupmarker.start;
  461. return st;
  462. }
  463. maskToken.matches = maskToken.matches.reverse();
  464. for (var match in maskToken.matches) {
  465. var intMatch = parseInt(match);
  466. if (maskToken.matches[match].isQuantifier && maskToken.matches[intMatch + 1] && maskToken.matches[intMatch + 1].isGroup) { //reposition quantifier
  467. var qt = maskToken.matches[match];
  468. maskToken.matches.splice(match, 1);
  469. maskToken.matches.splice(intMatch + 1, 0, qt);
  470. }
  471. if (maskToken.matches[match].matches !== undefined) {
  472. maskToken.matches[match] = reverseTokens(maskToken.matches[match]);
  473. } else {
  474. maskToken.matches[match] = reverseStatic(maskToken.matches[match]);
  475. }
  476. }
  477. return maskToken;
  478. }
  479. while (match = tokenizer.exec(mask)) {
  480. m = match[0];
  481. if (escaped) {
  482. defaultCase();
  483. continue;
  484. }
  485. switch (m.charAt(0)) {
  486. case opts.escapeChar:
  487. escaped = true;
  488. break;
  489. case opts.optionalmarker.end:
  490. // optional closing
  491. case opts.groupmarker.end:
  492. // Group closing
  493. openingToken = openenings.pop();
  494. if (openingToken !== undefined) {
  495. if (openenings.length > 0) {
  496. currentOpeningToken = openenings[openenings.length - 1];
  497. currentOpeningToken.matches.push(openingToken);
  498. if (currentOpeningToken.isAlternator) { //handle alternator (a) | (b) case
  499. alternator = openenings.pop();
  500. for (var mndx = 0; mndx < alternator.matches.length; mndx++) {
  501. alternator.matches[mndx].isGroup = false; //don't mark alternate groups as group
  502. }
  503. if (openenings.length > 0) {
  504. currentOpeningToken = openenings[openenings.length - 1];
  505. currentOpeningToken.matches.push(alternator);
  506. } else {
  507. currentToken.matches.push(alternator);
  508. }
  509. }
  510. } else {
  511. currentToken.matches.push(openingToken);
  512. }
  513. } else defaultCase();
  514. break;
  515. case opts.optionalmarker.start:
  516. // optional opening
  517. openenings.push(new MaskToken(false, true));
  518. break;
  519. case opts.groupmarker.start:
  520. // Group opening
  521. openenings.push(new MaskToken(true));
  522. break;
  523. case opts.quantifiermarker.start:
  524. //Quantifier
  525. var quantifier = new MaskToken(false, false, true);
  526. m = m.replace(/[{}]/g, "");
  527. var mq = m.split(","),
  528. mq0 = isNaN(mq[0]) ? mq[0] : parseInt(mq[0]),
  529. mq1 = mq.length === 1 ? mq0 : (isNaN(mq[1]) ? mq[1] : parseInt(mq[1]));
  530. if (mq1 === "*" || mq1 === "+") {
  531. mq0 = mq1 === "*" ? 0 : 1;
  532. }
  533. quantifier.quantifier = {
  534. min: mq0,
  535. max: mq1
  536. };
  537. if (openenings.length > 0) {
  538. var matches = openenings[openenings.length - 1].matches;
  539. match = matches.pop();
  540. if (!match.isGroup) {
  541. groupToken = new MaskToken(true);
  542. groupToken.matches.push(match);
  543. match = groupToken;
  544. }
  545. matches.push(match);
  546. matches.push(quantifier);
  547. } else {
  548. match = currentToken.matches.pop();
  549. if (!match.isGroup) {
  550. groupToken = new MaskToken(true);
  551. groupToken.matches.push(match);
  552. match = groupToken;
  553. }
  554. currentToken.matches.push(match);
  555. currentToken.matches.push(quantifier);
  556. }
  557. break;
  558. case opts.alternatormarker:
  559. if (openenings.length > 0) {
  560. currentOpeningToken = openenings[openenings.length - 1];
  561. lastMatch = currentOpeningToken.matches.pop();
  562. } else {
  563. lastMatch = currentToken.matches.pop();
  564. }
  565. if (lastMatch.isAlternator) {
  566. openenings.push(lastMatch);
  567. } else {
  568. alternator = new MaskToken(false, false, false, true);
  569. alternator.matches.push(lastMatch);
  570. openenings.push(alternator);
  571. }
  572. break;
  573. default:
  574. defaultCase();
  575. }
  576. }
  577. while (openenings.length > 0) {
  578. openingToken = openenings.pop();
  579. verifyGroupMarker(openingToken, true);
  580. currentToken.matches.push(openingToken);
  581. }
  582. if (currentToken.matches.length > 0) {
  583. lastMatch = currentToken.matches[currentToken.matches.length - 1];
  584. verifyGroupMarker(lastMatch);
  585. maskTokens.push(currentToken);
  586. }
  587. if (opts.numericInput) {
  588. reverseTokens(maskTokens[0]);
  589. }
  590. // console.log(JSON.stringify(maskTokens));
  591. return maskTokens;
  592. }
  593. function generateMask(mask, metadata) {
  594. if (mask === null || mask === "") {
  595. return undefined;
  596. } else {
  597. if (mask.length === 1 && opts.greedy === false && opts.repeat !== 0) {
  598. opts.placeholder = "";
  599. } //hide placeholder with single non-greedy mask
  600. if (opts.repeat > 0 || opts.repeat === "*" || opts.repeat === "+") {
  601. var repeatStart = opts.repeat === "*" ? 0 : (opts.repeat === "+" ? 1 : opts.repeat);
  602. mask = opts.groupmarker.start + mask + opts.groupmarker.end + opts.quantifiermarker.start + repeatStart + "," + opts.repeat + opts.quantifiermarker.end;
  603. }
  604. // console.log(mask);
  605. var masksetDefinition;
  606. if (Inputmask.prototype.masksCache[mask] === undefined || nocache === true) {
  607. masksetDefinition = {
  608. "mask": mask,
  609. "maskToken": analyseMask(mask),
  610. "validPositions": {},
  611. "_buffer": undefined,
  612. "buffer": undefined,
  613. "tests": {},
  614. "metadata": metadata
  615. };
  616. if (nocache !== true) {
  617. Inputmask.prototype.masksCache[opts.numericInput ? mask.split("").reverse().join("") : mask] = masksetDefinition;
  618. }
  619. } else masksetDefinition = $.extend(true, {}, Inputmask.prototype.masksCache[mask]);
  620. return masksetDefinition;
  621. }
  622. }
  623. function preProcessMask(mask) {
  624. mask = mask.toString();
  625. // if (opts.numericInput) {
  626. // mask = mask.split('').reverse();
  627. // mask = mask.join('');
  628. // }
  629. return mask;
  630. }
  631. if ($.isFunction(opts.mask)) { //allow mask to be a preprocessing fn - should return a valid mask
  632. opts.mask = opts.mask.call(this, opts);
  633. }
  634. if ($.isArray(opts.mask)) {
  635. if (opts.mask.length > 1) {
  636. opts.keepStatic = opts.keepStatic === null ? true : opts.keepStatic; //enable by default when passing multiple masks when the option is not explicitly specified
  637. var altMask = "(";
  638. $.each(opts.numericInput ? opts.mask.reverse() : opts.mask, function(ndx, msk) {
  639. if (altMask.length > 1) {
  640. altMask += ")|(";
  641. }
  642. if (msk.mask !== undefined && !$.isFunction(msk.mask)) {
  643. altMask += preProcessMask(msk.mask);
  644. } else {
  645. altMask += preProcessMask(msk);
  646. }
  647. });
  648. altMask += ")";
  649. return generateMask(altMask, opts.mask);
  650. } else opts.mask = opts.mask.pop();
  651. }
  652. if (opts.mask) {
  653. if (opts.mask.mask !== undefined && !$.isFunction(opts.mask.mask)) {
  654. ms = generateMask(preProcessMask(opts.mask.mask), opts.mask);
  655. } else {
  656. ms = generateMask(preProcessMask(opts.mask), opts.mask);
  657. }
  658. }
  659. return ms;
  660. }
  661. var ua = navigator.userAgent,
  662. iphone = ua.match(new RegExp("iphone", "i")) !== null,
  663. // android = ua.match(new RegExp("android.*safari.*", "i")) !== null,
  664. androidchrome = ua.match(new RegExp("android.*chrome.*", "i")) !== null,
  665. androidfirefox = ua.match(new RegExp("android.*firefox.*", "i")) !== null,
  666. // 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),
  667. PasteEventType = isInputEventSupported("paste") ? "paste" : isInputEventSupported("input") ? "input" : "propertychange";
  668. //if (androidchrome) {
  669. // var browser = navigator.userAgent.match(new RegExp("chrome.*", "i")),
  670. // version = parseInt(new RegExp(/[0-9]+/).exec(browser));
  671. // androidchrome32 = (version == 32);
  672. //}
  673. //masking scope
  674. //actionObj definition see below
  675. function maskScope(actionObj, maskset, opts) {
  676. var isRTL = false,
  677. undoValue,
  678. // compositionValidPos,
  679. compositionCaretPos,
  680. compositionData,
  681. el, $el,
  682. skipKeyPressEvent = false, //Safari 5.1.x - modal dialog fires keypress twice workaround
  683. skipInputEvent = false, //skip when triggered from within inputmask
  684. ignorable = false,
  685. maxLength,
  686. mouseEnter = true;
  687. //maskset helperfunctions
  688. function getMaskTemplate(baseOnInput, minimalPos, includeInput) {
  689. minimalPos = minimalPos || 0;
  690. var maskTemplate = [],
  691. ndxIntlzr, pos = 0,
  692. test, testPos;
  693. do {
  694. if (baseOnInput === true && getMaskSet().validPositions[pos]) {
  695. var validPos = getMaskSet().validPositions[pos];
  696. test = validPos.match;
  697. ndxIntlzr = validPos.locator.slice();
  698. maskTemplate.push(includeInput === true ? validPos.input : getPlaceholder(pos, test));
  699. } else {
  700. //console.log("getmasktemplate " + pos + " " + JSON.stringify(ndxIntlzr));
  701. testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
  702. test = testPos.match;
  703. ndxIntlzr = testPos.locator.slice();
  704. maskTemplate.push(getPlaceholder(pos, test));
  705. }
  706. pos++;
  707. } while ((maxLength === undefined || pos - 1 < maxLength) && test.fn !== null || (test.fn === null && test.def !== "") || minimalPos >= pos);
  708. maskTemplate.pop(); //drop the last one which is empty
  709. return maskTemplate;
  710. }
  711. function getMaskSet() {
  712. return maskset;
  713. }
  714. function resetMaskSet(soft) {
  715. var maskset = getMaskSet();
  716. maskset.buffer = undefined;
  717. maskset.tests = {};
  718. if (soft !== true) {
  719. maskset._buffer = undefined;
  720. maskset.validPositions = {};
  721. maskset.p = 0;
  722. }
  723. }
  724. function getLastValidPosition(closestTo, strict) {
  725. var maskset = getMaskSet(),
  726. lastValidPosition = -1,
  727. valids = maskset.validPositions;
  728. if (closestTo === undefined) closestTo = -1;
  729. var before = lastValidPosition,
  730. after = lastValidPosition;
  731. for (var posNdx in valids) {
  732. var psNdx = parseInt(posNdx);
  733. if (valids[psNdx] && (strict || valids[psNdx].match.fn !== null)) {
  734. if (psNdx <= closestTo) before = psNdx;
  735. if (psNdx >= closestTo) after = psNdx;
  736. }
  737. }
  738. lastValidPosition = (before !== -1 && (closestTo - before) > 1) || after < closestTo ? before : after;
  739. return lastValidPosition;
  740. }
  741. function setValidPosition(pos, validTest, fromSetValid) {
  742. if (opts.insertMode && getMaskSet().validPositions[pos] !== undefined && fromSetValid === undefined) {
  743. //reposition & revalidate others
  744. var positionsClone = $.extend(true, {}, getMaskSet().validPositions),
  745. lvp = getLastValidPosition(),
  746. i;
  747. for (i = pos; i <= lvp; i++) { //clear selection
  748. delete getMaskSet().validPositions[i];
  749. }
  750. getMaskSet().validPositions[pos] = validTest;
  751. var valid = true,
  752. j, vps = getMaskSet().validPositions;
  753. for (i = (j = pos); i <= lvp; i++) {
  754. var t = positionsClone[i];
  755. if (t !== undefined) {
  756. var posMatch = j,
  757. prevPosMatch = -1;
  758. while (posMatch < getMaskLength() && ((t.match.fn == null && vps[i] && (vps[i].match.optionalQuantifier === true || vps[i].match.optionality === true)) || t.match.fn != null)) {
  759. //determine next position
  760. if (t.match.fn === null || (!opts.keepStatic && vps[i] && (vps[i + 1] !== undefined && getTests(i + 1, vps[i].locator.slice(), i).length > 1 || vps[i].alternation !== undefined))) {
  761. posMatch++;
  762. } else posMatch = seekNext(j);
  763. //does it match
  764. if (positionCanMatchDefinition(posMatch, t.match.def)) {
  765. valid = isValid(posMatch, t.input, true, true) !== false;
  766. j = posMatch;
  767. break;
  768. } else {
  769. valid = t.match.fn == null;
  770. if (prevPosMatch === posMatch) break; //prevent endless loop
  771. prevPosMatch = posMatch;
  772. }
  773. }
  774. }
  775. if (!valid) break;
  776. }
  777. if (!valid) {
  778. getMaskSet().validPositions = $.extend(true, {}, positionsClone);
  779. return false;
  780. }
  781. } else getMaskSet().validPositions[pos] = validTest;
  782. return true;
  783. }
  784. function stripValidPositions(start, end, nocheck, strict) {
  785. var i, startPos = start;
  786. getMaskSet().p = start; //needed for alternated position after overtype selection
  787. for (i = startPos; i < end; i++) { //clear selection
  788. if (getMaskSet().validPositions[i] !== undefined) {
  789. if (nocheck === true || opts.canClearPosition(getMaskSet(), i, getLastValidPosition(), strict, opts) !== false) {
  790. delete getMaskSet().validPositions[i];
  791. }
  792. }
  793. }
  794. resetMaskSet(true);
  795. /*eslint-disable semi-spacing */
  796. for (i = startPos + 1; i <= getLastValidPosition();) {
  797. /*eslint-disable semi-spacing */
  798. while (getMaskSet().validPositions[startPos] !== undefined) startPos++;
  799. var s = getMaskSet().validPositions[startPos];
  800. if (i < startPos) i = startPos + 1;
  801. // while (getMaskSet().validPositions[i] == undefined) i++;
  802. var t = getMaskSet().validPositions[i];
  803. if (t !== undefined && isMask(i) && s === undefined) {
  804. if (positionCanMatchDefinition(startPos, t.match.def) && isValid(startPos, t.input, true) !== false) {
  805. delete getMaskSet().validPositions[i];
  806. i++;
  807. }
  808. startPos++;
  809. } else i++;
  810. }
  811. //remove radixpoint if needed
  812. var lvp = getLastValidPosition(),
  813. ml = getMaskLength();
  814. if (strict !== true && nocheck !== true && getMaskSet().validPositions[lvp] !== undefined && getMaskSet().validPositions[lvp].input === opts.radixPoint) {
  815. delete getMaskSet().validPositions[lvp];
  816. }
  817. for (i = lvp + 1; i <= ml; i++) {
  818. if (getMaskSet().validPositions[i]) {
  819. delete getMaskSet().validPositions[i];
  820. }
  821. }
  822. resetMaskSet(true);
  823. }
  824. function getTestTemplate(pos, ndxIntlzr, tstPs) {
  825. var testPos = getMaskSet().validPositions[pos];
  826. if (testPos === undefined) {
  827. var testPositions = getTests(pos, ndxIntlzr, tstPs),
  828. lvp = getLastValidPosition(),
  829. lvTest = getMaskSet().validPositions[lvp] || getTests(0)[0],
  830. lvTestAltArr = (lvTest.alternation !== undefined) ? lvTest.locator[lvTest.alternation].toString().split(",") : [];
  831. for (var ndx = 0; ndx < testPositions.length; ndx++) {
  832. testPos = testPositions[ndx];
  833. if (testPos.match &&
  834. (((opts.greedy && testPos.match.optionalQuantifier !== true) || (testPos.match.optionality === false || testPos.match.newBlockMarker === false) && testPos.match.optionalQuantifier !== true) &&
  835. ((lvTest.alternation === undefined || lvTest.alternation !== testPos.alternation) ||
  836. (testPos.locator[lvTest.alternation] !== undefined && checkAlternationMatch(testPos.locator[lvTest.alternation].toString().split(","), lvTestAltArr))))) {
  837. break;
  838. }
  839. }
  840. }
  841. return testPos;
  842. }
  843. function getTest(pos) {
  844. if (getMaskSet().validPositions[pos]) {
  845. return getMaskSet().validPositions[pos].match;
  846. }
  847. return getTests(pos)[0].match;
  848. }
  849. function positionCanMatchDefinition(pos, def) {
  850. var valid = false,
  851. tests = getTests(pos);
  852. for (var tndx = 0; tndx < tests.length; tndx++) {
  853. if (tests[tndx].match && tests[tndx].match.def === def) {
  854. valid = true;
  855. break;
  856. }
  857. }
  858. return valid;
  859. }
  860. function getTests(pos, ndxIntlzr, tstPs, cacheable) {
  861. var maskTokens = getMaskSet().maskToken,
  862. testPos = ndxIntlzr ? tstPs : 0,
  863. ndxInitializer = ndxIntlzr || [0],
  864. matches = [],
  865. insertStop = false,
  866. latestMatch, isFirstMatch;
  867. function resolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) { //ndxInitilizer contains a set of indexes to speedup searches in the mtokens
  868. function handleMatch(match, loopNdx, quantifierRecurse) {
  869. if (testPos > 10000) {
  870. 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;
  871. }
  872. if (testPos === pos && match.matches === undefined) {
  873. matches.push({
  874. "match": match,
  875. "locator": loopNdx.reverse()
  876. });
  877. return true;
  878. } else if (match.matches !== undefined) {
  879. if (match.isGroup && quantifierRecurse !== match) { //when a group pass along to the quantifier
  880. match = handleMatch(maskToken.matches[$.inArray(match, maskToken.matches) + 1], loopNdx);
  881. if (match) return true;
  882. } else if (match.isOptional) {
  883. var optionalToken = match;
  884. match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse);
  885. if (match) {
  886. latestMatch = matches[matches.length - 1].match;
  887. isFirstMatch = $.inArray(latestMatch, optionalToken.matches) === 0;
  888. if (isFirstMatch) {
  889. insertStop = true; //insert a stop
  890. testPos = pos; //match the position after the group
  891. } else return true;
  892. }
  893. } else if (match.isAlternator) {
  894. var alternateToken = match,
  895. malternateMatches = [],
  896. maltMatches,
  897. currentMatches = matches.slice(),
  898. loopNdxCnt = loopNdx.length;
  899. var altIndex = ndxInitializer.length > 0 ? ndxInitializer.shift() : -1;
  900. if (altIndex === -1 || typeof altIndex === "string") {
  901. var currentPos = testPos,
  902. ndxInitializerClone = ndxInitializer.slice(),
  903. altIndexArr = [];
  904. if (typeof altIndex == "string") altIndexArr = altIndex.split(",");
  905. for (var amndx = 0; amndx < alternateToken.matches.length; amndx++) {
  906. matches = [];
  907. match = handleMatch(alternateToken.matches[amndx], [amndx].concat(loopNdx), quantifierRecurse) || match;
  908. if (match !== true && match !== undefined && (altIndexArr[altIndexArr.length - 1] < alternateToken.matches.length)) { //no match in the alternations (length mismatch) => look further
  909. var ntndx = maskToken.matches.indexOf(match) + 1;
  910. if (maskToken.matches.length > ntndx) {
  911. match = handleMatch(maskToken.matches[ntndx], [ntndx].concat(loopNdx.slice(1, loopNdx.length)), quantifierRecurse);
  912. if (match) {
  913. altIndexArr.push(ntndx.toString());
  914. $.each(matches, function(ndx, lmnt) {
  915. lmnt.alternation = loopNdx.length - 1;
  916. });
  917. }
  918. }
  919. }
  920. maltMatches = matches.slice();
  921. testPos = currentPos;
  922. matches = [];
  923. //cloneback
  924. for (var i = 0; i < ndxInitializerClone.length; i++) {
  925. ndxInitializer[i] = ndxInitializerClone[i];
  926. }
  927. //fuzzy merge matches
  928. for (var ndx1 = 0; ndx1 < maltMatches.length; ndx1++) {
  929. var altMatch = maltMatches[ndx1];
  930. altMatch.alternation = altMatch.alternation || loopNdxCnt;
  931. for (var ndx2 = 0; ndx2 < malternateMatches.length; ndx2++) {
  932. var altMatch2 = malternateMatches[ndx2];
  933. //verify equality
  934. if (altMatch.match.mask === altMatch2.match.mask && (typeof altIndex !== "string" || $.inArray(altMatch.locator[altMatch.alternation].toString(), altIndexArr) !== -1)) {
  935. maltMatches.splice(ndx1, 1);
  936. ndx1--;
  937. altMatch2.locator[altMatch.alternation] = altMatch2.locator[altMatch.alternation] + "," + altMatch.locator[altMatch.alternation];
  938. altMatch2.alternation = altMatch.alternation; //we pass the alternation index => used in determineLastRequiredPosition
  939. break;
  940. }
  941. }
  942. }
  943. malternateMatches = malternateMatches.concat(maltMatches);
  944. }
  945. if (typeof altIndex == "string") { //filter matches
  946. malternateMatches = $.map(malternateMatches, function(lmnt, ndx) {
  947. if (isFinite(ndx)) {
  948. var mamatch,
  949. alternation = lmnt.alternation,
  950. altLocArr = lmnt.locator[alternation].toString().split(",");
  951. lmnt.locator[alternation] = undefined;
  952. lmnt.alternation = undefined;
  953. for (var alndx = 0; alndx < altLocArr.length; alndx++) {
  954. mamatch = $.inArray(altLocArr[alndx], altIndexArr) !== -1;
  955. if (mamatch) { //rebuild the locator with valid entries
  956. if (lmnt.locator[alternation] !== undefined) {
  957. lmnt.locator[alternation] += ",";
  958. lmnt.locator[alternation] += altLocArr[alndx];
  959. } else lmnt.locator[alternation] = parseInt(altLocArr[alndx]);
  960. lmnt.alternation = alternation;
  961. }
  962. }
  963. if (lmnt.locator[alternation] !== undefined) return lmnt;
  964. }
  965. });
  966. }
  967. matches = currentMatches.concat(malternateMatches);
  968. testPos = pos;
  969. insertStop = matches.length > 0; //insert a stopelemnt when there is an alternate
  970. } else {
  971. if (alternateToken.matches[altIndex]) { //if not in the initial alternation => look further
  972. match = handleMatch(alternateToken.matches[altIndex], [altIndex].concat(loopNdx), quantifierRecurse);
  973. } else match = false;
  974. }
  975. if (match) return true;
  976. } else if (match.isQuantifier && quantifierRecurse !== maskToken.matches[$.inArray(match, maskToken.matches) - 1]) {
  977. var qt = match;
  978. for (var qndx = (ndxInitializer.length > 0) ? ndxInitializer.shift() : 0;
  979. (qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max)) && testPos <= pos; qndx++) {
  980. var tokenGroup = maskToken.matches[$.inArray(qt, maskToken.matches) - 1];
  981. match = handleMatch(tokenGroup, [qndx].concat(loopNdx), tokenGroup); //set the tokenGroup as quantifierRecurse marker
  982. if (match) {
  983. //get latest match
  984. latestMatch = matches[matches.length - 1].match;
  985. latestMatch.optionalQuantifier = qndx > (qt.quantifier.min - 1);
  986. isFirstMatch = $.inArray(latestMatch, tokenGroup.matches) === 0;
  987. if (isFirstMatch) { //search for next possible match
  988. if (qndx > (qt.quantifier.min - 1)) {
  989. insertStop = true;
  990. testPos = pos; //match the position after the group
  991. break; //stop quantifierloop
  992. } else return true;
  993. } else {
  994. return true;
  995. }
  996. }
  997. }
  998. } else {
  999. match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse);
  1000. if (match) return true;
  1001. }
  1002. } else testPos++;
  1003. }
  1004. for (var tndx = (ndxInitializer.length > 0 ? ndxInitializer.shift() : 0); tndx < maskToken.matches.length; tndx++) {
  1005. if (maskToken.matches[tndx].isQuantifier !== true) {
  1006. var match = handleMatch(maskToken.matches[tndx], [tndx].concat(loopNdx), quantifierRecurse);
  1007. if (match && testPos === pos) {
  1008. return match;
  1009. } else if (testPos > pos) {
  1010. break;
  1011. }
  1012. }
  1013. }
  1014. }
  1015. if (cacheable === true && getMaskSet().tests[pos]) {
  1016. return getMaskSet().tests[pos];
  1017. }
  1018. if (ndxIntlzr === undefined) {
  1019. var previousPos = pos - 1,
  1020. test;
  1021. while ((test = getMaskSet().validPositions[previousPos]) === undefined && previousPos > -1) {
  1022. if (getMaskSet().tests[previousPos] && (test = getMaskSet().tests[previousPos][0]) !== undefined) {
  1023. break;
  1024. }
  1025. previousPos--;
  1026. }
  1027. if (test !== undefined && previousPos > -1) {
  1028. testPos = previousPos;
  1029. ndxInitializer = test.locator.slice();
  1030. }
  1031. }
  1032. for (var mtndx = ndxInitializer.shift(); mtndx < maskTokens.length; mtndx++) {
  1033. var match = resolveTestFromToken(maskTokens[mtndx], ndxInitializer, [mtndx]);
  1034. if ((match && testPos === pos) || testPos > pos) {
  1035. break;
  1036. }
  1037. }
  1038. if (matches.length === 0 || insertStop) {
  1039. matches.push({
  1040. "match": {
  1041. fn: null,
  1042. cardinality: 0,
  1043. optionality: true,
  1044. casing: null,
  1045. def: ""
  1046. },
  1047. "locator": []
  1048. });
  1049. }
  1050. getMaskSet().tests[pos] = $.extend(true, [], matches); //set a clone to prevent overwriting some props
  1051. // console.log(pos + " - " + JSON.stringify(matches));
  1052. return getMaskSet().tests[pos];
  1053. }
  1054. function getBufferTemplate() {
  1055. if (getMaskSet()._buffer === undefined) {
  1056. //generate template
  1057. getMaskSet()._buffer = getMaskTemplate(false, 1);
  1058. }
  1059. return getMaskSet()._buffer;
  1060. }
  1061. function getBuffer() {
  1062. if (getMaskSet().buffer === undefined) {
  1063. getMaskSet().buffer = getMaskTemplate(true, getLastValidPosition(), true);
  1064. }
  1065. return getMaskSet().buffer;
  1066. }
  1067. function refreshFromBuffer(start, end, buffer) {
  1068. var i;
  1069. buffer = buffer || getBuffer().slice(); //pass or work on clone
  1070. if (start === true) {
  1071. resetMaskSet();
  1072. start = 0;
  1073. end = buffer.length;
  1074. } else {
  1075. for (i = start; i < end; i++) {
  1076. delete getMaskSet().validPositions[i];
  1077. delete getMaskSet().tests[i];
  1078. }
  1079. }
  1080. for (i = start; i < end; i++) {
  1081. resetMaskSet(true); //prevents clobber from the buffer
  1082. if (buffer[i] !== opts.skipOptionalPartCharacter) {
  1083. isValid(i, buffer[i], true, true);
  1084. }
  1085. }
  1086. }
  1087. function casing(elem, test) {
  1088. switch (test.casing) {
  1089. case "upper":
  1090. elem = elem.toUpperCase();
  1091. break;
  1092. case "lower":
  1093. elem = elem.toLowerCase();
  1094. break;
  1095. }
  1096. return elem;
  1097. }
  1098. function checkAlternationMatch(altArr1, altArr2) {
  1099. var altArrC = opts.greedy ? altArr2 : altArr2.slice(0, 1),
  1100. isMatch = false;
  1101. for (var alndx = 0; alndx < altArr1.length; alndx++) {
  1102. if ($.inArray(altArr1[alndx], altArrC) !== -1) {
  1103. isMatch = true;
  1104. break;
  1105. }
  1106. }
  1107. return isMatch;
  1108. }
  1109. function isValid(pos, c, strict, fromSetValid) { //strict true ~ no correction or autofill
  1110. strict = strict === true; //always set a value to strict to prevent possible strange behavior in the extensions
  1111. function _isValid(position, c, strict, fromSetValid) {
  1112. var rslt = false;
  1113. $.each(getTests(position), function(ndx, tst) {
  1114. var test = tst.match;
  1115. var loopend = c ? 1 : 0,
  1116. chrs = "";
  1117. for (var i = test.cardinality; i > loopend; i--) {
  1118. chrs += getBufferElement(position - (i - 1));
  1119. }
  1120. if (c) {
  1121. chrs += c;
  1122. }
  1123. //return is false or a json object => { pos: ??, c: ??} or true
  1124. rslt = test.fn != null ?
  1125. test.fn.test(chrs, getMaskSet(), position, strict, opts) : (c === test.def || c === opts.skipOptionalPartCharacter) && test.def !== "" ? //non mask
  1126. {
  1127. c: test.def,
  1128. pos: position
  1129. } : false;
  1130. if (rslt !== false) {
  1131. var elem = rslt.c !== undefined ? rslt.c : c;
  1132. elem = (elem === opts.skipOptionalPartCharacter && test.fn === null) ? test.def : elem;
  1133. var validatedPos = position,
  1134. possibleModifiedBuffer = getBuffer();
  1135. if (rslt.remove !== undefined) { //remove position(s)
  1136. if (!$.isArray(rslt.remove)) rslt.remove = [rslt.remove];
  1137. $.each(rslt.remove.sort(function(a, b) {
  1138. return b - a;
  1139. }), function(ndx, lmnt) {
  1140. stripValidPositions(lmnt, lmnt + 1, true);
  1141. });
  1142. }
  1143. if (rslt.insert !== undefined) { //insert position(s)
  1144. if (!$.isArray(rslt.insert)) rslt.insert = [rslt.insert];
  1145. $.each(rslt.insert.sort(function(a, b) {
  1146. return a - b;
  1147. }), function(ndx, lmnt) {
  1148. isValid(lmnt.pos, lmnt.c, true);
  1149. });
  1150. }
  1151. if (rslt.refreshFromBuffer) {
  1152. var refresh = rslt.refreshFromBuffer;
  1153. strict = true;
  1154. refreshFromBuffer(refresh === true ? refresh : refresh.start, refresh.end, possibleModifiedBuffer);
  1155. if (rslt.pos === undefined && rslt.c === undefined) {
  1156. rslt.pos = getLastValidPosition();
  1157. return false; //breakout if refreshFromBuffer && nothing to insert
  1158. }
  1159. validatedPos = rslt.pos !== undefined ? rslt.pos : position;
  1160. if (validatedPos !== position) {
  1161. rslt = $.extend(rslt, isValid(validatedPos, elem, true)); //revalidate new position strict
  1162. return false;
  1163. }
  1164. } else if (rslt !== true && rslt.pos !== undefined && rslt.pos !== position) { //their is a position offset
  1165. validatedPos = rslt.pos;
  1166. refreshFromBuffer(position, validatedPos);
  1167. if (validatedPos !== position) {
  1168. rslt = $.extend(rslt, isValid(validatedPos, elem, true)); //revalidate new position strict
  1169. return false;
  1170. }
  1171. }
  1172. if (rslt !== true && rslt.pos === undefined && rslt.c === undefined) {
  1173. return false; //breakout if nothing to insert
  1174. }
  1175. if (ndx > 0) {
  1176. resetMaskSet(true);
  1177. }
  1178. if (!setValidPosition(validatedPos, $.extend({}, tst, {
  1179. "input": casing(elem, test)
  1180. }), fromSetValid)) {
  1181. rslt = false;
  1182. }
  1183. return false; //break from $.each
  1184. }
  1185. });
  1186. return rslt;
  1187. }
  1188. function alternate(pos, c, strict, fromSetValid) {
  1189. var validPsClone = $.extend(true, {}, getMaskSet().validPositions),
  1190. lastAlt,
  1191. alternation,
  1192. isValidRslt,
  1193. altPos, i, validPos;
  1194. //find last modified alternation
  1195. for (var lAlt = getLastValidPosition(); lAlt >= 0; lAlt--) {
  1196. altPos = getMaskSet().validPositions[lAlt];
  1197. if (altPos && altPos.alternation !== undefined) {
  1198. lastAlt = lAlt;
  1199. alternation = getMaskSet().validPositions[lastAlt].alternation;
  1200. if (getTestTemplate(lastAlt).locator[altPos.alternation] !== altPos.locator[altPos.alternation]) {
  1201. break;
  1202. }
  1203. }
  1204. }
  1205. if (alternation !== undefined) {
  1206. //find first decision making position
  1207. lastAlt = parseInt(lastAlt);
  1208. for (var decisionPos in getMaskSet().validPositions) {
  1209. decisionPos = parseInt(decisionPos);
  1210. altPos = getMaskSet().validPositions[decisionPos];
  1211. if (decisionPos >= lastAlt && altPos.alternation !== undefined) {
  1212. var altNdxs = getMaskSet().validPositions[lastAlt].locator[alternation].toString().split(","),
  1213. decisionTaker = altPos.locator[alternation] || altNdxs[0]; //no match in the alternations (length mismatch)
  1214. if (decisionTaker.length > 0) { //no decision taken ~ take first one as decider
  1215. decisionTaker = decisionTaker.split(",")[0];
  1216. }
  1217. for (var mndx = 0; mndx < altNdxs.length; mndx++) {
  1218. if (decisionTaker < altNdxs[mndx]) {
  1219. var possibilityPos, possibilities;
  1220. for (var dp = decisionPos; dp >= 0; dp--) {
  1221. possibilityPos = getMaskSet().validPositions[dp];
  1222. if (possibilityPos !== undefined) {
  1223. possibilities = possibilityPos.locator[alternation]; //store to reset
  1224. //possibilityPos.alternation = undefined;
  1225. possibilityPos.locator[alternation] = parseInt(altNdxs[mndx]);
  1226. break;
  1227. }
  1228. }
  1229. if (decisionTaker !== possibilityPos.locator[alternation]) {
  1230. var validInputs = [],
  1231. staticInputsBeforePos = 0;
  1232. for (i = decisionPos + 1; i < getLastValidPosition() + 1; i++) {
  1233. validPos = getMaskSet().validPositions[i];
  1234. if (validPos) {
  1235. if (validPos.match.fn != null) {
  1236. validInputs.push(validPos.input);
  1237. } else if (i < pos) staticInputsBeforePos++;
  1238. }
  1239. delete getMaskSet().validPositions[i];
  1240. delete getMaskSet().tests[i];
  1241. }
  1242. resetMaskSet(true); //clear getbuffer
  1243. opts.keepStatic = !opts.keepStatic; //disable keepStatic on getMaskLength
  1244. isValidRslt = true;
  1245. while (validInputs.length > 0) {
  1246. var input = validInputs.shift();
  1247. if (input !== opts.skipOptionalPartCharacter) {
  1248. if (!(isValidRslt = isValid(getLastValidPosition() + 1, input, false, true))) {
  1249. break;
  1250. }
  1251. }
  1252. }
  1253. possibilityPos.alternation = alternation;
  1254. possibilityPos.locator[alternation] = possibilities; //reset forceddecision ~ needed for proper delete
  1255. if (isValidRslt) {
  1256. var targetLvp = getLastValidPosition(pos) + 1;
  1257. var staticInputsBeforePosAlternate = 0;
  1258. for (i = decisionPos + 1; i < getLastValidPosition() + 1; i++) {
  1259. validPos = getMaskSet().validPositions[i];
  1260. if (validPos && validPos.match.fn == null && i < pos) {
  1261. staticInputsBeforePosAlternate++;
  1262. }
  1263. }
  1264. pos = pos + (staticInputsBeforePosAlternate - staticInputsBeforePos);
  1265. isValidRslt = isValid(pos > targetLvp ? targetLvp : pos, c, strict, fromSetValid);
  1266. }
  1267. opts.keepStatic = !opts.keepStatic; //enable keepStatic on getMaskLength
  1268. if (!isValidRslt) {
  1269. resetMaskSet();
  1270. getMaskSet().validPositions = $.extend(true, {}, validPsClone);
  1271. } else return isValidRslt;
  1272. }
  1273. }
  1274. }
  1275. break;
  1276. }
  1277. }
  1278. }
  1279. return false;
  1280. }
  1281. //set alternator choice on previous skipped placeholder positions
  1282. function trackbackAlternations(originalPos, newPos) {
  1283. var vp = getMaskSet().validPositions[newPos],
  1284. targetLocator = vp.locator,
  1285. tll = targetLocator.length;
  1286. for (var ps = originalPos; ps < newPos; ps++) {
  1287. if (!isMask(ps)) {
  1288. var tests = getTests(ps),
  1289. bestMatch = tests[0],
  1290. equality = -1;
  1291. $.each(tests, function(ndx, tst) {
  1292. for (var i = 0; i < tll; i++) {
  1293. if (tst.locator[i] && checkAlternationMatch(tst.locator[i].toString().split(","), targetLocator[i].toString().split(",")) && equality < i) {
  1294. equality = i;
  1295. bestMatch = tst;
  1296. }
  1297. }
  1298. });
  1299. setValidPosition(ps, $.extend({}, bestMatch, {
  1300. "input": bestMatch.match.def
  1301. }), true);
  1302. }
  1303. }
  1304. }
  1305. //Check for a nonmask before the pos
  1306. var buffer = getBuffer();
  1307. //find previous valid
  1308. for (var pndx = pos - 1; pndx > -1; pndx--) {
  1309. if (getMaskSet().validPositions[pndx]) {
  1310. break;
  1311. }
  1312. }
  1313. ////fill missing nonmask and valid placeholders
  1314. pndx++;
  1315. for (; pndx < pos; pndx++) {
  1316. //console.log("missing " + pndx + " " + buffer[pndx] + " ismask " + isMask(pndx) + " plchldr " + getPlaceholder(pndx) + " nrt " + getTests(pndx).len);
  1317. if (getMaskSet().validPositions[pndx] === undefined && (((!isMask(pndx) || buffer[pndx] !== getPlaceholder(pndx)) && getTests(pndx).length > 1) || (buffer[pndx] === opts.radixPoint || buffer[pndx] === "0" && $.inArray(opts.radixPoint, buffer) < pndx))) //special case for decimals ~ = placeholder but yet valid input
  1318. {
  1319. //console.log("inject " + pndx + " " + buffer[pndx]);
  1320. _isValid(pndx, buffer[pndx], true);
  1321. }
  1322. }
  1323. var maskPos = pos,
  1324. result = false,
  1325. positionsClone = $.extend(true, {}, getMaskSet().validPositions); //clone the currentPositions
  1326. //if (fromSetValid && maskPos >= getMaskLength()) {
  1327. // resetMaskSet(true); //masklenght can be altered on the process => reset to get the actual length
  1328. //}
  1329. if (maskPos < getMaskLength()) {
  1330. getBuffer(); //make sure the buffer
  1331. result = _isValid(maskPos, c, strict, fromSetValid);
  1332. if ((!strict || fromSetValid) && result === false) {
  1333. var currentPosValid = getMaskSet().validPositions[maskPos];
  1334. if (currentPosValid && currentPosValid.match.fn === null && (currentPosValid.match.def === c || c === opts.skipOptionalPartCharacter)) {
  1335. result = {
  1336. "caret": seekNext(maskPos)
  1337. };
  1338. } else if ((opts.insertMode || getMaskSet().validPositions[seekNext(maskPos)] === undefined) && !isMask(maskPos)) { //does the input match on a further position?
  1339. for (var nPos = maskPos + 1, snPos = seekNext(maskPos); nPos <= snPos; nPos++) {
  1340. result = _isValid(nPos, c, strict, fromSetValid);
  1341. if (result !== false) {
  1342. trackbackAlternations(maskPos, nPos);
  1343. maskPos = nPos;
  1344. break;
  1345. }
  1346. }
  1347. }
  1348. }
  1349. }
  1350. if (result === false && opts.keepStatic && isComplete(buffer)) { //try fuzzy alternator logic
  1351. result = alternate(pos, c, strict, fromSetValid);
  1352. }
  1353. if (result === true) {
  1354. result = {
  1355. "pos": maskPos
  1356. };
  1357. }
  1358. if ($.isFunction(opts.postValidation) && result !== false && !strict) {
  1359. resetMaskSet(true);
  1360. var postValidResult = opts.postValidation(getBuffer(), opts);
  1361. if (!postValidResult) {
  1362. resetMaskSet(true);
  1363. getMaskSet().validPositions = $.extend(true, {}, positionsClone); //revert validation changes
  1364. result = false;
  1365. } else if (postValidResult.refreshFromBuffer) {
  1366. var refresh = postValidResult.refreshFromBuffer;
  1367. refreshFromBuffer(refresh === true ? refresh : refresh.start, refresh.end, postValidResult.buffer);
  1368. resetMaskSet(true);
  1369. result = postValidResult;
  1370. }
  1371. }
  1372. return result;
  1373. }
  1374. function isMask(pos) {
  1375. var test = getTest(pos);
  1376. if (test.fn != null) {
  1377. return test.fn;
  1378. } else if (pos > -1 && !opts.keepStatic && getMaskSet().validPositions[pos] === undefined) {
  1379. var tests = getTests(pos),
  1380. staticAlternations = true;
  1381. for (var i = 0; i < tests.length; i++) {
  1382. if (tests[i].match.def !== "" && ( /*tests[i].match.fn !== null || */ (tests[i].alternation === undefined || tests[i].locator[tests[i].alternation].length > 1))) {
  1383. staticAlternations = false;
  1384. break;
  1385. }
  1386. }
  1387. return staticAlternations;
  1388. }
  1389. return false;
  1390. }
  1391. function getMaskLength() {
  1392. var maskLength;
  1393. maxLength = el !== undefined ? el.maxLength : undefined;
  1394. if (maxLength === -1) maxLength = undefined; /* FF sets no defined max length to -1 */
  1395. var pos, lvp = getLastValidPosition(),
  1396. testPos = getMaskSet().validPositions[lvp],
  1397. ndxIntlzr = testPos !== undefined ? testPos.locator.slice() : undefined;
  1398. for (pos = lvp + 1; testPos === undefined || (testPos.match.fn !== null || (testPos.match.fn === null && testPos.match.def !== "")); pos++) {
  1399. testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
  1400. ndxIntlzr = testPos.locator.slice();
  1401. }
  1402. var lastTest = getTest(pos - 1);
  1403. maskLength = (lastTest.def !== "") ? pos : pos - 1;
  1404. return (maxLength === undefined || maskLength < maxLength) ? maskLength : maxLength;
  1405. }
  1406. function seekNext(pos, newBlock) {
  1407. var maskL = getMaskLength();
  1408. if (pos >= maskL) return maskL;
  1409. var position = pos;
  1410. while (++position < maskL && ((newBlock === true && (getTest(position).newBlockMarker !== true || !isMask(position))) || (newBlock !== true && !isMask(position) && (opts.nojumps !== true || opts.nojumpsThreshold > position)))) {}
  1411. return position;
  1412. }
  1413. function seekPrevious(pos, newBlock) {
  1414. var position = pos;
  1415. if (position <= 0) return 0;
  1416. while (--position > 0 && ((newBlock === true && getTest(position).newBlockMarker !== true) || (newBlock !== true && !isMask(position)))) {}
  1417. return position;
  1418. }
  1419. function getBufferElement(position) {
  1420. return getMaskSet().validPositions[position] === undefined ? getPlaceholder(position) : getMaskSet().validPositions[position].input;
  1421. }
  1422. function writeBuffer(input, buffer, caretPos, event, triggerInputEvent) {
  1423. if (event && $.isFunction(opts.onBeforeWrite)) {
  1424. var result = opts.onBeforeWrite.call(input, event, buffer, caretPos, opts);
  1425. if (result) {
  1426. if (result.refreshFromBuffer) {
  1427. var refresh = result.refreshFromBuffer;
  1428. refreshFromBuffer(refresh === true ? refresh : refresh.start, refresh.end, result.buffer || buffer);
  1429. resetMaskSet(true);
  1430. buffer = getBuffer();
  1431. }
  1432. //only alter when intented !== undefined
  1433. if (caretPos !== undefined) caretPos = result.caret !== undefined ? result.caret : caretPos;
  1434. }
  1435. }
  1436. input.inputmask._valueSet(buffer.join(""));
  1437. if (caretPos !== undefined && (event === undefined || event.type !== "blur")) {
  1438. caret(input, caretPos);
  1439. }
  1440. if (triggerInputEvent === true) {
  1441. skipInputEvent = true;
  1442. $(input).trigger("input");
  1443. }
  1444. }
  1445. function getPlaceholder(pos, test) {
  1446. test = test || getTest(pos);
  1447. if (test.placeholder !== undefined) {
  1448. return test.placeholder;
  1449. } else if (test.fn === null) {
  1450. if (pos > -1 && !opts.keepStatic && getMaskSet().validPositions[pos] === undefined) {
  1451. var tests = getTests(pos),
  1452. hasAlternations = false,
  1453. prevTest;
  1454. for (var i = 0; i < tests.length; i++) {
  1455. if (prevTest && tests[i].match.def !== "" && (tests[i].match.def !== prevTest.match.def && (tests[i].alternation === undefined || tests[i].alternation === prevTest.alternation))) {
  1456. hasAlternations = true;
  1457. break;
  1458. }
  1459. if (tests[i].match.optionality !== true && tests[i].match.optionalQuantifier !== true) {
  1460. prevTest = tests[i];
  1461. }
  1462. }
  1463. if (hasAlternations) {
  1464. return opts.placeholder.charAt(pos % opts.placeholder.length);
  1465. }
  1466. }
  1467. return test.def;
  1468. } else {
  1469. return opts.placeholder.charAt(pos % opts.placeholder.length);
  1470. }
  1471. }
  1472. function checkVal(input, writeOut, strict, nptvl) {
  1473. var inputValue = nptvl.slice(),
  1474. charCodes = "",
  1475. initialNdx = 0;
  1476. function isTemplateMatch() {
  1477. var isMatch = false;
  1478. var charCodeNdx = getBufferTemplate().slice(initialNdx, seekNext(initialNdx)).join("").indexOf(charCodes);
  1479. if (charCodeNdx !== -1 && !isMask(initialNdx)) {
  1480. isMatch = true;
  1481. var bufferTemplateArr = getBufferTemplate().slice(initialNdx, initialNdx + charCodeNdx);
  1482. for (var i = 0; i < bufferTemplateArr.length; i++) {
  1483. if (bufferTemplateArr[i] !== " ") {
  1484. isMatch = false;
  1485. break;
  1486. }
  1487. }
  1488. }
  1489. return isMatch;
  1490. }
  1491. resetMaskSet();
  1492. getMaskSet().p = seekNext(-1);
  1493. // if (writeOut) input.inputmask._valueSet(""); //initial clear
  1494. if (!strict) {
  1495. if (opts.autoUnmask !== true) {
  1496. var staticInput = getBufferTemplate().slice(0, seekNext(-1)).join(""),
  1497. matches = inputValue.join("").match(new RegExp("^" + Inputmask.escapeRegex(staticInput), "g"));
  1498. if (matches && matches.length > 0) {
  1499. inputValue.splice(0, matches.length * staticInput.length);
  1500. initialNdx = seekNext(initialNdx);
  1501. }
  1502. } else {
  1503. initialNdx = seekNext(initialNdx);
  1504. }
  1505. }
  1506. $.each(inputValue, function(ndx, charCode) {
  1507. var keypress = $.Event("keypress");
  1508. keypress.which = charCode.charCodeAt(0);
  1509. charCodes += charCode;
  1510. var lvp = getLastValidPosition(undefined, true),
  1511. lvTest = getMaskSet().validPositions[lvp],
  1512. nextTest = getTestTemplate(lvp + 1, lvTest ? lvTest.locator.slice() : undefined, lvp);
  1513. if (!isTemplateMatch() || strict || opts.autoUnmask) {
  1514. var pos = strict ? ndx : (nextTest.match.fn == null && nextTest.match.optionality && (lvp + 1) < getMaskSet().p ? lvp + 1 : getMaskSet().p);
  1515. keypressEvent.call(input, keypress, true, false, strict, pos);
  1516. initialNdx = pos + 1;
  1517. charCodes = "";
  1518. } else {
  1519. keypressEvent.call(input, keypress, true, false, true, lvp + 1);
  1520. }
  1521. });
  1522. if (writeOut) {
  1523. writeBuffer(input, getBuffer(), document.activeElement === input ? seekNext(getLastValidPosition(0)) : undefined, $.Event("checkval"));
  1524. }
  1525. }
  1526. function unmaskedvalue(input) {
  1527. if (input && input.inputmask === undefined) {
  1528. return input.value;
  1529. }
  1530. var umValue = [],
  1531. vps = getMaskSet().validPositions;
  1532. for (var pndx in vps) {
  1533. if (vps[pndx].match && vps[pndx].match.fn != null) {
  1534. umValue.push(vps[pndx].input);
  1535. }
  1536. }
  1537. var unmaskedValue = umValue.length === 0 ? null : (isRTL ? umValue.reverse() : umValue).join("");
  1538. if (unmaskedValue !== null) {
  1539. var bufferValue = (isRTL ? getBuffer().slice().reverse() : getBuffer()).join("");
  1540. if ($.isFunction(opts.onUnMask)) {
  1541. unmaskedValue = (opts.onUnMask.call(input, bufferValue, unmaskedValue, opts) || unmaskedValue);
  1542. }
  1543. }
  1544. return unmaskedValue;
  1545. }
  1546. function caret(input, begin, end) {
  1547. function translatePosition(pos) {
  1548. if (isRTL && typeof pos === "number" && (!opts.greedy || opts.placeholder !== "")) {
  1549. var bffrLght = getBuffer().join("").length; //join is needed because sometimes we get an empty buffer element which must not be counted for the caret position (numeric alias)
  1550. pos = bffrLght - pos;
  1551. }
  1552. return pos;
  1553. }
  1554. var range;
  1555. if (typeof begin === "number") {
  1556. begin = translatePosition(begin);
  1557. end = translatePosition(end);
  1558. end = (typeof end == "number") ? end : begin;
  1559. // if (!$(input).is(":visible")) {
  1560. // return;
  1561. // }
  1562. var scrollCalc = (input.ownerDocument.defaultView || window).getComputedStyle(input, null).fontSize.replace("px", "") * end;
  1563. input.scrollLeft = scrollCalc > input.scrollWidth ? scrollCalc : 0;
  1564. if (!androidchrome && opts.insertMode === false && begin === end) end++; //set visualization for insert/overwrite mode
  1565. if (input.setSelectionRange) {
  1566. input.selectionStart = begin;
  1567. input.selectionEnd = end;
  1568. } else if (window.getSelection) {
  1569. range = document.createRange();
  1570. if (input.firstChild === undefined) {
  1571. var textNode = document.createTextNode("");
  1572. input.appendChild(textNode);
  1573. }
  1574. range.setStart(input.firstChild, begin < input.inputmask._valueGet().length ? begin : input.inputmask._valueGet().length);
  1575. range.setEnd(input.firstChild, end < input.inputmask._valueGet().length ? end : input.inputmask._valueGet().length);
  1576. range.collapse(true);
  1577. var sel = window.getSelection();
  1578. sel.removeAllRanges();
  1579. sel.addRange(range);
  1580. //input.focus();
  1581. } else if (input.createTextRange) {
  1582. range = input.createTextRange();
  1583. range.collapse(true);
  1584. range.moveEnd("character", end);
  1585. range.moveStart("character", begin);
  1586. range.select();
  1587. }
  1588. } else {
  1589. if (input.setSelectionRange) {
  1590. begin = input.selectionStart;
  1591. end = input.selectionEnd;
  1592. } else if (window.getSelection) {
  1593. range = window.getSelection().getRangeAt(0);
  1594. if (range.commonAncestorContainer.parentNode === input || range.commonAncestorContainer === input) {
  1595. begin = range.startOffset;
  1596. end = range.endOffset;
  1597. }
  1598. } else if (document.selection && document.selection.createRange) {
  1599. range = document.selection.createRange();
  1600. begin = 0 - range.duplicate().moveStart("character", -100000);
  1601. end = begin + range.text.length;
  1602. }
  1603. /*eslint-disable consistent-return */
  1604. return {
  1605. "begin": translatePosition(begin),
  1606. "end": translatePosition(end)
  1607. };
  1608. /*eslint-enable consistent-return */
  1609. }
  1610. }
  1611. function determineLastRequiredPosition(returnDefinition) {
  1612. var buffer = getBuffer(),
  1613. bl = buffer.length,
  1614. pos, lvp = getLastValidPosition(),
  1615. positions = {},
  1616. lvTest = getMaskSet().validPositions[lvp],
  1617. ndxIntlzr = lvTest !== undefined ? lvTest.locator.slice() : undefined,
  1618. testPos;
  1619. for (pos = lvp + 1; pos < buffer.length; pos++) {
  1620. testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
  1621. ndxIntlzr = testPos.locator.slice();
  1622. positions[pos] = $.extend(true, {}, testPos);
  1623. }
  1624. var lvTestAlt = lvTest && lvTest.alternation !== undefined ? lvTest.locator[lvTest.alternation] : undefined;
  1625. for (pos = bl - 1; pos > lvp; pos--) {
  1626. testPos = positions[pos];
  1627. if ((testPos.match.optionality ||
  1628. testPos.match.optionalQuantifier ||
  1629. (lvTestAlt && ((lvTestAlt !== positions[pos].locator[lvTest.alternation] && testPos.match.fn != null) ||
  1630. (testPos.match.fn === null && testPos.locator[lvTest.alternation] && checkAlternationMatch(testPos.locator[lvTest.alternation].toString().split(","), lvTestAlt.toString().split(",")) && getTests(pos)[0].def !== "")))) && buffer[pos] === getPlaceholder(pos, testPos.match)) {
  1631. bl--;
  1632. } else break;
  1633. }
  1634. return returnDefinition ? {
  1635. "l": bl,
  1636. "def": positions[bl] ? positions[bl].match : undefined
  1637. } : bl;
  1638. }
  1639. function clearOptionalTail(buffer) {
  1640. var rl = determineLastRequiredPosition(),
  1641. lmib = buffer.length - 1;
  1642. for (; lmib > rl; lmib--) {
  1643. if (isMask(lmib)) break; //fixme ismask is not good enough
  1644. }
  1645. buffer.splice(rl, lmib + 1 - rl);
  1646. return buffer;
  1647. }
  1648. function isComplete(buffer) { //return true / false / undefined (repeat *)
  1649. if ($.isFunction(opts.isComplete)) return opts.isComplete.call(el, buffer, opts);
  1650. if (opts.repeat === "*") return undefined;
  1651. var complete = false,
  1652. lrp = determineLastRequiredPosition(true),
  1653. aml = seekPrevious(lrp.l);
  1654. if (lrp.def === undefined || lrp.def.newBlockMarker || lrp.def.optionality || lrp.def.optionalQuantifier) {
  1655. complete = true;
  1656. for (var i = 0; i <= aml; i++) {
  1657. var test = getTestTemplate(i).match;
  1658. if ((test.fn !== null && getMaskSet().validPositions[i] === undefined && test.optionality !== true && test.optionalQuantifier !== true) || (test.fn === null && buffer[i] !== getPlaceholder(i, test))) {
  1659. complete = false;
  1660. break;
  1661. }
  1662. }
  1663. }
  1664. return complete;
  1665. }
  1666. function isSelection(begin, end) {
  1667. return isRTL ? (begin - end) > 1 || ((begin - end) === 1 && opts.insertMode) :
  1668. (end - begin) > 1 || ((end - begin) === 1 && opts.insertMode);
  1669. }
  1670. function wrapEvent(eventHandler) {
  1671. return function(e) {
  1672. // console.log("triggered " + e.type);
  1673. var inComposition = false;
  1674. if (this.inputmask === undefined) { //happens when cloning an object with jquery.clone
  1675. var imOpts = $.data(this, "_inputmask_opts");
  1676. if (imOpts)(new Inputmask(imOpts)).mask(this);
  1677. else $(this).off(".inputmask");
  1678. } else if (e.type !== "setvalue" && (this.disabled || (this.readOnly && !(e.type === "keydown" && (e.ctrlKey && e.keyCode === 67) || (opts.tabThrough === false && e.keyCode === Inputmask.keyCode.TAB))))) {
  1679. e.preventDefault();
  1680. } else {
  1681. switch (e.type) {
  1682. case "input":
  1683. if (skipInputEvent === true || inComposition === true) {
  1684. skipInputEvent = false;
  1685. return e.preventDefault();
  1686. }
  1687. break;
  1688. case "keydown":
  1689. //Safari 5.1.x - modal dialog fires keypress twice workaround
  1690. skipKeyPressEvent = false;
  1691. inComposition = false;
  1692. break;
  1693. case "keypress":
  1694. if (skipKeyPressEvent === true) {
  1695. return e.preventDefault();
  1696. }
  1697. skipKeyPressEvent = true;
  1698. break;
  1699. case "compositionstart":
  1700. inComposition = true;
  1701. break;
  1702. case "compositionupdate":
  1703. skipInputEvent = true;
  1704. break;
  1705. case "compositionend":
  1706. inComposition = false;
  1707. break;
  1708. }
  1709. //console.log("executed " + e.type);
  1710. return eventHandler.apply(this, arguments);
  1711. }
  1712. };
  1713. }
  1714. function patchValueProperty(npt) {
  1715. var valueGet;
  1716. var valueSet;
  1717. function patchValhook(type) {
  1718. if ($.valHooks && $.valHooks[type] === undefined || $.valHooks[type].inputmaskpatch !== true) {
  1719. var valhookGet = $.valHooks[type] && $.valHooks[type].get ? $.valHooks[type].get : function(elem) {
  1720. return elem.value;
  1721. };
  1722. var valhookSet = $.valHooks[type] && $.valHooks[type].set ? $.valHooks[type].set : function(elem, value) {
  1723. elem.value = value;
  1724. return elem;
  1725. };
  1726. $.valHooks[type] = {
  1727. get: function(elem) {
  1728. if (elem.inputmask) {
  1729. if (elem.inputmask.opts.autoUnmask) {
  1730. return elem.inputmask.unmaskedvalue();
  1731. } else {
  1732. var result = valhookGet(elem),
  1733. maskset = elem.inputmask.maskset,
  1734. bufferTemplate = maskset._buffer;
  1735. bufferTemplate = bufferTemplate ? bufferTemplate.join("") : "";
  1736. return result !== bufferTemplate ? result : "";
  1737. }
  1738. } else return valhookGet(elem);
  1739. },
  1740. set: function(elem, value) {
  1741. var $elem = $(elem),
  1742. result;
  1743. result = valhookSet(elem, value);
  1744. if (elem.inputmask) {
  1745. $elem.trigger("setvalue.inputmask");
  1746. }
  1747. return result;
  1748. },
  1749. inputmaskpatch: true
  1750. };
  1751. }
  1752. }
  1753. function getter() {
  1754. if (this.inputmask) {
  1755. return this.inputmask.opts.autoUnmask ? this.inputmask.unmaskedvalue() : (valueGet.call(this) !== getBufferTemplate().join("") ? valueGet.call(this) : "");
  1756. } else return valueGet.call(this);
  1757. }
  1758. function setter(value) {
  1759. valueSet.call(this, value);
  1760. if (this.inputmask) {
  1761. $(this).trigger("setvalue.inputmask");
  1762. }
  1763. }
  1764. function installNativeValueSetFallback(npt) {
  1765. $(npt).on("mouseenter.inputmask", wrapEvent(function(event) {
  1766. var $input = $(this),
  1767. input = this,
  1768. value = input.inputmask._valueGet();
  1769. if (value !== "" && value !== getBuffer().join("")) {
  1770. $input.trigger("setvalue.inputmask");
  1771. }
  1772. }));
  1773. // //!! the bound handlers are executed in the order they where bound
  1774. // //reorder the events - the mouseenter event is internally mapped to the mouseover event
  1775. // var events = $._data(npt).events;
  1776. // var handlers = events.mouseover;
  1777. // if (handlers) {
  1778. // var ourHandler = handlers[handlers.length - 1];
  1779. // for (var i = handlers.length - 1; i > 0; i--) {
  1780. // handlers[i] = handlers[i - 1];
  1781. // }
  1782. // handlers[0] = ourHandler;
  1783. // }
  1784. }
  1785. if (!npt.inputmask.__valueGet) {
  1786. if (Object.getOwnPropertyDescriptor && npt.value === undefined) { // && npt.isContentEditable) {
  1787. valueGet = function() {
  1788. return this.textContent;
  1789. };
  1790. valueSet = function(value) {
  1791. this.textContent = value;
  1792. };
  1793. Object.defineProperty(npt, "value", {
  1794. get: getter,
  1795. set: setter
  1796. });
  1797. } else if (document.__lookupGetter__ && npt.__lookupGetter__("value")) {
  1798. valueGet = npt.__lookupGetter__("value");
  1799. valueSet = npt.__lookupSetter__("value");
  1800. npt.__defineGetter__("value", getter);
  1801. npt.__defineSetter__("value", setter);
  1802. } else { //jquery.val
  1803. valueGet = function() {
  1804. return npt.value;
  1805. };
  1806. valueSet = function(value) {
  1807. npt.value = value;
  1808. };
  1809. patchValhook(npt.type);
  1810. installNativeValueSetFallback(npt);
  1811. }
  1812. npt.inputmask.__valueGet = valueGet; //store native property getter
  1813. npt.inputmask._valueGet = function(overruleRTL) {
  1814. return isRTL && overruleRTL !== true ? valueGet.call(this.el).split("").reverse().join("") : valueGet.call(this.el);
  1815. };
  1816. npt.inputmask.__valueSet = valueSet; //store native property setter
  1817. npt.inputmask._valueSet = function(value, overruleRTL) {
  1818. valueSet.call(this.el, (overruleRTL !== true && isRTL && value !== null && value !== undefined) ? value.split("").reverse().join("") : value);
  1819. };
  1820. }
  1821. }
  1822. function handleRemove(input, k, pos, strict) {
  1823. function generalize() {
  1824. if (opts.keepStatic) {
  1825. resetMaskSet(true);
  1826. var validInputs = [],
  1827. lastAlt, positionsClone = $.extend(true, {}, getMaskSet().validPositions);
  1828. //find last alternation
  1829. for (lastAlt = getLastValidPosition(); lastAlt >= 0; lastAlt--) {
  1830. var validPos = getMaskSet().validPositions[lastAlt];
  1831. if (validPos) {
  1832. if (validPos.match.fn != null) {
  1833. validInputs.push(validPos.input);
  1834. }
  1835. delete getMaskSet().validPositions[lastAlt];
  1836. if (validPos.alternation !== undefined && validPos.locator[validPos.alternation] === getTestTemplate(lastAlt).locator[validPos.alternation]) {
  1837. break;
  1838. }
  1839. }
  1840. }
  1841. if (lastAlt > -1) {
  1842. while (validInputs.length > 0) {
  1843. getMaskSet().p = seekNext(getLastValidPosition());
  1844. var keypress = $.Event("keypress");
  1845. keypress.which = validInputs.pop().charCodeAt(0);
  1846. keypressEvent.call(input, keypress, true, false, false, getMaskSet().p);
  1847. }
  1848. } else getMaskSet().validPositions = $.extend(true, {}, positionsClone); //restore original positions
  1849. }
  1850. }
  1851. if (opts.numericInput || isRTL) {
  1852. if (k === Inputmask.keyCode.BACKSPACE) {
  1853. k = Inputmask.keyCode.DELETE;
  1854. } else if (k === Inputmask.keyCode.DELETE) {
  1855. k = Inputmask.keyCode.BACKSPACE;
  1856. }
  1857. if (isRTL) {
  1858. var pend = pos.end;
  1859. pos.end = pos.begin;
  1860. pos.begin = pend;
  1861. }
  1862. }
  1863. if (k === Inputmask.keyCode.BACKSPACE && (pos.end - pos.begin < 1 || opts.insertMode === false)) {
  1864. pos.begin = seekPrevious(pos.begin);
  1865. if (getMaskSet().validPositions[pos.begin] !== undefined && (getMaskSet().validPositions[pos.begin].input === opts.groupSeparator || getMaskSet().validPositions[pos.begin].input === opts.radixPoint)) {
  1866. pos.begin--;
  1867. }
  1868. } else if (k === Inputmask.keyCode.DELETE && pos.begin === pos.end) {
  1869. pos.end = isMask(pos.end) ? pos.end + 1 : seekNext(pos.end) + 1;
  1870. if (getMaskSet().validPositions[pos.begin] !== undefined && (getMaskSet().validPositions[pos.begin].input === opts.groupSeparator || getMaskSet().validPositions[pos.begin].input === opts.radixPoint)) {
  1871. pos.end++;
  1872. }
  1873. }
  1874. stripValidPositions(pos.begin, pos.end, false, strict);
  1875. if (strict !== true) {
  1876. generalize(); //revert the alternation
  1877. }
  1878. var lvp = getLastValidPosition(pos.begin);
  1879. if (lvp < pos.begin) {
  1880. if (lvp === -1) resetMaskSet();
  1881. getMaskSet().p = seekNext(lvp);
  1882. } else if (strict !== true) {
  1883. getMaskSet().p = pos.begin;
  1884. }
  1885. }
  1886. function keydownEvent(e) {
  1887. var input = this,
  1888. $input = $(input),
  1889. k = e.keyCode,
  1890. pos = caret(input);
  1891. //backspace, delete, and escape get special treatment
  1892. if (k === Inputmask.keyCode.BACKSPACE || k === Inputmask.keyCode.DELETE || (iphone && k === 127) || (e.ctrlKey && k === 88 && !isInputEventSupported("cut"))) { //backspace/delete
  1893. e.preventDefault(); //stop default action but allow propagation
  1894. if (k === 88) undoValue = getBuffer().join("");
  1895. handleRemove(input, k, pos);
  1896. writeBuffer(input, getBuffer(), getMaskSet().p, e, undoValue !== getBuffer().join(""));
  1897. if (input.inputmask._valueGet() === getBufferTemplate().join("")) {
  1898. $input.trigger("cleared");
  1899. } else if (isComplete(getBuffer()) === true) {
  1900. $input.trigger("complete");
  1901. }
  1902. if (opts.showTooltip) { //update tooltip
  1903. $input.prop("title", getMaskSet().mask);
  1904. }
  1905. } else if (k === Inputmask.keyCode.END || k === Inputmask.keyCode.PAGE_DOWN) { //when END or PAGE_DOWN pressed set position at lastmatch
  1906. setTimeout(function() {
  1907. var caretPos = seekNext(getLastValidPosition());
  1908. if (!opts.insertMode && caretPos === getMaskLength() && !e.shiftKey) caretPos--;
  1909. caret(input, e.shiftKey ? pos.begin : caretPos, caretPos);
  1910. }, 0);
  1911. } else if ((k === Inputmask.keyCode.HOME && !e.shiftKey) || k === Inputmask.keyCode.PAGE_UP) { //Home or page_up
  1912. caret(input, 0, e.shiftKey ? pos.begin : 0);
  1913. } else if (((opts.undoOnEscape && k === Inputmask.keyCode.ESCAPE) || (k === 90 && e.ctrlKey)) && e.altKey !== true) { //escape && undo && #762
  1914. checkVal(input, true, false, undoValue.split(""));
  1915. $input.trigger("click");
  1916. } else if (k === Inputmask.keyCode.INSERT && !(e.shiftKey || e.ctrlKey)) { //insert
  1917. opts.insertMode = !opts.insertMode;
  1918. caret(input, !opts.insertMode && pos.begin === getMaskLength() ? pos.begin - 1 : pos.begin);
  1919. } else if (opts.tabThrough === true && k === Inputmask.keyCode.TAB) {
  1920. if (e.shiftKey === true) {
  1921. if (getTest(pos.begin).fn === null) {
  1922. pos.begin = seekNext(pos.begin);
  1923. }
  1924. pos.end = seekPrevious(pos.begin, true);
  1925. pos.begin = seekPrevious(pos.end, true);
  1926. } else {
  1927. pos.begin = seekNext(pos.begin, true);
  1928. pos.end = seekNext(pos.begin, true);
  1929. if (pos.end < getMaskLength()) pos.end--;
  1930. }
  1931. if (pos.begin < getMaskLength()) {
  1932. e.preventDefault();
  1933. caret(input, pos.begin, pos.end);
  1934. }
  1935. } else if (opts.insertMode === false && !e.shiftKey) {
  1936. if (k === Inputmask.keyCode.RIGHT) {
  1937. setTimeout(function() {
  1938. var caretPos = caret(input);
  1939. caret(input, caretPos.begin);
  1940. }, 0);
  1941. } else if (k === Inputmask.keyCode.LEFT) {
  1942. setTimeout(function() {
  1943. var caretPos = caret(input);
  1944. caret(input, isRTL ? caretPos.begin + 1 : caretPos.begin - 1);
  1945. }, 0);
  1946. }
  1947. }
  1948. opts.onKeyDown.call(this, e, getBuffer(), caret(input).begin, opts);
  1949. ignorable = $.inArray(k, opts.ignorables) !== -1;
  1950. }
  1951. function keypressEvent(e, checkval, writeOut, strict, ndx) {
  1952. var input = this,
  1953. $input = $(input),
  1954. k = e.which || e.charCode || e.keyCode;
  1955. if (checkval !== true && (!(e.ctrlKey && e.altKey) && (e.ctrlKey || e.metaKey || ignorable))) {
  1956. if (k === Inputmask.keyCode.ENTER && undoValue !== getBuffer().join("")) {
  1957. setTimeout(function() {
  1958. $input.trigger("change");
  1959. undoValue = getBuffer().join("");
  1960. }, 0);
  1961. }
  1962. return true;
  1963. } else {
  1964. if (k) {
  1965. //special treat the decimal separator
  1966. if (k === 46 && e.shiftKey === false && opts.radixPoint === ",") k = 44;
  1967. var pos = checkval ? {
  1968. begin: ndx,
  1969. end: ndx
  1970. } : caret(input),
  1971. forwardPosition, c = String.fromCharCode(k);
  1972. //should we clear a possible selection??
  1973. var isSlctn = isSelection(pos.begin, pos.end);
  1974. if (isSlctn) {
  1975. getMaskSet().undoPositions = $.extend(true, {}, getMaskSet().validPositions); //init undobuffer for recovery when not valid
  1976. handleRemove(input, Inputmask.keyCode.DELETE, pos, true);
  1977. pos.begin = getMaskSet().p;
  1978. if (!opts.insertMode) { //preserve some space
  1979. opts.insertMode = !opts.insertMode;
  1980. setValidPosition(pos.begin, strict);
  1981. opts.insertMode = !opts.insertMode;
  1982. }
  1983. isSlctn = !opts.multi;
  1984. }
  1985. getMaskSet().writeOutBuffer = true;
  1986. var p = isRTL && !isSlctn ? pos.end : pos.begin;
  1987. var valResult = isValid(p, c, strict);
  1988. if (valResult !== false) {
  1989. if (valResult !== true) {
  1990. p = valResult.pos !== undefined ? valResult.pos : p; //set new position from isValid
  1991. c = valResult.c !== undefined ? valResult.c : c; //set new char from isValid
  1992. }
  1993. resetMaskSet(true);
  1994. if (valResult.caret !== undefined) {
  1995. forwardPosition = valResult.caret;
  1996. } else {
  1997. var vps = getMaskSet().validPositions;
  1998. if (!opts.keepStatic && (vps[p + 1] !== undefined && getTests(p + 1, vps[p].locator.slice(), p).length > 1 || vps[p].alternation !== undefined)) {
  1999. forwardPosition = p + 1;
  2000. } else forwardPosition = seekNext(p);
  2001. }
  2002. getMaskSet().p = forwardPosition; //needed for checkval
  2003. }
  2004. if (writeOut !== false) {
  2005. var self = this;
  2006. setTimeout(function() {
  2007. opts.onKeyValidation.call(self, valResult, opts);
  2008. }, 0);
  2009. if (getMaskSet().writeOutBuffer && valResult !== false) {
  2010. var buffer = getBuffer();
  2011. writeBuffer(input, buffer, checkval ? undefined : opts.numericInput ? seekPrevious(forwardPosition) : forwardPosition, e, checkval !== true);
  2012. if (checkval !== true) {
  2013. setTimeout(function() { //timeout needed for IE
  2014. if (isComplete(buffer) === true) $input.trigger("complete");
  2015. }, 0);
  2016. }
  2017. } else if (isSlctn) {
  2018. getMaskSet().buffer = undefined;
  2019. getMaskSet().validPositions = getMaskSet().undoPositions;
  2020. }
  2021. } else if (isSlctn) {
  2022. getMaskSet().buffer = undefined;
  2023. getMaskSet().validPositions = getMaskSet().undoPositions;
  2024. }
  2025. if (opts.showTooltip) { //update tooltip
  2026. $input.prop("title", getMaskSet().mask);
  2027. }
  2028. if (checkval && $.isFunction(opts.onBeforeWrite)) {
  2029. var result = opts.onBeforeWrite.call(this, e, getBuffer(), forwardPosition, opts);
  2030. if (result && result.refreshFromBuffer) {
  2031. var refresh = result.refreshFromBuffer;
  2032. refreshFromBuffer(refresh === true ? refresh : refresh.start, refresh.end, result.buffer);
  2033. resetMaskSet(true);
  2034. if (result.caret) {
  2035. getMaskSet().p = result.caret;
  2036. }
  2037. }
  2038. }
  2039. e.preventDefault();
  2040. if (checkval) {
  2041. return valResult;
  2042. }
  2043. }
  2044. }
  2045. }
  2046. function pasteEvent(e) {
  2047. var input = this,
  2048. $input = $(input),
  2049. inputValue = input.inputmask._valueGet(true),
  2050. caretPos = caret(input);
  2051. //paste event for IE8 and lower I guess ;-)
  2052. if (e.type === "propertychange" && input.inputmask._valueGet().length <= getMaskLength()) {
  2053. return true;
  2054. } else if (e.type === "paste") {
  2055. var valueBeforeCaret = inputValue.substr(0, caretPos.begin),
  2056. valueAfterCaret = inputValue.substr(caretPos.end, inputValue.length);
  2057. if (valueBeforeCaret === getBufferTemplate().slice(0, caretPos.begin).join("")) valueBeforeCaret = "";
  2058. if (valueAfterCaret === getBufferTemplate().slice(caretPos.end).join("")) valueAfterCaret = "";
  2059. if (window.clipboardData && window.clipboardData.getData) { // IE
  2060. inputValue = valueBeforeCaret + window.clipboardData.getData("Text") + valueAfterCaret;
  2061. } else if (e.originalEvent && e.originalEvent.clipboardData && e.originalEvent.clipboardData.getData) {
  2062. inputValue = valueBeforeCaret + e.originalEvent.clipboardData.getData("text/plain") + valueAfterCaret;
  2063. }
  2064. }
  2065. var pasteValue = inputValue;
  2066. if ($.isFunction(opts.onBeforePaste)) {
  2067. pasteValue = opts.onBeforePaste.call(input, inputValue, opts);
  2068. if (pasteValue === false) {
  2069. e.preventDefault();
  2070. return false;
  2071. }
  2072. if (!pasteValue) {
  2073. pasteValue = inputValue;
  2074. }
  2075. }
  2076. checkVal(input, false, false, isRTL ? pasteValue.split("").reverse() : pasteValue.toString().split(""));
  2077. writeBuffer(input, getBuffer(), undefined, e, true);
  2078. $input.trigger("click");
  2079. if (isComplete(getBuffer()) === true) {
  2080. $input.trigger("complete");
  2081. }
  2082. return false;
  2083. }
  2084. function inputFallBackEvent(e) { //fallback when keypress & compositionevents fail
  2085. var input = this;
  2086. checkVal(input, true, false, input.inputmask._valueGet().split(''));
  2087. if (isComplete(getBuffer()) === true) {
  2088. $(input).trigger("complete");
  2089. }
  2090. e.preventDefault();
  2091. }
  2092. function compositionStartEvent(e) {
  2093. var input = this;
  2094. undoValue = getBuffer().join("");
  2095. if (compositionData === "" || e.originalEvent.data.indexOf(compositionData) !== 0) {
  2096. compositionCaretPos = caret(input);
  2097. }
  2098. }
  2099. function compositionUpdateEvent(e) {
  2100. var input = this,
  2101. caretPos = caret(input);
  2102. if (e.originalEvent.data.indexOf(compositionData) === 0) {
  2103. resetMaskSet();
  2104. caretPos = compositionCaretPos;
  2105. }
  2106. var newData = e.originalEvent.data;
  2107. caret(input, caretPos.begin, caretPos.end);
  2108. for (var i = 0; i < newData.length; i++) {
  2109. var keypress = $.Event("keypress");
  2110. keypress.which = newData.charCodeAt(i);
  2111. skipKeyPressEvent = false;
  2112. ignorable = false;
  2113. keypressEvent.call(input, keypress); //needs update
  2114. }
  2115. setTimeout(function() {
  2116. var forwardPosition = getMaskSet().p;
  2117. writeBuffer(input, getBuffer(), opts.numericInput ? seekPrevious(forwardPosition) : forwardPosition);
  2118. }, 0);
  2119. compositionData = e.originalEvent.data;
  2120. }
  2121. function compositionEndEvent(e) {
  2122. //pickup by inputfallback
  2123. }
  2124. function setValueEvent(e) {
  2125. var input = this,
  2126. value = input.inputmask._valueGet();
  2127. checkVal(input, true, false, ($.isFunction(opts.onBeforeMask) ? (opts.onBeforeMask.call(input, value, opts) || value) : value).split(""));
  2128. undoValue = getBuffer().join("");
  2129. if ((opts.clearMaskOnLostFocus || opts.clearIncomplete) && input.inputmask._valueGet() === getBufferTemplate().join("")) {
  2130. input.inputmask._valueSet("");
  2131. }
  2132. }
  2133. function focusEvent(e) {
  2134. var input = this,
  2135. nptValue = input.inputmask._valueGet();
  2136. if (opts.showMaskOnFocus && (!opts.showMaskOnHover || (opts.showMaskOnHover && nptValue === ""))) {
  2137. if (input.inputmask._valueGet() !== getBuffer().join("")) {
  2138. writeBuffer(input, getBuffer(), seekNext(getLastValidPosition()));
  2139. }
  2140. } else if (mouseEnter === false) { //only executed on focus without mouseenter
  2141. caret(input, seekNext(getLastValidPosition()));
  2142. }
  2143. if (opts.positionCaretOnTab === true) {
  2144. setTimeout(function() {
  2145. caret(input, seekNext(getLastValidPosition()));
  2146. }, 0);
  2147. }
  2148. undoValue = getBuffer().join("");
  2149. }
  2150. function mouseleaveEvent(e) {
  2151. var input = this;
  2152. mouseEnter = false;
  2153. if (opts.clearMaskOnLostFocus) {
  2154. var buffer = getBuffer().slice(),
  2155. nptValue = input.inputmask._valueGet();
  2156. if (document.activeElement !== input && nptValue !== input.getAttribute("placeholder") && nptValue !== "") {
  2157. if (getLastValidPosition() === -1 && nptValue === getBufferTemplate().join("")) {
  2158. buffer = [];
  2159. } else { //clearout optional tail of the mask
  2160. clearOptionalTail(buffer);
  2161. }
  2162. writeBuffer(input, buffer);
  2163. }
  2164. }
  2165. }
  2166. function clickEvent(e) {
  2167. function doRadixFocus(clickPos) {
  2168. if (opts.radixFocus && opts.radixPoint !== "") {
  2169. var vps = getMaskSet().validPositions;
  2170. if (vps[clickPos] === undefined || (vps[clickPos].input === getPlaceholder(clickPos))) {
  2171. if (clickPos < seekNext(-1)) return true;
  2172. var radixPos = $.inArray(opts.radixPoint, getBuffer());
  2173. if (radixPos !== -1) {
  2174. for (var vp in vps) {
  2175. if (radixPos < vp && vps[vp].input !== getPlaceholder(vp)) {
  2176. return false;
  2177. }
  2178. }
  2179. return true;
  2180. }
  2181. }
  2182. }
  2183. return false;
  2184. }
  2185. var input = this;
  2186. if (document.activeElement === input) {
  2187. var selectedCaret = caret(input);
  2188. if (selectedCaret.begin === selectedCaret.end) {
  2189. if (doRadixFocus(selectedCaret.begin)) {
  2190. caret(input, $.inArray(opts.radixPoint, getBuffer()));
  2191. } else {
  2192. var clickPosition = selectedCaret.begin,
  2193. lvclickPosition = getLastValidPosition(clickPosition),
  2194. lastPosition = seekNext(lvclickPosition);
  2195. if (clickPosition < lastPosition) {
  2196. caret(input, !isMask(clickPosition) && !isMask(clickPosition - 1) ? seekNext(clickPosition) : clickPosition);
  2197. } else {
  2198. caret(input, opts.numericInput ? 0 : lastPosition);
  2199. }
  2200. }
  2201. }
  2202. }
  2203. }
  2204. function dblclickEvent(e) {
  2205. var input = this;
  2206. setTimeout(function() {
  2207. caret(input, 0, seekNext(getLastValidPosition()));
  2208. }, 0);
  2209. }
  2210. function cutEvent(e) {
  2211. skipInputEvent = true; //stop inputFallback
  2212. var input = this,
  2213. $input = $(input),
  2214. pos = caret(input);
  2215. //correct clipboardData
  2216. if (isRTL) {
  2217. var clipboardData = window.clipboardData || e.originalEvent.clipboardData,
  2218. clipData = clipboardData.getData("text").split("").reverse().join("");
  2219. clipboardData.setData("text", clipData);
  2220. }
  2221. handleRemove(input, Inputmask.keyCode.DELETE, pos);
  2222. writeBuffer(input, getBuffer(), getMaskSet().p, e, undoValue !== getBuffer().join(""));
  2223. if (input.inputmask._valueGet() === getBufferTemplate().join("")) {
  2224. $input.trigger("cleared");
  2225. }
  2226. if (opts.showTooltip) { //update tooltip
  2227. input.title = getMaskSet().mask;
  2228. }
  2229. }
  2230. function blurEvent(e) {
  2231. var $input = $(this),
  2232. input = this;
  2233. if (input.inputmask) {
  2234. var nptValue = input.inputmask._valueGet(),
  2235. buffer = getBuffer().slice();
  2236. if (undoValue !== buffer.join("")) {
  2237. setTimeout(function() { //change event should be triggered after the other buffer manipulations on blur
  2238. $input.trigger("change");
  2239. undoValue = buffer.join("");
  2240. }, 0);
  2241. }
  2242. if (nptValue !== "") {
  2243. if (opts.clearMaskOnLostFocus) {
  2244. if (getLastValidPosition() === -1 && nptValue === getBufferTemplate().join("")) {
  2245. buffer = [];
  2246. } else { //clearout optional tail of the mask
  2247. clearOptionalTail(buffer);
  2248. }
  2249. }
  2250. if (isComplete(buffer) === false) {
  2251. setTimeout(function() {
  2252. $input.trigger("incomplete");
  2253. }, 0);
  2254. if (opts.clearIncomplete) {
  2255. resetMaskSet();
  2256. if (opts.clearMaskOnLostFocus) {
  2257. buffer = [];
  2258. } else {
  2259. buffer = getBufferTemplate().slice();
  2260. }
  2261. }
  2262. }
  2263. writeBuffer(input, buffer, undefined, e);
  2264. }
  2265. }
  2266. }
  2267. function mouseenterEvent(e) {
  2268. var input = this;
  2269. mouseEnter = true;
  2270. if (document.activeElement !== input && opts.showMaskOnHover) {
  2271. if (input.inputmask._valueGet() !== getBuffer().join("")) {
  2272. writeBuffer(input, getBuffer());
  2273. }
  2274. }
  2275. }
  2276. function mask(elem) {
  2277. el = elem;
  2278. $el = $(el);
  2279. //show tooltip
  2280. if (opts.showTooltip) {
  2281. el.title = getMaskSet().mask;
  2282. }
  2283. if (el.dir === "rtl" || opts.rightAlign) {
  2284. el.style.textAlign = "right";
  2285. }
  2286. if (el.dir === "rtl" || opts.numericInput) {
  2287. el.dir = "ltr";
  2288. el.removeAttribute("dir");
  2289. el.inputmask.isRTL = true;
  2290. isRTL = true;
  2291. }
  2292. //unbind all events - to make sure that no other mask will interfere when re-masking
  2293. $el.off(".inputmask");
  2294. patchValueProperty(el);
  2295. if ((el.tagName === "INPUT" && isInputTypeSupported(el.getAttribute("type"))) || el.isContentEditable) {
  2296. //bind events
  2297. $(el.form).on("submit", function() { //trigger change on submit if any
  2298. if (undoValue !== getBuffer().join("")) {
  2299. $el.trigger("change");
  2300. }
  2301. if (opts.clearMaskOnLostFocus && getLastValidPosition() === -1 && el.inputmask._valueGet && el.inputmask._valueGet() === getBufferTemplate().join("")) {
  2302. el.inputmask._valueSet(""); //clear masktemplete on submit and still has focus
  2303. }
  2304. if (opts.removeMaskOnSubmit) {
  2305. el.inputmask._valueSet(el.inputmask.unmaskedvalue(), true);
  2306. setTimeout(function() {
  2307. writeBuffer(el, getBuffer());
  2308. }, 0);
  2309. }
  2310. }).on("reset", function() {
  2311. setTimeout(function() {
  2312. $el.trigger("setvalue.inputmask");
  2313. }, 0);
  2314. });
  2315. $el.on("mouseenter.inputmask", wrapEvent(mouseenterEvent))
  2316. .on("blur.inputmask", wrapEvent(blurEvent))
  2317. .on("focus.inputmask", wrapEvent(focusEvent))
  2318. .on("mouseleave.inputmask", wrapEvent(mouseleaveEvent))
  2319. .on("click.inputmask", wrapEvent(clickEvent))
  2320. .on("dblclick.inputmask", wrapEvent(dblclickEvent))
  2321. .on(PasteEventType + ".inputmask dragdrop.inputmask drop.inputmask", wrapEvent(pasteEvent))
  2322. .on("cut.inputmask", wrapEvent(cutEvent))
  2323. .on("complete.inputmask", wrapEvent(opts.oncomplete))
  2324. .on("incomplete.inputmask", wrapEvent(opts.onincomplete))
  2325. .on("cleared.inputmask", wrapEvent(opts.oncleared))
  2326. .on("keydown.inputmask", wrapEvent(keydownEvent))
  2327. .on("keypress.inputmask", wrapEvent(keypressEvent));
  2328. if (!androidfirefox) {
  2329. $el.on("compositionstart.inputmask", wrapEvent(compositionStartEvent))
  2330. .on("compositionupdate.inputmask", wrapEvent(compositionUpdateEvent))
  2331. .on("compositionend.inputmask", wrapEvent(compositionEndEvent));
  2332. }
  2333. if (PasteEventType === "paste") {
  2334. $el.on("input.inputmask", wrapEvent(inputFallBackEvent));
  2335. }
  2336. //if (android || androidfirefox || androidchrome || kindle) {
  2337. // $el.off("input.inputmask");
  2338. // $el.on("input.inputmask", mobileInputEvent);
  2339. //}
  2340. }
  2341. $el.on("setvalue.inputmask", wrapEvent(setValueEvent));
  2342. //apply mask
  2343. var initialValue = $.isFunction(opts.onBeforeMask) ? (opts.onBeforeMask.call(el, el.inputmask._valueGet(), opts) || el.inputmask._valueGet()) : el.inputmask._valueGet();
  2344. checkVal(el, true, false, initialValue.split(""));
  2345. var buffer = getBuffer().slice();
  2346. undoValue = buffer.join("");
  2347. // Wrap document.activeElement in a try/catch block since IE9 throw "Unspecified error" if document.activeElement is undefined when we are in an IFrame.
  2348. var activeElement;
  2349. try {
  2350. activeElement = document.activeElement;
  2351. } catch (e) {}
  2352. if (isComplete(buffer) === false) {
  2353. if (opts.clearIncomplete) {
  2354. resetMaskSet();
  2355. }
  2356. }
  2357. if (opts.clearMaskOnLostFocus) {
  2358. if (buffer.join("") === getBufferTemplate().join("")) {
  2359. buffer = [];
  2360. } else {
  2361. clearOptionalTail(buffer);
  2362. }
  2363. }
  2364. writeBuffer(el, buffer);
  2365. if (activeElement === el) { //position the caret when in focus
  2366. caret(el, seekNext(getLastValidPosition()));
  2367. }
  2368. }
  2369. //action object
  2370. var valueBuffer;
  2371. if (actionObj !== undefined) {
  2372. switch (actionObj.action) {
  2373. case "isComplete":
  2374. el = actionObj.el;
  2375. $el = $(el);
  2376. maskset = el.inputmask.maskset;
  2377. opts = el.inputmask.opts;
  2378. return isComplete(actionObj.buffer);
  2379. case "unmaskedvalue":
  2380. el = actionObj.el;
  2381. if (el !== undefined && el.inputmask !== undefined) {
  2382. maskset = el.inputmask.maskset;
  2383. opts = el.inputmask.opts;
  2384. isRTL = el.inputmask.isRTL;
  2385. valueBuffer = isRTL ? el.inputmask._valueGet().split("").reverse().join("") : el.inputmask._valueGet();
  2386. } else valueBuffer = actionObj.value;
  2387. if (opts.numericInput) {
  2388. isRTL = true;
  2389. }
  2390. valueBuffer = ($.isFunction(opts.onBeforeMask) ? (opts.onBeforeMask.call($el, valueBuffer, opts) || valueBuffer) : valueBuffer).split("");
  2391. checkVal(undefined, false, false, isRTL ? valueBuffer.reverse() : valueBuffer);
  2392. if ($.isFunction(opts.onBeforeWrite)) opts.onBeforeWrite.call(this, undefined, getBuffer(), 0, opts);
  2393. return unmaskedvalue(el);
  2394. case "mask":
  2395. undoValue = getBuffer().join("");
  2396. mask(actionObj.el);
  2397. break;
  2398. case "format":
  2399. if (opts.numericInput) {
  2400. isRTL = true;
  2401. }
  2402. valueBuffer = ($.isFunction(opts.onBeforeMask) ? (opts.onBeforeMask.call($el, actionObj.value, opts) || actionObj.value) : actionObj.value).split("");
  2403. checkVal(undefined, false, false, isRTL ? valueBuffer.reverse() : valueBuffer);
  2404. if ($.isFunction(opts.onBeforeWrite)) opts.onBeforeWrite.call(this, undefined, getBuffer(), 0, opts);
  2405. if (actionObj.metadata) {
  2406. return {
  2407. value: isRTL ? getBuffer().slice().reverse().join("") : getBuffer().join(""),
  2408. metadata: $el.inputmask("getmetadata")
  2409. };
  2410. }
  2411. return isRTL ? getBuffer().slice().reverse().join("") : getBuffer().join("");
  2412. case "isValid":
  2413. if (opts.numericInput) {
  2414. isRTL = true;
  2415. }
  2416. valueBuffer = actionObj.value.split("");
  2417. checkVal(undefined, false, true, isRTL ? valueBuffer.reverse() : valueBuffer);
  2418. var buffer = getBuffer();
  2419. var rl = determineLastRequiredPosition(),
  2420. lmib = buffer.length - 1;
  2421. for (; lmib > rl; lmib--) {
  2422. if (isMask(lmib)) break;
  2423. }
  2424. buffer.splice(rl, lmib + 1 - rl);
  2425. return isComplete(buffer) && actionObj.value === buffer.join("");
  2426. case "getemptymask":
  2427. el = actionObj.el;
  2428. $el = $(el);
  2429. maskset = el.inputmask.maskset;
  2430. opts = el.inputmask.opts;
  2431. return getBufferTemplate();
  2432. case "remove":
  2433. el = actionObj.el;
  2434. $el = $(el);
  2435. maskset = el.inputmask.maskset;
  2436. opts = el.inputmask.opts;
  2437. //writeout the unmaskedvalue
  2438. el.inputmask._valueSet(unmaskedvalue(el));
  2439. //unbind all events
  2440. $el.off(".inputmask");
  2441. //restore the value property
  2442. var valueProperty;
  2443. if (Object.getOwnPropertyDescriptor) {
  2444. valueProperty = Object.getOwnPropertyDescriptor(el, "value");
  2445. }
  2446. if (valueProperty && valueProperty.get) {
  2447. if (el.inputmask.__valueGet) {
  2448. Object.defineProperty(el, "value", {
  2449. get: el.inputmask.__valueGet,
  2450. set: el.inputmask.__valueSet
  2451. });
  2452. }
  2453. } else if (document.__lookupGetter__ && el.__lookupGetter__("value")) {
  2454. if (el.inputmask.__valueGet) {
  2455. el.__defineGetter__("value", el.inputmask.__valueGet);
  2456. el.__defineSetter__("value", el.inputmask.__valueSet);
  2457. }
  2458. }
  2459. //clear data
  2460. el.inputmask = undefined;
  2461. break;
  2462. case "getmetadata":
  2463. el = actionObj.el;
  2464. $el = $(el);
  2465. maskset = el.inputmask.maskset;
  2466. opts = el.inputmask.opts;
  2467. if ($.isArray(maskset.metadata)) {
  2468. //find last alternation
  2469. var alternation, lvp = getLastValidPosition();
  2470. for (var firstAlt = lvp; firstAlt >= 0; firstAlt--) {
  2471. if (getMaskSet().validPositions[firstAlt] && getMaskSet().validPositions[firstAlt].alternation !== undefined) {
  2472. alternation = getMaskSet().validPositions[firstAlt].alternation;
  2473. break;
  2474. }
  2475. }
  2476. if (alternation !== undefined) {
  2477. return maskset.metadata[getMaskSet().validPositions[lvp].locator[alternation]];
  2478. } else return maskset.metadata[0];
  2479. }
  2480. return maskset.metadata;
  2481. }
  2482. }
  2483. }
  2484. //make inputmask available
  2485. window.Inputmask = Inputmask;
  2486. return Inputmask;
  2487. }));