jquery.inputmask.bundle.js 124 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258
  1. /**
  2. * @license Input Mask plugin for jquery
  3. * http://github.com/RobinHerbots/jquery.inputmask
  4. * Copyright (c) 2010 - 2013 Robin Herbots
  5. * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. * Version: 2.2.48
  7. */
  8. (function ($) {
  9. if ($.fn.inputmask == undefined) {
  10. $.inputmask = {
  11. //options default
  12. defaults: {
  13. placeholder: "_",
  14. optionalmarker: {
  15. start: "[",
  16. end: "]"
  17. },
  18. escapeChar: "\\",
  19. mask: null,
  20. oncomplete: $.noop, //executes when the mask is complete
  21. onincomplete: $.noop, //executes when the mask is incomplete and focus is lost
  22. oncleared: $.noop, //executes when the mask is cleared
  23. repeat: 0, //repetitions of the mask
  24. greedy: true, //true: allocated buffer for the mask and repetitions - false: allocate only if needed
  25. autoUnmask: false, //automatically unmask when retrieving the value with $.fn.val or value if the browser supports __lookupGetter__ or getOwnPropertyDescriptor
  26. clearMaskOnLostFocus: true,
  27. insertMode: true, //insert the input or overwrite the input
  28. clearIncomplete: false, //clear the incomplete input on blur
  29. aliases: {}, //aliases definitions => see jquery.inputmask.extensions.js
  30. onKeyUp: $.noop, //override to implement autocomplete on certain keys for example
  31. onKeyDown: $.noop, //override to implement autocomplete on certain keys for example
  32. showMaskOnFocus: true, //show the mask-placeholder when the input has focus
  33. showMaskOnHover: true, //show the mask-placeholder when hovering the empty input
  34. onKeyValidation: $.noop, //executes on every key-press with the result of isValid. Params: result, opts
  35. skipOptionalPartCharacter: " ", //a character which can be used to skip an optional part of a mask
  36. showTooltip: false, //show the activemask as tooltip
  37. //numeric basic properties
  38. numericInput: false, //numericInput input direction style (input shifts to the left while holding the caret position)
  39. radixPoint: "", //".", // | ","
  40. skipRadixDance: false, //disable radixpoint caret positioning
  41. rightAlignNumerics: true, //align numerics to the right
  42. //numeric basic properties
  43. definitions: {
  44. '9': {
  45. validator: "[0-9]",
  46. cardinality: 1
  47. },
  48. 'a': {
  49. validator: "[A-Za-z\u0410-\u044F\u0401\u0451]",
  50. cardinality: 1
  51. },
  52. '*': {
  53. validator: "[A-Za-z\u0410-\u044F\u0401\u04510-9]",
  54. cardinality: 1
  55. }
  56. },
  57. keyCode: {
  58. 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,
  59. 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
  60. },
  61. //specify keycodes which should not be considered in the keypress event, otherwise the preventDefault will stop their default behavior especially in FF
  62. ignorables: [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],
  63. getMaskLength: function (buffer, greedy, repeat, currentBuffer, opts) {
  64. var calculatedLength = buffer.length;
  65. if (!greedy && repeat > 1) {
  66. calculatedLength += (buffer.length * (repeat - 1));
  67. }
  68. return calculatedLength;
  69. }
  70. },
  71. val: $.fn.val, //store the original jquery val function
  72. escapeRegex: function (str) {
  73. var specials = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\'];
  74. return str.replace(new RegExp('(\\' + specials.join('|\\') + ')', 'gim'), '\\$1');
  75. }
  76. };
  77. $.fn.inputmask = function (fn, options) {
  78. var opts = $.extend(true, {}, $.inputmask.defaults, options),
  79. msie10 = navigator.userAgent.match(new RegExp("msie 10", "i")) !== null,
  80. iphone = navigator.userAgent.match(new RegExp("iphone", "i")) !== null,
  81. android = navigator.userAgent.match(new RegExp("android.*safari.*", "i")) !== null,
  82. pasteEvent = isInputEventSupported('paste') && !msie10 ? 'paste' : 'input',
  83. android533,
  84. masksets,
  85. activeMasksetIndex = 0;
  86. if (android) {
  87. var browser = navigator.userAgent.match(/safari.*/i),
  88. version = parseInt(new RegExp(/[0-9]+/).exec(browser));
  89. android533 = (version <= 533);
  90. //android534 = (533 < version) && (version <= 534);
  91. }
  92. if (typeof fn === "string") {
  93. switch (fn) {
  94. case "mask":
  95. //resolve possible aliases given by options
  96. resolveAlias(opts.alias, options);
  97. masksets = generateMaskSets();
  98. return this.each(function () {
  99. maskScope($.extend(true, {}, masksets), 0).mask(this);
  100. });
  101. case "unmaskedvalue":
  102. var $input = $(this), input = this;
  103. masksets = $input.data('_inputmask')['masksets'];
  104. activeMasksetIndex = $input.data('_inputmask')['activeMasksetIndex'];
  105. opts = $input.data('_inputmask')['opts'];
  106. return maskScope(masksets, activeMasksetIndex).unmaskedvalue(this);
  107. case "remove":
  108. return this.each(function () {
  109. var $input = $(this), input = this;
  110. setTimeout(function () {
  111. if ($input.data('_inputmask')) {
  112. masksets = $input.data('_inputmask')['masksets'];
  113. activeMasksetIndex = $input.data('_inputmask')['activeMasksetIndex'];
  114. opts = $input.data('_inputmask')['opts'];
  115. //writeout the unmaskedvalue
  116. input._valueSet(maskScope(masksets, activeMasksetIndex).unmaskedvalue($input, true));
  117. //clear data
  118. $input.removedata('_inputmask');
  119. //unbind all events
  120. $input.unbind(".inputmask");
  121. $input.removeClass('focus.inputmask');
  122. //restore the value property
  123. var valueProperty;
  124. if (Object.getOwnPropertyDescriptor)
  125. valueProperty = Object.getOwnPropertyDescriptor(input, "value");
  126. if (valueProperty && valueProperty.get) {
  127. if (input._valueGet) {
  128. Object.defineProperty(input, "value", {
  129. get: input._valueGet,
  130. set: input._valueSet
  131. });
  132. }
  133. } else if (document.__lookupGetter__ && input.__lookupGetter__("value")) {
  134. if (input._valueGet) {
  135. input.__defineGetter__("value", input._valueGet);
  136. input.__defineSetter__("value", input._valueSet);
  137. }
  138. }
  139. delete input._valueGet;
  140. delete input._valueSet;
  141. }
  142. }, 0);
  143. });
  144. break;
  145. case "getemptymask": //return the default (empty) mask value, usefull for setting the default value in validation
  146. if (this.data('_inputmask')) {
  147. masksets = this.data('_inputmask')['masksets'];
  148. activeMasksetIndex = this.data('_inputmask')['activeMasksetIndex'];
  149. return masksets[activeMasksetIndex]['_buffer'].join('');
  150. }
  151. else return "";
  152. case "hasMaskedValue": //check wheter the returned value is masked or not; currently only works reliable when using jquery.val fn to retrieve the value
  153. return this.data('_inputmask') ? !this.data('_inputmask')['opts'].autoUnmask : false;
  154. case "isComplete":
  155. masksets = this.data('_inputmask')['masksets'];
  156. activeMasksetIndex = this.data('_inputmask')['activeMasksetIndex'];
  157. opts = this.data('_inputmask')['opts'];
  158. return maskScope(masksets, activeMasksetIndex).isComplete(this[0]._valueGet().split(''));
  159. default:
  160. //check if the fn is an alias
  161. if (!resolveAlias(fn, options)) {
  162. //maybe fn is a mask so we try
  163. //set mask
  164. opts.mask = fn;
  165. }
  166. masksets = generateMaskSets();
  167. return this.each(function () {
  168. maskScope($.extend(true, {}, masksets), activeMasksetIndex).mask(this);
  169. });
  170. break;
  171. }
  172. } else if (typeof fn == "object") {
  173. opts = $.extend(true, {}, $.inputmask.defaults, fn);
  174. resolveAlias(opts.alias, fn); //resolve aliases
  175. masksets = generateMaskSets();
  176. return this.each(function () {
  177. maskScope($.extend(true, {}, masksets), activeMasksetIndex).mask(this);
  178. });
  179. } else if (fn == undefined) {
  180. //look for data-inputmask atribute - the attribute should only contain optipns
  181. return this.each(function () {
  182. var attrOptions = $(this).attr("data-inputmask");
  183. if (attrOptions && attrOptions != "") {
  184. try {
  185. attrOptions = attrOptions.replace(new RegExp("'", "g"), '"');
  186. var dataoptions = $.parseJSON("{" + attrOptions + "}");
  187. $.extend(true, dataoptions, options);
  188. opts = $.extend(true, {}, $.inputmask.defaults, dataoptions);
  189. resolveAlias(opts.alias, dataoptions);
  190. opts.alias = undefined;
  191. $(this).inputmask(opts);
  192. } catch (ex) { } //need a more relax parseJSON
  193. }
  194. });
  195. }
  196. //helper functions
  197. function isInputEventSupported(eventName) {
  198. var el = document.createElement('input'),
  199. eventName = 'on' + eventName,
  200. isSupported = (eventName in el);
  201. if (!isSupported) {
  202. el.setAttribute(eventName, 'return;');
  203. isSupported = typeof el[eventName] == 'function';
  204. }
  205. el = null;
  206. return isSupported;
  207. }
  208. function resolveAlias(aliasStr, options) {
  209. var aliasDefinition = opts.aliases[aliasStr];
  210. if (aliasDefinition) {
  211. if (aliasDefinition.alias) resolveAlias(aliasDefinition.alias); //alias is another alias
  212. $.extend(true, opts, aliasDefinition); //merge alias definition in the options
  213. $.extend(true, opts, options); //reapply extra given options
  214. return true;
  215. }
  216. return false;
  217. }
  218. function getMaskTemplate(mask) {
  219. var escaped = false, outCount = 0, greedy = opts.greedy, repeat = opts.repeat;
  220. if (mask.length == 1 && greedy == false) { opts.placeholder = ""; } //hide placeholder with single non-greedy mask
  221. var singleMask = $.map(mask.split(""), function (element, index) {
  222. var outElem = [];
  223. if (element == opts.escapeChar) {
  224. escaped = true;
  225. }
  226. else if ((element != opts.optionalmarker.start && element != opts.optionalmarker.end) || escaped) {
  227. var maskdef = opts.definitions[element];
  228. if (maskdef && !escaped) {
  229. for (var i = 0; i < maskdef.cardinality; i++) {
  230. outElem.push(getPlaceHolder(outCount + i));
  231. }
  232. } else {
  233. outElem.push(element);
  234. escaped = false;
  235. }
  236. outCount += outElem.length;
  237. return outElem;
  238. }
  239. });
  240. //allocate repetitions
  241. var repeatedMask = singleMask.slice();
  242. for (var i = 1; i < repeat && greedy; i++) {
  243. repeatedMask = repeatedMask.concat(singleMask.slice());
  244. }
  245. return { "mask": repeatedMask, "repeat": repeat, "greedy": greedy };
  246. }
  247. //test definition => {fn: RegExp/function, cardinality: int, optionality: bool, newBlockMarker: bool, offset: int, casing: null/upper/lower, def: definitionSymbol}
  248. function getTestingChain(mask) {
  249. var isOptional = false, escaped = false;
  250. var newBlockMarker = false; //indicates wheter the begin/ending of a block should be indicated
  251. return $.map(mask.split(""), function (element, index) {
  252. var outElem = [];
  253. if (element == opts.escapeChar) {
  254. escaped = true;
  255. } else if (element == opts.optionalmarker.start && !escaped) {
  256. isOptional = true;
  257. newBlockMarker = true;
  258. }
  259. else if (element == opts.optionalmarker.end && !escaped) {
  260. isOptional = false;
  261. newBlockMarker = true;
  262. }
  263. else {
  264. var maskdef = opts.definitions[element];
  265. if (maskdef && !escaped) {
  266. var prevalidators = maskdef["prevalidator"], prevalidatorsL = prevalidators ? prevalidators.length : 0;
  267. for (var i = 1; i < maskdef.cardinality; i++) {
  268. var prevalidator = prevalidatorsL >= i ? prevalidators[i - 1] : [], validator = prevalidator["validator"], cardinality = prevalidator["cardinality"];
  269. outElem.push({ fn: validator ? typeof validator == 'string' ? new RegExp(validator) : new function () { this.test = validator; } : new RegExp("."), cardinality: cardinality ? cardinality : 1, optionality: isOptional, newBlockMarker: isOptional == true ? newBlockMarker : false, offset: 0, casing: maskdef["casing"], def: maskdef["definitionSymbol"] | element });
  270. if (isOptional == true) //reset newBlockMarker
  271. newBlockMarker = false;
  272. }
  273. outElem.push({ fn: maskdef.validator ? typeof maskdef.validator == 'string' ? new RegExp(maskdef.validator) : new function () { this.test = maskdef.validator; } : new RegExp("."), cardinality: maskdef.cardinality, optionality: isOptional, newBlockMarker: newBlockMarker, offset: 0, casing: maskdef["casing"], def: maskdef["definitionSymbol"] | element });
  274. } else {
  275. outElem.push({ fn: null, cardinality: 0, optionality: isOptional, newBlockMarker: newBlockMarker, offset: 0, casing: null, def: element });
  276. escaped = false;
  277. }
  278. //reset newBlockMarker
  279. newBlockMarker = false;
  280. return outElem;
  281. }
  282. });
  283. }
  284. function generateMaskSets() {
  285. var ms = [];
  286. var genmasks = []; //used to keep track of the masks that where processed, to avoid duplicates
  287. function markOptional(maskPart) { //needed for the clearOptionalTail functionality
  288. return opts.optionalmarker.start + maskPart + opts.optionalmarker.end;
  289. }
  290. function splitFirstOptionalEndPart(maskPart) {
  291. var optionalStartMarkers = 0, optionalEndMarkers = 0, mpl = maskPart.length;
  292. for (i = 0; i < mpl; i++) {
  293. if (maskPart.charAt(i) == opts.optionalmarker.start) {
  294. optionalStartMarkers++;
  295. }
  296. if (maskPart.charAt(i) == opts.optionalmarker.end) {
  297. optionalEndMarkers++;
  298. }
  299. if (optionalStartMarkers > 0 && optionalStartMarkers == optionalEndMarkers)
  300. break;
  301. }
  302. var maskParts = [maskPart.substring(0, i)];
  303. if (i < mpl) {
  304. maskParts.push(maskPart.substring(i + 1, mpl));
  305. }
  306. return maskParts;
  307. }
  308. function splitFirstOptionalStartPart(maskPart) {
  309. var mpl = maskPart.length;
  310. for (i = 0; i < mpl; i++) {
  311. if (maskPart.charAt(i) == opts.optionalmarker.start) {
  312. break;
  313. }
  314. }
  315. var maskParts = [maskPart.substring(0, i)];
  316. if (i < mpl) {
  317. maskParts.push(maskPart.substring(i + 1, mpl));
  318. }
  319. return maskParts;
  320. }
  321. function generateMask(maskPrefix, maskPart) {
  322. var maskParts = splitFirstOptionalEndPart(maskPart);
  323. var newMask, maskTemplate;
  324. var masks = splitFirstOptionalStartPart(maskParts[0]);
  325. if (masks.length > 1) {
  326. newMask = maskPrefix + masks[0] + markOptional(masks[1]) + (maskParts.length > 1 ? maskParts[1] : "");
  327. if ($.inArray(newMask, genmasks) == -1) {
  328. genmasks.push(newMask);
  329. maskTemplate = getMaskTemplate(newMask);
  330. ms.push({
  331. "mask": newMask,
  332. "_buffer": maskTemplate["mask"],
  333. "buffer": maskTemplate["mask"].slice(),
  334. "tests": getTestingChain(newMask),
  335. "lastValidPosition": undefined,
  336. "greedy": maskTemplate["greedy"],
  337. "repeat": maskTemplate["repeat"]
  338. });
  339. }
  340. newMask = maskPrefix + masks[0] + (maskParts.length > 1 ? maskParts[1] : "");
  341. if ($.inArray(newMask, genmasks) == -1) {
  342. genmasks.push(newMask);
  343. maskTemplate = getMaskTemplate(newMask);
  344. ms.push({
  345. "mask": newMask,
  346. "_buffer": maskTemplate["mask"],
  347. "buffer": maskTemplate["mask"].slice(),
  348. "tests": getTestingChain(newMask),
  349. "lastValidPosition": undefined,
  350. "greedy": maskTemplate["greedy"],
  351. "repeat": maskTemplate["repeat"]
  352. });
  353. }
  354. if (splitFirstOptionalStartPart(masks[1]).length > 1) { //optional contains another optional
  355. generateMask(maskPrefix + masks[0], masks[1] + maskParts[1]);
  356. }
  357. if (maskParts.length > 1 && splitFirstOptionalStartPart(maskParts[1]).length > 1) {
  358. generateMask(maskPrefix + masks[0] + markOptional(masks[1]), maskParts[1]);
  359. generateMask(maskPrefix + masks[0], maskParts[1]);
  360. }
  361. }
  362. else {
  363. newMask = maskPrefix + maskParts;
  364. if ($.inArray(newMask, genmasks) == -1) {
  365. genmasks.push(newMask);
  366. maskTemplate = getMaskTemplate(newMask);
  367. ms.push({
  368. "mask": newMask,
  369. "_buffer": maskTemplate["mask"],
  370. "buffer": maskTemplate["mask"].slice(),
  371. "tests": getTestingChain(newMask),
  372. "lastValidPosition": undefined,
  373. "greedy": maskTemplate["greedy"],
  374. "repeat": maskTemplate["repeat"]
  375. });
  376. }
  377. }
  378. }
  379. if ($.isArray(opts.mask)) {
  380. $.each(opts.mask, function (ndx, lmnt) {
  381. generateMask("", lmnt.toString());
  382. });
  383. } else generateMask("", opts.mask.toString());
  384. return ms;
  385. }
  386. function getPlaceHolder(pos) {
  387. return opts.placeholder.charAt(pos % opts.placeholder.length);
  388. }
  389. function maskScope(masksets, activeMasksetIndex) {
  390. //maskset helperfunctions
  391. function getActiveMaskSet() {
  392. return masksets[activeMasksetIndex];
  393. }
  394. function getActiveTests() {
  395. return getActiveMaskSet()['tests'];
  396. }
  397. function getActiveBufferTemplate() {
  398. return getActiveMaskSet()['_buffer'];
  399. }
  400. function getActiveBuffer() {
  401. return getActiveMaskSet()['buffer'];
  402. }
  403. function isValid(pos, c, strict, isRTL) { //strict true ~ no correction or autofill
  404. strict = strict === true; //always set a value to strict to prevent possible strange behavior in the extensions
  405. function _isValid(position, activeMaskset) {
  406. var testPos = determineTestPosition(position), loopend = c ? 1 : 0, chrs = '', buffer = activeMaskset["buffer"];
  407. for (var i = activeMaskset['tests'][testPos].cardinality; i > loopend; i--) {
  408. chrs += getBufferElement(buffer, testPos - (i - 1));
  409. }
  410. if (c) {
  411. chrs += c;
  412. }
  413. //return is false or a json object => { pos: ??, c: ??} or true
  414. return activeMaskset['tests'][testPos].fn != null ? activeMaskset['tests'][testPos].fn.test(chrs, buffer, position, strict, opts) : false;
  415. }
  416. if (strict) {
  417. var result = _isValid(pos, getActiveMaskSet()); //only check validity in current mask when validating strict
  418. if (result === true) {
  419. result = { "pos": pos }; //always take a possible corrected maskposition into account
  420. }
  421. return result;
  422. }
  423. var results = [], result = false, currentActiveMasksetIndex = activeMasksetIndex;
  424. $.each(masksets, function (index, value) {
  425. var activeMaskset = this;
  426. activeMasksetIndex = index;
  427. var maskPos = pos;
  428. if (currentActiveMasksetIndex != activeMasksetIndex && !isMask(pos)) {
  429. if (c == activeMaskset['_buffer'][maskPos] || c == opts.skipOptionalPartCharacter) { //match non-mask item
  430. results.push({ "activeMasksetIndex": index, "result": { "refresh": true, c: activeMaskset['_buffer'][maskPos] } }); //new command hack only rewrite buffer
  431. activeMaskset['lastValidPosition'] = maskPos;
  432. return false;
  433. } else activeMaskset['lastValidPosition'] = isRTL ? getMaskLength() + 1 : -1; //mark mask as validated and invalid
  434. //maskPos = isRTL ? seekPrevious(pos) : seekNext(pos);
  435. }
  436. if ((activeMaskset['lastValidPosition'] == undefined
  437. && maskPos == (isRTL ? seekPrevious(getMaskLength()) : seekNext(-1))
  438. )
  439. || (isRTL || opts.numericInput)
  440. ? activeMaskset['lastValidPosition'] <= opts.numericInput ? getMaskLength() : seekNext(maskPos)
  441. : activeMaskset['lastValidPosition'] >= seekPrevious(maskPos)) {
  442. if (maskPos >= 0 && maskPos < getMaskLength()) {
  443. result = _isValid(maskPos, activeMaskset);
  444. if (result !== false) {
  445. if (result === true) {
  446. result = { "pos": maskPos }; //always take a possible corrected maskposition into account
  447. }
  448. var newValidPosition = result.pos || maskPos;
  449. if (activeMaskset['lastValidPosition'] == undefined ||
  450. (isRTL ? (opts.greedy ? activeMaskset['lastValidPosition'] > newValidPosition : newValidPosition == getActiveBuffer().length - 1)
  451. : activeMaskset['lastValidPosition'] < newValidPosition))
  452. activeMaskset['lastValidPosition'] = newValidPosition; //set new position from isValid
  453. } else activeMaskset['lastValidPosition'] = isRTL ? pos == getMaskLength() ? undefined : seekNext(pos) : pos == 0 ? undefined : seekPrevious(pos); //autocorrect validposition from backspace etc
  454. results.push({ "activeMasksetIndex": index, "result": result });
  455. }
  456. }
  457. });
  458. activeMasksetIndex = currentActiveMasksetIndex; //reset activeMasksetIndex
  459. return results; //return results of the multiple mask validations
  460. }
  461. function determineActiveMasksetIndex(isRTL) {
  462. var currentMasksetIndex = activeMasksetIndex,
  463. highestValid = { "activeMasksetIndex": 0, "lastValidPosition": isRTL ? getMaskLength() + 1 : -1 };
  464. $.each(masksets, function (index, value) {
  465. var activeMaskset = this;
  466. if (activeMaskset['lastValidPosition'] != undefined) {
  467. if ((isRTL || opts.numericInput) ? (activeMaskset['lastValidPosition'] < highestValid['lastValidPosition']) : (activeMaskset['lastValidPosition'] > highestValid['lastValidPosition'])) {
  468. highestValid["activeMasksetIndex"] = index;
  469. highestValid["lastValidPosition"] = activeMaskset['lastValidPosition'];
  470. }
  471. }
  472. });
  473. activeMasksetIndex = highestValid["activeMasksetIndex"];
  474. if (currentMasksetIndex != activeMasksetIndex) {
  475. if (isRTL) {
  476. clearBuffer(getActiveBuffer(), 0, seekPrevious(highestValid["lastValidPosition"]));
  477. } else {
  478. clearBuffer(getActiveBuffer(), seekNext(highestValid["lastValidPosition"]), getMaskLength());
  479. }
  480. getActiveMaskSet()["writeOutBuffer"] = true;
  481. }
  482. }
  483. function isMask(pos) {
  484. var testPos = determineTestPosition(pos);
  485. var test = getActiveTests()[testPos];
  486. return test != undefined ? test.fn : false;
  487. }
  488. function determineTestPosition(pos) {
  489. return pos % getActiveTests().length;
  490. }
  491. function getMaskLength() {
  492. return opts.getMaskLength(getActiveBufferTemplate(), getActiveMaskSet()['greedy'], getActiveMaskSet()['repeat'], getActiveBuffer(), opts);
  493. }
  494. //pos: from position
  495. function seekNext(pos) {
  496. var maskL = getMaskLength();
  497. if (pos >= maskL) return maskL;
  498. var position = pos;
  499. while (++position < maskL && !isMask(position)) {
  500. }
  501. ;
  502. return position;
  503. }
  504. //pos: from position
  505. function seekPrevious(pos) {
  506. var position = pos;
  507. if (position <= 0) return 0;
  508. while (--position > 0 && !isMask(position)) {
  509. }
  510. ;
  511. return position;
  512. }
  513. function setBufferElement(buffer, position, element, autoPrepare, isRTL) {
  514. if (autoPrepare) position = prepareBuffer(buffer, position, isRTL);
  515. var test = getActiveTests()[determineTestPosition(position)];
  516. var elem = element;
  517. if (elem != undefined) {
  518. switch (test.casing) {
  519. case "upper":
  520. elem = element.toUpperCase();
  521. break;
  522. case "lower":
  523. elem = element.toLowerCase();
  524. break;
  525. }
  526. }
  527. buffer[position] = elem;
  528. }
  529. function getBufferElement(buffer, position, autoPrepare) {
  530. if (autoPrepare) position = prepareBuffer(buffer, position);
  531. return buffer[position];
  532. }
  533. //needed to handle the non-greedy mask repetitions
  534. function prepareBuffer(buffer, position, isRTL) {
  535. var j;
  536. if (isRTL) {
  537. while (position < 0 && buffer.length < getMaskLength()) {
  538. j = getActiveBufferTemplate().length - 1;
  539. position = getActiveBufferTemplate().length;
  540. while (getActiveBufferTemplate()[j] !== undefined) {
  541. buffer.unshift(getActiveBufferTemplate()[j--]);
  542. }
  543. }
  544. } else {
  545. while (buffer[position] == undefined && buffer.length < getMaskLength()) {
  546. j = 0;
  547. while (getActiveBufferTemplate()[j] !== undefined) { //add a new buffer
  548. buffer.push(getActiveBufferTemplate()[j++]);
  549. }
  550. }
  551. }
  552. return position;
  553. }
  554. function writeBuffer(input, buffer, caretPos) {
  555. input._valueSet(buffer.join(''));
  556. if (caretPos != undefined) {
  557. caret(input, caretPos);
  558. }
  559. }
  560. ;
  561. function clearBuffer(buffer, start, end) {
  562. for (var i = start, maskL = getMaskLength() ; i < end && i < maskL; i++) {
  563. setBufferElement(buffer, i, getBufferElement(getActiveBufferTemplate().slice(), i, true));
  564. }
  565. }
  566. ;
  567. function setReTargetPlaceHolder(buffer, pos) {
  568. var testPos = determineTestPosition(pos);
  569. setBufferElement(buffer, pos, getBufferElement(getActiveBufferTemplate(), testPos));
  570. }
  571. function checkVal(input, writeOut, strict, nptvl) {
  572. var isRTL = $(input).data('_inputmask')['isRTL'],
  573. inputValue = nptvl != undefined ? nptvl.slice() : truncateInput(input._valueGet(), isRTL).split('');
  574. $.each(masksets, function (ndx, ms) {
  575. ms["buffer"] = ms["_buffer"].slice();
  576. ms["lastValidPosition"] = undefined;
  577. ms["p"] = isRTL ? getMaskLength() : 0;
  578. });
  579. if (strict !== true) activeMasksetIndex = 0;
  580. //caret(input, getActiveMaskSet()["p"]);
  581. if (isRTL && !opts.numericInput)
  582. inputValue = inputValue.reverse();
  583. var ml = getMaskLength();
  584. $.each(inputValue, function (ndx, charCode) {
  585. var index = isRTL ? (opts.numericInput ? ml : ml - ndx - 1) : ndx;
  586. if (isMask(isRTL ? (opts.numericInput ? seekPrevious(ml) : ml - ndx - 1) : ndx)
  587. || (strict !== true && charCode != getBufferElement(getActiveBufferTemplate(), index, true))) {
  588. $(input).trigger("keypress", [true, charCode.charCodeAt(0), writeOut, strict, index]);
  589. }
  590. });
  591. if (strict === true)
  592. getActiveMaskSet()["lastValidPosition"] = isRTL ? seekNext(getActiveMaskSet()["p"]) : seekPrevious(getActiveMaskSet()["p"]);
  593. }
  594. function escapeRegex(str) {
  595. return $.inputmask.escapeRegex.call(this, str);
  596. }
  597. function truncateInput(inputValue, rtl) {
  598. return rtl ? inputValue.replace(new RegExp("^(" + escapeRegex(getActiveBufferTemplate().join('')) + ")*"), "") : inputValue.replace(new RegExp("(" + escapeRegex(getActiveBufferTemplate().join('')) + ")*$"), "");
  599. }
  600. function clearOptionalTail(input) {
  601. var buffer = getActiveBuffer(), tmpBuffer = buffer.slice(), testPos, pos;
  602. if ($(input).data('_inputmask')['isRTL']) {
  603. for (var pos = 0; pos <= tmpBuffer.length - 1; pos++) {
  604. var testPos = determineTestPosition(pos);
  605. if (getActiveTests()[testPos].optionality) {
  606. if (!isMask(pos) || !isValid(pos, buffer[pos], true))
  607. tmpBuffer.splice(0, 1);
  608. else break;
  609. } else break;
  610. }
  611. } else {
  612. for (var pos = tmpBuffer.length - 1; pos >= 0; pos--) {
  613. var testPos = determineTestPosition(pos);
  614. if (getActiveTests()[testPos].optionality) {
  615. if (!isMask(pos) || !isValid(pos, buffer[pos], true))
  616. tmpBuffer.pop();
  617. else break;
  618. } else break;
  619. }
  620. }
  621. writeBuffer(input, tmpBuffer);
  622. }
  623. //functionality fn
  624. this.unmaskedvalue = function ($input, skipDatepickerCheck) {
  625. return unmaskedvalue($input, skipDatepickerCheck);
  626. };
  627. function unmaskedvalue($input, skipDatepickerCheck) {
  628. var input = $input[0];
  629. if (getActiveTests() && (skipDatepickerCheck === true || !$input.hasClass('hasDatepicker'))) {
  630. checkVal(input, false, true);
  631. return $.map(getActiveBuffer(), function (element, index) {
  632. return isMask(index) && isValid(index, element, true) ? element : null;
  633. }).join('');
  634. } else {
  635. return input._valueGet();
  636. }
  637. }
  638. var caretSavePoint;
  639. function caret(input, begin, end) {
  640. var npt = input.jquery && input.length > 0 ? input[0] : input, range;
  641. if (typeof begin == 'number') {
  642. if (!$(input).is(':visible')) {
  643. return;
  644. }
  645. end = (typeof end == 'number') ? end : begin;
  646. if (opts.insertMode == false && begin == end) end++; //set visualization for insert/overwrite mode
  647. if (npt.setSelectionRange) {
  648. if (android) {
  649. setTimeout(function () {
  650. npt.selectionStart = begin;
  651. npt.selectionEnd = android ? begin : end;
  652. }, 10);
  653. caretSavePoint = { "begin": begin, "end": end };
  654. } else {
  655. npt.selectionStart = begin;
  656. npt.selectionEnd = end;
  657. }
  658. } else if (npt.createTextRange) {
  659. range = npt.createTextRange();
  660. range.collapse(true);
  661. range.moveEnd('character', end);
  662. range.moveStart('character', begin);
  663. range.select();
  664. }
  665. } else {
  666. if (!$(input).is(':visible')) {
  667. return { "begin": 0, "end": 0 };
  668. }
  669. if (npt.setSelectionRange) {
  670. begin = npt.selectionStart;
  671. end = npt.selectionEnd;
  672. } else if (document.selection && document.selection.createRange) {
  673. range = document.selection.createRange();
  674. begin = 0 - range.duplicate().moveStart('character', -100000);
  675. end = begin + range.text.length;
  676. }
  677. return { "begin": begin, "end": end };
  678. }
  679. };
  680. this.isComplete = function (buffer) {
  681. return isComplete(buffer);
  682. };
  683. function isComplete(buffer) {
  684. var complete = false, highestValidPosition = 0, currentActiveMasksetIndex = activeMasksetIndex;
  685. $.each(masksets, function (ndx, ms) {
  686. activeMasksetIndex = ndx;
  687. var aml = seekPrevious(getMaskLength());
  688. if (ms["lastValidPosition"] != undefined && ms["lastValidPosition"] >= highestValidPosition && ms["lastValidPosition"] == aml) {
  689. var msComplete = true;
  690. for (var i = 0; i <= aml; i++) {
  691. var mask = isMask(i), testPos = determineTestPosition(i);
  692. if ((mask && (buffer[i] == undefined || buffer[i] == getPlaceHolder(i))) || (!mask && buffer[i] != getActiveBufferTemplate()[testPos])) {
  693. msComplete = false;
  694. break;
  695. }
  696. }
  697. complete = complete || msComplete;
  698. if (complete) //break loop
  699. return false;
  700. }
  701. highestValidPosition = ms["lastValidPosition"];
  702. });
  703. activeMasksetIndex = currentActiveMasksetIndex; //reset activeMaskset
  704. return complete;
  705. }
  706. this.mask = function (el) {
  707. var $input = $(el);
  708. if (!$input.is(":input")) return;
  709. //store tests & original buffer in the input element - used to get the unmasked value
  710. $input.data('_inputmask', {
  711. 'masksets': masksets,
  712. 'activeMasksetIndex': activeMasksetIndex,
  713. 'opts': opts,
  714. 'isRTL': false
  715. });
  716. //show tooltip
  717. if (opts.showTooltip) {
  718. $input.prop("title", getActiveMaskSet()["mask"]);
  719. }
  720. //correct greedy setting if needed
  721. getActiveMaskSet()['greedy'] = getActiveMaskSet()['greedy'] ? getActiveMaskSet()['greedy'] : getActiveMaskSet()['repeat'] == 0;
  722. //handle maxlength attribute
  723. var maxLength = $input.prop('maxLength');
  724. if (getMaskLength() > maxLength && maxLength > -1) { //FF sets no defined max length to -1
  725. if (maxLength < getActiveBufferTemplate().length) getActiveBufferTemplate().length = maxLength;
  726. if (getActiveMaskSet()['greedy'] == false) {
  727. getActiveMaskSet()['repeat'] = Math.round(maxLength / getActiveBufferTemplate().length);
  728. }
  729. $input.prop('maxLength', getMaskLength() * 2);
  730. }
  731. patchValueProperty(el);
  732. //init vars
  733. getActiveMaskSet()["undoBuffer"] = el._valueGet();
  734. var skipKeyPressEvent = false, //Safari 5.1.x - modal dialog fires keypress twice workaround
  735. ignorable = false,
  736. isRTL = false;
  737. if (el.dir == "rtl" || opts.numericInput) {
  738. if (el.dir == "rtl" || (opts.numericInput && opts.rightAlignNumerics))
  739. $input.css("text-align", "right");
  740. el.dir = "ltr";
  741. $input.removeAttr("dir");
  742. var inputData = $input.data('_inputmask');
  743. inputData['isRTL'] = true;
  744. $input.data('_inputmask', inputData);
  745. isRTL = true;
  746. }
  747. //unbind all events - to make sure that no other mask will interfere when re-masking
  748. $input.unbind(".inputmask");
  749. $input.removeClass('focus.inputmask');
  750. //bind events
  751. $input.bind("mouseenter.inputmask", function () {
  752. var $input = $(this), input = this;
  753. if (!$input.hasClass('focus.inputmask') && opts.showMaskOnHover) {
  754. if (input._valueGet() != getActiveBuffer().join('')) {
  755. writeBuffer(input, getActiveBuffer());
  756. }
  757. }
  758. }).bind("blur.inputmask", function () {
  759. var $input = $(this), input = this, nptValue = input._valueGet(), buffer = getActiveBuffer();
  760. $input.removeClass('focus.inputmask');
  761. if (nptValue != getActiveMaskSet()["undoBuffer"]) {
  762. $input.change();
  763. }
  764. if (opts.clearMaskOnLostFocus && nptValue != '') {
  765. if (nptValue == getActiveBufferTemplate().join(''))
  766. input._valueSet('');
  767. else { //clearout optional tail of the mask
  768. clearOptionalTail(input);
  769. }
  770. }
  771. if (!isComplete(buffer)) {
  772. $input.trigger("incomplete");
  773. if (opts.clearIncomplete) {
  774. $.each(masksets, function (ndx, ms) {
  775. ms["buffer"] = ms["_buffer"].slice();
  776. ms["lastValidPosition"] = undefined;
  777. ms["p"] = isRTL ? getMaskLength() : 0;
  778. });
  779. activeMasksetIndex = 0;
  780. if (opts.clearMaskOnLostFocus)
  781. input._valueSet('');
  782. else {
  783. buffer = getActiveBufferTemplate().slice();
  784. writeBuffer(input, buffer);
  785. }
  786. }
  787. }
  788. }).bind("focus.inputmask", function () {
  789. var $input = $(this), input = this, nptValue = input._valueGet();
  790. if (opts.showMaskOnFocus && !$input.hasClass('focus.inputmask') && (!opts.showMaskOnHover || (opts.showMaskOnHover && nptValue == ''))) {
  791. if (input._valueGet() != getActiveBuffer().join('')) {
  792. writeBuffer(input, getActiveBuffer(), getActiveMaskSet()["p"]);
  793. }
  794. }
  795. $input.addClass('focus.inputmask');
  796. getActiveMaskSet()["undoBuffer"] = input._valueGet();
  797. }).bind("mouseleave.inputmask", function () {
  798. var $input = $(this), input = this;
  799. if (opts.clearMaskOnLostFocus) {
  800. if (!$input.hasClass('focus.inputmask')) {
  801. if (input._valueGet() == getActiveBufferTemplate().join('') || input._valueGet() == '')
  802. input._valueSet('');
  803. else { //clearout optional tail of the mask
  804. clearOptionalTail(input);
  805. }
  806. }
  807. }
  808. }).bind("click.inputmask", function () {
  809. var input = this;
  810. setTimeout(function () {
  811. var selectedCaret = caret(input), buffer = getActiveBuffer();
  812. if (selectedCaret.begin == selectedCaret.end) {
  813. var clickPosition = selectedCaret.begin,
  814. lvp = getActiveMaskSet()["lastValidPosition"],
  815. lastPosition;
  816. determineInputDirection(input, selectedCaret);
  817. if (isRTL) {
  818. if (opts.numericInput) {
  819. lastPosition = opts.skipRadixDance === false && opts.radixPoint != "" && $.inArray(opts.radixPoint, buffer) != -1 ? $.inArray(opts.radixPoint, buffer) : getMaskLength();
  820. } else {
  821. lastPosition = seekPrevious((lvp == undefined ? getMaskLength() : lvp) + 1);
  822. }
  823. caret(input, clickPosition > lastPosition && (isValid(clickPosition, buffer[clickPosition], true, isRTL) !== false || !isMask(clickPosition)) ? clickPosition : lastPosition);
  824. } else {
  825. lastPosition = seekNext(lvp == undefined ? -1 : lvp);
  826. caret(input, clickPosition < lastPosition && (isValid(clickPosition, buffer[clickPosition], true, isRTL) !== false || !isMask(clickPosition)) ? clickPosition : lastPosition);
  827. }
  828. }
  829. }, 0);
  830. }).bind('dblclick.inputmask', function () {
  831. var input = this;
  832. if (getActiveMaskSet()["lastValidPosition"] != undefined) {
  833. setTimeout(function () {
  834. isRTL ?
  835. caret(input, seekPrevious(getActiveMaskSet()["lastValidPosition"]), getMaskLength()) :
  836. caret(input, 0, seekNext(getActiveMaskSet()["lastValidPosition"]));
  837. }, 0);
  838. }
  839. }).bind("keydown.inputmask", keydownEvent
  840. ).bind("keypress.inputmask", keypressEvent
  841. ).bind("keyup.inputmask", keyupEvent
  842. ).bind(pasteEvent + ".inputmask dragdrop.inputmask drop.inputmask", function () {
  843. var input = this, $input = $(input);
  844. setTimeout(function () {
  845. checkVal(input, true, false);
  846. if (isComplete(getActiveBuffer()))
  847. $input.trigger("complete");
  848. $input.click();
  849. }, 0);
  850. }).bind('setvalue.inputmask', function () {
  851. var input = this;
  852. getActiveMaskSet()["undoBuffer"] = input._valueGet();
  853. checkVal(input, true);
  854. if (input._valueGet() == getActiveBufferTemplate().join(''))
  855. input._valueSet('');
  856. }).bind('complete.inputmask', opts.oncomplete)
  857. .bind('incomplete.inputmask', opts.onincomplete)
  858. .bind('cleared.inputmask', opts.oncleared);
  859. //apply mask
  860. checkVal(el, true, false);
  861. // Wrap document.activeElement in a try/catch block since IE9 throw "Unspecified error" if document.activeElement is undefined when we are in an IFrame.
  862. var activeElement;
  863. try {
  864. activeElement = document.activeElement;
  865. } catch (e) {
  866. }
  867. if (activeElement === el) { //position the caret when in focus
  868. $input.addClass('focus.inputmask');
  869. caret(el, getActiveMaskSet()["lastValidPosition"]);
  870. } else if (opts.clearMaskOnLostFocus) {
  871. if (getActiveBuffer().join('') == getActiveBufferTemplate().join('')) {
  872. el._valueSet('');
  873. } else {
  874. clearOptionalTail(el);
  875. }
  876. }
  877. installEventRuler(el);
  878. //private functions
  879. function installEventRuler(npt) {
  880. var events = $._data(npt).events;
  881. $.each(events, function (eventType, eventHandlers) {
  882. $.each(eventHandlers, function (ndx, eventHandler) {
  883. if (eventHandler.namespace == "inputmask") {
  884. var handler = eventHandler.handler;
  885. eventHandler.handler = function (e) {
  886. if (this.readOnly || this.disabled)
  887. e.preventDefault;
  888. else
  889. return handler.apply(this, arguments);
  890. };
  891. }
  892. });
  893. });
  894. }
  895. function patchValueProperty(npt) {
  896. var valueProperty;
  897. if (Object.getOwnPropertyDescriptor)
  898. valueProperty = Object.getOwnPropertyDescriptor(npt, "value");
  899. if (valueProperty && valueProperty.get) {
  900. if (!npt._valueGet) {
  901. npt._valueGet = valueProperty.get;
  902. npt._valueSet = valueProperty.set;
  903. Object.defineProperty(npt, "value", {
  904. get: function () {
  905. var $self = $(this), inputData = $(this).data('_inputmask'), masksets = inputData['masksets'],
  906. activeMasksetIndex = inputData['activeMasksetIndex'];
  907. return inputData && inputData['opts'].autoUnmask ? $self.inputmask('unmaskedvalue') : this._valueGet() != masksets[activeMasksetIndex]['_buffer'].join('') ? this._valueGet() : '';
  908. },
  909. set: function (value) {
  910. this._valueSet(value);
  911. $(this).triggerHandler('setvalue.inputmask');
  912. }
  913. });
  914. }
  915. } else if (document.__lookupGetter__ && npt.__lookupGetter__("value")) {
  916. if (!npt._valueGet) {
  917. npt._valueGet = npt.__lookupGetter__("value");
  918. npt._valueSet = npt.__lookupSetter__("value");
  919. npt.__defineGetter__("value", function () {
  920. var $self = $(this), inputData = $(this).data('_inputmask'), masksets = inputData['masksets'],
  921. activeMasksetIndex = inputData['activeMasksetIndex'];
  922. return inputData && inputData['opts'].autoUnmask ? $self.inputmask('unmaskedvalue') : this._valueGet() != masksets[activeMasksetIndex]['_buffer'].join('') ? this._valueGet() : '';
  923. });
  924. npt.__defineSetter__("value", function (value) {
  925. this._valueSet(value);
  926. $(this).triggerHandler('setvalue.inputmask');
  927. });
  928. }
  929. } else {
  930. if (!npt._valueGet) {
  931. npt._valueGet = function () { return this.value; };
  932. npt._valueSet = function (value) { this.value = value; };
  933. }
  934. if ($.fn.val.inputmaskpatch != true) {
  935. $.fn.val = function () {
  936. if (arguments.length == 0) {
  937. var $self = $(this);
  938. if ($self.data('_inputmask')) {
  939. if ($self.data('_inputmask')['opts'].autoUnmask)
  940. return $self.inputmask('unmaskedvalue');
  941. else {
  942. var result = $.inputmask.val.apply($self);
  943. var inputData = $(this).data('_inputmask'), masksets = inputData['masksets'],
  944. activeMasksetIndex = inputData['activeMasksetIndex'];
  945. return result != masksets[activeMasksetIndex]['_buffer'].join('') ? result : '';
  946. }
  947. } else return $.inputmask.val.apply($self);
  948. } else {
  949. var args = arguments;
  950. return this.each(function () {
  951. var $self = $(this);
  952. var result = $.inputmask.val.apply($self, args);
  953. if ($self.data('_inputmask')) $self.triggerHandler('setvalue.inputmask');
  954. return result;
  955. });
  956. }
  957. };
  958. $.extend($.fn.val, {
  959. inputmaskpatch: true
  960. });
  961. }
  962. }
  963. }
  964. function determineInputDirection(input, pos) {
  965. //set input direction according the position to the radixPoint
  966. if (opts.numericInput && opts.radixPoint != "" && opts.skipRadixDance === false) {
  967. var nptStr = input._valueGet();
  968. var radixPosition = nptStr.indexOf(opts.radixPoint);
  969. isRTL = pos.begin <= radixPosition || pos.end <= radixPosition || radixPosition == -1;
  970. }
  971. }
  972. //shift chars to left from start to end and put c at end position if defined
  973. function shiftL(start, end, c) {
  974. var buffer = getActiveBuffer();
  975. while (!isMask(start) && start - 1 >= 0) start--; //jumping over nonmask position
  976. for (var i = start; i < end && i < getMaskLength() ; i++) {
  977. if (isMask(i)) {
  978. setReTargetPlaceHolder(buffer, i);
  979. var j = seekNext(i);
  980. var p = getBufferElement(buffer, j);
  981. if (p != getPlaceHolder(j)) {
  982. if (j < getMaskLength() && isValid(i, p, true, isRTL) !== false && getActiveTests()[determineTestPosition(i)].def == getActiveTests()[determineTestPosition(j)].def) {
  983. setBufferElement(buffer, i, getBufferElement(buffer, j), true, isRTL);
  984. if (j < end) {
  985. setReTargetPlaceHolder(buffer, j); //cleanup next position
  986. }
  987. } else {
  988. if (isMask(i))
  989. break;
  990. }
  991. } //else if (c == undefined) break;
  992. } else {
  993. setReTargetPlaceHolder(buffer, i);
  994. }
  995. }
  996. if (c != undefined)
  997. setBufferElement(buffer, isRTL ? end : seekPrevious(end), c);
  998. if (getActiveMaskSet()["greedy"] == false) {
  999. var trbuffer = truncateInput(buffer.join(''), isRTL).split('');
  1000. buffer.length = trbuffer.length;
  1001. for (var i = 0, bl = buffer.length; i < bl; i++) {
  1002. buffer[i] = trbuffer[i];
  1003. }
  1004. if (buffer.length == 0) getActiveMaskSet()["buffer"] = getActiveBufferTemplate().slice();
  1005. }
  1006. return start; //return the used start position
  1007. }
  1008. function shiftR(start, end, c, full) { //full => behave like a push right ~ do not stop on placeholders
  1009. var buffer = getActiveBuffer();
  1010. for (var i = start; i <= end && i < getMaskLength() ; i++) {
  1011. if (isMask(i)) {
  1012. var t = getBufferElement(buffer, i);
  1013. setBufferElement(buffer, i, c, true, isRTL);
  1014. if (t != getPlaceHolder(i)) {
  1015. var j = seekNext(i);
  1016. if (j < getMaskLength()) {
  1017. if (isValid(j, t, true, isRTL) !== false && getActiveTests()[determineTestPosition(i)].def == getActiveTests()[determineTestPosition(j)].def)
  1018. c = t;
  1019. else {
  1020. if (isMask(j))
  1021. break;
  1022. else c = t;
  1023. }
  1024. } else break;
  1025. } else {
  1026. c = t;
  1027. if (full !== true) break;
  1028. }
  1029. } else
  1030. setReTargetPlaceHolder(buffer, i);
  1031. }
  1032. var lengthBefore = buffer.length;
  1033. if (getActiveMaskSet()["greedy"] == false) {
  1034. var trbuffer = truncateInput(buffer.join(''), isRTL).split('');
  1035. buffer.length = trbuffer.length;
  1036. for (var i = 0, bl = buffer.length; i < bl; i++) {
  1037. buffer[i] = trbuffer[i];
  1038. }
  1039. if (buffer.length == 0) getActiveMaskSet()["buffer"] = getActiveBufferTemplate().slice();
  1040. }
  1041. return end - (lengthBefore - buffer.length); //return new start position
  1042. }
  1043. ;
  1044. function keydownEvent(e) {
  1045. //Safari 5.1.x - modal dialog fires keypress twice workaround
  1046. skipKeyPressEvent = false;
  1047. var input = this, k = e.keyCode, pos = caret(input);
  1048. determineInputDirection(input, pos);
  1049. //backspace, delete, and escape get special treatment
  1050. if (k == opts.keyCode.BACKSPACE || k == opts.keyCode.DELETE || (iphone && k == 127) || (e.ctrlKey && k == 88)) { //backspace/delete
  1051. e.preventDefault(); //stop default action but allow propagation
  1052. var beginPos = pos.begin;
  1053. if (pos.begin == 0 && pos.end == getMaskLength()) {
  1054. clearBuffer(getActiveBuffer(), pos.begin, pos.end);
  1055. $.each(masksets, function (ndx, ms) {
  1056. ms["buffer"] = ms["_buffer"].slice();
  1057. ms["lastValidPosition"] = undefined;
  1058. ms["p"] = isRTL ? getMaskLength() : 0;
  1059. });
  1060. } else if ((pos.end - pos.begin) > 1 || ((pos.end - pos.begin) == 1 && opts.insertMode)) { //partial selection
  1061. clearBuffer(getActiveBuffer(), pos.begin, pos.end);
  1062. var ml = getMaskLength();
  1063. if (opts.greedy == false) {
  1064. isRTL ? shiftR(0, pos.end - 1, getPlaceHolder(pos.end), true) : shiftL(pos.begin, ml);
  1065. } else {
  1066. for (var i = pos.begin; i < pos.end; i++) {
  1067. if (isMask(i))
  1068. isRTL ? shiftR(0, pos.end - 1, getPlaceHolder(pos.end), true) : shiftL(pos.begin, ml);
  1069. }
  1070. }
  1071. checkVal(input, false, true, getActiveBuffer());
  1072. } else {
  1073. $.each(masksets, function (ndx, ms) {
  1074. activeMasksetIndex = ndx;
  1075. beginPos = android533 ? pos.end : pos.begin;
  1076. var buffer = getActiveBuffer(), firstMaskPos = isRTL ? seekPrevious(getMaskLength() + 1) : seekNext(-1),
  1077. maskL = getMaskLength();
  1078. if (k == opts.keyCode.DELETE) { //handle delete
  1079. if (isRTL ? beginPos > firstMaskPos : beginPos < firstMaskPos)
  1080. beginPos = firstMaskPos;
  1081. if (beginPos < maskL) {
  1082. if (opts.numericInput && opts.radixPoint != "" && buffer[beginPos] == opts.radixPoint) {
  1083. beginPos = (buffer.length - 1 == beginPos) /* radixPoint is latest? delete it */ ? beginPos : seekNext(beginPos);
  1084. beginPos = shiftL(beginPos, maskL);
  1085. } else {
  1086. if (isRTL) {
  1087. beginPos = shiftR(0, beginPos, getPlaceHolder(beginPos), true);
  1088. beginPos = seekNext(beginPos);
  1089. } else {
  1090. beginPos = shiftL(beginPos, maskL);
  1091. }
  1092. }
  1093. if (getActiveMaskSet()['lastValidPosition'] != undefined) {
  1094. if (getActiveMaskSet()['lastValidPosition'] != -1 && getActiveBuffer()[getActiveMaskSet()['lastValidPosition']] == getActiveBufferTemplate()[getActiveMaskSet()['lastValidPosition']])
  1095. getActiveMaskSet()["lastValidPosition"] = isRTL ? seekNext(getActiveMaskSet()["lastValidPosition"]) : (getActiveMaskSet()["lastValidPosition"] == 0 ? -1 : seekPrevious(getActiveMaskSet()["lastValidPosition"]));
  1096. if (isRTL ? getActiveMaskSet()['lastValidPosition'] > firstMaskPos : getActiveMaskSet()['lastValidPosition'] < firstMaskPos) {
  1097. getActiveMaskSet()["lastValidPosition"] = undefined;
  1098. getActiveMaskSet()["p"] = firstMaskPos;
  1099. } else {
  1100. getActiveMaskSet()["writeOutBuffer"] = true;
  1101. getActiveMaskSet()["p"] = beginPos;
  1102. }
  1103. }
  1104. }
  1105. } else if (k == opts.keyCode.BACKSPACE) { //handle backspace
  1106. if (isRTL ? beginPos <= firstMaskPos : beginPos > firstMaskPos) {
  1107. beginPos -= 1;
  1108. if (opts.numericInput && opts.radixPoint != "" && buffer[beginPos] == opts.radixPoint) {
  1109. beginPos = shiftR(0, (buffer.length - 1 == beginPos) /* radixPoint is latest? delete it */ ? beginPos : beginPos - 1, getPlaceHolder(beginPos), true);
  1110. beginPos++;
  1111. } else {
  1112. if (isRTL) {
  1113. beginPos = shiftR(0, beginPos, getPlaceHolder(beginPos), true);
  1114. beginPos = buffer[beginPos + 1] == opts.radixPoint ? beginPos + 1 : seekNext(beginPos);
  1115. } else {
  1116. beginPos = shiftL(beginPos, maskL);
  1117. }
  1118. }
  1119. if (getActiveMaskSet()['lastValidPosition'] != undefined) {
  1120. if (getActiveMaskSet()['lastValidPosition'] != -1 && getActiveBuffer()[getActiveMaskSet()['lastValidPosition']] == getActiveBufferTemplate()[getActiveMaskSet()['lastValidPosition']])
  1121. getActiveMaskSet()["lastValidPosition"] = isRTL ? seekNext(getActiveMaskSet()["lastValidPosition"]) : (getActiveMaskSet()["lastValidPosition"] == 0 ? -1 : seekPrevious(getActiveMaskSet()["lastValidPosition"]));
  1122. if (isRTL ? getActiveMaskSet()['lastValidPosition'] > firstMaskPos : getActiveMaskSet()['lastValidPosition'] < firstMaskPos) {
  1123. getActiveMaskSet()["lastValidPosition"] = undefined;
  1124. getActiveMaskSet()["p"] = firstMaskPos;
  1125. } else {
  1126. getActiveMaskSet()["writeOutBuffer"] = true;
  1127. getActiveMaskSet()["p"] = beginPos;
  1128. }
  1129. }
  1130. } else if (activeMasksetIndex > 0) { //retry other masks
  1131. getActiveMaskSet()["lastValidPosition"] = undefined;
  1132. getActiveMaskSet()["writeOutBuffer"] = true;
  1133. getActiveMaskSet()["p"] = firstMaskPos;
  1134. //init first
  1135. activeMasksetIndex = 0;
  1136. getActiveMaskSet()["buffer"] = getActiveBufferTemplate().slice();
  1137. getActiveMaskSet()["p"] = isRTL ? seekPrevious(getMaskLength() + 1) : seekNext(-1);
  1138. getActiveMaskSet()["lastValidPosition"] = undefined;
  1139. }
  1140. }
  1141. });
  1142. }
  1143. determineActiveMasksetIndex(isRTL);
  1144. writeBuffer(input, getActiveBuffer(), getActiveMaskSet()["p"]);
  1145. if (input._valueGet() == getActiveBufferTemplate().join(''))
  1146. $(input).trigger('cleared');
  1147. if (opts.showTooltip) { //update tooltip
  1148. $input.prop("title", getActiveMaskSet()["mask"]);
  1149. }
  1150. } else if (k == opts.keyCode.END || k == opts.keyCode.PAGE_DOWN) { //when END or PAGE_DOWN pressed set position at lastmatch
  1151. setTimeout(function () {
  1152. var caretPos = isRTL ? getActiveMaskSet()["lastValidPosition"] : seekNext(getActiveMaskSet()["lastValidPosition"]);
  1153. if (!opts.insertMode && caretPos == getMaskLength() && !e.shiftKey) caretPos--;
  1154. caret(input, e.shiftKey ? pos.begin : caretPos, caretPos);
  1155. }, 0);
  1156. } else if ((k == opts.keyCode.HOME && !e.shiftKey) || k == opts.keyCode.PAGE_UP) { //Home or page_up
  1157. caret(input, 0, e.shiftKey ? pos.begin : 0);
  1158. } else if (k == opts.keyCode.ESCAPE) { //escape
  1159. input._valueSet(getActiveMaskSet()["undoBuffer"]);
  1160. checkVal(input, true, true);
  1161. } else if (k == opts.keyCode.INSERT) { //insert
  1162. opts.insertMode = !opts.insertMode;
  1163. caret(input, !opts.insertMode && pos.begin == getMaskLength() ? pos.begin - 1 : pos.begin);
  1164. } else if (opts.insertMode == false && !e.shiftKey) {
  1165. if (k == opts.keyCode.RIGHT) {
  1166. setTimeout(function () {
  1167. var caretPos = caret(input);
  1168. caret(input, caretPos.begin);
  1169. }, 0);
  1170. } else if (k == opts.keyCode.LEFT) {
  1171. setTimeout(function () {
  1172. var caretPos = caret(input);
  1173. caret(input, caretPos.begin - 1);
  1174. }, 0);
  1175. }
  1176. }
  1177. opts.onKeyDown.call(this, e, getActiveBuffer(), opts); //extra stuff to execute on keydown
  1178. ignorable = $.inArray(k, opts.ignorables) != -1;
  1179. }
  1180. function keypressEvent(e, checkval, k, writeOut, strict, ndx) {
  1181. //Safari 5.1.x - modal dialog fires keypress twice workaround
  1182. if (k == undefined && skipKeyPressEvent) return false;
  1183. skipKeyPressEvent = true;
  1184. var input = this, $input = $(input);
  1185. e = e || window.event;
  1186. var k = k || e.which || e.charCode || e.keyCode,
  1187. c = String.fromCharCode(k);
  1188. if (opts.numericInput && c == opts.radixPoint && checkval !== true) {
  1189. var nptStr = input._valueGet();
  1190. var radixPosition = nptStr.indexOf(opts.radixPoint);
  1191. caret(input, seekNext(radixPosition != -1 ? radixPosition : getMaskLength()));
  1192. }
  1193. if ((e.ctrlKey || e.metaKey || ignorable) && checkval !== true) {
  1194. return true;
  1195. } else {
  1196. if (k) {
  1197. var pos, results, result;
  1198. if (checkval) {
  1199. var pcaret = strict ? ndx : (opts.numericInput ? seekNext(getActiveMaskSet()["p"]) : getActiveMaskSet()["p"]);
  1200. pos = { begin: pcaret, end: pcaret };
  1201. } else {
  1202. pos = caret(input);
  1203. }
  1204. //clear possible selection
  1205. var initialIndex = activeMasksetIndex, selectionCleared = false;
  1206. $.each(masksets, function (ndx, lmnt) {
  1207. activeMasksetIndex = ndx;
  1208. getActiveMaskSet()["undoBuffer"] = getActiveBuffer().join('');
  1209. if ((pos.end - pos.begin) > 1 || ((pos.end - pos.begin) == 1 && opts.insertMode)) {
  1210. var posend = pos.end < getMaskLength() ? pos.end : getMaskLength();
  1211. clearBuffer(getActiveBuffer(), pos.begin, posend);
  1212. var ml = getMaskLength();
  1213. if (opts.greedy == false) {
  1214. isRTL ? shiftR(0, posend - 1, getPlaceHolder(posend), true) : shiftL(pos.begin, ml);
  1215. } else {
  1216. for (var i = pos.begin; i < posend; i++) {
  1217. if (isMask(i))
  1218. isRTL ? shiftR(0, posend - 1, getPlaceHolder(posend), true) : shiftL(pos.begin, ml);
  1219. }
  1220. }
  1221. selectionCleared = true;
  1222. }
  1223. });
  1224. activeMasksetIndex = initialIndex; //restore index
  1225. if (isRTL) {
  1226. var p = seekPrevious(selectionCleared ? pos.begin : pos.end);
  1227. results = isValid(p, c, strict, isRTL);
  1228. if (strict === true) results = [{ "activeMasksetIndex": activeMasksetIndex, "result": results }];
  1229. $.each(results, function (index, result) {
  1230. activeMasksetIndex = result["activeMasksetIndex"];
  1231. getActiveMaskSet()["writeOutBuffer"] = true;
  1232. var np = result["result"];
  1233. if (np !== false) {
  1234. var refresh = false, buffer = getActiveBuffer();
  1235. if (np !== true) {
  1236. refresh = np["refresh"]; //only rewrite buffer from isValid
  1237. p = np.pos != undefined ? np.pos : p; //set new position from isValid
  1238. c = np.c != undefined ? np.c : c; //set new char from isValid
  1239. }
  1240. if (refresh !== true) {
  1241. var maskL = getMaskLength(); //update masklength to include possible groupSeparator offset
  1242. var firstMaskPos = seekNext(-1), firstUnmaskedPosition = firstMaskPos;
  1243. if (opts.insertMode == true) {
  1244. if (getActiveMaskSet()['greedy'] == true) {
  1245. var bfrClone = buffer.slice();
  1246. while (getBufferElement(bfrClone, firstUnmaskedPosition, true) != getPlaceHolder(firstUnmaskedPosition) && firstUnmaskedPosition <= p) {
  1247. firstUnmaskedPosition = firstUnmaskedPosition == maskL ? (maskL + 1) : seekNext(firstUnmaskedPosition);
  1248. }
  1249. }
  1250. if (firstUnmaskedPosition <= p && (getActiveMaskSet()['greedy'] || (buffer.length < maskL || getBufferElement(buffer, p) == getPlaceHolder(p)))) {
  1251. if (buffer[firstMaskPos] != getPlaceHolder(firstMaskPos) && buffer.length < maskL) {
  1252. var offset = prepareBuffer(buffer, -1, isRTL);
  1253. if ((selectionCleared ? pos.begin : pos.end) != 0) p = p + offset;
  1254. maskL = buffer.length;
  1255. }
  1256. shiftL(firstUnmaskedPosition, p, c);
  1257. } else getActiveMaskSet()["writeOutBuffer"] = false;
  1258. } else setBufferElement(buffer, p, c, true, isRTL);
  1259. }
  1260. getActiveMaskSet()["p"] = p;
  1261. }
  1262. });
  1263. if (strict !== true) determineActiveMasksetIndex(isRTL);
  1264. if (writeOut !== false) {
  1265. $.each(results, function (ndx, rslt) {
  1266. if (rslt["activeMasksetIndex"] == activeMasksetIndex) {
  1267. result = rslt;
  1268. return false;
  1269. }
  1270. });
  1271. if (result != undefined) {
  1272. var self = this;
  1273. setTimeout(function () { opts.onKeyValidation.call(self, result["result"], opts); }, 0);
  1274. if (getActiveMaskSet()["writeOutBuffer"] && result["result"] !== false) {
  1275. var buffer = getActiveBuffer();
  1276. writeBuffer(input, buffer, checkval ? undefined : (opts.numericInput ? seekNext(getActiveMaskSet()["p"]) : getActiveMaskSet()["p"]));
  1277. setTimeout(function () { //timeout needed for IE
  1278. if (isComplete(buffer))
  1279. $input.trigger("complete");
  1280. }, 0);
  1281. } else {
  1282. getActiveMaskSet()["buffer"] = getActiveMaskSet()["undoBuffer"].split('');
  1283. }
  1284. }
  1285. }
  1286. } else {
  1287. var p = seekNext(pos.begin - 1);
  1288. results = isValid(p, c, strict, isRTL);
  1289. if (strict === true) results = [{ "activeMasksetIndex": activeMasksetIndex, "result": results }];
  1290. $.each(results, function (index, result) {
  1291. activeMasksetIndex = result["activeMasksetIndex"];
  1292. getActiveMaskSet()["writeOutBuffer"] = true;
  1293. var np = result["result"];
  1294. if (np !== false) {
  1295. var refresh = false, buffer = getActiveBuffer();
  1296. if (np !== true) {
  1297. refresh = np["refresh"]; //only rewrite buffer from isValid
  1298. p = np.pos != undefined ? np.pos : p; //set new position from isValid
  1299. c = np.c != undefined ? np.c : c; //set new char from isValid
  1300. }
  1301. if (refresh !== true) {
  1302. if (opts.insertMode == true) {
  1303. var lastUnmaskedPosition = getMaskLength();
  1304. var bfrClone = buffer.slice();
  1305. while (getBufferElement(bfrClone, lastUnmaskedPosition, true) != getPlaceHolder(lastUnmaskedPosition) && lastUnmaskedPosition >= p) {
  1306. lastUnmaskedPosition = lastUnmaskedPosition == 0 ? -1 : seekPrevious(lastUnmaskedPosition);
  1307. }
  1308. if (lastUnmaskedPosition >= p)
  1309. shiftR(p, buffer.length, c);
  1310. else getActiveMaskSet()["writeOutBuffer"] = false;
  1311. } else setBufferElement(buffer, p, c, true, isRTL);
  1312. }
  1313. getActiveMaskSet()["p"] = seekNext(p);
  1314. }
  1315. });
  1316. if (strict !== true) determineActiveMasksetIndex(isRTL);
  1317. if (writeOut !== false) {
  1318. $.each(results, function (ndx, rslt) {
  1319. if (rslt["activeMasksetIndex"] == activeMasksetIndex) {
  1320. result = rslt;
  1321. return false;
  1322. }
  1323. });
  1324. if (result != undefined) {
  1325. var self = this;
  1326. setTimeout(function () { opts.onKeyValidation.call(self, result["result"], opts); }, 0);
  1327. if (getActiveMaskSet()["writeOutBuffer"] && result["result"] !== false) {
  1328. var p = getActiveMaskSet()["p"], buffer = getActiveBuffer();
  1329. writeBuffer(input, buffer, checkval ? undefined : p);
  1330. setTimeout(function () { //timeout needed for IE
  1331. if (isComplete(buffer))
  1332. $input.trigger("complete");
  1333. }, 0);
  1334. } else {
  1335. getActiveMaskSet()["buffer"] = getActiveMaskSet()["undoBuffer"].split('');
  1336. }
  1337. }
  1338. }
  1339. }
  1340. if (android && checkval !== true) {
  1341. caret(input, caretSavePoint.begin, caretSavePoint.end);
  1342. }
  1343. if (opts.showTooltip) { //update tooltip
  1344. $input.prop("title", getActiveMaskSet()["mask"]);
  1345. }
  1346. e.preventDefault();
  1347. }
  1348. }
  1349. }
  1350. function keyupEvent(e) {
  1351. var $input = $(this), input = this, k = e.keyCode, buffer = getActiveBuffer();
  1352. opts.onKeyUp.call(this, e, buffer, opts); //extra stuff to execute on keyup
  1353. if (k == opts.keyCode.TAB && $input.hasClass('focus.inputmask') && input._valueGet().length == 0 && opts.showMaskOnFocus) {
  1354. buffer = getActiveBufferTemplate().slice();
  1355. writeBuffer(input, buffer);
  1356. if (!isRTL) caret(input, 0);
  1357. getActiveMaskSet()["undoBuffer"] = input._valueGet();
  1358. }
  1359. }
  1360. };
  1361. return this;
  1362. };
  1363. return this;
  1364. };
  1365. }
  1366. })(jQuery);
  1367. /*
  1368. Input Mask plugin extensions
  1369. http://github.com/RobinHerbots/jquery.inputmask
  1370. Copyright (c) 2010 - 2013 Robin Herbots
  1371. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  1372. Version: 2.2.48
  1373. Optional extensions on the jquery.inputmask base
  1374. */
  1375. (function ($) {
  1376. //extra definitions
  1377. $.extend($.inputmask.defaults.definitions, {
  1378. 'A': { //auto uppercasing
  1379. validator: "[A-Za-z]",
  1380. cardinality: 1,
  1381. casing: "upper"
  1382. },
  1383. '#': {
  1384. validator: "[A-Za-z\u0410-\u044F\u0401\u04510-9]",
  1385. cardinality: 1,
  1386. casing: "upper"
  1387. }
  1388. });
  1389. $.extend($.inputmask.defaults.aliases, {
  1390. 'url': {
  1391. mask: "ir",
  1392. placeholder: "",
  1393. separator: "",
  1394. defaultPrefix: "http://",
  1395. regex: {
  1396. urlpre1: new RegExp("[fh]"),
  1397. urlpre2: new RegExp("(ft|ht)"),
  1398. urlpre3: new RegExp("(ftp|htt)"),
  1399. urlpre4: new RegExp("(ftp:|http|ftps)"),
  1400. urlpre5: new RegExp("(ftp:/|ftps:|http:|https)"),
  1401. urlpre6: new RegExp("(ftp://|ftps:/|http:/|https:)"),
  1402. urlpre7: new RegExp("(ftp://|ftps://|http://|https:/)"),
  1403. urlpre8: new RegExp("(ftp://|ftps://|http://|https://)")
  1404. },
  1405. definitions: {
  1406. 'i': {
  1407. validator: function (chrs, buffer, pos, strict, opts) {
  1408. return true;
  1409. },
  1410. cardinality: 8,
  1411. prevalidator: (function () {
  1412. var result = [], prefixLimit = 8;
  1413. for (var i = 0; i < prefixLimit; i++) {
  1414. result[i] = (function () {
  1415. var j = i;
  1416. return {
  1417. validator: function (chrs, buffer, pos, strict, opts) {
  1418. if (opts.regex["urlpre" + (j + 1)]) {
  1419. var tmp = chrs, k;
  1420. if (((j + 1) - chrs.length) > 0) {
  1421. tmp = buffer.join('').substring(0, ((j + 1) - chrs.length)) + "" + tmp;
  1422. }
  1423. var isValid = opts.regex["urlpre" + (j + 1)].test(tmp);
  1424. if (!strict && !isValid) {
  1425. pos = pos - j;
  1426. for (k = 0; k < opts.defaultPrefix.length; k++) {
  1427. buffer[pos] = opts.defaultPrefix[k]; pos++;
  1428. }
  1429. for (k = 0; k < tmp.length - 1; k++) {
  1430. buffer[pos] = tmp[k]; pos++;
  1431. }
  1432. return { "pos": pos };
  1433. }
  1434. return isValid;
  1435. } else {
  1436. return false;
  1437. }
  1438. }, cardinality: j
  1439. };
  1440. })();
  1441. }
  1442. return result;
  1443. })()
  1444. },
  1445. "r": {
  1446. validator: ".",
  1447. cardinality: 50
  1448. }
  1449. },
  1450. insertMode: false,
  1451. autoUnmask: false
  1452. },
  1453. "ip": {
  1454. mask: "i.i.i.i",
  1455. definitions: {
  1456. 'i': {
  1457. validator: "25[0-5]|2[0-4][0-9]|[01][0-9][0-9]",
  1458. cardinality: 3,
  1459. prevalidator: [
  1460. { validator: "[0-2]", cardinality: 1 },
  1461. { validator: "2[0-5]|[01][0-9]", cardinality: 2 }
  1462. ]
  1463. }
  1464. }
  1465. }
  1466. });
  1467. })(jQuery);/*
  1468. Input Mask plugin extensions
  1469. http://github.com/RobinHerbots/jquery.inputmask
  1470. Copyright (c) 2010 - 2012 Robin Herbots
  1471. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  1472. Version: 2.2.48
  1473. Optional extensions on the jquery.inputmask base
  1474. */
  1475. (function ($) {
  1476. //date & time aliases
  1477. $.extend($.inputmask.defaults.definitions, {
  1478. 'h': { //hours
  1479. validator: "[01][0-9]|2[0-3]",
  1480. cardinality: 2,
  1481. prevalidator: [{ validator: "[0-2]", cardinality: 1 }]
  1482. },
  1483. 's': { //seconds || minutes
  1484. validator: "[0-5][0-9]",
  1485. cardinality: 2,
  1486. prevalidator: [{ validator: "[0-5]", cardinality: 1 }]
  1487. },
  1488. 'd': { //basic day
  1489. validator: "0[1-9]|[12][0-9]|3[01]",
  1490. cardinality: 2,
  1491. prevalidator: [{ validator: "[0-3]", cardinality: 1 }]
  1492. },
  1493. 'm': { //basic month
  1494. validator: "0[1-9]|1[012]",
  1495. cardinality: 2,
  1496. prevalidator: [{ validator: "[01]", cardinality: 1 }]
  1497. },
  1498. 'y': { //basic year
  1499. validator: "(19|20)\\d{2}",
  1500. cardinality: 4,
  1501. prevalidator: [
  1502. { validator: "[12]", cardinality: 1 },
  1503. { validator: "(19|20)", cardinality: 2 },
  1504. { validator: "(19|20)\\d", cardinality: 3 }
  1505. ]
  1506. }
  1507. });
  1508. $.extend($.inputmask.defaults.aliases, {
  1509. 'dd/mm/yyyy': {
  1510. mask: "1/2/y",
  1511. placeholder: "dd/mm/yyyy",
  1512. regex: {
  1513. val1pre: new RegExp("[0-3]"), //daypre
  1514. val1: new RegExp("0[1-9]|[12][0-9]|3[01]"), //day
  1515. val2pre: function (separator) { var escapedSeparator = $.inputmask.escapeRegex.call(this, separator); return new RegExp("((0[1-9]|[12][0-9]|3[01])" + escapedSeparator + "[01])"); }, //monthpre
  1516. val2: function (separator) { var escapedSeparator = $.inputmask.escapeRegex.call(this, separator); return new RegExp("((0[1-9]|[12][0-9])" + escapedSeparator + "(0[1-9]|1[012]))|(30" + escapedSeparator + "(0[13-9]|1[012]))|(31" + escapedSeparator + "(0[13578]|1[02]))"); }//month
  1517. },
  1518. leapday: "29/02/",
  1519. separator: '/',
  1520. yearrange: { minyear: 1900, maxyear: 2099 },
  1521. isInYearRange: function (chrs, minyear, maxyear) {
  1522. var enteredyear = parseInt(chrs.concat(minyear.toString().slice(chrs.length)));
  1523. var enteredyear2 = parseInt(chrs.concat(maxyear.toString().slice(chrs.length)));
  1524. return (enteredyear != NaN ? minyear <= enteredyear && enteredyear <= maxyear : false) ||
  1525. (enteredyear2 != NaN ? minyear <= enteredyear2 && enteredyear2 <= maxyear : false);
  1526. },
  1527. determinebaseyear: function (minyear, maxyear) {
  1528. var currentyear = (new Date()).getFullYear();
  1529. if (minyear > currentyear) return minyear;
  1530. if (maxyear < currentyear) return maxyear;
  1531. return currentyear;
  1532. },
  1533. onKeyUp: function (e, buffer, opts) {
  1534. var $input = $(this);
  1535. if (e.ctrlKey && e.keyCode == opts.keyCode.RIGHT) {
  1536. var today = new Date();
  1537. $input.val(today.getDate().toString() + (today.getMonth() + 1).toString() + today.getFullYear().toString());
  1538. }
  1539. },
  1540. definitions: {
  1541. '1': { //val1 ~ day or month
  1542. validator: function (chrs, buffer, pos, strict, opts) {
  1543. var isValid = opts.regex.val1.test(chrs);
  1544. if (!strict && !isValid) {
  1545. if (chrs.charAt(1) == opts.separator || "-./".indexOf(chrs.charAt(1)) != -1) {
  1546. isValid = opts.regex.val1.test("0" + chrs.charAt(0));
  1547. if (isValid) {
  1548. buffer[pos - 1] = "0";
  1549. return { "pos": pos, "c": chrs.charAt(0) };
  1550. }
  1551. }
  1552. }
  1553. return isValid;
  1554. },
  1555. cardinality: 2,
  1556. prevalidator: [{
  1557. validator: function (chrs, buffer, pos, strict, opts) {
  1558. var isValid = opts.regex.val1pre.test(chrs);
  1559. if (!strict && !isValid) {
  1560. isValid = opts.regex.val1.test("0" + chrs);
  1561. if (isValid) {
  1562. buffer[pos] = "0";
  1563. pos++;
  1564. return { "pos": pos };
  1565. }
  1566. }
  1567. return isValid;
  1568. }, cardinality: 1
  1569. }]
  1570. },
  1571. '2': { //val2 ~ day or month
  1572. validator: function (chrs, buffer, pos, strict, opts) {
  1573. var frontValue = buffer.join('').substr(0, 3);
  1574. var isValid = opts.regex.val2(opts.separator).test(frontValue + chrs);
  1575. if (!strict && !isValid) {
  1576. if (chrs.charAt(1) == opts.separator || "-./".indexOf(chrs.charAt(1)) != -1) {
  1577. isValid = opts.regex.val2(opts.separator).test(frontValue + "0" + chrs.charAt(0));
  1578. if (isValid) {
  1579. buffer[pos - 1] = "0";
  1580. return { "pos": pos, "c": chrs.charAt(0) };
  1581. }
  1582. }
  1583. }
  1584. return isValid;
  1585. },
  1586. cardinality: 2,
  1587. prevalidator: [{
  1588. validator: function (chrs, buffer, pos, strict, opts) {
  1589. var frontValue = buffer.join('').substr(0, 3);
  1590. var isValid = opts.regex.val2pre(opts.separator).test(frontValue + chrs);
  1591. if (!strict && !isValid) {
  1592. isValid = opts.regex.val2(opts.separator).test(frontValue + "0" + chrs);
  1593. if (isValid) {
  1594. buffer[pos] = "0";
  1595. pos++;
  1596. return { "pos": pos };
  1597. }
  1598. }
  1599. return isValid;
  1600. }, cardinality: 1
  1601. }]
  1602. },
  1603. 'y': { //year
  1604. validator: function (chrs, buffer, pos, strict, opts) {
  1605. if (opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear)) {
  1606. var dayMonthValue = buffer.join('').substr(0, 6);
  1607. if (dayMonthValue != opts.leapday)
  1608. return true;
  1609. else {
  1610. var year = parseInt(chrs, 10);//detect leap year
  1611. if (year % 4 === 0)
  1612. if (year % 100 === 0)
  1613. if (year % 400 === 0)
  1614. return true;
  1615. else return false;
  1616. else return true;
  1617. else return false;
  1618. }
  1619. } else return false;
  1620. },
  1621. cardinality: 4,
  1622. prevalidator: [
  1623. {
  1624. validator: function (chrs, buffer, pos, strict, opts) {
  1625. var isValid = opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  1626. if (!strict && !isValid) {
  1627. var yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear).toString().slice(0, 1);
  1628. isValid = opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  1629. if (isValid) {
  1630. buffer[pos++] = yearPrefix[0];
  1631. return { "pos": pos };
  1632. }
  1633. yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear).toString().slice(0, 2);
  1634. isValid = opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  1635. if (isValid) {
  1636. buffer[pos++] = yearPrefix[0];
  1637. buffer[pos++] = yearPrefix[1];
  1638. return { "pos": pos };
  1639. }
  1640. }
  1641. return isValid;
  1642. },
  1643. cardinality: 1
  1644. },
  1645. {
  1646. validator: function (chrs, buffer, pos, strict, opts) {
  1647. var isValid = opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  1648. if (!strict && !isValid) {
  1649. var yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear).toString().slice(0, 2);
  1650. isValid = opts.isInYearRange(chrs[0] + yearPrefix[1] + chrs[1], opts.yearrange.minyear, opts.yearrange.maxyear);
  1651. if (isValid) {
  1652. buffer[pos++] = yearPrefix[1];
  1653. return { "pos": pos };
  1654. }
  1655. yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear).toString().slice(0, 2);
  1656. if (opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear)) {
  1657. var dayMonthValue = buffer.join('').substr(0, 6);
  1658. if (dayMonthValue != opts.leapday)
  1659. isValid = true;
  1660. else {
  1661. var year = parseInt(chrs, 10);//detect leap year
  1662. if (year % 4 === 0)
  1663. if (year % 100 === 0)
  1664. if (year % 400 === 0)
  1665. isValid = true;
  1666. else isValid = false;
  1667. else isValid = true;
  1668. else isValid = false;
  1669. }
  1670. } else isValid = false;
  1671. if (isValid) {
  1672. buffer[pos - 1] = yearPrefix[0];
  1673. buffer[pos++] = yearPrefix[1];
  1674. buffer[pos++] = chrs[0];
  1675. return { "pos": pos };
  1676. }
  1677. }
  1678. return isValid;
  1679. }, cardinality: 2
  1680. },
  1681. {
  1682. validator: function (chrs, buffer, pos, strict, opts) {
  1683. return opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  1684. }, cardinality: 3
  1685. }
  1686. ]
  1687. }
  1688. },
  1689. insertMode: false,
  1690. autoUnmask: false
  1691. },
  1692. 'mm/dd/yyyy': {
  1693. placeholder: "mm/dd/yyyy",
  1694. alias: "dd/mm/yyyy", //reuse functionality of dd/mm/yyyy alias
  1695. regex: {
  1696. val2pre: function (separator) { var escapedSeparator = $.inputmask.escapeRegex.call(this, separator); return new RegExp("((0[13-9]|1[012])" + escapedSeparator + "[0-3])|(02" + escapedSeparator + "[0-2])"); }, //daypre
  1697. val2: function (separator) { var escapedSeparator = $.inputmask.escapeRegex.call(this, separator); return new RegExp("((0[1-9]|1[012])" + escapedSeparator + "(0[1-9]|[12][0-9]))|((0[13-9]|1[012])" + escapedSeparator + "30)|((0[13578]|1[02])" + escapedSeparator + "31)"); }, //day
  1698. val1pre: new RegExp("[01]"), //monthpre
  1699. val1: new RegExp("0[1-9]|1[012]") //month
  1700. },
  1701. leapday: "02/29/",
  1702. onKeyUp: function (e, buffer, opts) {
  1703. var $input = $(this);
  1704. if (e.ctrlKey && e.keyCode == opts.keyCode.RIGHT) {
  1705. var today = new Date();
  1706. $input.val((today.getMonth() + 1).toString() + today.getDate().toString() + today.getFullYear().toString());
  1707. }
  1708. }
  1709. },
  1710. 'yyyy/mm/dd': {
  1711. mask: "y/1/2",
  1712. placeholder: "yyyy/mm/dd",
  1713. alias: "mm/dd/yyyy",
  1714. leapday: "/02/29",
  1715. onKeyUp: function (e, buffer, opts) {
  1716. var $input = $(this);
  1717. if (e.ctrlKey && e.keyCode == opts.keyCode.RIGHT) {
  1718. var today = new Date();
  1719. $input.val(today.getFullYear().toString() + (today.getMonth() + 1).toString() + today.getDate().toString());
  1720. }
  1721. },
  1722. definitions: {
  1723. '2': { //val2 ~ day or month
  1724. validator: function (chrs, buffer, pos, strict, opts) {
  1725. var frontValue = buffer.join('').substr(5, 3);
  1726. var isValid = opts.regex.val2(opts.separator).test(frontValue + chrs);
  1727. if (!strict && !isValid) {
  1728. if (chrs.charAt(1) == opts.separator || "-./".indexOf(chrs.charAt(1)) != -1) {
  1729. isValid = opts.regex.val2(opts.separator).test(frontValue + "0" + chrs.charAt(0));
  1730. if (isValid) {
  1731. buffer[pos - 1] = "0";
  1732. return { "pos": pos, "c": chrs.charAt(0) };
  1733. }
  1734. }
  1735. }
  1736. //check leap yeap
  1737. if (isValid) {
  1738. var dayMonthValue = buffer.join('').substr(4, 4) + chrs;
  1739. if (dayMonthValue != opts.leapday)
  1740. return true;
  1741. else {
  1742. var year = parseInt(buffer.join('').substr(0, 4), 10); //detect leap year
  1743. if (year % 4 === 0)
  1744. if (year % 100 === 0)
  1745. if (year % 400 === 0)
  1746. return true;
  1747. else return false;
  1748. else return true;
  1749. else return false;
  1750. }
  1751. }
  1752. return isValid;
  1753. },
  1754. cardinality: 2,
  1755. prevalidator: [{
  1756. validator: function (chrs, buffer, pos, strict, opts) {
  1757. var frontValue = buffer.join('').substr(5, 3);
  1758. var isValid = opts.regex.val2pre(opts.separator).test(frontValue + chrs);
  1759. if (!strict && !isValid) {
  1760. isValid = opts.regex.val2(opts.separator).test(frontValue + "0" + chrs);
  1761. if (isValid) {
  1762. buffer[pos] = "0";
  1763. pos++;
  1764. return { "pos": pos };
  1765. }
  1766. }
  1767. return isValid;
  1768. }, cardinality: 1
  1769. }]
  1770. }
  1771. }
  1772. },
  1773. 'dd.mm.yyyy': {
  1774. mask: "1.2.y",
  1775. placeholder: "dd.mm.yyyy",
  1776. leapday: "29.02.",
  1777. separator: '.',
  1778. alias: "dd/mm/yyyy"
  1779. },
  1780. 'dd-mm-yyyy': {
  1781. mask: "1-2-y",
  1782. placeholder: "dd-mm-yyyy",
  1783. leapday: "29-02-",
  1784. separator: '-',
  1785. alias: "dd/mm/yyyy"
  1786. },
  1787. 'mm.dd.yyyy': {
  1788. mask: "1.2.y",
  1789. placeholder: "mm.dd.yyyy",
  1790. leapday: "02.29.",
  1791. separator: '.',
  1792. alias: "mm/dd/yyyy"
  1793. },
  1794. 'mm-dd-yyyy': {
  1795. mask: "1-2-y",
  1796. placeholder: "mm-dd-yyyy",
  1797. leapday: "02-29-",
  1798. separator: '-',
  1799. alias: "mm/dd/yyyy"
  1800. },
  1801. 'yyyy.mm.dd': {
  1802. mask: "y.1.2",
  1803. placeholder: "yyyy.mm.dd",
  1804. leapday: ".02.29",
  1805. separator: '.',
  1806. alias: "yyyy/mm/dd"
  1807. },
  1808. 'yyyy-mm-dd': {
  1809. mask: "y-1-2",
  1810. placeholder: "yyyy-mm-dd",
  1811. leapday: "-02-29",
  1812. separator: '-',
  1813. alias: "yyyy/mm/dd"
  1814. },
  1815. 'datetime': {
  1816. mask: "1/2/y h:s",
  1817. placeholder: "dd/mm/yyyy hh:mm",
  1818. alias: "dd/mm/yyyy",
  1819. regex: {
  1820. hrspre: new RegExp("[012]"), //hours pre
  1821. hrs24: new RegExp("2[0-9]|1[3-9]"),
  1822. hrs: new RegExp("[01][0-9]|2[0-3]"), //hours
  1823. ampm: new RegExp("^[a|p|A|P][m|M]")
  1824. },
  1825. timeseparator: ':',
  1826. hourFormat: "24", // or 12
  1827. definitions: {
  1828. 'h': { //hours
  1829. validator: function (chrs, buffer, pos, strict, opts) {
  1830. var isValid = opts.regex.hrs.test(chrs);
  1831. if (!strict && !isValid) {
  1832. if (chrs.charAt(1) == opts.timeseparator || "-.:".indexOf(chrs.charAt(1)) != -1) {
  1833. isValid = opts.regex.hrs.test("0" + chrs.charAt(0));
  1834. if (isValid) {
  1835. buffer[pos - 1] = "0";
  1836. buffer[pos] = chrs.charAt(0);
  1837. pos++;
  1838. return { "pos": pos };
  1839. }
  1840. }
  1841. }
  1842. if (isValid && opts.hourFormat !== "24" && opts.regex.hrs24.test(chrs)) {
  1843. var tmp = parseInt(chrs, 10);
  1844. if (tmp == 24) {
  1845. buffer[pos + 5] = "a";
  1846. buffer[pos + 6] = "m";
  1847. } else {
  1848. buffer[pos + 5] = "p";
  1849. buffer[pos + 6] = "m";
  1850. }
  1851. tmp = tmp - 12;
  1852. if (tmp < 10) {
  1853. buffer[pos] = tmp.toString();
  1854. buffer[pos - 1] = "0";
  1855. } else {
  1856. buffer[pos] = tmp.toString().charAt(1);
  1857. buffer[pos - 1] = tmp.toString().charAt(0);
  1858. }
  1859. return { "pos": pos, "c": buffer[pos] };
  1860. }
  1861. return isValid;
  1862. },
  1863. cardinality: 2,
  1864. prevalidator: [{
  1865. validator: function (chrs, buffer, pos, strict, opts) {
  1866. var isValid = opts.regex.hrspre.test(chrs);
  1867. if (!strict && !isValid) {
  1868. isValid = opts.regex.hrs.test("0" + chrs);
  1869. if (isValid) {
  1870. buffer[pos] = "0";
  1871. pos++;
  1872. return { "pos": pos };
  1873. }
  1874. }
  1875. return isValid;
  1876. }, cardinality: 1
  1877. }]
  1878. },
  1879. 't': { //am/pm
  1880. validator: function (chrs, buffer, pos, strict, opts) {
  1881. return opts.regex.ampm.test(chrs + "m");
  1882. },
  1883. casing: "lower",
  1884. cardinality: 1
  1885. }
  1886. },
  1887. insertMode: false,
  1888. autoUnmask: false
  1889. },
  1890. 'datetime12': {
  1891. mask: "1/2/y h:s t\\m",
  1892. placeholder: "dd/mm/yyyy hh:mm xm",
  1893. alias: "datetime",
  1894. hourFormat: "12"
  1895. },
  1896. 'hh:mm t': {
  1897. mask: "h:s t\\m",
  1898. placeholder: "hh:mm xm",
  1899. alias: "datetime",
  1900. hourFormat: "12"
  1901. },
  1902. 'h:s t': {
  1903. mask: "h:s t\\m",
  1904. placeholder: "hh:mm xm",
  1905. alias: "datetime",
  1906. hourFormat: "12"
  1907. },
  1908. 'hh:mm:ss': {
  1909. mask: "h:s:s",
  1910. autoUnmask: false
  1911. },
  1912. 'hh:mm': {
  1913. mask: "h:s",
  1914. autoUnmask: false
  1915. },
  1916. 'date': {
  1917. alias: "dd/mm/yyyy" // "mm/dd/yyyy"
  1918. }
  1919. });
  1920. })(jQuery);/*
  1921. Input Mask plugin extensions
  1922. http://github.com/RobinHerbots/jquery.inputmask
  1923. Copyright (c) 2010 - 2013 Robin Herbots
  1924. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  1925. Version: 2.2.48
  1926. Optional extensions on the jquery.inputmask base
  1927. */
  1928. (function ($) {
  1929. //number aliases
  1930. $.extend($.inputmask.defaults.aliases, {
  1931. 'decimal': {
  1932. mask: "~",
  1933. placeholder: "",
  1934. repeat: 10,
  1935. greedy: false,
  1936. numericInput: true,
  1937. digits: "*", //numer of digits
  1938. groupSeparator: "",//",", // | "."
  1939. radixPoint: ".",
  1940. groupSize: 3,
  1941. autoGroup: false,
  1942. allowPlus: true,
  1943. allowMinus: true,
  1944. getMaskLength: function (buffer, greedy, repeat, currentBuffer, opts) { //custom getMaskLength to take the groupSeparator into account
  1945. var calculatedLength = buffer.length;
  1946. if (!greedy && repeat > 1) {
  1947. calculatedLength += (buffer.length * (repeat - 1));
  1948. }
  1949. var escapedGroupSeparator = $.inputmask.escapeRegex.call(this, opts.groupSeparator);
  1950. var escapedRadixPoint = $.inputmask.escapeRegex.call(this, opts.radixPoint);
  1951. var currentBufferStr = currentBuffer.join(''), strippedBufferStr = currentBufferStr.replace(new RegExp(escapedGroupSeparator, "g"), "").replace(new RegExp(escapedRadixPoint), ""),
  1952. groupOffset = currentBufferStr.length - strippedBufferStr.length;
  1953. return calculatedLength + groupOffset;
  1954. },
  1955. postFormat: function (buffer, pos, reformatOnly, opts) {
  1956. if (opts.groupSeparator == "") return pos;
  1957. var cbuf = buffer.slice(),
  1958. radixPos = $.inArray(opts.radixPoint, buffer);
  1959. if (!reformatOnly) {
  1960. cbuf.splice(pos == 0 || pos <= radixPos || opts.skipRadixDance ? pos + 1 : pos, 0, "?"); //set position indicator
  1961. }
  1962. var bufVal = cbuf.join('');
  1963. if (opts.autoGroup || (reformatOnly && bufVal.indexOf(opts.groupSeparator) != -1)) {
  1964. var escapedGroupSeparator = $.inputmask.escapeRegex.call(this, opts.groupSeparator);
  1965. bufVal = bufVal.replace(new RegExp(escapedGroupSeparator, "g"), '');
  1966. var radixSplit = bufVal.split(opts.radixPoint);
  1967. bufVal = radixSplit[0];
  1968. var reg = new RegExp('([-\+]?[\\d\?]+)([\\d\?]{' + opts.groupSize + '})');
  1969. while (reg.test(bufVal)) {
  1970. bufVal = bufVal.replace(reg, '$1' + opts.groupSeparator + '$2');
  1971. bufVal = bufVal.replace(opts.groupSeparator + opts.groupSeparator, opts.groupSeparator);
  1972. }
  1973. if (radixSplit.length > 1)
  1974. bufVal += opts.radixPoint + radixSplit[1];
  1975. }
  1976. buffer.length = bufVal.length; //align the length
  1977. for (var i = 0, l = bufVal.length; i < l; i++) {
  1978. buffer[i] = bufVal.charAt(i);
  1979. }
  1980. var newPos = $.inArray("?", buffer);
  1981. if (!reformatOnly) buffer.splice(newPos, 1);
  1982. return reformatOnly ? pos : newPos <= radixPos || (opts.skipRadixDance && newPos != 0) ? newPos - 1 : newPos;
  1983. },
  1984. regex: {
  1985. number: function (groupSeparator, groupSize, radixPoint, digits, allowPlus, allowMinus) {
  1986. var escapedGroupSeparator = $.inputmask.escapeRegex.call(this, groupSeparator);
  1987. var escapedRadixPoint = $.inputmask.escapeRegex.call(this, radixPoint);
  1988. var digitExpression = isNaN(digits) ? digits : '{0,' + digits + '}';
  1989. var signedExpression = "[" + (allowPlus ? "\+" : "") + (allowMinus ? "-" : "") + "]?";
  1990. return new RegExp("^" + signedExpression + "(\\d+|\\d{1," + groupSize + "}((" + escapedGroupSeparator + "\\d{" + groupSize + "})?)+)(" + escapedRadixPoint + "\\d" + digitExpression + ")?$");
  1991. }
  1992. },
  1993. onKeyDown: function (e, buffer, opts) {
  1994. var $input = $(this), input = this;
  1995. if (e.keyCode == opts.keyCode.TAB) {
  1996. var radixPosition = $.inArray(opts.radixPoint, buffer);
  1997. if (radixPosition != -1) {
  1998. var masksets = $input.data('_inputmask')['masksets'];
  1999. var activeMasksetIndex = $input.data('_inputmask')['activeMasksetIndex'];
  2000. for (var i = 1; i <= opts.digits && i < opts.getMaskLength(masksets[activeMasksetIndex]["_buffer"], masksets[activeMasksetIndex]["greedy"], masksets[activeMasksetIndex]["repeat"], buffer, opts) ; i++) {
  2001. if (buffer[radixPosition + i] == undefined) buffer[radixPosition + i] = "0";
  2002. }
  2003. input._valueSet(buffer.join(''));
  2004. }
  2005. } else if (e.keyCode == opts.keyCode.DELETE || e.keyCode == opts.keyCode.BACKSPACE) {
  2006. opts.postFormat(buffer, 0, true, opts);
  2007. input._valueSet(buffer.join(''));
  2008. }
  2009. },
  2010. definitions: {
  2011. '~': { //real number
  2012. validator: function (chrs, buffer, pos, strict, opts) {
  2013. if (chrs == "") return false;
  2014. if (!strict && pos <= 1 && buffer[0] === '0' && new RegExp("[\\d-]").test(chrs)) { //handle first char
  2015. buffer[0] = "";
  2016. return { "pos": 0 };
  2017. }
  2018. var cbuf = strict ? buffer.slice(0, pos) : buffer.slice();
  2019. cbuf.splice((pos == 0 && buffer.length == 0) ? pos : pos + 1, 0, chrs);
  2020. var bufferStr = cbuf.join('');
  2021. if (opts.autoGroup && !strict) { //strip groupseparator
  2022. var escapedGroupSeparator = $.inputmask.escapeRegex.call(this, opts.groupSeparator);
  2023. bufferStr = bufferStr.replace(new RegExp(escapedGroupSeparator, "g"), '');
  2024. }
  2025. var isValid = opts.regex.number(opts.groupSeparator, opts.groupSize, opts.radixPoint, opts.digits, opts.allowPlus, opts.allowMinus).test(bufferStr);
  2026. if (!isValid) {
  2027. //let's help the regex a bit
  2028. bufferStr += "0";
  2029. isValid = opts.regex.number(opts.groupSeparator, opts.groupSize, opts.radixPoint, opts.digits, opts.allowPlus, opts.allowMinus).test(bufferStr);
  2030. if (!isValid) {
  2031. //make a valid group
  2032. var lastGroupSeparator = bufferStr.lastIndexOf(opts.groupSeparator);
  2033. for (i = bufferStr.length - lastGroupSeparator; i <= 3; i++) {
  2034. bufferStr += "0";
  2035. }
  2036. isValid = opts.regex.number(opts.groupSeparator, opts.groupSize, opts.radixPoint, opts.digits, opts.allowPlus, opts.allowMinus).test(bufferStr);
  2037. if (!isValid && !strict) {
  2038. if (chrs == opts.radixPoint) {
  2039. isValid = opts.regex.number(opts.groupSeparator, opts.groupSize, opts.radixPoint, opts.digits, opts.allowPlus, opts.allowMinus).test("0" + bufferStr + "0");
  2040. if (isValid) {
  2041. buffer[pos] = "0";
  2042. pos++;
  2043. return { "pos": pos };
  2044. }
  2045. }
  2046. }
  2047. }
  2048. }
  2049. if (isValid != false && !strict && chrs != opts.radixPoint) {
  2050. var newPos = opts.postFormat(buffer, pos, false, opts);
  2051. return { "pos": newPos };
  2052. }
  2053. return isValid;
  2054. },
  2055. cardinality: 1,
  2056. prevalidator: null
  2057. }
  2058. },
  2059. insertMode: true,
  2060. autoUnmask: false
  2061. },
  2062. 'integer': {
  2063. regex: {
  2064. number: function (groupSeparator, groupSize, radixPoint, digits, allowPlus, allowMinus) {
  2065. var escapedGroupSeparator = $.inputmask.escapeRegex.call(this, groupSeparator);
  2066. var signedExpression = "[" + (allowPlus ? "\+" : "") + (allowMinus ? "-" : "") + "]?";
  2067. return new RegExp("^" + signedExpression + "(\\d+|\\d{1," + groupSize + "}((" + escapedGroupSeparator + "\\d{" + groupSize + "})?)+)$");
  2068. }
  2069. },
  2070. alias: "decimal"
  2071. }
  2072. });
  2073. })(jQuery);
  2074. /*
  2075. Input Mask plugin extensions
  2076. http://github.com/RobinHerbots/jquery.inputmask
  2077. Copyright (c) 2010 - 2013 Robin Herbots
  2078. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  2079. Version: 2.2.48
  2080. Regex extensions on the jquery.inputmask base
  2081. Allows for using regular expressions as a mask
  2082. */
  2083. (function ($) {
  2084. $.extend($.inputmask.defaults.aliases, { // $(selector).inputmask("Regex", { regex: "[0-9]*"}
  2085. 'Regex': {
  2086. mask: "r",
  2087. greedy: false,
  2088. repeat: 10, //needs to be computed
  2089. regex: null,
  2090. regexSplit: null,
  2091. definitions: {
  2092. 'r': {
  2093. validator: function (chrs, buffer, pos, strict, opts) {
  2094. function analyseRegex() { //ENHANCE ME
  2095. var regexSplitRegex = "\\[.*?\]\\*";
  2096. opts.regexSplit = opts.regex.match(new RegExp(regexSplitRegex, "g"));
  2097. //if (opts.regex.indexOf("*") != (opts.regex.length - 1)) {
  2098. // opts.regex += "{1}";
  2099. //}
  2100. //opts.regexSplit.push(opts.regex);
  2101. }
  2102. if (opts.regexSplit == null) {
  2103. analyseRegex();
  2104. }
  2105. var cbuffer = buffer.slice(), regexPart = "", isValid = false;
  2106. cbuffer.splice(pos, 0, chrs);
  2107. var bufferStr = cbuffer.join('');
  2108. for (var i = 0; i < opts.regexSplit.length; i++) {
  2109. regexPart += opts.regexSplit[i];
  2110. var exp = new RegExp("^" + regexPart + "$");
  2111. isValid = exp.test(bufferStr);
  2112. console.log(bufferStr + ' ' + isValid + ' ' + regexPart);
  2113. if (isValid) break;
  2114. }
  2115. return isValid;
  2116. },
  2117. cardinality: 1
  2118. }
  2119. }
  2120. }
  2121. });
  2122. })(jQuery);