jquery.inputmask.js 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551
  1. /**
  2. * @license Input Mask plugin for jquery
  3. * http://github.com/RobinHerbots/jquery.inputmask
  4. * Copyright (c) 2010 - 2014 Robin Herbots
  5. * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. * Version: 0.0.0
  7. */
  8. (function ($) {
  9. if ($.fn.inputmask === undefined) {
  10. //helper functions
  11. function isInputEventSupported(eventName) {
  12. var el = document.createElement('input'),
  13. eventName = 'on' + eventName,
  14. isSupported = (eventName in el);
  15. if (!isSupported) {
  16. el.setAttribute(eventName, 'return;');
  17. isSupported = typeof el[eventName] == 'function';
  18. }
  19. el = null;
  20. return isSupported;
  21. }
  22. function resolveAlias(aliasStr, options, opts) {
  23. var aliasDefinition = opts.aliases[aliasStr];
  24. if (aliasDefinition) {
  25. if (aliasDefinition.alias) resolveAlias(aliasDefinition.alias, undefined, opts); //alias is another alias
  26. $.extend(true, opts, aliasDefinition); //merge alias definition in the options
  27. $.extend(true, opts, options); //reapply extra given options
  28. return true;
  29. }
  30. return false;
  31. }
  32. function generateMaskSet(opts) {
  33. var ms;
  34. function analyseMask(mask) {
  35. var tokenizer = /(?:[?*+]|\{[0-9]+(?:,[0-9\+\*]*)?\})\??|[^.?*+^${[]()|\\]+|./g,
  36. escaped = false;
  37. function maskToken(isGroup, isOptional, isQuantifier) {
  38. this.matches = [];
  39. this.isGroup = isGroup || false;
  40. this.isOptional = isOptional || false;
  41. this.isQuantifier = isQuantifier || false;
  42. this.quantifier = { min: 1, max: 1 };
  43. };
  44. //test definition => {fn: RegExp/function, cardinality: int, optionality: bool, newBlockMarker: bool, offset: int, casing: null/upper/lower, def: definitionSymbol}
  45. function insertTestDefinition(mtoken, element, position) {
  46. var maskdef = opts.definitions[element];
  47. position = position != undefined ? position : mtoken.matches.length;
  48. if (maskdef && !escaped) {
  49. var prevalidators = maskdef["prevalidator"], prevalidatorsL = prevalidators ? prevalidators.length : 0;
  50. for (var i = 1; i < maskdef.cardinality; i++) {
  51. var prevalidator = prevalidatorsL >= i ? prevalidators[i - 1] : [], validator = prevalidator["validator"], cardinality = prevalidator["cardinality"];
  52. mtoken.matches.splice(position++, 0, { fn: validator ? typeof validator == 'string' ? new RegExp(validator) : new function () { this.test = validator; } : new RegExp("."), cardinality: cardinality ? cardinality : 1, optionality: mtoken.isOptional, casing: maskdef["casing"], def: maskdef["definitionSymbol"] || element });
  53. }
  54. mtoken.matches.splice(position++, 0, { fn: maskdef.validator ? typeof maskdef.validator == 'string' ? new RegExp(maskdef.validator) : new function () { this.test = maskdef.validator; } : new RegExp("."), cardinality: maskdef.cardinality, optionality: mtoken.isOptional, casing: maskdef["casing"], def: maskdef["definitionSymbol"] || element });
  55. } else {
  56. mtoken.matches.splice(position++, 0, { fn: null, cardinality: 0, optionality: mtoken.isOptional, casing: null, def: element });
  57. escaped = false;
  58. }
  59. }
  60. var currentToken = new maskToken(),
  61. match, m, openenings = [], maskTokens = [];
  62. while (match = tokenizer.exec(mask)) {
  63. m = match[0];
  64. switch (m.charAt(0)) {
  65. case opts.optionalmarker.end:
  66. // optional closing
  67. case opts.groupmarker.end:
  68. // Group closing
  69. var openingToken = openenings.pop();
  70. if (openenings.length > 0) {
  71. openenings[openenings.length - 1]["matches"].push(openingToken);
  72. } else {
  73. currentToken.matches.push(openingToken);
  74. }
  75. break;
  76. case opts.optionalmarker.start:
  77. // optional opening
  78. openenings.push(new maskToken(false, true));
  79. break;
  80. case opts.groupmarker.start:
  81. // Group opening
  82. openenings.push(new maskToken(true));
  83. break;
  84. case opts.quantifiermarker.start:
  85. //Quantifier
  86. var quantifier = new maskToken(false, false, true);
  87. m = m.replace(/[{}]/g, "");
  88. var mq = m.split(","), mq0 = isNaN(mq[0]) ? mq[0] : parseInt(mq[0]), mq1 = mq.length == 1 ? mq0 : (isNaN(mq[1]) ? mq[1] : parseInt(mq[1]));
  89. quantifier.quantifier = { min: mq0, max: mq1 };
  90. if (mq1 == "*" || mq1 == "+") opts.greedy = false;
  91. if (openenings.length > 0) {
  92. var matches = openenings[openenings.length - 1]["matches"];
  93. var match = matches.pop();
  94. if (!match["isGroup"]) {
  95. var groupToken = new maskToken(true);
  96. groupToken.matches.push(match);
  97. match = groupToken;
  98. }
  99. matches.push(match);
  100. matches.push(quantifier);
  101. } else {
  102. var match = currentToken.matches.pop();
  103. if (!match["isGroup"]) {
  104. var groupToken = new maskToken(true);
  105. groupToken.matches.push(match);
  106. match = groupToken;
  107. }
  108. currentToken.matches.push(match);
  109. currentToken.matches.push(quantifier);
  110. }
  111. break;
  112. case opts.escapeChar:
  113. escaped = true;
  114. break;
  115. default:
  116. if (openenings.length > 0) {
  117. insertTestDefinition(openenings[openenings.length - 1], m);
  118. } else {
  119. if (currentToken.matches.length > 0) {
  120. var lastMatch = currentToken.matches[currentToken.matches.length - 1];
  121. if (lastMatch["isGroup"]) { //this is not a group but a normal mask => convert
  122. lastMatch.isGroup = false;
  123. insertTestDefinition(lastMatch, opts.groupmarker.start, 0);
  124. insertTestDefinition(lastMatch, opts.groupmarker.end);
  125. }
  126. }
  127. insertTestDefinition(currentToken, m);
  128. }
  129. }
  130. }
  131. if (currentToken.matches.length > 0)
  132. maskTokens.push(currentToken);
  133. console.log(JSON.stringify(maskTokens));
  134. return maskTokens;
  135. }
  136. function generateMask(mask, metadata) {
  137. if (opts.numericInput) { //TODO FIXME for dynamic masks
  138. mask = mask.split('').reverse().join('');
  139. }
  140. if (mask == undefined || mask == "")
  141. return undefined;
  142. else {
  143. if (opts.repeat > 0 || opts.repeat == "*" || opts.repeat == "+") {
  144. var repeatStart = opts.repeat == "*" ? 0 : (opts.repeat == "+" ? 1 : opts.repeat);
  145. mask = opts.groupmarker.start + mask + opts.groupmarker.end + opts.quantifiermarker.start + repeatStart + "," + opts.repeat + opts.quantifiermarker.end;
  146. }
  147. if ($.inputmask.masksCache[mask] == undefined) {
  148. $.inputmask.masksCache[mask] = {
  149. "mask": mask,
  150. "maskToken": analyseMask(mask),
  151. "validPositions": {},
  152. "_buffer": undefined,
  153. "buffer": undefined,
  154. "tests": {},
  155. "metadata": metadata
  156. };
  157. }
  158. return $.extend(true, {}, $.inputmask.masksCache[mask]);
  159. }
  160. }
  161. if ($.isFunction(opts.mask)) { //allow mask to be a preprocessing fn - should return a valid mask
  162. opts.mask = opts.mask.call(this, opts);
  163. }
  164. if ($.isArray(opts.mask)) {
  165. $.each(opts.mask, function (ndx, msk) {
  166. if (msk["mask"] != undefined) {
  167. ms = generateMask(msk["mask"].toString(), msk);
  168. } else {
  169. ms = generateMask(msk.toString());
  170. }
  171. return false; //break after first multiple not supported for now (again)
  172. });
  173. } else {
  174. if (opts.mask.length == 1 && opts.greedy == false && opts.repeat != 0) {
  175. opts.placeholder = "";
  176. } //hide placeholder with single non-greedy mask
  177. if (opts.mask["mask"] != undefined) {
  178. ms = generateMask(opts.mask["mask"].toString(), opts.mask);
  179. } else {
  180. ms = generateMask(opts.mask.toString());
  181. }
  182. }
  183. return ms;
  184. }
  185. var msie1x = typeof ScriptEngineMajorVersion === "function"
  186. ? ScriptEngineMajorVersion() //IE11 detection
  187. : new Function("/*@cc_on return @_jscript_version; @*/")() >= 10, //conditional compilation from mickeysoft trick
  188. ua = navigator.userAgent,
  189. iphone = ua.match(new RegExp("iphone", "i")) !== null,
  190. android = ua.match(new RegExp("android.*safari.*", "i")) !== null,
  191. androidchrome = ua.match(new RegExp("android.*chrome.*", "i")) !== null,
  192. androidfirefox = ua.match(new RegExp("android.*firefox.*", "i")) !== null,
  193. 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),
  194. PasteEventType = isInputEventSupported('paste') ? 'paste' : isInputEventSupported('input') ? 'input' : "propertychange";
  195. //if (androidchrome) {
  196. // var browser = navigator.userAgent.match(new RegExp("chrome.*", "i")),
  197. // version = parseInt(new RegExp(/[0-9]+/).exec(browser));
  198. // androidchrome32 = (version == 32);
  199. //}
  200. //masking scope
  201. //actionObj definition see below
  202. function maskScope(maskset, opts, actionObj) {
  203. var isRTL = false,
  204. valueOnFocus = getBuffer().join(''),
  205. $el,
  206. skipKeyPressEvent = false, //Safari 5.1.x - modal dialog fires keypress twice workaround
  207. skipInputEvent = false, //skip when triggered from within inputmask
  208. ignorable = false,
  209. maxLength;
  210. //maskset helperfunctions
  211. function getMaskTemplate(baseOnInput, minimalPos, includeInput) {
  212. minimalPos = minimalPos || 0;
  213. var maskTemplate = [], ndxIntlzr, pos = 0, test;
  214. do {
  215. if (baseOnInput === true && getMaskSet()['validPositions'][pos]) {
  216. var validPos = getMaskSet()['validPositions'][pos];
  217. test = validPos["match"];
  218. ndxIntlzr = validPos["locator"].slice();
  219. maskTemplate.push(test["fn"] == null ? test["def"] : (includeInput === true ? validPos["input"] : opts.placeholder.charAt(pos % opts.placeholder.length)));
  220. } else {
  221. var testPos = getTests(pos, false, ndxIntlzr, pos - 1);
  222. testPos = testPos[opts.greedy || minimalPos > pos ? 0 : (testPos.length - 1)];
  223. test = testPos["match"];
  224. ndxIntlzr = testPos["locator"].slice();
  225. maskTemplate.push(test["fn"] == null ? test["def"] : opts.placeholder.charAt(pos % opts.placeholder.length));
  226. }
  227. pos++;
  228. } while ((maxLength == undefined || (pos - 1 < maxLength && maxLength > -1)) && test["fn"] != null || (test["fn"] == null && test["def"] != "") || minimalPos >= pos);
  229. maskTemplate.pop(); //drop the last one which is empty
  230. return maskTemplate;
  231. }
  232. function getMaskSet() {
  233. return maskset;
  234. }
  235. function resetMaskSet() {
  236. var maskset = getMaskSet();
  237. maskset["buffer"] = undefined;
  238. maskset["_buffer"] = undefined;
  239. maskset["validPositions"] = {};
  240. maskset["tests"] = {};
  241. maskset["p"] = -1;
  242. }
  243. function getLastValidPosition(maskset, closestTo) { //TODO implement closest to
  244. maskset = maskset || getMaskSet();
  245. var lastValidPosition = -1;
  246. for (var posNdx in maskset["validPositions"]) {
  247. var psNdx = parseInt(posNdx);
  248. if (psNdx > lastValidPosition) lastValidPosition = psNdx;
  249. }
  250. return lastValidPosition;
  251. }
  252. function setValidPosition(pos, validTest, strict) {
  253. if (opts.insertMode && getMaskSet()["validPositions"][pos] != undefined) {
  254. var currentValid = getMaskSet()["validPositions"][pos];
  255. getMaskSet()["validPositions"][pos] = validTest;
  256. //reposition & revalidate others
  257. isValid(pos + 1, currentValid["input"], strict);
  258. } else
  259. getMaskSet()["validPositions"][pos] = validTest;
  260. }
  261. function getTest(pos) {
  262. if (getMaskSet()['validPositions'][pos]) {
  263. return getMaskSet()['validPositions'][pos]["match"];
  264. }
  265. return getTests(pos)[0]["match"];
  266. }
  267. function getTests(pos, disableCache, ndxIntlzr, tstPs) {
  268. var maskTokens = getMaskSet()["maskToken"], testPos = ndxIntlzr ? tstPs : 0, ndxInitializer = ndxIntlzr || [0], matches = [], insertStop = false;
  269. function ResolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) { //ndxInitilizer contains a set of indexes to speedup searches in the mtokens
  270. function handleMatch(match, loopNdx, quantifierRecurse) {
  271. var currentPos = testPos;
  272. if (testPos == pos && match.matches == undefined) {
  273. matches.push({ "match": match, "locator": loopNdx.reverse() });
  274. return true;
  275. } else if (match.matches != undefined) {
  276. if (match.isGroup && quantifierRecurse !== true) { //when a group pass along to the quantifier
  277. match = handleMatch(maskToken.matches[tndx + 1], loopNdx);
  278. if (match) return true;
  279. } else if (match.isOptional) {
  280. match = ResolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse);
  281. if (match) {
  282. //search for next possible match
  283. testPos = currentPos;
  284. }
  285. } else if (match.isQuantifier && quantifierRecurse !== true) {
  286. var qt = match;
  287. for (var qndx = (ndxInitializer.length > 0 && quantifierRecurse !== true) ? ndxInitializer.shift() : 0; (qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max)) && testPos <= pos; qndx++) {
  288. var tokenGroup = maskToken.matches[maskToken.matches.indexOf(qt) - 1];
  289. match = handleMatch(tokenGroup, [qndx].concat(loopNdx), true);
  290. if (match) {
  291. //get latest match
  292. var latestMatch = matches[matches.length - 1]["match"];
  293. var isFirstMatch = (tokenGroup.matches.indexOf(latestMatch) == 0);
  294. if (isFirstMatch) { //search for next possible match
  295. if (qndx > qt.quantifier.min - 1) {
  296. insertStop = true;
  297. testPos = pos; //match the position after the group
  298. break; //stop quantifierloop
  299. } else return true;
  300. } else {
  301. return true;
  302. }
  303. }
  304. }
  305. } else {
  306. match = ResolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse);
  307. if (match)
  308. return true;
  309. }
  310. } else testPos++;
  311. }
  312. for (var tndx = (ndxInitializer.length > 0 ? ndxInitializer.shift() : 0) ; tndx < maskToken.matches.length; tndx++) {
  313. if (maskToken.matches[tndx]["isQuantifier"] !== true) {
  314. var match = handleMatch(maskToken.matches[tndx], [tndx].concat(loopNdx), quantifierRecurse);
  315. if (match && testPos == pos) {
  316. return match;
  317. } else if (testPos > pos) {
  318. break;
  319. }
  320. }
  321. }
  322. }
  323. if (disableCache !== true && getMaskSet()['tests'][pos] && !getMaskSet()['validPositions'][pos]) {
  324. return getMaskSet()['tests'][pos];
  325. }
  326. if (ndxIntlzr == undefined) {
  327. var previousPos = pos - 1, test;
  328. while ((test = getMaskSet()['validPositions'][previousPos]) == undefined && previousPos > -1) {
  329. previousPos--;
  330. }
  331. if (test != undefined && previousPos > -1) {
  332. testPos = previousPos;
  333. ndxInitializer = test["locator"].slice();
  334. } else {
  335. previousPos = pos - 1;
  336. while ((test = getMaskSet()['tests'][previousPos]) == undefined && previousPos > -1) {
  337. previousPos--;
  338. }
  339. if (test != undefined && previousPos > -1) {
  340. testPos = previousPos;
  341. ndxInitializer = test[0]["locator"].slice();
  342. }
  343. }
  344. }
  345. for (var mtndx = ndxInitializer.shift() ; mtndx < maskTokens.length; mtndx++) {
  346. var match = ResolveTestFromToken(maskTokens[mtndx], ndxInitializer, [mtndx]);
  347. if ((match && testPos == pos) || testPos > pos) {
  348. break;
  349. }
  350. }
  351. if (matches.length == 0 || insertStop)
  352. matches.push({ "match": { fn: null, cardinality: 0, optionality: true, casing: null, def: "" }, "locator": [] });
  353. getMaskSet()['tests'][pos] = matches;
  354. console.log(pos + " - " + JSON.stringify(matches));
  355. return matches;
  356. }
  357. function getBufferTemplate() {
  358. if (getMaskSet()['_buffer'] == undefined) {
  359. //generate template
  360. getMaskSet()["_buffer"] = getMaskTemplate(false, 1);
  361. }
  362. return getMaskSet()['_buffer'];
  363. }
  364. function getBuffer() {
  365. if (getMaskSet()['buffer'] == undefined) {
  366. getMaskSet()['buffer'] = getMaskTemplate(true, 0, true);
  367. }
  368. return getMaskSet()['buffer'];
  369. }
  370. function isValid(pos, c, strict) { //strict true ~ no correction or autofill
  371. strict = strict === true; //always set a value to strict to prevent possible strange behavior in the extensions
  372. function _isValid(position, c, strict) {
  373. var rslt = false;
  374. $.each(getTests(position, !strict), function (ndx, tst) {
  375. var test = tst["match"];
  376. var loopend = c ? 1 : 0, chrs = '', buffer = getBuffer();
  377. for (var i = test.cardinality; i > loopend; i--) {
  378. chrs += getBufferElement(buffer, position - (i - 1), true);
  379. }
  380. if (c) {
  381. chrs += c;
  382. }
  383. //return is false or a json object => { pos: ??, c: ??} or true
  384. rslt = test.fn != null ?
  385. test.fn.test(chrs, buffer, position, strict, opts)
  386. : (c == test["def"] || c == opts.skipOptionalPartCharacter) ?
  387. { "refresh": ndx == 0, c: test["def"], pos: position }
  388. : false;
  389. if (rslt !== false) {
  390. var elem = c;
  391. switch (test.casing) {
  392. case "upper":
  393. elem = elem.toUpperCase();
  394. break;
  395. case "lower":
  396. elem = elem.toLowerCase();
  397. break;
  398. }
  399. var validatedPos = position;
  400. if (rslt !== true && rslt["pos"] != position) { //their is an position offset
  401. setValidPosition(position, $.extend({}, tst, { "input": buffer[position] }), strict);
  402. validatedPos = rslt["pos"];
  403. for (var op = position + 1; op < validatedPos; op++) {
  404. setValidPosition(op, $.extend({}, getTests(op, !strict)[0], { "input": buffer[op] }), strict);
  405. }
  406. tst = getTests(validatedPos, !strict)[0]; //possible mismatch TODO
  407. }
  408. if (ndx != 0) {
  409. getMaskSet()["buffer"] = undefined;
  410. getMaskSet()["tests"] = {}; //clear the tests cache
  411. }
  412. setValidPosition(validatedPos, $.extend({}, tst, { "input": elem }), strict);
  413. return false; //break from $.each
  414. }
  415. });
  416. return rslt;
  417. }
  418. var maskPos = pos;
  419. var result = _isValid(maskPos, c, strict);
  420. if (!strict && result === false && !isMask(maskPos)) { //does the input match on a further position?
  421. for (var nPos = maskPos + 1, snPos = seekNext(maskPos) ; nPos <= snPos; nPos++) {
  422. result = _isValid(nPos, c, strict);
  423. if (result !== false) {
  424. maskPos = nPos;
  425. break;
  426. }
  427. }
  428. }
  429. if (result === true) result = { "pos": maskPos };
  430. return result;
  431. }
  432. function isMask(pos) {
  433. var test = getTest(pos);
  434. return test.fn != null ? test.fn : false;
  435. }
  436. function getMaskLength() {
  437. var maskLength; maxLength = $el.prop('maxLength');
  438. if (opts.greedy == false) {
  439. var lvp = getLastValidPosition() + 1,
  440. test = getTest(lvp);
  441. while (test.fn != null && test.def != "") {
  442. var tests = getTests(++lvp);
  443. test = tests[tests.length - 1];
  444. }
  445. maskLength = getMaskTemplate(false, lvp).length;
  446. } else
  447. maskLength = getBuffer().length;
  448. return maxLength == undefined || (maskLength < maxLength && maxLength > -1) /* FF sets no defined max length to -1 */ ? maskLength : maxLength;
  449. }
  450. function seekNext(pos) {
  451. var maskL = getMaskLength();
  452. if (pos >= maskL) return maskL;
  453. var position = pos;
  454. while (++position < maskL && !isMask(position)) {
  455. }
  456. return position;
  457. }
  458. function seekPrevious(pos) {
  459. var position = pos;
  460. if (position <= 0) return 0;
  461. while (--position > 0 && !isMask(position)) {
  462. }
  463. ;
  464. return position;
  465. }
  466. function setBufferElement(buffer, position, element) {
  467. position = prepareBuffer(buffer, position);
  468. var test = getTest(position);
  469. var elem = element;
  470. if (elem != undefined && test != undefined) {
  471. switch (test.casing) {
  472. case "upper":
  473. elem = element.toUpperCase();
  474. break;
  475. case "lower":
  476. elem = element.toLowerCase();
  477. break;
  478. }
  479. }
  480. buffer[position] = elem;
  481. }
  482. function getBufferElement(buffer, position) {
  483. position = prepareBuffer(buffer, position);
  484. return buffer[position];
  485. }
  486. //needed to handle the non-greedy mask repetitions
  487. function prepareBuffer(buffer, position) { //TODO DROP BUFFER PASSING + optimize me
  488. if (buffer.length <= position) {
  489. var trbuffer = getMaskTemplate(true, position);
  490. buffer.length = trbuffer.length;
  491. for (var i = 0, bl = buffer.length; i < bl; i++) {
  492. if (buffer[i] == undefined)
  493. buffer[i] = trbuffer[i];
  494. }
  495. buffer[position] = getPlaceholder(position);
  496. }
  497. return position;
  498. }
  499. function writeBuffer(input, buffer, caretPos) {
  500. input._valueSet(buffer.join(''));
  501. if (caretPos != undefined) {
  502. caret(input, caretPos);
  503. }
  504. }
  505. function clearBuffer(buffer, start, end, stripNomasks) {
  506. for (var i = start, maskL = getMaskLength() ; i < end && i < maskL; i++) {
  507. if (stripNomasks === true) {
  508. if (!isMask(i))
  509. setBufferElement(buffer, i, "");
  510. } else
  511. setBufferElement(buffer, i, getPlaceholder(i));
  512. }
  513. }
  514. function setPlaceholder(pos) {
  515. setBufferElement(getBuffer(), pos, getPlaceholder(pos));
  516. }
  517. function getPlaceholder(pos) {
  518. var test = getTest(pos);
  519. return test["fn"] == null ? test["def"] : opts.placeholder.charAt(pos % opts.placeholder.length);
  520. }
  521. function checkVal(input, writeOut, strict, nptvl, intelliCheck) {
  522. var inputValue = nptvl != undefined ? nptvl.slice() : truncateInput(input._valueGet()).split('');
  523. resetMaskSet();
  524. if (writeOut) input._valueSet(""); //initial clear
  525. $.each(inputValue, function (ndx, charCode) {
  526. if (intelliCheck === true) {
  527. var p = getMaskSet()["p"], lvp = p == -1 ? p : seekPrevious(p),
  528. pos = lvp == -1 ? ndx : seekNext(lvp);
  529. if ($.inArray(charCode, getBufferTemplate().slice(lvp + 1, pos)) == -1) {
  530. keypressEvent.call(input, undefined, true, charCode.charCodeAt(0), writeOut, strict, ndx);
  531. }
  532. } else {
  533. keypressEvent.call(input, undefined, true, charCode.charCodeAt(0), writeOut, strict, ndx);
  534. strict = strict || (ndx > 0 && ndx > getMaskSet()["p"]);
  535. }
  536. });
  537. }
  538. function escapeRegex(str) {
  539. return $.inputmask.escapeRegex.call(this, str);
  540. }
  541. function truncateInput(inputValue) {
  542. return inputValue.replace(new RegExp("(" + escapeRegex(getBufferTemplate().join('')) + ")*$"), "");
  543. }
  544. function clearOptionalTail(input) {
  545. var buffer = getBuffer(), tmpBuffer = buffer.slice(), testPos, pos;
  546. for (var pos = tmpBuffer.length - 1; pos >= 0; pos--) {
  547. if (getTest(pos).optionality) {
  548. if (!isMask(pos) || !isValid(pos, buffer[pos], true))
  549. tmpBuffer.pop();
  550. else break;
  551. } else break;
  552. }
  553. writeBuffer(input, tmpBuffer);
  554. }
  555. function unmaskedvalue($input, skipDatepickerCheck) {
  556. if ($input.data('_inputmask') && (skipDatepickerCheck === true || !$input.hasClass('hasDatepicker'))) {
  557. var umValue = $.map(getBuffer(), function (element, index) {
  558. return isMask(index) && isValid(index, element, true) ? element : null;
  559. });
  560. var unmaskedValue = (isRTL ? umValue.reverse() : umValue).join('');
  561. return $.isFunction(opts.onUnMask) ? opts.onUnMask.call($input, getBuffer().join(''), unmaskedValue, opts) : unmaskedValue;
  562. } else {
  563. return $input[0]._valueGet();
  564. }
  565. }
  566. function TranslatePosition(pos) {
  567. if (isRTL && typeof pos == 'number' && (!opts.greedy || opts.placeholder != "")) {
  568. var bffrLght = getBuffer().length;
  569. pos = bffrLght - pos;
  570. }
  571. return pos;
  572. }
  573. function caret(input, begin, end) {
  574. var npt = input.jquery && input.length > 0 ? input[0] : input, range;
  575. if (typeof begin == 'number') {
  576. begin = TranslatePosition(begin);
  577. end = TranslatePosition(end);
  578. if (!$(npt).is(':visible')) {
  579. return;
  580. }
  581. end = (typeof end == 'number') ? end : begin;
  582. npt.scrollLeft = npt.scrollWidth;
  583. if (opts.insertMode == false && begin == end) end++; //set visualization for insert/overwrite mode
  584. if (npt.setSelectionRange) {
  585. npt.selectionStart = begin;
  586. npt.selectionEnd = end;
  587. } else if (npt.createTextRange) {
  588. range = npt.createTextRange();
  589. range.collapse(true);
  590. range.moveEnd('character', end);
  591. range.moveStart('character', begin);
  592. range.select();
  593. }
  594. } else {
  595. if (!$(input).is(':visible')) {
  596. return { "begin": 0, "end": 0 };
  597. }
  598. if (npt.setSelectionRange) {
  599. begin = npt.selectionStart;
  600. end = npt.selectionEnd;
  601. } else if (document.selection && document.selection.createRange) {
  602. range = document.selection.createRange();
  603. begin = 0 - range.duplicate().moveStart('character', -100000);
  604. end = begin + range.text.length;
  605. }
  606. begin = TranslatePosition(begin);
  607. end = TranslatePosition(end);
  608. return { "begin": begin, "end": end };
  609. }
  610. }
  611. function isComplete(buffer) { //return true / false / undefined (repeat *)
  612. if ($.isFunction(opts.isComplete)) return opts.isComplete.call($el, buffer, opts);
  613. if (opts.repeat == "*") return undefined;
  614. var complete = false,
  615. aml = seekPrevious(getMaskLength());
  616. if (getLastValidPosition() == aml) {
  617. complete = true;
  618. for (var i = 0; i <= aml; i++) {
  619. var mask = isMask(i);
  620. if ((mask && (buffer[i] == undefined || buffer[i] == getPlaceholder(i))) || (!mask && buffer[i] != getPlaceholder(i))) {
  621. complete = false;
  622. break;
  623. }
  624. }
  625. }
  626. return complete;
  627. }
  628. function isSelection(begin, end) {
  629. return isRTL ? (begin - end) > 1 || ((begin - end) == 1 && opts.insertMode) :
  630. (end - begin) > 1 || ((end - begin) == 1 && opts.insertMode);
  631. }
  632. function installEventRuler(npt) {
  633. var events = $._data(npt).events;
  634. $.each(events, function (eventType, eventHandlers) {
  635. $.each(eventHandlers, function (ndx, eventHandler) {
  636. if (eventHandler.namespace == "inputmask") {
  637. if (eventHandler.type != "setvalue") {
  638. var handler = eventHandler.handler;
  639. eventHandler.handler = function (e) {
  640. if (this.readOnly || this.disabled)
  641. e.preventDefault;
  642. else
  643. return handler.apply(this, arguments);
  644. };
  645. }
  646. }
  647. });
  648. });
  649. }
  650. function patchValueProperty(npt) {
  651. function PatchValhook(type) {
  652. if ($.valHooks[type] == undefined || $.valHooks[type].inputmaskpatch != true) {
  653. var valueGet = $.valHooks[type] && $.valHooks[type].get ? $.valHooks[type].get : function (elem) { return elem.value; };
  654. var valueSet = $.valHooks[type] && $.valHooks[type].set ? $.valHooks[type].set : function (elem, value) {
  655. elem.value = value;
  656. return elem;
  657. };
  658. $.valHooks[type] = {
  659. get: function (elem) {
  660. var $elem = $(elem);
  661. if ($elem.data('_inputmask')) {
  662. if ($elem.data('_inputmask')['opts'].autoUnmask)
  663. return $elem.inputmask('unmaskedvalue');
  664. else {
  665. var result = valueGet(elem),
  666. inputData = $elem.data('_inputmask'), maskset = inputData['maskset'],
  667. bufferTemplate = maskset['_buffer'];
  668. bufferTemplate = bufferTemplate ? bufferTemplate.join('') : '';
  669. return result != bufferTemplate ? result : '';
  670. }
  671. } else return valueGet(elem);
  672. },
  673. set: function (elem, value) {
  674. var $elem = $(elem);
  675. var result = valueSet(elem, value);
  676. if ($elem.data('_inputmask')) $elem.triggerHandler('setvalue.inputmask');
  677. return result;
  678. },
  679. inputmaskpatch: true
  680. };
  681. }
  682. }
  683. var valueProperty;
  684. if (Object.getOwnPropertyDescriptor)
  685. valueProperty = Object.getOwnPropertyDescriptor(npt, "value");
  686. if (valueProperty && valueProperty.get) {
  687. if (!npt._valueGet) {
  688. var valueGet = valueProperty.get;
  689. var valueSet = valueProperty.set;
  690. npt._valueGet = function () {
  691. return isRTL ? valueGet.call(this).split('').reverse().join('') : valueGet.call(this);
  692. };
  693. npt._valueSet = function (value) {
  694. valueSet.call(this, isRTL ? value.split('').reverse().join('') : value);
  695. };
  696. Object.defineProperty(npt, "value", {
  697. get: function () {
  698. var $self = $(this), inputData = $(this).data('_inputmask'), maskset = inputData['maskset'];
  699. return inputData && inputData['opts'].autoUnmask ? $self.inputmask('unmaskedvalue') : valueGet.call(this) != maskset['_buffer'].join('') ? valueGet.call(this) : '';
  700. },
  701. set: function (value) {
  702. valueSet.call(this, value);
  703. $(this).triggerHandler('setvalue.inputmask');
  704. }
  705. });
  706. }
  707. } else if (document.__lookupGetter__ && npt.__lookupGetter__("value")) {
  708. if (!npt._valueGet) {
  709. var valueGet = npt.__lookupGetter__("value");
  710. var valueSet = npt.__lookupSetter__("value");
  711. npt._valueGet = function () {
  712. return isRTL ? valueGet.call(this).split('').reverse().join('') : valueGet.call(this);
  713. };
  714. npt._valueSet = function (value) {
  715. valueSet.call(this, isRTL ? value.split('').reverse().join('') : value);
  716. };
  717. npt.__defineGetter__("value", function () {
  718. var $self = $(this), inputData = $(this).data('_inputmask'), maskset = inputData['maskset'];
  719. return inputData && inputData['opts'].autoUnmask ? $self.inputmask('unmaskedvalue') : valueGet.call(this) != maskset['_buffer'].join('') ? valueGet.call(this) : '';
  720. });
  721. npt.__defineSetter__("value", function (value) {
  722. valueSet.call(this, value);
  723. $(this).triggerHandler('setvalue.inputmask');
  724. });
  725. }
  726. } else {
  727. if (!npt._valueGet) {
  728. npt._valueGet = function () { return isRTL ? this.value.split('').reverse().join('') : this.value; };
  729. npt._valueSet = function (value) { this.value = isRTL ? value.split('').reverse().join('') : value; };
  730. }
  731. PatchValhook(npt.type);
  732. }
  733. }
  734. //shift chars to left from start to end and put c at end position if defined
  735. function shiftL(start, end, c, maskJumps) {
  736. var buffer = getBuffer();
  737. if (maskJumps !== false) //jumping over nonmask position
  738. while (!isMask(start) && start - 1 >= 0) start--;
  739. for (var i = start; i < end && i < getMaskLength() ; i++) {
  740. if (isMask(i)) {
  741. setPlaceholder(i);
  742. var j = seekNext(i);
  743. var p = getBufferElement(buffer, j);
  744. if (p != getPlaceholder(j)) {
  745. if (j < getMaskLength() && isValid(i, p, true) !== false && getTest(i).def == getTest(j).def) {
  746. setBufferElement(buffer, i, p);
  747. if (j < end) {
  748. setPlaceholder(j); //cleanup next position
  749. }
  750. } else {
  751. if (isMask(i))
  752. break;
  753. }
  754. }
  755. } else {
  756. setPlaceholder(i);
  757. }
  758. }
  759. if (c != undefined)
  760. setBufferElement(buffer, seekPrevious(end), c);
  761. if (opts.greedy == false) {
  762. var trbuffer = truncateInput(buffer.join('')).split('');
  763. buffer.length = trbuffer.length;
  764. for (var i = 0, bl = buffer.length; i < bl; i++) {
  765. buffer[i] = trbuffer[i];
  766. }
  767. if (buffer.length == 0) getMaskSet()["buffer"] = getBufferTemplate().slice();
  768. }
  769. return start; //return the used start position
  770. }
  771. function shiftR(start, end, c) {
  772. var buffer = getBuffer();
  773. if (getBufferElement(buffer, start) != getPlaceholder(start)) {
  774. for (var i = seekPrevious(end) ; i > start && i >= 0; i--) {
  775. if (isMask(i)) {
  776. var j = seekPrevious(i);
  777. var t = getBufferElement(buffer, j);
  778. if (t != getPlaceholder(j)) {
  779. if (isValid(i, t, true) !== false && getTest(i).def == getTest(j).def) {
  780. setBufferElement(buffer, i, t);
  781. setPlaceholder(j);
  782. } //else break;
  783. }
  784. } else
  785. setPlaceholder(i);
  786. }
  787. }
  788. if (c != undefined && getBufferElement(buffer, start) == getPlaceholder(start))
  789. setBufferElement(buffer, start, c);
  790. var lengthBefore = buffer.length;
  791. if (opts.greedy == false) {
  792. var trbuffer = truncateInput(buffer.join('')).split('');
  793. buffer.length = trbuffer.length;
  794. for (var i = 0, bl = buffer.length; i < bl; i++) {
  795. buffer[i] = trbuffer[i];
  796. }
  797. if (buffer.length == 0) getMaskSet()["buffer"] = getBufferTemplate().slice();
  798. }
  799. return end - (lengthBefore - buffer.length); //return new start position
  800. }
  801. function HandleRemove(input, k, pos) {
  802. if (opts.numericInput || isRTL) {
  803. switch (k) {
  804. case opts.keyCode.BACKSPACE:
  805. k = opts.keyCode.DELETE;
  806. break;
  807. case opts.keyCode.DELETE:
  808. k = opts.keyCode.BACKSPACE;
  809. break;
  810. }
  811. if (isRTL) {
  812. var pend = pos.end;
  813. pos.end = pos.begin;
  814. pos.begin = pend;
  815. }
  816. }
  817. var isSelection = true;
  818. if (pos.begin == pos.end) {
  819. var posBegin = k == opts.keyCode.BACKSPACE ? pos.begin - 1 : pos.begin;
  820. if (opts.isNumeric && opts.radixPoint != "" && getBuffer()[posBegin] == opts.radixPoint) {
  821. pos.begin = (getBuffer().length - 1 == posBegin) /* radixPoint is latest? delete it */ ? pos.begin : k == opts.keyCode.BACKSPACE ? posBegin : seekNext(posBegin);
  822. pos.end = pos.begin;
  823. }
  824. isSelection = false;
  825. if (k == opts.keyCode.BACKSPACE)
  826. pos.begin--;
  827. else if (k == opts.keyCode.DELETE)
  828. pos.end++;
  829. } else if (pos.end - pos.begin == 1 && !opts.insertMode) {
  830. isSelection = false;
  831. if (k == opts.keyCode.BACKSPACE)
  832. pos.begin--;
  833. }
  834. clearBuffer(getBuffer(), pos.begin, pos.end);
  835. var ml = getMaskLength();
  836. if (opts.greedy == false && (isNaN(opts.repeat) || opts.repeat > 0)) {
  837. shiftL(pos.begin, ml, undefined, !isRTL && (k == opts.keyCode.BACKSPACE && !isSelection));
  838. } else {
  839. var newpos = pos.begin;
  840. for (var i = pos.begin; i < pos.end; i++) { //seeknext to skip placeholders at start in selection
  841. if (isMask(i) || !isSelection)
  842. newpos = shiftL(pos.begin, ml, undefined, !isRTL && (k == opts.keyCode.BACKSPACE && !isSelection));
  843. }
  844. if (!isSelection) pos.begin = newpos;
  845. }
  846. var firstMaskPos = seekNext(-1);
  847. clearBuffer(getBuffer(), pos.begin, pos.end, true);
  848. checkVal(input, false, false, getBuffer());
  849. if (getLastValidPosition() < firstMaskPos) {
  850. getMaskSet()["p"] = firstMaskPos;
  851. } else {
  852. getMaskSet()["p"] = pos.begin;
  853. }
  854. }
  855. function keydownEvent(e) {
  856. //Safari 5.1.x - modal dialog fires keypress twice workaround
  857. skipKeyPressEvent = false;
  858. var input = this, $input = $(input), k = e.keyCode, pos = caret(input);
  859. //backspace, delete, and escape get special treatment
  860. if (k == opts.keyCode.BACKSPACE || k == opts.keyCode.DELETE || (iphone && k == 127) || e.ctrlKey && k == 88) { //backspace/delete
  861. e.preventDefault(); //stop default action but allow propagation
  862. if (k == 88) valueOnFocus = getBuffer().join('');
  863. HandleRemove(input, k, pos);
  864. writeBuffer(input, getBuffer(), getMaskSet()["p"]);
  865. if (input._valueGet() == getBufferTemplate().join(''))
  866. $input.trigger('cleared');
  867. if (opts.showTooltip) { //update tooltip
  868. $input.prop("title", getMaskSet()["mask"]);
  869. }
  870. } else if (k == opts.keyCode.END || k == opts.keyCode.PAGE_DOWN) { //when END or PAGE_DOWN pressed set position at lastmatch
  871. setTimeout(function () {
  872. var caretPos = seekNext(getLastValidPosition());
  873. if (!opts.insertMode && caretPos == getMaskLength() && !e.shiftKey) caretPos--;
  874. caret(input, e.shiftKey ? pos.begin : caretPos, caretPos);
  875. }, 0);
  876. } else if ((k == opts.keyCode.HOME && !e.shiftKey) || k == opts.keyCode.PAGE_UP) { //Home or page_up
  877. caret(input, 0, e.shiftKey ? pos.begin : 0);
  878. } else if (k == opts.keyCode.ESCAPE || (k == 90 && e.ctrlKey)) { //escape && undo
  879. checkVal(input, true, false, valueOnFocus.split(''));
  880. $input.click();
  881. } else if (k == opts.keyCode.INSERT && !(e.shiftKey || e.ctrlKey)) { //insert
  882. opts.insertMode = !opts.insertMode;
  883. caret(input, !opts.insertMode && pos.begin == getMaskLength() ? pos.begin - 1 : pos.begin);
  884. } else if (opts.insertMode == false && !e.shiftKey) {
  885. if (k == opts.keyCode.RIGHT) {
  886. setTimeout(function () {
  887. var caretPos = caret(input);
  888. caret(input, caretPos.begin);
  889. }, 0);
  890. } else if (k == opts.keyCode.LEFT) {
  891. setTimeout(function () {
  892. var caretPos = caret(input);
  893. caret(input, caretPos.begin - 1);
  894. }, 0);
  895. }
  896. }
  897. var currentCaretPos = caret(input);
  898. if (opts.onKeyDown.call(this, e, getBuffer(), opts) === true) //extra stuff to execute on keydown
  899. caret(input, currentCaretPos.begin, currentCaretPos.end);
  900. ignorable = $.inArray(k, opts.ignorables) != -1;
  901. }
  902. function keypressEvent(e, checkval, k, writeOut, strict, ndx) {
  903. //Safari 5.1.x - modal dialog fires keypress twice workaround
  904. if (k == undefined && skipKeyPressEvent) return false;
  905. skipKeyPressEvent = true;
  906. var input = this, $input = $(input);
  907. e = e || window.event;
  908. var k = checkval ? k : (e.which || e.charCode || e.keyCode);
  909. if (checkval !== true && (!(e.ctrlKey && e.altKey) && (e.ctrlKey || e.metaKey || ignorable))) {
  910. return true;
  911. } else {
  912. if (k) {
  913. //special treat the decimal separator
  914. if (checkval !== true && k == 46 && e.shiftKey == false && opts.radixPoint == ",") k = 44;
  915. var pos, forwardPosition, c = String.fromCharCode(k);
  916. if (checkval) {
  917. var pcaret = strict ? ndx : getLastValidPosition() + 1;
  918. pos = { begin: pcaret, end: pcaret };
  919. } else {
  920. pos = caret(input);
  921. }
  922. //should we clear a possible selection??
  923. var isSlctn = isSelection(pos.begin, pos.end);
  924. if (isSlctn) {
  925. getMaskSet()["undoBuffer"] = getBuffer().join(''); //init undobuffer for recovery when not valid
  926. HandleRemove(input, opts.keyCode.DELETE, pos);
  927. if (!opts.insertMode) { //preserve some space
  928. shiftR(pos.begin, getMaskLength());
  929. }
  930. }
  931. var radixPosition = getBuffer().join('').indexOf(opts.radixPoint);
  932. if (opts.isNumeric && checkval !== true && radixPosition != -1) {
  933. if (opts.greedy && pos.begin <= radixPosition) {
  934. pos.begin = seekPrevious(pos.begin);
  935. pos.end = pos.begin;
  936. } else if (c == opts.radixPoint) {
  937. pos.begin = radixPosition;
  938. pos.end = pos.begin;
  939. }
  940. }
  941. getMaskSet()["writeOutBuffer"] = true;
  942. var p = pos.begin;
  943. var valResult = isValid(p, c, strict);
  944. if (valResult !== false) {
  945. var refresh = false, buffer = getBuffer();
  946. if (valResult !== true) {
  947. refresh = valResult["refresh"]; //only rewrite buffer from isValid
  948. p = valResult.pos != undefined ? valResult.pos : p; //set new position from isValid
  949. c = valResult.c != undefined ? valResult.c : c; //set new char from isValid
  950. }
  951. if (refresh !== true) {
  952. if (opts.insertMode == true) {
  953. getMaskSet()["buffer"] = undefined;
  954. } else setBufferElement(buffer, p, c);
  955. }
  956. forwardPosition = seekNext(p);
  957. getMaskSet()["p"] = forwardPosition; //needed for checkval
  958. }
  959. if (writeOut !== false) {
  960. var self = this;
  961. setTimeout(function () { opts.onKeyValidation.call(self, valResult, opts); }, 0);
  962. if (getMaskSet()["writeOutBuffer"] && valResult !== false) {
  963. var buffer = getBuffer();
  964. var newCaretPosition;
  965. if (checkval) {
  966. newCaretPosition = undefined;
  967. } else if (opts.numericInput) {
  968. if (p > radixPosition) {
  969. newCaretPosition = seekPrevious(forwardPosition);
  970. } else if (c == opts.radixPoint) {
  971. newCaretPosition = forwardPosition - 1;
  972. } else newCaretPosition = seekPrevious(forwardPosition - 1);
  973. } else {
  974. newCaretPosition = forwardPosition;
  975. }
  976. writeBuffer(input, buffer, newCaretPosition);
  977. if (checkval !== true) {
  978. setTimeout(function () { //timeout needed for IE
  979. if (isComplete(buffer) === true)
  980. $input.trigger("complete");
  981. skipInputEvent = true;
  982. $input.trigger("input");
  983. }, 0);
  984. }
  985. } else if (isSlctn) { //TODO FIXME
  986. getMaskSet()["buffer"] = getMaskSet()["undoBuffer"].split('');
  987. }
  988. } else if (isSlctn) { //TODO FIXME
  989. getMaskSet()["buffer"] = getMaskSet()["undoBuffer"].split('');
  990. }
  991. if (opts.showTooltip) { //update tooltip
  992. $input.prop("title", getMaskSet()["mask"]);
  993. }
  994. //needed for IE8 and below
  995. if (e) e.preventDefault ? e.preventDefault() : e.returnValue = false;
  996. }
  997. }
  998. }
  999. function keyupEvent(e) {
  1000. var $input = $(this), input = this, k = e.keyCode, buffer = getBuffer();
  1001. opts.onKeyUp.call(this, e, buffer, opts); //extra stuff to execute on keyup
  1002. if (k == opts.keyCode.TAB && opts.showMaskOnFocus) {
  1003. if ($input.hasClass('focus.inputmask') && input._valueGet().length == 0) {
  1004. buffer = getBufferTemplate().slice();
  1005. writeBuffer(input, buffer);
  1006. caret(input, 0);
  1007. valueOnFocus = getBuffer().join('');
  1008. } else {
  1009. writeBuffer(input, buffer);
  1010. if (buffer.join('') == getBufferTemplate().join('') && $.inArray(opts.radixPoint, buffer) != -1) {
  1011. caret(input, TranslatePosition(0));
  1012. $input.click();
  1013. } else
  1014. caret(input, TranslatePosition(0), TranslatePosition(getMaskLength()));
  1015. }
  1016. }
  1017. }
  1018. function pasteEvent(e) {
  1019. if (skipInputEvent === true && e.type == "input") {
  1020. skipInputEvent = false;
  1021. return true;
  1022. }
  1023. var input = this, $input = $(input);
  1024. //paste event for IE8 and lower I guess ;-)
  1025. if (e.type == "propertychange" && input._valueGet().length <= getMaskLength()) {
  1026. return true;
  1027. }
  1028. setTimeout(function () {
  1029. var pasteValue = $.isFunction(opts.onBeforePaste) ? opts.onBeforePaste.call(input, input._valueGet(), opts) : input._valueGet();
  1030. checkVal(input, false, false, pasteValue.split(''), true);
  1031. writeBuffer(input, getBuffer());
  1032. if (isComplete(getBuffer()) === true)
  1033. $input.trigger("complete");
  1034. $input.click();
  1035. }, 0);
  1036. }
  1037. function mobileInputEvent(e) {
  1038. var input = this, $input = $(input);
  1039. //backspace in chrome32 only fires input event - detect & treat
  1040. var caretPos = caret(input),
  1041. currentValue = input._valueGet();
  1042. currentValue = currentValue.replace(new RegExp("(" + escapeRegex(getBufferTemplate().join('')) + ")*"), "");
  1043. //correct caretposition for chrome
  1044. if (caretPos.begin > currentValue.length) {
  1045. caret(input, currentValue.length);
  1046. caretPos = caret(input);
  1047. }
  1048. if ((getBuffer().length - currentValue.length) == 1 && currentValue.charAt(caretPos.begin) != getBuffer()[caretPos.begin]
  1049. && currentValue.charAt(caretPos.begin + 1) != getBuffer()[caretPos.begin]
  1050. && !isMask(caretPos.begin)) {
  1051. e.keyCode = opts.keyCode.BACKSPACE;
  1052. keydownEvent.call(input, e);
  1053. } else { //nonnumerics don't fire keypress
  1054. checkVal(input, false, false, currentValue.split(''));
  1055. writeBuffer(input, getBuffer());
  1056. if (isComplete(getBuffer()) === true)
  1057. $input.trigger("complete");
  1058. $input.click();
  1059. }
  1060. e.preventDefault();
  1061. }
  1062. function mask(el) {
  1063. $el = $(el);
  1064. if ($el.is(":input")) {
  1065. //store tests & original buffer in the input element - used to get the unmasked value
  1066. $el.data('_inputmask', {
  1067. 'maskset': maskset,
  1068. 'opts': opts,
  1069. 'isRTL': false
  1070. });
  1071. //show tooltip
  1072. if (opts.showTooltip) {
  1073. $el.prop("title", getMaskSet()["mask"]);
  1074. }
  1075. patchValueProperty(el);
  1076. if (opts.numericInput) opts.isNumeric = opts.numericInput;
  1077. if (el.dir == "rtl" || (opts.numericInput && opts.rightAlignNumerics) || (opts.isNumeric && opts.rightAlignNumerics))
  1078. $el.css("text-align", "right");
  1079. if (el.dir == "rtl" || opts.numericInput) {
  1080. el.dir = "ltr";
  1081. $el.removeAttr("dir");
  1082. var inputData = $el.data('_inputmask');
  1083. inputData['isRTL'] = true;
  1084. $el.data('_inputmask', inputData);
  1085. isRTL = true;
  1086. }
  1087. //unbind all events - to make sure that no other mask will interfere when re-masking
  1088. $el.unbind(".inputmask");
  1089. $el.removeClass('focus.inputmask');
  1090. //bind events
  1091. $el.closest('form').bind("submit", function () { //trigger change on submit if any
  1092. if (valueOnFocus != getBuffer().join('')) {
  1093. $el.change();
  1094. }
  1095. }).bind('reset', function () {
  1096. setTimeout(function () {
  1097. $el.trigger("setvalue");
  1098. }, 0);
  1099. });
  1100. $el.bind("mouseenter.inputmask", function () {
  1101. var $input = $(this), input = this;
  1102. if (!$input.hasClass('focus.inputmask') && opts.showMaskOnHover) {
  1103. if (input._valueGet() != getBuffer().join('')) {
  1104. writeBuffer(input, getBuffer());
  1105. }
  1106. }
  1107. }).bind("blur.inputmask", function () {
  1108. var $input = $(this), input = this, nptValue = input._valueGet(), buffer = getBuffer();
  1109. $input.removeClass('focus.inputmask');
  1110. if (valueOnFocus != getBuffer().join('')) {
  1111. $input.change();
  1112. }
  1113. if (opts.clearMaskOnLostFocus && nptValue != '') {
  1114. if (nptValue == getBufferTemplate().join(''))
  1115. input._valueSet('');
  1116. else { //clearout optional tail of the mask
  1117. clearOptionalTail(input);
  1118. }
  1119. }
  1120. if (isComplete(buffer) === false) {
  1121. $input.trigger("incomplete");
  1122. if (opts.clearIncomplete) {
  1123. resetMaskSet();
  1124. if (opts.clearMaskOnLostFocus)
  1125. input._valueSet('');
  1126. else {
  1127. buffer = getBufferTemplate().slice();
  1128. writeBuffer(input, buffer);
  1129. }
  1130. }
  1131. }
  1132. }).bind("focus.inputmask", function () {
  1133. var $input = $(this), input = this, nptValue = input._valueGet();
  1134. if (opts.showMaskOnFocus && !$input.hasClass('focus.inputmask') && (!opts.showMaskOnHover || (opts.showMaskOnHover && nptValue == ''))) {
  1135. if (input._valueGet() != getBuffer().join('')) {
  1136. writeBuffer(input, getBuffer(), seekNext(getLastValidPosition()));
  1137. }
  1138. }
  1139. $input.addClass('focus.inputmask');
  1140. valueOnFocus = getBuffer().join('');
  1141. }).bind("mouseleave.inputmask", function () {
  1142. var $input = $(this), input = this;
  1143. if (opts.clearMaskOnLostFocus) {
  1144. if (!$input.hasClass('focus.inputmask') && input._valueGet() != $input.attr("placeholder")) {
  1145. if (input._valueGet() == getBufferTemplate().join('') || input._valueGet() == '')
  1146. input._valueSet('');
  1147. else { //clearout optional tail of the mask
  1148. clearOptionalTail(input);
  1149. }
  1150. }
  1151. }
  1152. }).bind("click.inputmask", function () {
  1153. var input = this;
  1154. setTimeout(function () {
  1155. var selectedCaret = caret(input), buffer = getBuffer();
  1156. if (selectedCaret.begin == selectedCaret.end) {
  1157. var clickPosition = isRTL ? TranslatePosition(selectedCaret.begin) : selectedCaret.begin,
  1158. lvp = getLastValidPosition(undefined, clickPosition),
  1159. lastPosition;
  1160. if (opts.isNumeric) {
  1161. lastPosition = opts.skipRadixDance === false && opts.radixPoint != "" && $.inArray(opts.radixPoint, buffer) != -1 ?
  1162. (opts.numericInput ? seekNext($.inArray(opts.radixPoint, buffer)) : $.inArray(opts.radixPoint, buffer)) :
  1163. seekNext(lvp);
  1164. } else {
  1165. lastPosition = seekNext(lvp);
  1166. }
  1167. if (clickPosition < lastPosition) {
  1168. if (isMask(clickPosition))
  1169. caret(input, clickPosition);
  1170. else caret(input, seekNext(clickPosition));
  1171. } else
  1172. caret(input, lastPosition);
  1173. }
  1174. }, 0);
  1175. }).bind('dblclick.inputmask', function () {
  1176. var input = this;
  1177. setTimeout(function () {
  1178. caret(input, 0, seekNext(getLastValidPosition()));
  1179. }, 0);
  1180. }).bind(PasteEventType + ".inputmask dragdrop.inputmask drop.inputmask", pasteEvent
  1181. ).bind('setvalue.inputmask', function () {
  1182. var input = this;
  1183. checkVal(input, true);
  1184. valueOnFocus = getBuffer().join('');
  1185. if (input._valueGet() == getBufferTemplate().join(''))
  1186. input._valueSet('');
  1187. }).bind('complete.inputmask', opts.oncomplete
  1188. ).bind('incomplete.inputmask', opts.onincomplete
  1189. ).bind('cleared.inputmask', opts.oncleared);
  1190. $el.bind("keydown.inputmask", keydownEvent
  1191. ).bind("keypress.inputmask", keypressEvent
  1192. ).bind("keyup.inputmask", keyupEvent);
  1193. // as the other inputevents aren't reliable for the moment we only base on the input event
  1194. // needs follow-up
  1195. if (android || androidfirefox || androidchrome || kindle) {
  1196. $el.attr("autocomplete", "off")
  1197. .attr("autocorrect", "off")
  1198. .attr("autocapitalize", "off")
  1199. .attr("spellcheck", false);
  1200. if (androidfirefox || kindle) {
  1201. $el.unbind("keydown.inputmask", keydownEvent
  1202. ).unbind("keypress.inputmask", keypressEvent
  1203. ).unbind("keyup.inputmask", keyupEvent);
  1204. if (PasteEventType == "input") {
  1205. $el.unbind(PasteEventType + ".inputmask");
  1206. }
  1207. $el.bind("input.inputmask", mobileInputEvent);
  1208. }
  1209. }
  1210. if (msie1x)
  1211. $el.bind("input.inputmask", pasteEvent);
  1212. //apply mask
  1213. var initialValue = $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(el, el._valueGet(), opts) : el._valueGet();
  1214. checkVal(el, true, false, initialValue.split(''), true);
  1215. valueOnFocus = getBuffer().join('');
  1216. // Wrap document.activeElement in a try/catch block since IE9 throw "Unspecified error" if document.activeElement is undefined when we are in an IFrame.
  1217. var activeElement;
  1218. try {
  1219. activeElement = document.activeElement;
  1220. } catch (e) {
  1221. }
  1222. if (activeElement === el) { //position the caret when in focus
  1223. $el.addClass('focus.inputmask');
  1224. caret(el, seekNext(getLastValidPosition()));
  1225. } else if (opts.clearMaskOnLostFocus) {
  1226. if (getBuffer().join('') == getBufferTemplate().join('')) {
  1227. el._valueSet('');
  1228. } else {
  1229. clearOptionalTail(el);
  1230. }
  1231. } else {
  1232. writeBuffer(el, getBuffer());
  1233. }
  1234. installEventRuler(el);
  1235. }
  1236. }
  1237. //action object
  1238. if (actionObj != undefined) {
  1239. switch (actionObj["action"]) {
  1240. case "isComplete":
  1241. return isComplete(actionObj["buffer"]);
  1242. case "unmaskedvalue":
  1243. isRTL = actionObj["$input"].data('_inputmask')['isRTL'];
  1244. return unmaskedvalue(actionObj["$input"], actionObj["skipDatepickerCheck"]);
  1245. case "mask":
  1246. mask(actionObj["el"]);
  1247. break;
  1248. case "format":
  1249. $el = $({});
  1250. $el.data('_inputmask', {
  1251. 'maskset': maskset,
  1252. 'opts': opts,
  1253. 'isRTL': opts.numericInput
  1254. });
  1255. if (opts.numericInput) {
  1256. opts.isNumeric = opts.numericInput;
  1257. isRTL = true;
  1258. }
  1259. checkVal($el, false, false, actionObj["value"].split(''), true);
  1260. return getBuffer().join('');
  1261. case "isValid":
  1262. $el = $({});
  1263. $el.data('_inputmask', {
  1264. 'maskset': maskset,
  1265. 'opts': opts,
  1266. 'isRTL': opts.numericInput
  1267. });
  1268. if (opts.numericInput) {
  1269. opts.isNumeric = opts.numericInput;
  1270. isRTL = true;
  1271. }
  1272. checkVal($el, false, true, actionObj["value"].split(''));
  1273. return isComplete(getBuffer());
  1274. }
  1275. }
  1276. };
  1277. $.inputmask = {
  1278. //options default
  1279. defaults: {
  1280. placeholder: "_",
  1281. optionalmarker: { start: "[", end: "]" },
  1282. quantifiermarker: { start: "{", end: "}" },
  1283. groupmarker: { start: "(", end: ")" },
  1284. escapeChar: "\\",
  1285. mask: null,
  1286. oncomplete: $.noop, //executes when the mask is complete
  1287. onincomplete: $.noop, //executes when the mask is incomplete and focus is lost
  1288. oncleared: $.noop, //executes when the mask is cleared
  1289. repeat: 0, //repetitions of the mask: * ~ forever, otherwise specify an integer
  1290. greedy: true, //true: allocated buffer for the mask and repetitions - false: allocate only if needed
  1291. autoUnmask: false, //automatically unmask when retrieving the value with $.fn.val or value if the browser supports __lookupGetter__ or getOwnPropertyDescriptor
  1292. clearMaskOnLostFocus: true,
  1293. insertMode: true, //insert the input or overwrite the input
  1294. clearIncomplete: false, //clear the incomplete input on blur
  1295. aliases: {}, //aliases definitions => see jquery.inputmask.extensions.js
  1296. onKeyUp: $.noop, //override to implement autocomplete on certain keys for example
  1297. onKeyDown: $.noop, //override to implement autocomplete on certain keys for example
  1298. onBeforeMask: undefined, //executes before masking the initial value to allow preprocessing of the initial value. args => initialValue, opts => return processedValue
  1299. onBeforePaste: undefined, //executes before masking the pasted value to allow preprocessing of the pasted value. args => pastedValue, opts => return processedValue
  1300. onUnMask: undefined, //executes after unmasking to allow postprocessing of the unmaskedvalue. args => maskedValue, unmaskedValue, opts
  1301. showMaskOnFocus: true, //show the mask-placeholder when the input has focus
  1302. showMaskOnHover: true, //show the mask-placeholder when hovering the empty input
  1303. onKeyValidation: $.noop, //executes on every key-press with the result of isValid. Params: result, opts
  1304. skipOptionalPartCharacter: " ", //a character which can be used to skip an optional part of a mask
  1305. showTooltip: false, //show the activemask as tooltip
  1306. numericInput: false, //numericInput input direction style (input shifts to the left while holding the caret position)
  1307. //numeric basic properties
  1308. isNumeric: false, //enable numeric features
  1309. radixPoint: "", //".", // | ","
  1310. skipRadixDance: false, //disable radixpoint caret positioning
  1311. rightAlignNumerics: true, //align numerics to the right
  1312. //numeric basic properties
  1313. definitions: {
  1314. '9': {
  1315. validator: "[0-9]",
  1316. cardinality: 1,
  1317. definitionSymbol: "*"
  1318. },
  1319. 'a': {
  1320. validator: "[A-Za-z\u0410-\u044F\u0401\u0451]",
  1321. cardinality: 1,
  1322. definitionSymbol: "*"
  1323. },
  1324. '*': {
  1325. validator: "[A-Za-z\u0410-\u044F\u0401\u04510-9]",
  1326. cardinality: 1
  1327. }
  1328. },
  1329. keyCode: {
  1330. ALT: 18, BACKSPACE: 8, CAPS_LOCK: 20, COMMA: 188, COMMAND: 91, COMMAND_LEFT: 91, COMMAND_RIGHT: 93, CONTROL: 17, DELETE: 46, DOWN: 40, END: 35, ENTER: 13, ESCAPE: 27, HOME: 36, INSERT: 45, LEFT: 37, MENU: 93, NUMPAD_ADD: 107, NUMPAD_DECIMAL: 110, NUMPAD_DIVIDE: 111, NUMPAD_ENTER: 108,
  1331. NUMPAD_MULTIPLY: 106, NUMPAD_SUBTRACT: 109, PAGE_DOWN: 34, PAGE_UP: 33, PERIOD: 190, RIGHT: 39, SHIFT: 16, SPACE: 32, TAB: 9, UP: 38, WINDOWS: 91
  1332. },
  1333. //specify keycodes which should not be considered in the keypress event, otherwise the preventDefault will stop their default behavior especially in FF
  1334. 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],
  1335. isComplete: undefined //override for isComplete - args => buffer, opts - return true || false
  1336. },
  1337. masksCache: {},
  1338. escapeRegex: function (str) {
  1339. var specials = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\'];
  1340. return str.replace(new RegExp('(\\' + specials.join('|\\') + ')', 'gim'), '\\$1');
  1341. },
  1342. format: function (value, options) {
  1343. var opts = $.extend(true, {}, $.inputmask.defaults, options);
  1344. resolveAlias(opts.alias, options, opts);
  1345. return maskScope(generateMaskSet(opts), opts, { "action": "format", "value": value });
  1346. },
  1347. isValid: function (value, options) {
  1348. var opts = $.extend(true, {}, $.inputmask.defaults, options);
  1349. resolveAlias(opts.alias, options, opts);
  1350. return maskScope(generateMaskSet(opts), opts, { "action": "isValid", "value": value });
  1351. }
  1352. };
  1353. $.fn.inputmask = function (fn, options) {
  1354. var opts = $.extend(true, {}, $.inputmask.defaults, options),
  1355. maskset;
  1356. if (typeof fn === "string") {
  1357. switch (fn) {
  1358. case "mask":
  1359. //resolve possible aliases given by options
  1360. resolveAlias(opts.alias, options, opts);
  1361. maskset = generateMaskSet(opts);
  1362. if (maskset.length == 0) { return this; }
  1363. return this.each(function () {
  1364. maskScope($.extend(true, {}, maskset), 0, opts, { "action": "mask", "el": this });
  1365. });
  1366. case "unmaskedvalue":
  1367. var $input = $(this), input = this;
  1368. if ($input.data('_inputmask')) {
  1369. maskset = $input.data('_inputmask')['maskset'];
  1370. opts = $input.data('_inputmask')['opts'];
  1371. return maskScope(maskset, opts, { "action": "unmaskedvalue", "$input": $input });
  1372. } else return $input.val();
  1373. case "remove":
  1374. return this.each(function () {
  1375. var $input = $(this), input = this;
  1376. if ($input.data('_inputmask')) {
  1377. maskset = $input.data('_inputmask')['maskset'];
  1378. opts = $input.data('_inputmask')['opts'];
  1379. //writeout the unmaskedvalue
  1380. input._valueSet(maskScope(maskset, opts, { "action": "unmaskedvalue", "$input": $input, "skipDatepickerCheck": true }));
  1381. //clear data
  1382. $input.removeData('_inputmask');
  1383. //unbind all events
  1384. $input.unbind(".inputmask");
  1385. $input.removeClass('focus.inputmask');
  1386. //restore the value property
  1387. var valueProperty;
  1388. if (Object.getOwnPropertyDescriptor)
  1389. valueProperty = Object.getOwnPropertyDescriptor(input, "value");
  1390. if (valueProperty && valueProperty.get) {
  1391. if (input._valueGet) {
  1392. Object.defineProperty(input, "value", {
  1393. get: input._valueGet,
  1394. set: input._valueSet
  1395. });
  1396. }
  1397. } else if (document.__lookupGetter__ && input.__lookupGetter__("value")) {
  1398. if (input._valueGet) {
  1399. input.__defineGetter__("value", input._valueGet);
  1400. input.__defineSetter__("value", input._valueSet);
  1401. }
  1402. }
  1403. try { //try catch needed for IE7 as it does not supports deleting fns
  1404. delete input._valueGet;
  1405. delete input._valueSet;
  1406. } catch (e) {
  1407. input._valueGet = undefined;
  1408. input._valueSet = undefined;
  1409. }
  1410. }
  1411. });
  1412. break;
  1413. case "getemptymask": //return the default (empty) mask value, usefull for setting the default value in validation
  1414. if (this.data('_inputmask')) {
  1415. maskset = this.data('_inputmask')['maskset'];
  1416. return maskset['_buffer'].join('');
  1417. }
  1418. else return "";
  1419. case "hasMaskedValue": //check wheter the returned value is masked or not; currently only works reliable when using jquery.val fn to retrieve the value
  1420. return this.data('_inputmask') ? !this.data('_inputmask')['opts'].autoUnmask : false;
  1421. case "isComplete":
  1422. maskset = this.data('_inputmask')['maskset'];
  1423. opts = this.data('_inputmask')['opts'];
  1424. return maskScope(maskset, opts, { "action": "isComplete", "buffer": this[0]._valueGet().split('') });
  1425. case "getmetadata": //return mask metadata if exists
  1426. if (this.data('_inputmask')) {
  1427. maskset = this.data('_inputmask')['maskset'];
  1428. return maskset['metadata'];
  1429. }
  1430. else return undefined;
  1431. default:
  1432. //check if the fn is an alias
  1433. if (!resolveAlias(fn, options, opts)) {
  1434. //maybe fn is a mask so we try
  1435. //set mask
  1436. opts.mask = fn;
  1437. }
  1438. maskset = generateMaskSet(opts);
  1439. if (maskset == undefined) { return this; }
  1440. return this.each(function () {
  1441. maskScope($.extend(true, {}, maskset), opts, { "action": "mask", "el": this });
  1442. });
  1443. break;
  1444. }
  1445. } else if (typeof fn == "object") {
  1446. opts = $.extend(true, {}, $.inputmask.defaults, fn);
  1447. resolveAlias(opts.alias, fn, opts); //resolve aliases
  1448. maskset = generateMaskSet(opts);
  1449. if (maskset == undefined) { return this; }
  1450. return this.each(function () {
  1451. maskScope($.extend(true, {}, maskset), opts, { "action": "mask", "el": this });
  1452. });
  1453. } else if (fn == undefined) {
  1454. //look for data-inputmask atribute - the attribute should only contain optipns
  1455. return this.each(function () {
  1456. var attrOptions = $(this).attr("data-inputmask");
  1457. if (attrOptions && attrOptions != "") {
  1458. try {
  1459. attrOptions = attrOptions.replace(new RegExp("'", "g"), '"');
  1460. var dataoptions = $.parseJSON("{" + attrOptions + "}");
  1461. $.extend(true, dataoptions, options);
  1462. opts = $.extend(true, {}, $.inputmask.defaults, dataoptions);
  1463. resolveAlias(opts.alias, dataoptions, opts);
  1464. opts.alias = undefined;
  1465. $(this).inputmask(opts);
  1466. } catch (ex) { } //need a more relax parseJSON
  1467. }
  1468. });
  1469. }
  1470. };
  1471. }
  1472. })(jQuery);