inputmask.js 98 KB

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