jquery.inputmask.bundle.js 162 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173
  1. /**
  2. * @license Input Mask plugin for jquery
  3. * http://github.com/RobinHerbots/jquery.inputmask
  4. * Copyright (c) 2010 - 2014 Robin Herbots
  5. * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. * Version: 3.0.46
  7. */
  8. (function ($) {
  9. if ($.fn.inputmask === undefined) {
  10. //helper functions
  11. function isInputEventSupported(eventName) {
  12. var el = document.createElement('input'),
  13. eventName = 'on' + eventName,
  14. isSupported = (eventName in el);
  15. if (!isSupported) {
  16. el.setAttribute(eventName, 'return;');
  17. isSupported = typeof el[eventName] == 'function';
  18. }
  19. el = null;
  20. return isSupported;
  21. }
  22. function resolveAlias(aliasStr, options, opts) {
  23. var aliasDefinition = opts.aliases[aliasStr];
  24. if (aliasDefinition) {
  25. if (aliasDefinition.alias) resolveAlias(aliasDefinition.alias, undefined, opts); //alias is another alias
  26. $.extend(true, opts, aliasDefinition); //merge alias definition in the options
  27. $.extend(true, opts, options); //reapply extra given options
  28. return true;
  29. }
  30. return false;
  31. }
  32. function generateMaskSet(opts) {
  33. var ms = [];
  34. function analyseMask(mask) {
  35. var tokenizer = /(?:[?*+]|\{[0-9\+\*]+(?:,[0-9\+\*]*)?\})\??|[^.?*+^${[]()|\\]+|./g,
  36. escaped = false;
  37. function maskToken(isGroup, isOptional, isQuantifier, isAlternator) {
  38. this.matches = [];
  39. this.isGroup = isGroup || false;
  40. this.isOptional = isOptional || false;
  41. this.isQuantifier = isQuantifier || false;
  42. this.isAlternator = isAlternator || false;
  43. this.quantifier = { min: 1, max: 1 };
  44. };
  45. //test definition => {fn: RegExp/function, cardinality: int, optionality: bool, newBlockMarker: bool, offset: int, casing: null/upper/lower, def: definitionSymbol, placeholder: placeholder}
  46. function insertTestDefinition(mtoken, element, position) {
  47. var maskdef = opts.definitions[element];
  48. var newBlockMarker = mtoken.matches.length == 0;
  49. position = position != undefined ? position : mtoken.matches.length;
  50. if (maskdef && !escaped) {
  51. var prevalidators = maskdef["prevalidator"], prevalidatorsL = prevalidators ? prevalidators.length : 0;
  52. for (var i = 1; i < maskdef.cardinality; i++) {
  53. var prevalidator = prevalidatorsL >= i ? prevalidators[i - 1] : [], validator = prevalidator["validator"], cardinality = prevalidator["cardinality"];
  54. mtoken.matches.splice(position++, 0, { fn: validator ? typeof validator == 'string' ? new RegExp(validator) : new function () { this.test = validator; } : new RegExp("."), cardinality: cardinality ? cardinality : 1, optionality: mtoken.isOptional, newBlockMarker: newBlockMarker, casing: maskdef["casing"], def: maskdef["definitionSymbol"] || element, placeholder: maskdef["placeholder"] });
  55. }
  56. mtoken.matches.splice(position++, 0, { fn: maskdef.validator ? typeof maskdef.validator == 'string' ? new RegExp(maskdef.validator) : new function () { this.test = maskdef.validator; } : new RegExp("."), cardinality: maskdef.cardinality, optionality: mtoken.isOptional, newBlockMarker: newBlockMarker, casing: maskdef["casing"], def: maskdef["definitionSymbol"] || element, placeholder: maskdef["placeholder"] });
  57. } else {
  58. mtoken.matches.splice(position++, 0, { fn: null, cardinality: 0, optionality: mtoken.isOptional, newBlockMarker: newBlockMarker, casing: null, def: element, placeholder: undefined });
  59. escaped = false;
  60. }
  61. }
  62. var currentToken = new maskToken(),
  63. match,
  64. m,
  65. openenings = [],
  66. maskTokens = [];
  67. while (match = tokenizer.exec(mask)) {
  68. m = match[0];
  69. switch (m.charAt(0)) {
  70. case opts.optionalmarker.end:
  71. // optional closing
  72. case opts.groupmarker.end:
  73. // Group closing
  74. var openingToken = openenings.pop();
  75. if (openenings.length > 0) {
  76. openenings[openenings.length - 1]["matches"].push(openingToken);
  77. } else {
  78. currentToken.matches.push(openingToken);
  79. }
  80. break;
  81. case opts.optionalmarker.start:
  82. // optional opening
  83. openenings.push(new maskToken(false, true));
  84. break;
  85. case opts.groupmarker.start:
  86. // Group opening
  87. openenings.push(new maskToken(true));
  88. break;
  89. case opts.quantifiermarker.start:
  90. //Quantifier
  91. var quantifier = new maskToken(false, false, true);
  92. m = m.replace(/[{}]/g, "");
  93. var mq = m.split(","),
  94. mq0 = isNaN(mq[0]) ? mq[0] : parseInt(mq[0]),
  95. mq1 = mq.length == 1 ? mq0 : (isNaN(mq[1]) ? mq[1] : parseInt(mq[1]));
  96. if (mq1 == "*" || mq1 == "+") {
  97. mq0 = mq1 == "*" ? 0 : 1;
  98. }
  99. quantifier.quantifier = { min: mq0, max: mq1 };
  100. if (openenings.length > 0) {
  101. var matches = openenings[openenings.length - 1]["matches"];
  102. var match = matches.pop();
  103. if (!match["isGroup"]) {
  104. var groupToken = new maskToken(true);
  105. groupToken.matches.push(match);
  106. match = groupToken;
  107. }
  108. matches.push(match);
  109. matches.push(quantifier);
  110. } else {
  111. var match = currentToken.matches.pop();
  112. if (!match["isGroup"]) {
  113. var groupToken = new maskToken(true);
  114. groupToken.matches.push(match);
  115. match = groupToken;
  116. }
  117. currentToken.matches.push(match);
  118. currentToken.matches.push(quantifier);
  119. }
  120. break;
  121. case opts.escapeChar:
  122. escaped = true;
  123. break;
  124. case opts.alternatormarker:
  125. break;
  126. default:
  127. if (openenings.length > 0) {
  128. insertTestDefinition(openenings[openenings.length - 1], m);
  129. } else {
  130. if (currentToken.matches.length > 0) {
  131. var lastMatch = currentToken.matches[currentToken.matches.length - 1];
  132. if (lastMatch["isGroup"]) { //this is not a group but a normal mask => convert
  133. lastMatch.isGroup = false;
  134. insertTestDefinition(lastMatch, opts.groupmarker.start, 0);
  135. insertTestDefinition(lastMatch, opts.groupmarker.end);
  136. }
  137. }
  138. insertTestDefinition(currentToken, m);
  139. }
  140. }
  141. }
  142. if (currentToken.matches.length > 0) {
  143. var lastMatch = currentToken.matches[currentToken.matches.length - 1];
  144. if (lastMatch["isGroup"]) { //this is not a group but a normal mask => convert
  145. lastMatch.isGroup = false;
  146. insertTestDefinition(lastMatch, opts.groupmarker.start, 0);
  147. insertTestDefinition(lastMatch, opts.groupmarker.end);
  148. }
  149. maskTokens.push(currentToken);
  150. }
  151. //console.log(JSON.stringify(maskTokens));
  152. return maskTokens;
  153. }
  154. function generateMask(mask, metadata) {
  155. if (opts.numericInput && opts.multi !== true) { //TODO FIX FOR DYNAMIC MASKS WITH QUANTIFIERS
  156. mask = mask.split('').reverse();
  157. for (var ndx = 0; ndx < mask.length; ndx++) {
  158. if (mask[ndx] == opts.optionalmarker.start)
  159. mask[ndx] = opts.optionalmarker.end;
  160. else if (mask[ndx] == opts.optionalmarker.end)
  161. mask[ndx] = opts.optionalmarker.start;
  162. else if (mask[ndx] == opts.groupmarker.start)
  163. mask[ndx] = opts.groupmarker.end;
  164. else if (mask[ndx] == opts.groupmarker.end)
  165. mask[ndx] = opts.groupmarker.start;
  166. }
  167. mask = mask.join('');
  168. }
  169. if (mask == undefined || mask == "")
  170. return undefined;
  171. else {
  172. if (opts.repeat > 0 || opts.repeat == "*" || opts.repeat == "+") {
  173. var repeatStart = opts.repeat == "*" ? 0 : (opts.repeat == "+" ? 1 : opts.repeat);
  174. mask = opts.groupmarker.start + mask + opts.groupmarker.end + opts.quantifiermarker.start + repeatStart + "," + opts.repeat + opts.quantifiermarker.end;
  175. }
  176. if ($.inputmask.masksCache[mask] == undefined) {
  177. $.inputmask.masksCache[mask] = {
  178. "mask": mask,
  179. "maskToken": analyseMask(mask),
  180. "validPositions": {},
  181. "_buffer": undefined,
  182. "buffer": undefined,
  183. "tests": {},
  184. "metadata": metadata
  185. };
  186. }
  187. return $.extend(true, {}, $.inputmask.masksCache[mask]);
  188. }
  189. }
  190. if ($.isFunction(opts.mask)) { //allow mask to be a preprocessing fn - should return a valid mask
  191. opts.mask = opts.mask.call(this, opts);
  192. }
  193. if ($.isArray(opts.mask)) {
  194. $.each(opts.mask, function (ndx, msk) {
  195. if (msk["mask"] != undefined) {
  196. ms.push(generateMask(msk["mask"].toString(), msk));
  197. } else {
  198. ms.push(generateMask(msk.toString()));
  199. }
  200. });
  201. } else {
  202. if (opts.mask.length == 1 && opts.greedy == false && opts.repeat != 0) {
  203. opts.placeholder = "";
  204. } //hide placeholder with single non-greedy mask
  205. if (opts.mask["mask"] != undefined) {
  206. ms = generateMask(opts.mask["mask"].toString(), opts.mask);
  207. } else {
  208. ms = generateMask(opts.mask.toString());
  209. }
  210. }
  211. return ms;
  212. }
  213. var msie1x = typeof ScriptEngineMajorVersion === "function"
  214. ? ScriptEngineMajorVersion() //IE11 detection
  215. : new Function("/*@cc_on return @_jscript_version; @*/")() >= 10, //conditional compilation from mickeysoft trick
  216. ua = navigator.userAgent,
  217. iphone = ua.match(new RegExp("iphone", "i")) !== null,
  218. android = ua.match(new RegExp("android.*safari.*", "i")) !== null,
  219. androidchrome = ua.match(new RegExp("android.*chrome.*", "i")) !== null,
  220. androidfirefox = ua.match(new RegExp("android.*firefox.*", "i")) !== null,
  221. kindle = /Kindle/i.test(ua) || /Silk/i.test(ua) || /KFTT/i.test(ua) || /KFOT/i.test(ua) || /KFJWA/i.test(ua) || /KFJWI/i.test(ua) || /KFSOWI/i.test(ua) || /KFTHWA/i.test(ua) || /KFTHWI/i.test(ua) || /KFAPWA/i.test(ua) || /KFAPWI/i.test(ua),
  222. PasteEventType = isInputEventSupported('paste') ? 'paste' : isInputEventSupported('input') ? 'input' : "propertychange";
  223. //if (androidchrome) {
  224. // var browser = navigator.userAgent.match(new RegExp("chrome.*", "i")),
  225. // version = parseInt(new RegExp(/[0-9]+/).exec(browser));
  226. // androidchrome32 = (version == 32);
  227. //}
  228. //masking scope
  229. //actionObj definition see below
  230. function maskScope(actionObj, maskset, opts) {
  231. var isRTL = false,
  232. valueOnFocus,
  233. $el,
  234. skipKeyPressEvent = false, //Safari 5.1.x - modal dialog fires keypress twice workaround
  235. skipInputEvent = false, //skip when triggered from within inputmask
  236. ignorable = false,
  237. maxLength;
  238. //maskset helperfunctions
  239. function getMaskTemplate(baseOnInput, minimalPos, includeInput) {
  240. minimalPos = minimalPos || 0;
  241. var maskTemplate = [], ndxIntlzr, pos = 0, test, testPos;
  242. do {
  243. if (baseOnInput === true && getMaskSet()['validPositions'][pos]) {
  244. var validPos = getMaskSet()['validPositions'][pos];
  245. test = validPos["match"];
  246. ndxIntlzr = validPos["locator"].slice();
  247. maskTemplate.push(test["fn"] == null ? test["def"] : (includeInput === true ? validPos["input"] : test["placeholder"] || opts.placeholder.charAt(pos % opts.placeholder.length)));
  248. } else {
  249. if (minimalPos > pos) {
  250. var testPositions = getTests(pos, ndxIntlzr, pos - 1);
  251. testPos = testPositions[0];
  252. } else {
  253. testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
  254. }
  255. test = testPos["match"];
  256. ndxIntlzr = testPos["locator"].slice();
  257. maskTemplate.push(test["fn"] == null ? test["def"] : test["placeholder"] || opts.placeholder.charAt(pos % opts.placeholder.length));
  258. }
  259. pos++;
  260. } while ((maxLength == undefined || pos - 1 < maxLength) && test["fn"] != null || (test["fn"] == null && test["def"] != "") || minimalPos >= pos);
  261. maskTemplate.pop(); //drop the last one which is empty
  262. return maskTemplate;
  263. }
  264. function getMaskSet() {
  265. return maskset;
  266. }
  267. function resetMaskSet(soft) {
  268. var maskset = getMaskSet();
  269. maskset["buffer"] = undefined;
  270. maskset["tests"] = {};
  271. if (soft !== true) {
  272. maskset["_buffer"] = undefined;
  273. maskset["validPositions"] = {};
  274. maskset["p"] = -1;
  275. }
  276. }
  277. function getLastValidPosition(closestTo) {
  278. var maskset = getMaskSet(), lastValidPosition = -1, valids = maskset["validPositions"];
  279. if ($.isFunction(opts.getLastValidPosition))
  280. lastValidPosition = opts.getLastValidPosition.call($el, maskset, closestTo, opts);
  281. else {
  282. if (closestTo == undefined) closestTo = -1;
  283. var before = lastValidPosition, after = lastValidPosition;
  284. for (var posNdx in valids) {
  285. var psNdx = parseInt(posNdx);
  286. if (closestTo == -1 || valids[psNdx]["match"].fn != null) {
  287. if (psNdx < closestTo) before = psNdx;
  288. if (psNdx >= closestTo) after = psNdx;
  289. }
  290. }
  291. lastValidPosition = (closestTo - before) > 1 || after < closestTo ? before : after;
  292. }
  293. return lastValidPosition;
  294. }
  295. function setValidPosition(pos, validTest, fromSetValid) {
  296. if (opts.insertMode && getMaskSet()["validPositions"][pos] != undefined && fromSetValid == undefined) {
  297. //reposition & revalidate others
  298. var positionsClone = $.extend(true, {}, getMaskSet()["validPositions"]), lvp = getLastValidPosition(), i;
  299. for (i = pos; i <= lvp; i++) { //clear selection
  300. delete getMaskSet()["validPositions"][i];
  301. }
  302. getMaskSet()["validPositions"][pos] = validTest;
  303. var valid = true;
  304. for (i = pos; i <= lvp ; i++) {
  305. var t = positionsClone[i];
  306. if (t != undefined) {
  307. var j = t["match"].fn == null ? i + 1 : seekNext(i);
  308. if (positionCanMatchDefinition(j, t["match"].def)) {
  309. valid = valid && isValid(j, t["input"], true, true) !== false;
  310. } else valid = false;
  311. }
  312. if (!valid) break;
  313. }
  314. if (!valid) {
  315. getMaskSet()["validPositions"] = $.extend(true, {}, positionsClone);
  316. return false;
  317. }
  318. } else
  319. getMaskSet()["validPositions"][pos] = validTest;
  320. return true;
  321. }
  322. function stripValidPositions(start, end) {
  323. var i, startPos = start, lvp;
  324. for (i = start; i < end; i++) { //clear selection
  325. //TODO FIXME BETTER CHECK
  326. delete getMaskSet()["validPositions"][i];
  327. }
  328. for (i = end ; i <= getLastValidPosition() ;) {
  329. var t = getMaskSet()["validPositions"][i];
  330. var s = getMaskSet()["validPositions"][startPos];
  331. if (t != undefined && s == undefined) {
  332. if (positionCanMatchDefinition(startPos, t.match.def) && isValid(startPos, t["input"], true) !== false) {
  333. delete getMaskSet()["validPositions"][i];
  334. i++;
  335. }
  336. startPos++;
  337. } else i++;
  338. }
  339. lvp = getLastValidPosition();
  340. //catchup
  341. while (lvp > 0 && (getMaskSet()["validPositions"][lvp] == undefined || getMaskSet()["validPositions"][lvp].match.fn == null)) {
  342. delete getMaskSet()["validPositions"][lvp];
  343. lvp--;
  344. }
  345. resetMaskSet(true);
  346. }
  347. function getTestTemplate(pos, ndxIntlzr, tstPs) {
  348. var testPositions = getTests(pos, ndxIntlzr, tstPs), testPos;
  349. for (var ndx = 0; ndx < testPositions.length; ndx++) {
  350. testPos = testPositions[ndx];
  351. if (opts.greedy || (testPos["match"] && (testPos["match"].optionality === false || testPos["match"].newBlockMarker === false) && testPos["match"].optionalQuantifier !== true)) {
  352. break;
  353. }
  354. }
  355. return testPos;
  356. }
  357. function getTest(pos) {
  358. if (getMaskSet()['validPositions'][pos]) {
  359. return getMaskSet()['validPositions'][pos]["match"];
  360. }
  361. return getTests(pos)[0]["match"];
  362. }
  363. function positionCanMatchDefinition(pos, def) {
  364. var valid = false, tests = getTests(pos);
  365. for (var tndx = 0; tndx < tests.length; tndx++) {
  366. if (tests[tndx]["match"] && tests[tndx]["match"].def == def) {
  367. valid = true;
  368. break;
  369. }
  370. }
  371. return valid;
  372. };
  373. function getTests(pos, ndxIntlzr, tstPs) {
  374. var maskTokens = getMaskSet()["maskToken"], testPos = ndxIntlzr ? tstPs : 0, ndxInitializer = ndxIntlzr || [0], matches = [], insertStop = false;
  375. function ResolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) { //ndxInitilizer contains a set of indexes to speedup searches in the mtokens
  376. function handleMatch(match, loopNdx, quantifierRecurse) {
  377. if (testPos == pos && match.matches == undefined) {
  378. matches.push({ "match": match, "locator": loopNdx.reverse() });
  379. return true;
  380. } else if (match.matches != undefined) {
  381. if (match.isGroup && quantifierRecurse !== true) { //when a group pass along to the quantifier
  382. match = handleMatch(maskToken.matches[tndx + 1], loopNdx);
  383. if (match) return true;
  384. } else if (match.isOptional) {
  385. var optionalToken = match;
  386. match = ResolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse);
  387. if (match) {
  388. var latestMatch = matches[matches.length - 1]["match"];
  389. var isFirstMatch = $.inArray(latestMatch, optionalToken.matches) == 0;
  390. if (isFirstMatch) {
  391. insertStop = true; //insert a stop for non greedy
  392. }
  393. testPos = pos; //match the position after the group
  394. }
  395. } else if (match.isAlternator) {
  396. //TODO
  397. } else if (match.isQuantifier && quantifierRecurse !== true) {
  398. var qt = match;
  399. opts.greedy = opts.greedy && isFinite(qt.quantifier.max); //greedy must be off when * or + is used (always!!)
  400. for (var qndx = (ndxInitializer.length > 0 && quantifierRecurse !== true) ? ndxInitializer.shift() : 0; (qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max)) && testPos <= pos; qndx++) {
  401. var tokenGroup = maskToken.matches[$.inArray(qt, maskToken.matches) - 1];
  402. match = handleMatch(tokenGroup, [qndx].concat(loopNdx), true);
  403. if (match) {
  404. //get latest match
  405. var latestMatch = matches[matches.length - 1]["match"];
  406. latestMatch.optionalQuantifier = qndx > qt.quantifier.min - 1;
  407. var isFirstMatch = $.inArray(latestMatch, tokenGroup.matches) == 0;
  408. if (isFirstMatch) { //search for next possible match
  409. if (qndx > qt.quantifier.min - 1) {
  410. insertStop = true;
  411. testPos = pos; //match the position after the group
  412. break; //stop quantifierloop
  413. } else return true;
  414. } else {
  415. return true;
  416. }
  417. }
  418. }
  419. } else {
  420. match = ResolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse);
  421. if (match)
  422. return true;
  423. }
  424. } else testPos++;
  425. }
  426. for (var tndx = (ndxInitializer.length > 0 ? ndxInitializer.shift() : 0) ; tndx < maskToken.matches.length; tndx++) {
  427. if (maskToken.matches[tndx]["isQuantifier"] !== true) {
  428. var match = handleMatch(maskToken.matches[tndx], [tndx].concat(loopNdx), quantifierRecurse);
  429. if (match && testPos == pos) {
  430. return match;
  431. } else if (testPos > pos) {
  432. break;
  433. }
  434. }
  435. }
  436. }
  437. //if (disableCache !== true && getMaskSet()['tests'][pos] && !getMaskSet()['validPositions'][pos]) {
  438. // return getMaskSet()['tests'][pos];
  439. //}
  440. if (ndxIntlzr == undefined) {
  441. var previousPos = pos - 1, test;
  442. while ((test = getMaskSet()['validPositions'][previousPos]) == undefined && previousPos > -1) {
  443. previousPos--;
  444. }
  445. if (test != undefined && previousPos > -1) {
  446. testPos = previousPos;
  447. ndxInitializer = test["locator"].slice();
  448. } else {
  449. previousPos = pos - 1;
  450. while ((test = getMaskSet()['tests'][previousPos]) == undefined && previousPos > -1) {
  451. previousPos--;
  452. }
  453. if (test != undefined && previousPos > -1) {
  454. testPos = previousPos;
  455. ndxInitializer = test[0]["locator"].slice();
  456. }
  457. }
  458. }
  459. for (var mtndx = ndxInitializer.shift() ; mtndx < maskTokens.length; mtndx++) {
  460. var match = ResolveTestFromToken(maskTokens[mtndx], ndxInitializer, [mtndx]);
  461. if ((match && testPos == pos) || testPos > pos) {
  462. break;
  463. }
  464. }
  465. if (matches.length == 0 || insertStop)
  466. matches.push({ "match": { fn: null, cardinality: 0, optionality: true, casing: null, def: "" }, "locator": [] });
  467. getMaskSet()['tests'][pos] = matches;
  468. //console.log(pos + " - " + JSON.stringify(matches));
  469. return matches;
  470. }
  471. function getBufferTemplate() {
  472. if (getMaskSet()['_buffer'] == undefined) {
  473. //generate template
  474. getMaskSet()["_buffer"] = getMaskTemplate(false, 1);
  475. }
  476. return getMaskSet()['_buffer'];
  477. }
  478. function getBuffer() {
  479. if (getMaskSet()['buffer'] == undefined) {
  480. getMaskSet()['buffer'] = getMaskTemplate(true, getLastValidPosition(), true);
  481. }
  482. return getMaskSet()['buffer'];
  483. }
  484. function refreshFromBuffer(start, end) {
  485. var buffer = getBuffer().slice(); //work on clone
  486. if (start === true) {
  487. resetMaskSet();
  488. start = 0;
  489. end = buffer.length;
  490. } else {
  491. for (var i = start; i < end; i++) {
  492. delete getMaskSet()["validPositions"][i];
  493. delete getMaskSet()["tests"][i];
  494. }
  495. }
  496. for (var i = start; i < end; i++) {
  497. if (buffer[i] != opts.skipOptionalPartCharacter) {
  498. isValid(i, buffer[i], true, true);
  499. }
  500. }
  501. }
  502. function casing(elem, test) {
  503. switch (test.casing) {
  504. case "upper":
  505. elem = elem.toUpperCase();
  506. break;
  507. case "lower":
  508. elem = elem.toLowerCase();
  509. break;
  510. }
  511. return elem;
  512. }
  513. function isValid(pos, c, strict, fromSetValid) { //strict true ~ no correction or autofill
  514. strict = strict === true; //always set a value to strict to prevent possible strange behavior in the extensions
  515. function _isValid(position, c, strict, fromSetValid) {
  516. var rslt = false;
  517. $.each(getTests(position), function (ndx, tst) {
  518. var test = tst["match"];
  519. var loopend = c ? 1 : 0, chrs = '', buffer = getBuffer();
  520. for (var i = test.cardinality; i > loopend; i--) {
  521. chrs += getBufferElement(position - (i - 1));
  522. }
  523. if (c) {
  524. chrs += c;
  525. }
  526. //return is false or a json object => { pos: ??, c: ??} or true
  527. rslt = test.fn != null ?
  528. test.fn.test(chrs, getMaskSet(), position, strict, opts)
  529. : (c == test["def"] || c == opts.skipOptionalPartCharacter) && test["def"] != "" ? //non mask
  530. { c: test["def"], pos: position }
  531. : false;
  532. if (rslt !== false) {
  533. var elem = rslt.c != undefined ? rslt.c : c;
  534. elem = (elem == opts.skipOptionalPartCharacter && test["fn"] === null) ? test["def"] : elem;
  535. var validatedPos = position;
  536. if (rslt["remove"] != undefined) { //remove position
  537. stripValidPositions(rslt["remove"], rslt["remove"] + 1);
  538. }
  539. if (rslt["refreshFromBuffer"]) {
  540. var refresh = rslt["refreshFromBuffer"];
  541. strict = true;
  542. refreshFromBuffer(refresh === true ? refresh : refresh["start"], refresh["end"]);
  543. if (rslt.pos == undefined && rslt.c == undefined) {
  544. rslt.pos = getLastValidPosition();
  545. return false;//breakout if refreshFromBuffer && nothing to insert
  546. }
  547. validatedPos = rslt.pos != undefined ? rslt.pos : position;
  548. if (validatedPos != position) {
  549. rslt = $.extend(rslt, isValid(validatedPos, elem, true)); //revalidate new position strict
  550. return false;
  551. }
  552. } else if (rslt !== true && rslt.pos != undefined && rslt["pos"] != position) { //their is a position offset
  553. validatedPos = rslt["pos"];
  554. refreshFromBuffer(position, validatedPos);
  555. if (validatedPos != position) {
  556. rslt = $.extend(rslt, isValid(validatedPos, elem, true)); //revalidate new position strict
  557. return false;
  558. }
  559. }
  560. if (rslt != true && rslt.pos == undefined && rslt.c == undefined) {
  561. return false; //breakout if nothing to insert
  562. }
  563. if (ndx > 0) {
  564. resetMaskSet(true);
  565. }
  566. if (!setValidPosition(validatedPos, $.extend({}, tst, { "input": casing(elem, test) }), fromSetValid))
  567. rslt = false;
  568. return false; //break from $.each
  569. }
  570. });
  571. return rslt;
  572. }
  573. //Check for a nonmask before the pos
  574. var buffer = getBuffer();
  575. for (var pndx = pos - 1; pndx > -1; pndx--) {
  576. if (getMaskSet()["validPositions"][pndx] && getMaskSet()["validPositions"][pndx].fn == null)
  577. break;
  578. else if ((!isMask(pndx) || buffer[pndx] != getPlaceholder(pndx)) && getTests(pndx).length > 1) {
  579. _isValid(pndx, buffer[pndx], true);
  580. break;
  581. }
  582. }
  583. var maskPos = pos;
  584. if (maskPos >= getMaskLength()) return false;
  585. var result = _isValid(maskPos, c, strict, fromSetValid);
  586. if (!strict && result === false) {
  587. var currentPosValid = getMaskSet()["validPositions"][maskPos];
  588. if (currentPosValid && currentPosValid["match"].fn == null && (currentPosValid["match"].def == c || c == opts.skipOptionalPartCharacter)) {
  589. result = { "caret": seekNext(maskPos) };
  590. } else if ((opts.insertMode || getMaskSet()["validPositions"][seekNext(maskPos)] == undefined) && !isMask(maskPos)) { //does the input match on a further position?
  591. for (var nPos = maskPos + 1, snPos = seekNext(maskPos) ; nPos <= snPos; nPos++) {
  592. result = _isValid(nPos, c, strict, fromSetValid);
  593. if (result !== false) {
  594. maskPos = nPos;
  595. break;
  596. }
  597. }
  598. }
  599. }
  600. if (result === true) result = { "pos": maskPos };
  601. return result;
  602. }
  603. function isMask(pos) {
  604. var test = getTest(pos);
  605. return test.fn != null ? test.fn : false;
  606. }
  607. function getMaskLength() {
  608. var maskLength;
  609. maxLength = $el.prop('maxLength');
  610. if (maxLength == -1) maxLength = undefined; /* FF sets no defined max length to -1 */
  611. if (opts.greedy == false) {
  612. var pos, lvp = getLastValidPosition(), testPos = getMaskSet()["validPositions"][lvp],
  613. ndxIntlzr = testPos != undefined ? testPos["locator"].slice() : undefined;
  614. for (pos = lvp + 1; testPos == undefined || (testPos["match"]["fn"] != null || (testPos["match"]["fn"] == null && testPos["match"]["def"] != "")) ; pos++) {
  615. testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
  616. ndxIntlzr = testPos["locator"].slice();
  617. }
  618. maskLength = pos;
  619. } else
  620. maskLength = getBuffer().length;
  621. return (maxLength == undefined || maskLength < maxLength) ? maskLength : maxLength;
  622. }
  623. function seekNext(pos) {
  624. var maskL = getMaskLength();
  625. if (pos >= maskL) return maskL;
  626. var position = pos;
  627. while (++position < maskL && !isMask(position) && (opts.nojumps !== true || opts.nojumpsThreshold > position)) {
  628. }
  629. return position;
  630. }
  631. function seekPrevious(pos) {
  632. var position = pos;
  633. if (position <= 0) return 0;
  634. while (--position > 0 && !isMask(position)) {
  635. };
  636. return position;
  637. }
  638. function getBufferElement(position) {
  639. return getMaskSet()["validPositions"][position] == undefined ? getPlaceholder(position) : getMaskSet()["validPositions"][position]["input"];
  640. }
  641. function writeBuffer(input, buffer, caretPos) {
  642. input._valueSet(buffer.join(''));
  643. if (caretPos != undefined) {
  644. caret(input, caretPos);
  645. }
  646. }
  647. function getPlaceholder(pos, test) {
  648. test = test || getTest(pos);
  649. return test["placeholder"] || (test["fn"] == null ? test["def"] : opts.placeholder.charAt(pos % opts.placeholder.length));
  650. }
  651. function checkVal(input, writeOut, strict, nptvl, intelliCheck) {
  652. var inputValue = nptvl != undefined ? nptvl.slice() : truncateInput(input._valueGet()).split('');
  653. resetMaskSet();
  654. if (writeOut) input._valueSet(""); //initial clear
  655. $.each(inputValue, function (ndx, charCode) {
  656. if (intelliCheck === true) {
  657. var p = getMaskSet()["p"],
  658. lvp = p == -1 ? p : seekPrevious(p),
  659. pos = lvp == -1 ? ndx : seekNext(lvp);
  660. if ($.inArray(charCode, getBufferTemplate().slice(lvp + 1, pos)) == -1) {
  661. keypressEvent.call(input, undefined, true, charCode.charCodeAt(0), false, strict, ndx);
  662. }
  663. } else {
  664. keypressEvent.call(input, undefined, true, charCode.charCodeAt(0), false, strict, ndx);
  665. strict = strict || (ndx > 0 && ndx > getMaskSet()["p"]);
  666. }
  667. });
  668. if (writeOut)
  669. writeBuffer(input, getBuffer(), $(input).is(":focus") ? seekNext(getLastValidPosition(0)) : undefined);
  670. }
  671. function escapeRegex(str) {
  672. return $.inputmask.escapeRegex.call(this, str);
  673. }
  674. function truncateInput(inputValue) {
  675. return inputValue.replace(new RegExp("(" + escapeRegex(getBufferTemplate().join('')) + ")*$"), "");
  676. }
  677. function unmaskedvalue($input, skipDatepickerCheck) {
  678. if ($input.data('_inputmask') && (skipDatepickerCheck === true || !$input.hasClass('hasDatepicker'))) {
  679. var umValue = [], vps = getMaskSet()["validPositions"];
  680. for (var pndx in vps) {
  681. if (vps[pndx]["match"] && vps[pndx]["match"].fn != null) {
  682. umValue.push(vps[pndx]["input"]);
  683. }
  684. }
  685. var unmaskedValue = (isRTL ? umValue.reverse() : umValue).join('');
  686. var bufferValue = (isRTL ? getBuffer().reverse() : getBuffer()).join('');
  687. return $.isFunction(opts.onUnMask) ? opts.onUnMask.call($input, bufferValue, unmaskedValue, opts) : unmaskedValue;
  688. } else {
  689. return $input[0]._valueGet();
  690. }
  691. }
  692. function TranslatePosition(pos) {
  693. if (isRTL && typeof pos == 'number' && (!opts.greedy || opts.placeholder != "")) {
  694. var bffrLght = getBuffer().length;
  695. pos = bffrLght - pos;
  696. }
  697. return pos;
  698. }
  699. function caret(input, begin, end) {
  700. var npt = input.jquery && input.length > 0 ? input[0] : input, range;
  701. if (typeof begin == 'number') {
  702. begin = TranslatePosition(begin);
  703. end = TranslatePosition(end);
  704. end = (typeof end == 'number') ? end : begin;
  705. //store caret for multi scope
  706. var data = $(npt).data('_inputmask') || {};
  707. data["caret"] = { "begin": begin, "end": end };
  708. $(npt).data('_inputmask', data);
  709. if (!$(npt).is(":visible")) {
  710. return;
  711. }
  712. npt.scrollLeft = npt.scrollWidth;
  713. if (opts.insertMode == false && begin == end) end++; //set visualization for insert/overwrite mode
  714. if (npt.setSelectionRange) {
  715. npt.selectionStart = begin;
  716. npt.selectionEnd = end;
  717. } else if (npt.createTextRange) {
  718. range = npt.createTextRange();
  719. range.collapse(true);
  720. range.moveEnd('character', end);
  721. range.moveStart('character', begin);
  722. range.select();
  723. }
  724. } else {
  725. var data = $(npt).data('_inputmask');
  726. if (!$(npt).is(":visible") && data && data["caret"] != undefined) {
  727. begin = data["caret"]["begin"];
  728. end = data["caret"]["end"];
  729. } else if (npt.setSelectionRange) {
  730. begin = npt.selectionStart;
  731. end = npt.selectionEnd;
  732. } else if (document.selection && document.selection.createRange) {
  733. range = document.selection.createRange();
  734. begin = 0 - range.duplicate().moveStart('character', -100000);
  735. end = begin + range.text.length;
  736. }
  737. begin = TranslatePosition(begin);
  738. end = TranslatePosition(end);
  739. return { "begin": begin, "end": end };
  740. }
  741. }
  742. function determineLastRequiredPosition(returnDefinition) {
  743. var buffer = getBuffer(), bl = buffer.length,
  744. pos, lvp = getLastValidPosition(), positions = {},
  745. ndxIntlzr = getMaskSet()["validPositions"][lvp] != undefined ? getMaskSet()["validPositions"][lvp]["locator"].slice() : undefined, testPos;
  746. for (pos = lvp + 1; pos < buffer.length; pos++) {
  747. testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
  748. ndxIntlzr = testPos["locator"].slice();
  749. positions[pos] = $.extend(true, {}, testPos);
  750. }
  751. for (pos = bl - 1; pos > lvp; pos--) {
  752. testPos = positions[pos]["match"];
  753. if ((testPos.optionality || testPos.optionalQuantifier) && buffer[pos] == getPlaceholder(pos, testPos)) {
  754. bl--;
  755. } else break;
  756. }
  757. return returnDefinition ? { "l": bl, "def": positions[bl] ? positions[bl]["match"] : undefined } : bl;
  758. }
  759. function clearOptionalTail(input) {
  760. var buffer = getBuffer(), tmpBuffer = buffer.slice();
  761. var rl = determineLastRequiredPosition();
  762. tmpBuffer.length = rl;
  763. writeBuffer(input, tmpBuffer);
  764. }
  765. function isComplete(buffer) { //return true / false / undefined (repeat *)
  766. if ($.isFunction(opts.isComplete)) return opts.isComplete.call($el, buffer, opts);
  767. if (opts.repeat == "*") return undefined;
  768. var complete = false, lrp = determineLastRequiredPosition(true), aml = seekPrevious(lrp["l"]), lvp = getLastValidPosition();
  769. if (lvp == aml) {
  770. if (lrp["def"] == undefined || lrp["def"].newBlockMarker || lrp["def"].optionalQuantifier) {
  771. complete = true;
  772. for (var i = 0; i <= aml; i++) {
  773. var mask = isMask(i);
  774. if ((mask && (buffer[i] == undefined || buffer[i] == getPlaceholder(i))) || (!mask && buffer[i] != getPlaceholder(i))) {
  775. complete = false;
  776. break;
  777. }
  778. }
  779. }
  780. }
  781. return complete;
  782. }
  783. function isSelection(begin, end) {
  784. return isRTL ? (begin - end) > 1 || ((begin - end) == 1 && opts.insertMode) :
  785. (end - begin) > 1 || ((end - begin) == 1 && opts.insertMode);
  786. }
  787. function installEventRuler(npt) {
  788. var events = $._data(npt).events;
  789. $.each(events, function (eventType, eventHandlers) {
  790. $.each(eventHandlers, function (ndx, eventHandler) {
  791. if (eventHandler.namespace == "inputmask") {
  792. if (eventHandler.type != "setvalue") {
  793. var handler = eventHandler.handler;
  794. eventHandler.handler = function (e) {
  795. if (this.readOnly || this.disabled)
  796. e.preventDefault;
  797. else
  798. return handler.apply(this, arguments);
  799. };
  800. }
  801. }
  802. });
  803. });
  804. }
  805. function patchValueProperty(npt) {
  806. function PatchValhook(type) {
  807. if ($.valHooks[type] == undefined || $.valHooks[type].inputmaskpatch != true) {
  808. var valueGet = $.valHooks[type] && $.valHooks[type].get ? $.valHooks[type].get : function (elem) { return elem.value; };
  809. var valueSet = $.valHooks[type] && $.valHooks[type].set ? $.valHooks[type].set : function (elem, value) {
  810. elem.value = value;
  811. return elem;
  812. };
  813. $.valHooks[type] = {
  814. get: function (elem) {
  815. var $elem = $(elem);
  816. if ($elem.data('_inputmask')) {
  817. if ($elem.data('_inputmask')['opts'].autoUnmask)
  818. return $elem.inputmask('unmaskedvalue');
  819. else {
  820. var result = valueGet(elem),
  821. inputData = $elem.data('_inputmask'),
  822. maskset = inputData['maskset'],
  823. bufferTemplate = maskset['_buffer'];
  824. bufferTemplate = bufferTemplate ? bufferTemplate.join('') : '';
  825. return result != bufferTemplate ? result : '';
  826. }
  827. } else return valueGet(elem);
  828. },
  829. set: function (elem, value) {
  830. var $elem = $(elem), inputData = $elem.data('_inputmask'), result;
  831. if (inputData) {
  832. result = valueSet(elem, $.isFunction(inputData['opts'].onBeforeMask) ? inputData['opts'].onBeforeMask.call(el, value, inputData['opts']) : value);
  833. $elem.triggerHandler('setvalue.inputmask');
  834. } else {
  835. result = valueSet(elem, value);
  836. }
  837. return result;
  838. },
  839. inputmaskpatch: true
  840. };
  841. }
  842. }
  843. var valueProperty;
  844. if (Object.getOwnPropertyDescriptor)
  845. valueProperty = Object.getOwnPropertyDescriptor(npt, "value");
  846. if (valueProperty && valueProperty.get) {
  847. if (!npt._valueGet) {
  848. var valueGet = valueProperty.get;
  849. var valueSet = valueProperty.set;
  850. npt._valueGet = function () {
  851. return isRTL ? valueGet.call(this).split('').reverse().join('') : valueGet.call(this);
  852. };
  853. npt._valueSet = function (value) {
  854. valueSet.call(this, isRTL ? value.split('').reverse().join('') : value);
  855. };
  856. Object.defineProperty(npt, "value", {
  857. get: function () {
  858. var $self = $(this), inputData = $(this).data('_inputmask');
  859. if (inputData) {
  860. return inputData['opts'].autoUnmask ? $self.inputmask('unmaskedvalue') : (valueGet.call(this) != getBufferTemplate().join('') ? valueGet.call(this) : '');
  861. } else return valueGet.call(this);
  862. },
  863. set: function (value) {
  864. var inputData = $(this).data('_inputmask');
  865. if (inputData) {
  866. valueSet.call(this, $.isFunction(inputData['opts'].onBeforeMask) ? inputData['opts'].onBeforeMask.call(el, value, inputData['opts']) : value);
  867. $(this).triggerHandler('setvalue.inputmask');
  868. } else {
  869. valueSet.call(this, value);
  870. }
  871. }
  872. });
  873. }
  874. } else if (document.__lookupGetter__ && npt.__lookupGetter__("value")) {
  875. if (!npt._valueGet) {
  876. var valueGet = npt.__lookupGetter__("value");
  877. var valueSet = npt.__lookupSetter__("value");
  878. npt._valueGet = function () {
  879. return isRTL ? valueGet.call(this).split('').reverse().join('') : valueGet.call(this);
  880. };
  881. npt._valueSet = function (value) {
  882. valueSet.call(this, isRTL ? value.split('').reverse().join('') : value);
  883. };
  884. npt.__defineGetter__("value", function () {
  885. var $self = $(this), inputData = $(this).data('_inputmask');
  886. if (inputData) {
  887. return inputData['opts'].autoUnmask ? $self.inputmask('unmaskedvalue') : (valueGet.call(this) != getBufferTemplate().join('') ? valueGet.call(this) : '');
  888. } else return valueGet.call(this);
  889. });
  890. npt.__defineSetter__("value", function (value) {
  891. var inputData = $(this).data('_inputmask');
  892. if (inputData) {
  893. valueSet.call(this, $.isFunction(inputData['opts'].onBeforeMask) ? inputData['opts'].onBeforeMask.call(el, value, inputData['opts']) : value);
  894. $(this).triggerHandler('setvalue.inputmask');
  895. } else {
  896. valueSet.call(this, value);
  897. }
  898. });
  899. }
  900. } else {
  901. if (!npt._valueGet) {
  902. npt._valueGet = function () { return isRTL ? this.value.split('').reverse().join('') : this.value; };
  903. npt._valueSet = function (value) { this.value = isRTL ? value.split('').reverse().join('') : value; };
  904. }
  905. PatchValhook(npt.type);
  906. }
  907. }
  908. function handleRemove(input, k, pos) {
  909. if (opts.numericInput || isRTL) {
  910. switch (k) {
  911. case opts.keyCode.BACKSPACE:
  912. k = opts.keyCode.DELETE;
  913. break;
  914. case opts.keyCode.DELETE:
  915. k = opts.keyCode.BACKSPACE;
  916. break;
  917. }
  918. if (isRTL) {
  919. var pend = pos.end;
  920. pos.end = pos.begin;
  921. pos.begin = pend;
  922. }
  923. }
  924. if (pos.begin == pos.end) {
  925. if (k == opts.keyCode.BACKSPACE)
  926. pos.begin = seekPrevious(pos.begin);
  927. else if (k == opts.keyCode.DELETE)
  928. pos.end++;
  929. } else if (pos.end - pos.begin == 1 && !opts.insertMode) {
  930. if (k == opts.keyCode.BACKSPACE)
  931. pos.begin--;
  932. }
  933. stripValidPositions(pos.begin, pos.end);
  934. var firstMaskPos = seekNext(-1);
  935. if (getLastValidPosition() < firstMaskPos) {
  936. getMaskSet()["p"] = firstMaskPos;
  937. } else {
  938. getMaskSet()["p"] = pos.begin;
  939. }
  940. }
  941. function handleOnKeyResult(input, keyResult, caretPos) {
  942. if (keyResult && keyResult["refreshFromBuffer"]) {
  943. var refresh = keyResult["refreshFromBuffer"];
  944. refreshFromBuffer(refresh === true ? refresh : refresh["start"], refresh["end"]);
  945. resetMaskSet(true);
  946. writeBuffer(input, getBuffer());
  947. caret(input, keyResult.caret || caretPos.begin, keyResult.caret || caretPos.end);
  948. }
  949. }
  950. function keydownEvent(e) {
  951. //Safari 5.1.x - modal dialog fires keypress twice workaround
  952. skipKeyPressEvent = false;
  953. var input = this, $input = $(input), k = e.keyCode, pos = caret(input);
  954. //backspace, delete, and escape get special treatment
  955. if (k == opts.keyCode.BACKSPACE || k == opts.keyCode.DELETE || (iphone && k == 127) || e.ctrlKey && k == 88) { //backspace/delete
  956. e.preventDefault(); //stop default action but allow propagation
  957. if (k == 88) valueOnFocus = getBuffer().join('');
  958. handleRemove(input, k, pos);
  959. writeBuffer(input, getBuffer(), getMaskSet()["p"]);
  960. if (input._valueGet() == getBufferTemplate().join(''))
  961. $input.trigger('cleared');
  962. if (opts.showTooltip) { //update tooltip
  963. $input.prop("title", getMaskSet()["mask"]);
  964. }
  965. } else if (k == opts.keyCode.END || k == opts.keyCode.PAGE_DOWN) { //when END or PAGE_DOWN pressed set position at lastmatch
  966. setTimeout(function () {
  967. var caretPos = seekNext(getLastValidPosition());
  968. if (!opts.insertMode && caretPos == getMaskLength() && !e.shiftKey) caretPos--;
  969. caret(input, e.shiftKey ? pos.begin : caretPos, caretPos);
  970. }, 0);
  971. } else if ((k == opts.keyCode.HOME && !e.shiftKey) || k == opts.keyCode.PAGE_UP) { //Home or page_up
  972. caret(input, 0, e.shiftKey ? pos.begin : 0);
  973. } else if (k == opts.keyCode.ESCAPE || (k == 90 && e.ctrlKey)) { //escape && undo
  974. checkVal(input, true, false, valueOnFocus.split(''));
  975. $input.click();
  976. } else if (k == opts.keyCode.INSERT && !(e.shiftKey || e.ctrlKey)) { //insert
  977. opts.insertMode = !opts.insertMode;
  978. caret(input, !opts.insertMode && pos.begin == getMaskLength() ? pos.begin - 1 : pos.begin);
  979. } else if (opts.insertMode == false && !e.shiftKey) {
  980. if (k == opts.keyCode.RIGHT) {
  981. setTimeout(function () {
  982. var caretPos = caret(input);
  983. caret(input, caretPos.begin);
  984. }, 0);
  985. } else if (k == opts.keyCode.LEFT) {
  986. setTimeout(function () {
  987. var caretPos = caret(input);
  988. caret(input, isRTL ? caretPos.begin + 1 : caretPos.begin - 1);
  989. }, 0);
  990. }
  991. }
  992. var currentCaretPos = caret(input);
  993. var keydownResult = opts.onKeyDown.call(this, e, getBuffer(), opts);
  994. handleOnKeyResult(input, keydownResult, currentCaretPos);
  995. ignorable = $.inArray(k, opts.ignorables) != -1;
  996. }
  997. function keypressEvent(e, checkval, k, writeOut, strict, ndx) {
  998. //Safari 5.1.x - modal dialog fires keypress twice workaround
  999. if (k == undefined && skipKeyPressEvent) return false;
  1000. skipKeyPressEvent = true;
  1001. var input = this, $input = $(input);
  1002. e = e || window.event;
  1003. var k = checkval ? k : (e.which || e.charCode || e.keyCode);
  1004. if (checkval !== true && (!(e.ctrlKey && e.altKey) && (e.ctrlKey || e.metaKey || ignorable))) {
  1005. return true;
  1006. } else {
  1007. if (k) {
  1008. //special treat the decimal separator
  1009. if (checkval !== true && k == 46 && e.shiftKey == false && opts.radixPoint == ",") k = 44;
  1010. var pos, forwardPosition, c = String.fromCharCode(k);
  1011. if (checkval) {
  1012. var pcaret = strict ? ndx : getLastValidPosition() + 1;
  1013. pos = { begin: pcaret, end: pcaret };
  1014. } else {
  1015. pos = caret(input);
  1016. }
  1017. //should we clear a possible selection??
  1018. var isSlctn = isSelection(pos.begin, pos.end);
  1019. if (isSlctn) {
  1020. getMaskSet()["undoPositions"] = $.extend(true, {}, getMaskSet()["validPositions"]); //init undobuffer for recovery when not valid
  1021. handleRemove(input, opts.keyCode.DELETE, pos);
  1022. if (!opts.insertMode) { //preserve some space
  1023. opts.insertMode = !opts.insertMode;
  1024. setValidPosition(pos.begin, strict);
  1025. opts.insertMode = !opts.insertMode;
  1026. }
  1027. isSlctn = !opts.multi;
  1028. }
  1029. getMaskSet()["writeOutBuffer"] = true;
  1030. var p = isRTL && !isSlctn ? pos.end : pos.begin;
  1031. var valResult = isValid(p, c, strict);
  1032. if (valResult !== false) {
  1033. if (valResult !== true) {
  1034. p = valResult.pos != undefined ? valResult.pos : p; //set new position from isValid
  1035. c = valResult.c != undefined ? valResult.c : c; //set new char from isValid
  1036. }
  1037. resetMaskSet(true);
  1038. if (valResult.caret != undefined)
  1039. forwardPosition = valResult.caret;
  1040. else {
  1041. var vps = getMaskSet()["validPositions"];
  1042. if (vps[p + 1] != undefined && getTestTemplate(pos + 1, vps[p].locator.slice(), p)["match"].def != vps[p + 1]["match"].def)
  1043. forwardPosition = p + 1;
  1044. else forwardPosition = seekNext(p);
  1045. }
  1046. getMaskSet()["p"] = forwardPosition; //needed for checkval
  1047. }
  1048. if (writeOut !== false) {
  1049. var self = this;
  1050. setTimeout(function () { opts.onKeyValidation.call(self, valResult, opts); }, 0);
  1051. if (getMaskSet()["writeOutBuffer"] && valResult !== false) {
  1052. var buffer = getBuffer();
  1053. writeBuffer(input, buffer, checkval ? undefined : opts.numericInput ? seekPrevious(forwardPosition) : forwardPosition);
  1054. if (checkval !== true) {
  1055. setTimeout(function () { //timeout needed for IE
  1056. if (isComplete(buffer) === true)
  1057. $input.trigger("complete");
  1058. skipInputEvent = true;
  1059. $input.trigger("input");
  1060. }, 0);
  1061. }
  1062. } else if (isSlctn) {
  1063. getMaskSet()["buffer"] = undefined;
  1064. getMaskSet()["validPositions"] = getMaskSet()["undoPositions"];
  1065. }
  1066. } else if (isSlctn) {
  1067. getMaskSet()["buffer"] = undefined;
  1068. getMaskSet()["validPositions"] = getMaskSet()["undoPositions"];
  1069. }
  1070. if (opts.showTooltip) { //update tooltip
  1071. $input.prop("title", getMaskSet()["mask"]);
  1072. }
  1073. //needed for IE8 and below
  1074. if (e && checkval != true) {
  1075. e.preventDefault ? e.preventDefault() : e.returnValue = false;
  1076. var currentCaretPos = caret(input);
  1077. var keypressResult = opts.onKeyPress.call(this, e, getBuffer(), opts);
  1078. handleOnKeyResult(input, keypressResult, currentCaretPos);
  1079. }
  1080. var temp;
  1081. for (var i in getMaskSet().validPositions) {
  1082. temp += " " + i;
  1083. }
  1084. }
  1085. }
  1086. }
  1087. function keyupEvent(e) {
  1088. var $input = $(this), input = this, k = e.keyCode, buffer = getBuffer();
  1089. var currentCaretPos = caret(input);
  1090. var keyupResult = opts.onKeyUp.call(this, e, buffer, opts);
  1091. handleOnKeyResult(input, keyupResult, currentCaretPos);
  1092. if (k == opts.keyCode.TAB && opts.showMaskOnFocus) {
  1093. if ($input.hasClass('focus.inputmask') && input._valueGet().length == 0) {
  1094. resetMaskSet();
  1095. buffer = getBuffer();
  1096. writeBuffer(input, buffer);
  1097. caret(input, 0);
  1098. valueOnFocus = getBuffer().join('');
  1099. } else {
  1100. writeBuffer(input, buffer);
  1101. caret(input, TranslatePosition(0), TranslatePosition(getMaskLength()));
  1102. }
  1103. }
  1104. }
  1105. function pasteEvent(e) {
  1106. if (skipInputEvent === true && e.type == "input") {
  1107. skipInputEvent = false;
  1108. return true;
  1109. }
  1110. var input = this, $input = $(input), inputValue = input._valueGet();
  1111. //paste event for IE8 and lower I guess ;-)
  1112. if (e.type == "propertychange" && input._valueGet().length <= getMaskLength()) {
  1113. return true;
  1114. } else if (e.type == "paste") {
  1115. if (window.clipboardData && window.clipboardData.getData) { // IE
  1116. inputValue = window.clipboardData.getData('Text');
  1117. } else if (e.originalEvent && e.originalEvent.clipboardData && e.originalEvent.clipboardData.getData) {
  1118. inputValue = e.originalEvent.clipboardData.getData('text/plain');
  1119. }
  1120. }
  1121. var pasteValue = $.isFunction(opts.onBeforePaste) ? opts.onBeforePaste.call(input, inputValue, opts) : inputValue;
  1122. checkVal(input, true, false, pasteValue.split(''), true);
  1123. $input.click();
  1124. if (isComplete(getBuffer()) === true)
  1125. $input.trigger("complete");
  1126. return false;
  1127. }
  1128. function mobileInputEvent(e) {
  1129. if (skipInputEvent === true && e.type == "input") {
  1130. skipInputEvent = false;
  1131. return true;
  1132. }
  1133. var input = this;
  1134. //backspace in chrome32 only fires input event - detect & treat
  1135. var caretPos = caret(input),
  1136. currentValue = input._valueGet();
  1137. currentValue = currentValue.replace(new RegExp("(" + escapeRegex(getBufferTemplate().join('')) + ")*"), "");
  1138. //correct caretposition for chrome
  1139. if (caretPos.begin > currentValue.length) {
  1140. caret(input, currentValue.length);
  1141. caretPos = caret(input);
  1142. }
  1143. if ((getBuffer().length - currentValue.length) == 1 && currentValue.charAt(caretPos.begin) != getBuffer()[caretPos.begin]
  1144. && currentValue.charAt(caretPos.begin + 1) != getBuffer()[caretPos.begin]
  1145. && !isMask(caretPos.begin)) {
  1146. e.keyCode = opts.keyCode.BACKSPACE;
  1147. keydownEvent.call(input, e);
  1148. }
  1149. e.preventDefault();
  1150. }
  1151. function mask(el) {
  1152. $el = $(el);
  1153. if ($el.is(":input") && $el.attr("type") != "number") {
  1154. //store tests & original buffer in the input element - used to get the unmasked value
  1155. $el.data('_inputmask', {
  1156. 'maskset': maskset,
  1157. 'opts': opts,
  1158. 'isRTL': false
  1159. });
  1160. //show tooltip
  1161. if (opts.showTooltip) {
  1162. $el.prop("title", getMaskSet()["mask"]);
  1163. }
  1164. patchValueProperty(el);
  1165. if (el.dir == "rtl" || opts.rightAlign)
  1166. $el.css("text-align", "right");
  1167. if (el.dir == "rtl" || opts.numericInput) {
  1168. el.dir = "ltr";
  1169. $el.removeAttr("dir");
  1170. var inputData = $el.data('_inputmask');
  1171. inputData['isRTL'] = true;
  1172. $el.data('_inputmask', inputData);
  1173. isRTL = true;
  1174. }
  1175. //unbind all events - to make sure that no other mask will interfere when re-masking
  1176. $el.unbind(".inputmask");
  1177. $el.removeClass('focus.inputmask');
  1178. //bind events
  1179. $el.closest('form').bind("submit", function () { //trigger change on submit if any
  1180. if (valueOnFocus != getBuffer().join('')) {
  1181. $el.change();
  1182. }
  1183. }).bind('reset', function () {
  1184. setTimeout(function () {
  1185. $el.trigger("setvalue");
  1186. }, 0);
  1187. });
  1188. $el.bind("mouseenter.inputmask", function () {
  1189. var $input = $(this), input = this;
  1190. if (!$input.hasClass('focus.inputmask') && opts.showMaskOnHover) {
  1191. if (input._valueGet() != getBuffer().join('')) {
  1192. writeBuffer(input, getBuffer());
  1193. }
  1194. }
  1195. }).bind("blur.inputmask", function () {
  1196. var $input = $(this), input = this;
  1197. if ($input.data('_inputmask')) {
  1198. var nptValue = input._valueGet(), buffer = getBuffer();
  1199. $input.removeClass('focus.inputmask');
  1200. if (valueOnFocus != getBuffer().join('')) {
  1201. $input.change();
  1202. }
  1203. if (opts.clearMaskOnLostFocus && nptValue != '') {
  1204. if (nptValue == getBufferTemplate().join(''))
  1205. input._valueSet('');
  1206. else { //clearout optional tail of the mask
  1207. clearOptionalTail(input);
  1208. }
  1209. }
  1210. if (isComplete(buffer) === false) {
  1211. $input.trigger("incomplete");
  1212. if (opts.clearIncomplete) {
  1213. resetMaskSet();
  1214. if (opts.clearMaskOnLostFocus)
  1215. input._valueSet('');
  1216. else {
  1217. buffer = getBufferTemplate().slice();
  1218. writeBuffer(input, buffer);
  1219. }
  1220. }
  1221. }
  1222. }
  1223. }).bind("focus.inputmask", function () {
  1224. var $input = $(this), input = this, nptValue = input._valueGet();
  1225. if (opts.showMaskOnFocus && !$input.hasClass('focus.inputmask') && (!opts.showMaskOnHover || (opts.showMaskOnHover && nptValue == ''))) {
  1226. if (input._valueGet() != getBuffer().join('')) {
  1227. writeBuffer(input, getBuffer(), seekNext(getLastValidPosition()));
  1228. }
  1229. }
  1230. $input.addClass('focus.inputmask');
  1231. valueOnFocus = getBuffer().join('');
  1232. }).bind("mouseleave.inputmask", function () {
  1233. var $input = $(this), input = this;
  1234. if (opts.clearMaskOnLostFocus) {
  1235. if (!$input.hasClass('focus.inputmask') && input._valueGet() != $input.attr("placeholder")) {
  1236. if (input._valueGet() == getBufferTemplate().join('') || input._valueGet() == '')
  1237. input._valueSet('');
  1238. else { //clearout optional tail of the mask
  1239. clearOptionalTail(input);
  1240. }
  1241. }
  1242. }
  1243. }).bind("click.inputmask", function () {
  1244. var input = this;
  1245. if ($(input).is(":focus")) {
  1246. setTimeout(function() {
  1247. var selectedCaret = caret(input), buffer = getBuffer();
  1248. if (selectedCaret.begin == selectedCaret.end) {
  1249. var clickPosition = isRTL ? TranslatePosition(selectedCaret.begin) : selectedCaret.begin,
  1250. lvp = getLastValidPosition(clickPosition),
  1251. lastPosition = seekNext(lvp);
  1252. if (clickPosition < lastPosition) {
  1253. if (isMask(clickPosition))
  1254. caret(input, clickPosition);
  1255. else caret(input, seekNext(clickPosition));
  1256. } else
  1257. caret(input, lastPosition);
  1258. }
  1259. }, 0);
  1260. }
  1261. }).bind('dblclick.inputmask', function () {
  1262. var input = this;
  1263. setTimeout(function () {
  1264. caret(input, 0, seekNext(getLastValidPosition()));
  1265. }, 0);
  1266. }).bind(PasteEventType + ".inputmask dragdrop.inputmask drop.inputmask", pasteEvent
  1267. ).bind('setvalue.inputmask', function () {
  1268. var input = this;
  1269. checkVal(input, true);
  1270. valueOnFocus = getBuffer().join('');
  1271. if (input._valueGet() == getBufferTemplate().join(''))
  1272. input._valueSet('');
  1273. }).bind('complete.inputmask', opts.oncomplete
  1274. ).bind('incomplete.inputmask', opts.onincomplete
  1275. ).bind('cleared.inputmask', opts.oncleared);
  1276. $el.bind("keydown.inputmask", keydownEvent
  1277. ).bind("keypress.inputmask", keypressEvent
  1278. ).bind("keyup.inputmask", keyupEvent);
  1279. if (android || androidfirefox || androidchrome || kindle) {
  1280. if (PasteEventType == "input") {
  1281. $el.unbind(PasteEventType + ".inputmask");
  1282. }
  1283. $el.bind("input.inputmask", mobileInputEvent);
  1284. }
  1285. if (msie1x)
  1286. $el.bind("input.inputmask", pasteEvent);
  1287. //apply mask
  1288. var initialValue = $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(el, el._valueGet(), opts) : el._valueGet();
  1289. checkVal(el, true, false, initialValue.split(''), true);
  1290. valueOnFocus = getBuffer().join('');
  1291. // Wrap document.activeElement in a try/catch block since IE9 throw "Unspecified error" if document.activeElement is undefined when we are in an IFrame.
  1292. var activeElement;
  1293. try {
  1294. activeElement = document.activeElement;
  1295. } catch (e) {
  1296. }
  1297. if (activeElement === el) { //position the caret when in focus
  1298. $el.addClass('focus.inputmask');
  1299. caret(el, seekNext(getLastValidPosition()));
  1300. } else {
  1301. if (isComplete(getBuffer()) === false) {
  1302. if (opts.clearIncomplete)
  1303. resetMaskSet();
  1304. }
  1305. if (opts.clearMaskOnLostFocus) {
  1306. if (getBuffer().join('') == getBufferTemplate().join('')) {
  1307. el._valueSet('');
  1308. } else {
  1309. clearOptionalTail(el);
  1310. }
  1311. } else {
  1312. writeBuffer(el, getBuffer());
  1313. }
  1314. }
  1315. installEventRuler(el);
  1316. }
  1317. }
  1318. //action object
  1319. if (actionObj != undefined) {
  1320. switch (actionObj["action"]) {
  1321. case "isComplete":
  1322. $el = $(actionObj["el"]);
  1323. maskset = $el.data('_inputmask')['maskset'];
  1324. opts = $el.data('_inputmask')['opts'];
  1325. return isComplete(actionObj["buffer"]);
  1326. case "unmaskedvalue":
  1327. $el = actionObj["$input"];
  1328. maskset = $el.data('_inputmask')['maskset'];
  1329. opts = $el.data('_inputmask')['opts'];
  1330. isRTL = actionObj["$input"].data('_inputmask')['isRTL'];
  1331. return unmaskedvalue(actionObj["$input"], actionObj["skipDatepickerCheck"]);
  1332. case "mask":
  1333. valueOnFocus = getBuffer().join('');
  1334. mask(actionObj["el"]);
  1335. break;
  1336. case "format":
  1337. $el = $({});
  1338. $el.data('_inputmask', {
  1339. 'maskset': maskset,
  1340. 'opts': opts,
  1341. 'isRTL': opts.numericInput
  1342. });
  1343. if (opts.numericInput) {
  1344. isRTL = true;
  1345. }
  1346. var valueBuffer = actionObj["value"].split('');
  1347. checkVal($el, false, false, isRTL ? valueBuffer.reverse() : valueBuffer, true);
  1348. return isRTL ? getBuffer().reverse().join('') : getBuffer().join('');
  1349. case "isValid":
  1350. $el = $({});
  1351. $el.data('_inputmask', {
  1352. 'maskset': maskset,
  1353. 'opts': opts,
  1354. 'isRTL': opts.numericInput
  1355. });
  1356. if (opts.numericInput) {
  1357. isRTL = true;
  1358. }
  1359. var valueBuffer = actionObj["value"].split('');
  1360. checkVal($el, false, true, isRTL ? valueBuffer.reverse() : valueBuffer);
  1361. var buffer = getBuffer();
  1362. var rl = determineLastRequiredPosition();
  1363. buffer.length = rl;
  1364. return isComplete(buffer) && actionObj["value"] == buffer.join('');
  1365. case "getemptymask":
  1366. $el = $(actionObj["el"]);
  1367. maskset = $el.data('_inputmask')['maskset'];
  1368. opts = $el.data('_inputmask')['opts'];
  1369. return getBufferTemplate();
  1370. case "remove":
  1371. var el = actionObj["el"];
  1372. $el = $(el);
  1373. maskset = $el.data('_inputmask')['maskset'];
  1374. opts = $el.data('_inputmask')['opts'];
  1375. //writeout the unmaskedvalue
  1376. el._valueSet(unmaskedvalue($el));
  1377. //unbind all events
  1378. $el.unbind(".inputmask");
  1379. $el.removeClass('focus.inputmask');
  1380. //clear data
  1381. $el.removeData('_inputmask');
  1382. //restore the value property
  1383. var valueProperty;
  1384. if (Object.getOwnPropertyDescriptor)
  1385. valueProperty = Object.getOwnPropertyDescriptor(el, "value");
  1386. if (valueProperty && valueProperty.get) {
  1387. if (el._valueGet) {
  1388. Object.defineProperty(el, "value", {
  1389. get: el._valueGet,
  1390. set: el._valueSet
  1391. });
  1392. }
  1393. } else if (document.__lookupGetter__ && el.__lookupGetter__("value")) {
  1394. if (el._valueGet) {
  1395. el.__defineGetter__("value", el._valueGet);
  1396. el.__defineSetter__("value", el._valueSet);
  1397. }
  1398. }
  1399. try { //try catch needed for IE7 as it does not supports deleting fns
  1400. delete el._valueGet;
  1401. delete el._valueSet;
  1402. } catch (e) {
  1403. el._valueGet = undefined;
  1404. el._valueSet = undefined;
  1405. }
  1406. break;
  1407. }
  1408. }
  1409. };
  1410. $.inputmask = {
  1411. //options default
  1412. defaults: {
  1413. placeholder: "_",
  1414. optionalmarker: { start: "[", end: "]" },
  1415. quantifiermarker: { start: "{", end: "}" },
  1416. groupmarker: { start: "(", end: ")" },
  1417. alternatormarker: "|",
  1418. escapeChar: "\\",
  1419. mask: null,
  1420. oncomplete: $.noop, //executes when the mask is complete
  1421. onincomplete: $.noop, //executes when the mask is incomplete and focus is lost
  1422. oncleared: $.noop, //executes when the mask is cleared
  1423. repeat: 0, //repetitions of the mask: * ~ forever, otherwise specify an integer
  1424. greedy: true, //true: allocated buffer for the mask and repetitions - false: allocate only if needed
  1425. autoUnmask: false, //automatically unmask when retrieving the value with $.fn.val or value if the browser supports __lookupGetter__ or getOwnPropertyDescriptor
  1426. clearMaskOnLostFocus: true,
  1427. insertMode: true, //insert the input or overwrite the input
  1428. clearIncomplete: false, //clear the incomplete input on blur
  1429. aliases: {}, //aliases definitions => see jquery.inputmask.extensions.js
  1430. alias: null,
  1431. onKeyUp: $.noop, //callback to implement autocomplete on certain keys for example
  1432. onKeyPress: $.noop, //callback to implement autocomplete on certain keys for example
  1433. onKeyDown: $.noop, //callback to implement autocomplete on certain keys for example
  1434. onBeforeMask: undefined, //executes before masking the initial value to allow preprocessing of the initial value. args => initialValue, opts => return processedValue
  1435. onBeforePaste: undefined, //executes before masking the pasted value to allow preprocessing of the pasted value. args => pastedValue, opts => return processedValue
  1436. onUnMask: undefined, //executes after unmasking to allow postprocessing of the unmaskedvalue. args => maskedValue, unmaskedValue, opts
  1437. showMaskOnFocus: true, //show the mask-placeholder when the input has focus
  1438. showMaskOnHover: true, //show the mask-placeholder when hovering the empty input
  1439. onKeyValidation: $.noop, //executes on every key-press with the result of isValid. Params: result, opts
  1440. skipOptionalPartCharacter: " ", //a character which can be used to skip an optional part of a mask
  1441. showTooltip: false, //show the activemask as tooltip
  1442. numericInput: false, //numericInput input direction style (input shifts to the left while holding the caret position)
  1443. getLastValidPosition: undefined, //override getLastValidPosition - args => maskset, closestTo, opts - return position (int)
  1444. rightAlign: false, //align to the right
  1445. //numeric basic properties
  1446. radixPoint: "", //".", // | ","
  1447. //numeric basic properties
  1448. nojumps: false, //do not jump over fixed parts in the mask
  1449. nojumpsThreshold: 0, //start nojumps as of
  1450. definitions: {
  1451. '9': {
  1452. validator: "[0-9]",
  1453. cardinality: 1,
  1454. definitionSymbol: "*"
  1455. },
  1456. 'a': {
  1457. validator: "[A-Za-z\u0410-\u044F\u0401\u0451]",
  1458. cardinality: 1,
  1459. definitionSymbol: "*"
  1460. },
  1461. '*': {
  1462. validator: "[A-Za-z\u0410-\u044F\u0401\u04510-9]",
  1463. cardinality: 1
  1464. }
  1465. },
  1466. keyCode: {
  1467. 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,
  1468. 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
  1469. },
  1470. //specify keycodes which should not be considered in the keypress event, otherwise the preventDefault will stop their default behavior especially in FF
  1471. ignorables: [8, 9, 13, 19, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 93, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123],
  1472. isComplete: undefined //override for isComplete - args => buffer, opts - return true || false
  1473. },
  1474. masksCache: {},
  1475. escapeRegex: function (str) {
  1476. var specials = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\'];
  1477. return str.replace(new RegExp('(\\' + specials.join('|\\') + ')', 'gim'), '\\$1');
  1478. },
  1479. format: function (value, options) {
  1480. var opts = $.extend(true, {}, $.inputmask.defaults, options);
  1481. resolveAlias(opts.alias, options, opts);
  1482. return maskScope({ "action": "format", "value": value }, generateMaskSet(opts), opts);
  1483. },
  1484. isValid: function (value, options) {
  1485. var opts = $.extend(true, {}, $.inputmask.defaults, options);
  1486. resolveAlias(opts.alias, options, opts);
  1487. return maskScope({ "action": "isValid", "value": value }, generateMaskSet(opts), opts);
  1488. }
  1489. };
  1490. $.fn.inputmask = function (fn, options, targetScope, targetData, msk) {
  1491. targetScope = targetScope || maskScope;
  1492. targetData = targetData || "_inputmask";
  1493. function importAttributeOptions(npt, opts) {
  1494. var $npt = $(npt);
  1495. for (var option in opts) {
  1496. var optionData = $npt.data("inputmask-" + option.toLowerCase());
  1497. if (optionData != undefined)
  1498. opts[option] = optionData;
  1499. }
  1500. return opts;
  1501. }
  1502. var opts = $.extend(true, {}, $.inputmask.defaults, options),
  1503. maskset;
  1504. if (typeof fn === "string") {
  1505. switch (fn) {
  1506. case "mask":
  1507. //resolve possible aliases given by options
  1508. resolveAlias(opts.alias, options, opts);
  1509. maskset = generateMaskSet(opts);
  1510. if (maskset.length == 0) { return this; }
  1511. return this.each(function () {
  1512. targetScope({ "action": "mask", "el": this }, $.extend(true, {}, $.isArray(maskset) && targetScope === maskScope ? maskset[0] : maskset), importAttributeOptions(this, opts));
  1513. });
  1514. case "unmaskedvalue":
  1515. var $input = $(this);
  1516. if ($input.data(targetData)) {
  1517. return targetScope({ "action": "unmaskedvalue", "$input": $input });
  1518. } else return $input.val();
  1519. case "remove":
  1520. return this.each(function () {
  1521. var $input = $(this);
  1522. if ($input.data(targetData)) {
  1523. targetScope({ "action": "remove", "el": this });
  1524. }
  1525. });
  1526. case "getemptymask": //return the default (empty) mask value, usefull for setting the default value in validation
  1527. if (this.data(targetData)) {
  1528. return targetScope({ "action": "getemptymask", "el": this });
  1529. }
  1530. else return "";
  1531. case "hasMaskedValue": //check wheter the returned value is masked or not; currently only works reliable when using jquery.val fn to retrieve the value
  1532. return this.data(targetData) ? !this.data(targetData)['opts'].autoUnmask : false;
  1533. case "isComplete":
  1534. if (this.data(targetData)) {
  1535. return targetScope({ "action": "isComplete", "buffer": this[0]._valueGet().split(''), "el": this });
  1536. } else return true;
  1537. case "getmetadata": //return mask metadata if exists
  1538. if (this.data(targetData)) {
  1539. maskset = this.data(targetData)['maskset'];
  1540. return maskset['metadata'];
  1541. }
  1542. else return undefined;
  1543. case "_detectScope":
  1544. resolveAlias(opts.alias, options, opts);
  1545. if (msk != undefined && !resolveAlias(msk, options, opts) && $.inArray(msk, ["mask", "unmaskedvalue", "remove", "getemptymask", "hasMaskedValue", "isComplete", "getmetadata", "_detectScope"]) == -1) {
  1546. opts.mask = msk;
  1547. }
  1548. if ($.isFunction(opts.mask)) {
  1549. opts.mask = opts.mask.call(this, opts);
  1550. }
  1551. return $.isArray(opts.mask);
  1552. default:
  1553. //check if the fn is an alias
  1554. if (!resolveAlias(fn, options, opts)) {
  1555. //maybe fn is a mask so we try
  1556. //set mask
  1557. opts.mask = fn;
  1558. }
  1559. maskset = generateMaskSet(opts);
  1560. if (maskset == undefined) { return this; }
  1561. return this.each(function () {
  1562. targetScope({ "action": "mask", "el": this }, $.extend(true, {}, $.isArray(maskset) && targetScope === maskScope ? maskset[0] : maskset), importAttributeOptions(this, opts));
  1563. });
  1564. }
  1565. } else if (typeof fn == "object") {
  1566. opts = $.extend(true, {}, $.inputmask.defaults, fn);
  1567. resolveAlias(opts.alias, fn, opts); //resolve aliases
  1568. maskset = generateMaskSet(opts);
  1569. if (maskset == undefined) { return this; }
  1570. return this.each(function () {
  1571. targetScope({ "action": "mask", "el": this }, $.extend(true, {}, $.isArray(maskset) && targetScope === maskScope ? maskset[0] : maskset), importAttributeOptions(this, opts));
  1572. });
  1573. } else if (fn == undefined) {
  1574. //look for data-inputmask atribute - the attribute should only contain optipns
  1575. return this.each(function () {
  1576. var attrOptions = $(this).attr("data-inputmask");
  1577. if (attrOptions && attrOptions != "") {
  1578. try {
  1579. attrOptions = attrOptions.replace(new RegExp("'", "g"), '"');
  1580. var dataoptions = $.parseJSON("{" + attrOptions + "}");
  1581. $.extend(true, dataoptions, options);
  1582. opts = $.extend(true, {}, $.inputmask.defaults, dataoptions);
  1583. resolveAlias(opts.alias, dataoptions, opts);
  1584. opts.alias = undefined;
  1585. $(this).inputmask("mask", opts, targetScope);
  1586. } catch (ex) { } //need a more relax parseJSON
  1587. }
  1588. });
  1589. }
  1590. };
  1591. }
  1592. })(jQuery);
  1593. /**
  1594. * @license Input Mask plugin for jquery
  1595. * http://github.com/RobinHerbots/jquery.inputmask
  1596. * Copyright (c) 2010 - 2014 Robin Herbots
  1597. * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  1598. * Version: 3.0.46
  1599. */
  1600. (function ($) {
  1601. if ($.fn.inputmask != undefined) {
  1602. function multiMaskScope(actionObj, masksets, opts) {
  1603. function isInputEventSupported(eventName) {
  1604. var el = document.createElement('input'),
  1605. eventName = 'on' + eventName,
  1606. isSupported = (eventName in el);
  1607. if (!isSupported) {
  1608. el.setAttribute(eventName, 'return;');
  1609. isSupported = typeof el[eventName] == 'function';
  1610. }
  1611. el = null;
  1612. return isSupported;
  1613. }
  1614. var PasteEventType = isInputEventSupported('paste') ? 'paste' : isInputEventSupported('input') ? 'input' : "propertychange",
  1615. isRTL, el, $el, elmasks, activeMasksetIndex;
  1616. function PatchValhookMulti(type) {
  1617. if ($.valHooks[type] == undefined || $.valHooks[type].inputmaskmultipatch != true) {
  1618. var valueGet = $.valHooks[type] && $.valHooks[type].get ? $.valHooks[type].get : function (elem) { return elem.value; };
  1619. var valueSet = $.valHooks[type] && $.valHooks[type].set ? $.valHooks[type].set : function (elem, value) {
  1620. elem.value = value;
  1621. return elem;
  1622. };
  1623. $.valHooks[type] = {
  1624. get: function (elem) {
  1625. var $elem = $(elem);
  1626. if ($elem.data('_inputmask-multi')) {
  1627. var data = $elem.data('_inputmask-multi');
  1628. return valueGet(data["elmasks"][data["activeMasksetIndex"]]);
  1629. } else return valueGet(elem);
  1630. },
  1631. set: function (elem, value) {
  1632. var $elem = $(elem);
  1633. var result = valueSet(elem, value);
  1634. if ($elem.data('_inputmask-multi')) $elem.triggerHandler('setvalue');
  1635. return result;
  1636. },
  1637. inputmaskmultipatch: true
  1638. };
  1639. }
  1640. }
  1641. function mcaret(input, begin, end) {
  1642. var npt = input.jquery && input.length > 0 ? input[0] : input, range;
  1643. if (typeof begin == 'number') {
  1644. begin = TranslatePosition(begin);
  1645. end = TranslatePosition(end);
  1646. end = (typeof end == 'number') ? end : begin;
  1647. //store caret for multi scope
  1648. if (npt != el) {
  1649. var data = $(npt).data('_inputmask') || {};
  1650. data["caret"] = { "begin": begin, "end": end };
  1651. $(npt).data('_inputmask', data);
  1652. }
  1653. if (!$(npt).is(":visible")) {
  1654. return;
  1655. }
  1656. npt.scrollLeft = npt.scrollWidth;
  1657. if (opts.insertMode == false && begin == end) end++; //set visualization for insert/overwrite mode
  1658. if (npt.setSelectionRange) {
  1659. npt.selectionStart = begin;
  1660. npt.selectionEnd = end;
  1661. } else if (npt.createTextRange) {
  1662. range = npt.createTextRange();
  1663. range.collapse(true);
  1664. range.moveEnd('character', end);
  1665. range.moveStart('character', begin);
  1666. range.select();
  1667. }
  1668. } else {
  1669. var data = $(npt).data('_inputmask');
  1670. if (!$(npt).is(":visible") && data && data["caret"] != undefined) {
  1671. begin = data["caret"]["begin"];
  1672. end = data["caret"]["end"];
  1673. } else if (npt.setSelectionRange) {
  1674. begin = npt.selectionStart;
  1675. end = npt.selectionEnd;
  1676. } else if (document.selection && document.selection.createRange) {
  1677. range = document.selection.createRange();
  1678. begin = 0 - range.duplicate().moveStart('character', -100000);
  1679. end = begin + range.text.length;
  1680. }
  1681. begin = TranslatePosition(begin);
  1682. end = TranslatePosition(end);
  1683. return { "begin": begin, "end": end };
  1684. }
  1685. }
  1686. function TranslatePosition(pos) {
  1687. if (isRTL && typeof pos == 'number' && (!opts.greedy || opts.placeholder != "")) {
  1688. var bffrLght = el.value.length;
  1689. pos = bffrLght - pos;
  1690. }
  1691. return pos;
  1692. }
  1693. function determineActiveMask(eventType, elmasks) {
  1694. if (eventType != "multiMaskScope") {
  1695. if ($.isFunction(opts.determineActiveMasksetIndex))
  1696. activeMasksetIndex = opts.determineActiveMasksetIndex.call($el, eventType, elmasks);
  1697. else {
  1698. var lpc = -1, cp = -1, lvp = -1;;
  1699. $.each(elmasks, function (ndx, lmsk) {
  1700. var data = $(lmsk).data('_inputmask');
  1701. var maskset = data["maskset"];
  1702. var lastValidPosition = -1, validPositionCount = 0, caretPos = mcaret(lmsk).begin;
  1703. for (var posNdx in maskset["validPositions"]) {
  1704. var psNdx = parseInt(posNdx);
  1705. if (psNdx > lastValidPosition) lastValidPosition = psNdx;
  1706. validPositionCount++;
  1707. }
  1708. if (validPositionCount > lpc
  1709. || (validPositionCount == lpc && cp > caretPos && lvp > lastValidPosition)
  1710. || (validPositionCount == lpc && cp == caretPos && lvp < lastValidPosition)
  1711. ) {
  1712. //console.log("lvp " + lastValidPosition + " vpc " + validPositionCount + " caret " + caretPos + " ams " + ndx);
  1713. lpc = validPositionCount;
  1714. cp = caretPos;
  1715. activeMasksetIndex = ndx;
  1716. lvp = lastValidPosition;
  1717. }
  1718. });
  1719. }
  1720. var data = $el.data('_inputmask-multi') || { "activeMasksetIndex": 0, "elmasks": elmasks };
  1721. data["activeMasksetIndex"] = activeMasksetIndex;
  1722. $el.data('_inputmask-multi', data);
  1723. }
  1724. if ($.inArray(eventType, ["focus"]) == -1 && el.value != elmasks[activeMasksetIndex]._valueGet()) {
  1725. var value = $(elmasks[activeMasksetIndex]).val() == "" ? elmasks[activeMasksetIndex]._valueGet() : $(elmasks[activeMasksetIndex]).val();
  1726. el.value = value;
  1727. }
  1728. if ($.inArray(eventType, ["blur", "focus"]) == -1) {
  1729. if ($(elmasks[activeMasksetIndex]).hasClass("focus.inputmask")) {
  1730. var activeCaret = mcaret(elmasks[activeMasksetIndex]);
  1731. mcaret(el, activeCaret.begin, activeCaret.end);
  1732. }
  1733. }
  1734. }
  1735. opts.multi = true;
  1736. function mask(npt) {
  1737. el = npt;
  1738. $el = $(el);
  1739. isRTL = el.dir == "rtl" || opts.numericInput;
  1740. activeMasksetIndex = 0;
  1741. elmasks = $.map(masksets, function (msk, ndx) {
  1742. var elMaskStr = '<input type="text" ';
  1743. if ($el.attr("value")) elMaskStr += 'value="' + $el.attr("value") + '" ';
  1744. if ($el.attr("dir")) elMaskStr += 'dir="' + $el.attr("dir") + '" ';
  1745. elMaskStr += '/>';
  1746. var elmask = $(elMaskStr)[0];
  1747. $(elmask).inputmask($.extend({}, opts, { mask: msk.mask }));
  1748. return elmask;
  1749. });
  1750. $el.data('_inputmask-multi', { "activeMasksetIndex": 0, "elmasks": elmasks });
  1751. if (el.dir == "rtl" || opts.rightAlign)
  1752. $el.css("text-align", "right");
  1753. el.dir = "ltr";
  1754. $el.removeAttr("dir");
  1755. if ($el.attr("value") != "") {
  1756. determineActiveMask("init", elmasks);
  1757. }
  1758. $el.bind("mouseenter blur focus mouseleave click dblclick keydown keypress keypress", function (e) {
  1759. var caretPos = mcaret(el), k, goDetermine = true;
  1760. if (e.type == "keydown") {
  1761. k = e.keyCode;
  1762. if (k == opts.keyCode.DOWN && activeMasksetIndex < elmasks.length - 1) {
  1763. activeMasksetIndex++;
  1764. determineActiveMask("multiMaskScope", elmasks);
  1765. return false;
  1766. } else if (k == opts.keyCode.UP && activeMasksetIndex > 0) {
  1767. activeMasksetIndex--;
  1768. determineActiveMask("multiMaskScope", elmasks);
  1769. return false;
  1770. }
  1771. if (e.ctrlKey || e.shiftKey || e.altKey) {
  1772. return true;
  1773. }
  1774. } else if (e.type == "keypress" && (e.ctrlKey || e.shiftKey || e.altKey)) {
  1775. return true;
  1776. }
  1777. $.each(elmasks, function (ndx, lmnt) {
  1778. if (e.type == "keydown") {
  1779. k = e.keyCode;
  1780. if (k == opts.keyCode.BACKSPACE && lmnt._valueGet().length < caretPos.begin) {
  1781. return;
  1782. } else if (k == opts.keyCode.TAB) {
  1783. goDetermine = false;
  1784. } else if (k == opts.keyCode.RIGHT) {
  1785. mcaret(lmnt, caretPos.begin + 1, caretPos.end + 1);
  1786. goDetermine = false;
  1787. return;
  1788. } else if (k == opts.keyCode.LEFT) {
  1789. mcaret(lmnt, caretPos.begin - 1, caretPos.end - 1);
  1790. goDetermine = false;
  1791. return;
  1792. }
  1793. }
  1794. if ($.inArray(e.type, ["click"]) != -1) {
  1795. mcaret(lmnt, TranslatePosition(caretPos.begin), TranslatePosition(caretPos.end));
  1796. if (caretPos.begin != caretPos.end) {
  1797. goDetermine = false;
  1798. return;
  1799. }
  1800. }
  1801. if ($.inArray(e.type, ["keydown"]) != -1 && caretPos.begin != caretPos.end) {
  1802. mcaret(lmnt, caretPos.begin, caretPos.end);
  1803. }
  1804. $(lmnt).triggerHandler(e);
  1805. });
  1806. if (goDetermine) {
  1807. setTimeout(function () {
  1808. determineActiveMask(e.type, elmasks);
  1809. }, 0);
  1810. }
  1811. });
  1812. $el.bind(PasteEventType + " dragdrop drop setvalue", function (e) {
  1813. var caretPos = mcaret(el);
  1814. setTimeout(function () {
  1815. $.each(elmasks, function (ndx, lmnt) {
  1816. lmnt._valueSet(el.value);
  1817. $(lmnt).triggerHandler(e);
  1818. });
  1819. setTimeout(function () {
  1820. determineActiveMask(e.type, elmasks);
  1821. }, 0);
  1822. }, 0);
  1823. });
  1824. PatchValhookMulti(el.type);
  1825. }
  1826. //action object
  1827. if (actionObj != undefined) {
  1828. switch (actionObj["action"]) {
  1829. case "isComplete":
  1830. $el = $(actionObj["el"]);
  1831. var imdata = $el.data('_inputmask-multi'),
  1832. activeMask = imdata["elmasks"][imdata["activeMasksetIndex"]];
  1833. return $(activeMask).inputmask("isComplete");
  1834. case "unmaskedvalue":
  1835. $el = actionObj["$input"];
  1836. var imdata = $el.data('_inputmask-multi'),
  1837. activeMask = imdata["elmasks"][imdata["activeMasksetIndex"]];
  1838. return $(activeMask).inputmask("unmaskedvalue");
  1839. case "mask":
  1840. mask(actionObj["el"]);
  1841. break;
  1842. case "format": //TODO
  1843. $el = $({});
  1844. $el.data('_inputmask', {
  1845. 'maskset': maskset,
  1846. 'opts': opts,
  1847. 'isRTL': opts.numericInput
  1848. });
  1849. if (opts.numericInput) {
  1850. isRTL = true;
  1851. }
  1852. var valueBuffer = actionObj["value"].split('');
  1853. checkVal($el, false, false, isRTL ? valueBuffer.reverse() : valueBuffer, true);
  1854. return isRTL ? getBuffer().reverse().join('') : getBuffer().join('');
  1855. case "isValid": //TODO
  1856. $el = $({});
  1857. $el.data('_inputmask', {
  1858. 'maskset': maskset,
  1859. 'opts': opts,
  1860. 'isRTL': opts.numericInput
  1861. });
  1862. if (opts.numericInput) {
  1863. isRTL = true;
  1864. }
  1865. var valueBuffer = actionObj["value"].split('');
  1866. checkVal($el, false, true, isRTL ? valueBuffer.reverse() : valueBuffer);
  1867. return isComplete(getBuffer());
  1868. case "getemptymask": //TODO
  1869. $el = $(actionObj["el"]);
  1870. maskset = $el.data('_inputmask')['maskset'];
  1871. opts = $el.data('_inputmask')['opts'];
  1872. return getBufferTemplate();
  1873. case "remove": //TODO
  1874. var el = actionObj["el"];
  1875. $el = $(el);
  1876. maskset = $el.data('_inputmask')['maskset'];
  1877. opts = $el.data('_inputmask')['opts'];
  1878. //writeout the unmaskedvalue
  1879. el._valueSet(unmaskedvalue($el));
  1880. //unbind all events
  1881. $el.unbind(".inputmask");
  1882. $el.removeClass('focus.inputmask');
  1883. //clear data
  1884. $el.removeData('_inputmask');
  1885. //restore the value property
  1886. var valueProperty;
  1887. if (Object.getOwnPropertyDescriptor)
  1888. valueProperty = Object.getOwnPropertyDescriptor(el, "value");
  1889. if (valueProperty && valueProperty.get) {
  1890. if (el._valueGet) {
  1891. Object.defineProperty(el, "value", {
  1892. get: el._valueGet,
  1893. set: el._valueSet
  1894. });
  1895. }
  1896. } else if (document.__lookupGetter__ && el.__lookupGetter__("value")) {
  1897. if (el._valueGet) {
  1898. el.__defineGetter__("value", el._valueGet);
  1899. el.__defineSetter__("value", el._valueSet);
  1900. }
  1901. }
  1902. try { //try catch needed for IE7 as it does not supports deleting fns
  1903. delete el._valueGet;
  1904. delete el._valueSet;
  1905. } catch (e) {
  1906. el._valueGet = undefined;
  1907. el._valueSet = undefined;
  1908. }
  1909. break;
  1910. }
  1911. }
  1912. };
  1913. $.extend($.inputmask.defaults, {
  1914. //multi-masks
  1915. multi: false, //do not alter - internal use
  1916. determineActiveMasksetIndex: undefined //override determineActiveMasksetIndex - args => eventType, elmasks - return int
  1917. });
  1918. $.inputmask._fn = $.fn.inputmask;
  1919. $.fn.inputmask = function (fn, options) {
  1920. if (typeof fn === "string") {
  1921. if ($.inputmask._fn("_detectScope", options, undefined, undefined, fn))
  1922. return $.inputmask._fn.call(this, fn, options, multiMaskScope, "_inputmask-multi");
  1923. else return $.inputmask._fn.call(this, fn, options);
  1924. } else if (typeof fn == "object") {
  1925. if ($.inputmask._fn("_detectScope", fn))
  1926. return $.inputmask._fn.call(this, fn, options, multiMaskScope, "_inputmask-multi");
  1927. else return $.inputmask._fn.call(this, fn, options);
  1928. } else if (fn == undefined)
  1929. return $.inputmask._fn.call(this, fn, options);
  1930. };
  1931. }
  1932. })(jQuery);
  1933. /*
  1934. Input Mask plugin extensions
  1935. http://github.com/RobinHerbots/jquery.inputmask
  1936. Copyright (c) 2010 - 2014 Robin Herbots
  1937. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  1938. Version: 3.0.46
  1939. Optional extensions on the jquery.inputmask base
  1940. */
  1941. (function ($) {
  1942. //extra definitions
  1943. $.extend($.inputmask.defaults.definitions, {
  1944. 'A': {
  1945. validator: "[A-Za-z]",
  1946. cardinality: 1,
  1947. casing: "upper" //auto uppercasing
  1948. },
  1949. '#': {
  1950. validator: "[A-Za-z\u0410-\u044F\u0401\u04510-9]",
  1951. cardinality: 1,
  1952. casing: "upper"
  1953. }
  1954. });
  1955. $.extend($.inputmask.defaults.aliases, {
  1956. 'url': {
  1957. mask: "ir",
  1958. placeholder: "",
  1959. separator: "",
  1960. defaultPrefix: "http://",
  1961. regex: {
  1962. urlpre1: new RegExp("[fh]"),
  1963. urlpre2: new RegExp("(ft|ht)"),
  1964. urlpre3: new RegExp("(ftp|htt)"),
  1965. urlpre4: new RegExp("(ftp:|http|ftps)"),
  1966. urlpre5: new RegExp("(ftp:/|ftps:|http:|https)"),
  1967. urlpre6: new RegExp("(ftp://|ftps:/|http:/|https:)"),
  1968. urlpre7: new RegExp("(ftp://|ftps://|http://|https:/)"),
  1969. urlpre8: new RegExp("(ftp://|ftps://|http://|https://)")
  1970. },
  1971. definitions: {
  1972. 'i': {
  1973. validator: function (chrs, maskset, pos, strict, opts) {
  1974. return true;
  1975. },
  1976. cardinality: 8,
  1977. prevalidator: (function () {
  1978. var result = [], prefixLimit = 8;
  1979. for (var i = 0; i < prefixLimit; i++) {
  1980. result[i] = (function () {
  1981. var j = i;
  1982. return {
  1983. validator: function (chrs, maskset, pos, strict, opts) {
  1984. if (opts.regex["urlpre" + (j + 1)]) {
  1985. var tmp = chrs, k;
  1986. if (((j + 1) - chrs.length) > 0) {
  1987. tmp = maskset.buffer.join('').substring(0, ((j + 1) - chrs.length)) + "" + tmp;
  1988. }
  1989. var isValid = opts.regex["urlpre" + (j + 1)].test(tmp);
  1990. if (!strict && !isValid) {
  1991. pos = pos - j;
  1992. for (k = 0; k < opts.defaultPrefix.length; k++) {
  1993. maskset.buffer[pos] = opts.defaultPrefix[k]; pos++;
  1994. }
  1995. for (k = 0; k < tmp.length - 1; k++) {
  1996. maskset.buffer[pos] = tmp[k]; pos++;
  1997. }
  1998. return { "pos": pos };
  1999. }
  2000. return isValid;
  2001. } else {
  2002. return false;
  2003. }
  2004. }, cardinality: j
  2005. };
  2006. })();
  2007. }
  2008. return result;
  2009. })()
  2010. },
  2011. "r": {
  2012. validator: ".",
  2013. cardinality: 50
  2014. }
  2015. },
  2016. insertMode: false,
  2017. autoUnmask: false
  2018. },
  2019. "ip": { //ip-address mask
  2020. mask: "i[i[i]].i[i[i]].i[i[i]].i[i[i]]",
  2021. definitions: {
  2022. 'i': {
  2023. validator: function (chrs, maskset, pos, strict, opts) {
  2024. if (pos - 1 > -1 && maskset.buffer[pos - 1] != ".") {
  2025. chrs = maskset.buffer[pos - 1] + chrs;
  2026. if (pos - 2 > -1 && maskset.buffer[pos - 2] != ".") {
  2027. chrs = maskset.buffer[pos - 2] + chrs;
  2028. } else chrs = "0" + chrs;
  2029. } else chrs = "00" + chrs;
  2030. return new RegExp("25[0-5]|2[0-4][0-9]|[01][0-9][0-9]").test(chrs);
  2031. },
  2032. cardinality: 1
  2033. }
  2034. }
  2035. },
  2036. "email": {
  2037. mask: "*{1,20}[.*{1,20}][.*{1,20}][.*{1,20}]@*{1,20}.*{2,6}[.*{1,2}]",
  2038. greedy: false,
  2039. onBeforePaste: function (pastedValue, opts) {
  2040. pastedValue = pastedValue.toLowerCase();
  2041. return pastedValue.replace("mailto:", "");
  2042. },
  2043. definitions: {
  2044. '*': {
  2045. validator: "[A-Za-z\u0410-\u044F\u0401\u04510-9]",
  2046. cardinality: 1,
  2047. casing: "lower"
  2048. }
  2049. }
  2050. }
  2051. });
  2052. })(jQuery);
  2053. /*
  2054. Input Mask plugin extensions
  2055. http://github.com/RobinHerbots/jquery.inputmask
  2056. Copyright (c) 2010 - 2014 Robin Herbots
  2057. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  2058. Version: 3.0.46
  2059. Optional extensions on the jquery.inputmask base
  2060. */
  2061. (function ($) {
  2062. //date & time aliases
  2063. $.extend($.inputmask.defaults.definitions, {
  2064. 'h': { //hours
  2065. validator: "[01][0-9]|2[0-3]",
  2066. cardinality: 2,
  2067. prevalidator: [{ validator: "[0-2]", cardinality: 1 }]
  2068. },
  2069. 's': { //seconds || minutes
  2070. validator: "[0-5][0-9]",
  2071. cardinality: 2,
  2072. prevalidator: [{ validator: "[0-5]", cardinality: 1 }]
  2073. },
  2074. 'd': { //basic day
  2075. validator: "0[1-9]|[12][0-9]|3[01]",
  2076. cardinality: 2,
  2077. prevalidator: [{ validator: "[0-3]", cardinality: 1 }]
  2078. },
  2079. 'm': { //basic month
  2080. validator: "0[1-9]|1[012]",
  2081. cardinality: 2,
  2082. prevalidator: [{ validator: "[01]", cardinality: 1 }]
  2083. },
  2084. 'y': { //basic year
  2085. validator: "(19|20)\\d{2}",
  2086. cardinality: 4,
  2087. prevalidator: [
  2088. { validator: "[12]", cardinality: 1 },
  2089. { validator: "(19|20)", cardinality: 2 },
  2090. { validator: "(19|20)\\d", cardinality: 3 }
  2091. ]
  2092. }
  2093. });
  2094. $.extend($.inputmask.defaults.aliases, {
  2095. 'dd/mm/yyyy': {
  2096. mask: "1/2/y",
  2097. placeholder: "dd/mm/yyyy",
  2098. regex: {
  2099. val1pre: new RegExp("[0-3]"), //daypre
  2100. val1: new RegExp("0[1-9]|[12][0-9]|3[01]"), //day
  2101. val2pre: function (separator) { var escapedSeparator = $.inputmask.escapeRegex.call(this, separator); return new RegExp("((0[1-9]|[12][0-9]|3[01])" + escapedSeparator + "[01])"); }, //monthpre
  2102. 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
  2103. },
  2104. leapday: "29/02/",
  2105. separator: '/',
  2106. yearrange: { minyear: 1900, maxyear: 2099 },
  2107. isInYearRange: function (chrs, minyear, maxyear) {
  2108. if (isNaN(chrs)) return false;
  2109. var enteredyear = parseInt(chrs.concat(minyear.toString().slice(chrs.length)));
  2110. var enteredyear2 = parseInt(chrs.concat(maxyear.toString().slice(chrs.length)));
  2111. return (!isNaN(enteredyear) ? minyear <= enteredyear && enteredyear <= maxyear : false) ||
  2112. (!isNaN(enteredyear2) ? minyear <= enteredyear2 && enteredyear2 <= maxyear : false);
  2113. },
  2114. determinebaseyear: function (minyear, maxyear, hint) {
  2115. var currentyear = (new Date()).getFullYear();
  2116. if (minyear > currentyear) return minyear;
  2117. if (maxyear < currentyear) {
  2118. var maxYearPrefix = maxyear.toString().slice(0, 2);
  2119. var maxYearPostfix = maxyear.toString().slice(2, 4);
  2120. while (maxyear < maxYearPrefix + hint) {
  2121. maxYearPrefix--;
  2122. }
  2123. var maxxYear = maxYearPrefix + maxYearPostfix;
  2124. return minyear > maxxYear ? minyear : maxxYear;
  2125. }
  2126. return currentyear;
  2127. },
  2128. onKeyUp: function (e, buffer, opts) {
  2129. var $input = $(this);
  2130. if (e.ctrlKey && e.keyCode == opts.keyCode.RIGHT) {
  2131. var today = new Date();
  2132. $input.val(today.getDate().toString() + (today.getMonth() + 1).toString() + today.getFullYear().toString());
  2133. }
  2134. },
  2135. definitions: {
  2136. '1': { //val1 ~ day or month
  2137. validator: function (chrs, maskset, pos, strict, opts) {
  2138. var isValid = opts.regex.val1.test(chrs);
  2139. if (!strict && !isValid) {
  2140. if (chrs.charAt(1) == opts.separator || "-./".indexOf(chrs.charAt(1)) != -1) {
  2141. isValid = opts.regex.val1.test("0" + chrs.charAt(0));
  2142. if (isValid) {
  2143. maskset.buffer[pos - 1] = "0";
  2144. return { "refreshFromBuffer": { start: pos - 1, end: pos }, "pos": pos, "c": chrs.charAt(0) };
  2145. }
  2146. }
  2147. }
  2148. return isValid;
  2149. },
  2150. cardinality: 2,
  2151. prevalidator: [{
  2152. validator: function (chrs, maskset, pos, strict, opts) {
  2153. if (!isNaN(maskset.buffer[pos + 1])) chrs += maskset.buffer[pos + 1];
  2154. var isValid = chrs.length == 1 ? opts.regex.val1pre.test(chrs) : opts.regex.val1.test(chrs);
  2155. if (!strict && !isValid) {
  2156. isValid = opts.regex.val1.test("0" + chrs);
  2157. if (isValid) {
  2158. maskset.buffer[pos] = "0";
  2159. pos++;
  2160. return { "pos": pos };
  2161. }
  2162. }
  2163. return isValid;
  2164. }, cardinality: 1
  2165. }]
  2166. },
  2167. '2': { //val2 ~ day or month
  2168. validator: function (chrs, maskset, pos, strict, opts) {
  2169. var frontValue = (opts.mask.indexOf("2") == opts.mask.length - 1) ? maskset.buffer.join('').substr(5, 3) : maskset.buffer.join('').substr(0, 3);
  2170. if (frontValue.indexOf(opts.placeholder[0]) != -1) frontValue = "01" + opts.separator;
  2171. var isValid = opts.regex.val2(opts.separator).test(frontValue + chrs);
  2172. if (!strict && !isValid) {
  2173. if (chrs.charAt(1) == opts.separator || "-./".indexOf(chrs.charAt(1)) != -1) {
  2174. isValid = opts.regex.val2(opts.separator).test(frontValue + "0" + chrs.charAt(0));
  2175. if (isValid) {
  2176. maskset.buffer[pos - 1] = "0";
  2177. return { "refreshFromBuffer": { start: pos - 1, end: pos }, "pos": pos, "c": chrs.charAt(0) };
  2178. }
  2179. }
  2180. }
  2181. //check leap yeap
  2182. if ((opts.mask.indexOf("2") == opts.mask.length - 1) && isValid) {
  2183. var dayMonthValue = maskset.buffer.join('').substr(4, 4) + chrs;
  2184. if (dayMonthValue != opts.leapday)
  2185. return true;
  2186. else {
  2187. var year = parseInt(maskset.buffer.join('').substr(0, 4), 10); //detect leap year
  2188. if (year % 4 === 0)
  2189. if (year % 100 === 0)
  2190. if (year % 400 === 0)
  2191. return true;
  2192. else return false;
  2193. else return true;
  2194. else return false;
  2195. }
  2196. }
  2197. return isValid;
  2198. },
  2199. cardinality: 2,
  2200. prevalidator: [{
  2201. validator: function (chrs, maskset, pos, strict, opts) {
  2202. if (!isNaN(maskset.buffer[pos + 1])) chrs += maskset.buffer[pos + 1];
  2203. var frontValue = (opts.mask.indexOf("2") == opts.mask.length - 1) ? maskset.buffer.join('').substr(5, 3) : maskset.buffer.join('').substr(0, 3);
  2204. if (frontValue.indexOf(opts.placeholder[0]) != -1) frontValue = "01" + opts.separator;
  2205. var isValid = chrs.length == 1 ? opts.regex.val2pre(opts.separator).test(frontValue + chrs) : opts.regex.val2(opts.separator).test(frontValue + chrs);
  2206. if (!strict && !isValid) {
  2207. isValid = opts.regex.val2(opts.separator).test(frontValue + "0" + chrs);
  2208. if (isValid) {
  2209. maskset.buffer[pos] = "0";
  2210. pos++;
  2211. return { "pos": pos };
  2212. }
  2213. }
  2214. return isValid;
  2215. }, cardinality: 1
  2216. }]
  2217. },
  2218. 'y': { //year
  2219. validator: function (chrs, maskset, pos, strict, opts) {
  2220. if (opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear)) {
  2221. var dayMonthValue = maskset.buffer.join('').substr(0, 6);
  2222. if (dayMonthValue != opts.leapday)
  2223. return true;
  2224. else {
  2225. var year = parseInt(chrs, 10);//detect leap year
  2226. if (year % 4 === 0)
  2227. if (year % 100 === 0)
  2228. if (year % 400 === 0)
  2229. return true;
  2230. else return false;
  2231. else return true;
  2232. else return false;
  2233. }
  2234. } else return false;
  2235. },
  2236. cardinality: 4,
  2237. prevalidator: [
  2238. {
  2239. validator: function (chrs, maskset, pos, strict, opts) {
  2240. var isValid = opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  2241. if (!strict && !isValid) {
  2242. var yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs + "0").toString().slice(0, 1);
  2243. isValid = opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  2244. if (isValid) {
  2245. maskset.buffer[pos++] = yearPrefix[0];
  2246. return { "pos": pos };
  2247. }
  2248. yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs + "0").toString().slice(0, 2);
  2249. isValid = opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  2250. if (isValid) {
  2251. maskset.buffer[pos++] = yearPrefix[0];
  2252. maskset.buffer[pos++] = yearPrefix[1];
  2253. return { "pos": pos };
  2254. }
  2255. }
  2256. return isValid;
  2257. },
  2258. cardinality: 1
  2259. },
  2260. {
  2261. validator: function (chrs, maskset, pos, strict, opts) {
  2262. var isValid = opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  2263. if (!strict && !isValid) {
  2264. var yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs).toString().slice(0, 2);
  2265. isValid = opts.isInYearRange(chrs[0] + yearPrefix[1] + chrs[1], opts.yearrange.minyear, opts.yearrange.maxyear);
  2266. if (isValid) {
  2267. maskset.buffer[pos++] = yearPrefix[1];
  2268. return { "pos": pos };
  2269. }
  2270. yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs).toString().slice(0, 2);
  2271. if (opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear)) {
  2272. var dayMonthValue = maskset.buffer.join('').substr(0, 6);
  2273. if (dayMonthValue != opts.leapday)
  2274. isValid = true;
  2275. else {
  2276. var year = parseInt(chrs, 10);//detect leap year
  2277. if (year % 4 === 0)
  2278. if (year % 100 === 0)
  2279. if (year % 400 === 0)
  2280. isValid = true;
  2281. else isValid = false;
  2282. else isValid = true;
  2283. else isValid = false;
  2284. }
  2285. } else isValid = false;
  2286. if (isValid) {
  2287. maskset.buffer[pos - 1] = yearPrefix[0];
  2288. maskset.buffer[pos++] = yearPrefix[1];
  2289. maskset.buffer[pos++] = chrs[0];
  2290. return { "refreshFromBuffer": { start: pos - 3, end: pos }, "pos": pos };
  2291. }
  2292. }
  2293. return isValid;
  2294. }, cardinality: 2
  2295. },
  2296. {
  2297. validator: function (chrs, maskset, pos, strict, opts) {
  2298. return opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
  2299. }, cardinality: 3
  2300. }
  2301. ]
  2302. }
  2303. },
  2304. insertMode: false,
  2305. autoUnmask: false
  2306. },
  2307. 'mm/dd/yyyy': {
  2308. placeholder: "mm/dd/yyyy",
  2309. alias: "dd/mm/yyyy", //reuse functionality of dd/mm/yyyy alias
  2310. regex: {
  2311. 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
  2312. 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
  2313. val1pre: new RegExp("[01]"), //monthpre
  2314. val1: new RegExp("0[1-9]|1[012]") //month
  2315. },
  2316. leapday: "02/29/",
  2317. onKeyUp: function (e, buffer, opts) {
  2318. var $input = $(this);
  2319. if (e.ctrlKey && e.keyCode == opts.keyCode.RIGHT) {
  2320. var today = new Date();
  2321. $input.val((today.getMonth() + 1).toString() + today.getDate().toString() + today.getFullYear().toString());
  2322. }
  2323. }
  2324. },
  2325. 'yyyy/mm/dd': {
  2326. mask: "y/1/2",
  2327. placeholder: "yyyy/mm/dd",
  2328. alias: "mm/dd/yyyy",
  2329. leapday: "/02/29",
  2330. onKeyUp: function (e, buffer, opts) {
  2331. var $input = $(this);
  2332. if (e.ctrlKey && e.keyCode == opts.keyCode.RIGHT) {
  2333. var today = new Date();
  2334. $input.val(today.getFullYear().toString() + (today.getMonth() + 1).toString() + today.getDate().toString());
  2335. }
  2336. }
  2337. },
  2338. 'dd.mm.yyyy': {
  2339. mask: "1.2.y",
  2340. placeholder: "dd.mm.yyyy",
  2341. leapday: "29.02.",
  2342. separator: '.',
  2343. alias: "dd/mm/yyyy"
  2344. },
  2345. 'dd-mm-yyyy': {
  2346. mask: "1-2-y",
  2347. placeholder: "dd-mm-yyyy",
  2348. leapday: "29-02-",
  2349. separator: '-',
  2350. alias: "dd/mm/yyyy"
  2351. },
  2352. 'mm.dd.yyyy': {
  2353. mask: "1.2.y",
  2354. placeholder: "mm.dd.yyyy",
  2355. leapday: "02.29.",
  2356. separator: '.',
  2357. alias: "mm/dd/yyyy"
  2358. },
  2359. 'mm-dd-yyyy': {
  2360. mask: "1-2-y",
  2361. placeholder: "mm-dd-yyyy",
  2362. leapday: "02-29-",
  2363. separator: '-',
  2364. alias: "mm/dd/yyyy"
  2365. },
  2366. 'yyyy.mm.dd': {
  2367. mask: "y.1.2",
  2368. placeholder: "yyyy.mm.dd",
  2369. leapday: ".02.29",
  2370. separator: '.',
  2371. alias: "yyyy/mm/dd"
  2372. },
  2373. 'yyyy-mm-dd': {
  2374. mask: "y-1-2",
  2375. placeholder: "yyyy-mm-dd",
  2376. leapday: "-02-29",
  2377. separator: '-',
  2378. alias: "yyyy/mm/dd"
  2379. },
  2380. 'datetime': {
  2381. mask: "1/2/y h:s",
  2382. placeholder: "dd/mm/yyyy hh:mm",
  2383. alias: "dd/mm/yyyy",
  2384. regex: {
  2385. hrspre: new RegExp("[012]"), //hours pre
  2386. hrs24: new RegExp("2[0-4]|1[3-9]"),
  2387. hrs: new RegExp("[01][0-9]|2[0-4]"), //hours
  2388. ampm: new RegExp("^[a|p|A|P][m|M]")
  2389. },
  2390. timeseparator: ':',
  2391. hourFormat: "24", // or 12
  2392. definitions: {
  2393. 'h': { //hours
  2394. validator: function (chrs, maskset, pos, strict, opts) {
  2395. if (opts.hourFormat == "24") {
  2396. if (parseInt(chrs, 10) == 24) {
  2397. maskset.buffer[pos - 1] = "0";
  2398. maskset.buffer[pos] = "0";
  2399. return { "refreshFromBuffer": { start: pos - 1, end: pos }, "c": "0" };
  2400. }
  2401. }
  2402. var isValid = opts.regex.hrs.test(chrs);
  2403. if (!strict && !isValid) {
  2404. if (chrs.charAt(1) == opts.timeseparator || "-.:".indexOf(chrs.charAt(1)) != -1) {
  2405. isValid = opts.regex.hrs.test("0" + chrs.charAt(0));
  2406. if (isValid) {
  2407. maskset.buffer[pos - 1] = "0";
  2408. maskset.buffer[pos] = chrs.charAt(0);
  2409. pos++;
  2410. return { "refreshFromBuffer": { start: pos - 2, end: pos }, "pos": pos, "c": opts.timeseparator };
  2411. }
  2412. }
  2413. }
  2414. if (isValid && opts.hourFormat !== "24" && opts.regex.hrs24.test(chrs)) {
  2415. var tmp = parseInt(chrs, 10);
  2416. if (tmp == 24) {
  2417. maskset.buffer[pos + 5] = "a";
  2418. maskset.buffer[pos + 6] = "m";
  2419. } else {
  2420. maskset.buffer[pos + 5] = "p";
  2421. maskset.buffer[pos + 6] = "m";
  2422. }
  2423. tmp = tmp - 12;
  2424. if (tmp < 10) {
  2425. maskset.buffer[pos] = tmp.toString();
  2426. maskset.buffer[pos - 1] = "0";
  2427. } else {
  2428. maskset.buffer[pos] = tmp.toString().charAt(1);
  2429. maskset.buffer[pos - 1] = tmp.toString().charAt(0);
  2430. }
  2431. return { "refreshFromBuffer": { start: pos - 1, end: pos + 6 }, "c": maskset.buffer[pos] };
  2432. }
  2433. return isValid;
  2434. },
  2435. cardinality: 2,
  2436. prevalidator: [{
  2437. validator: function (chrs, maskset, pos, strict, opts) {
  2438. var isValid = opts.regex.hrspre.test(chrs);
  2439. if (!strict && !isValid) {
  2440. isValid = opts.regex.hrs.test("0" + chrs);
  2441. if (isValid) {
  2442. maskset.buffer[pos] = "0";
  2443. pos++;
  2444. return { "pos": pos };
  2445. }
  2446. }
  2447. return isValid;
  2448. }, cardinality: 1
  2449. }]
  2450. },
  2451. 't': { //am/pm
  2452. validator: function (chrs, maskset, pos, strict, opts) {
  2453. return opts.regex.ampm.test(chrs + "m");
  2454. },
  2455. casing: "lower",
  2456. cardinality: 1
  2457. }
  2458. },
  2459. insertMode: false,
  2460. autoUnmask: false
  2461. },
  2462. 'datetime12': {
  2463. mask: "1/2/y h:s t\\m",
  2464. placeholder: "dd/mm/yyyy hh:mm xm",
  2465. alias: "datetime",
  2466. hourFormat: "12"
  2467. },
  2468. 'hh:mm t': {
  2469. mask: "h:s t\\m",
  2470. placeholder: "hh:mm xm",
  2471. alias: "datetime",
  2472. hourFormat: "12"
  2473. },
  2474. 'h:s t': {
  2475. mask: "h:s t\\m",
  2476. placeholder: "hh:mm xm",
  2477. alias: "datetime",
  2478. hourFormat: "12"
  2479. },
  2480. 'hh:mm:ss': {
  2481. mask: "h:s:s",
  2482. autoUnmask: false
  2483. },
  2484. 'hh:mm': {
  2485. mask: "h:s",
  2486. autoUnmask: false
  2487. },
  2488. 'date': {
  2489. alias: "dd/mm/yyyy" // "mm/dd/yyyy"
  2490. },
  2491. 'mm/yyyy': {
  2492. mask: "1/y",
  2493. placeholder: "mm/yyyy",
  2494. leapday: "donotuse",
  2495. separator: '/',
  2496. alias: "mm/dd/yyyy"
  2497. }
  2498. });
  2499. })(jQuery);
  2500. /*
  2501. Input Mask plugin extensions
  2502. http://github.com/RobinHerbots/jquery.inputmask
  2503. Copyright (c) 2010 - 2014 Robin Herbots
  2504. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  2505. Version: 3.0.46
  2506. Optional extensions on the jquery.inputmask base
  2507. */
  2508. (function ($) {
  2509. //number aliases
  2510. $.extend($.inputmask.defaults.aliases, {
  2511. 'numeric': {
  2512. mask: function (opts) {
  2513. if (opts.repeat !== 0 && isNaN(opts.integerDigits)) {
  2514. opts.integerDigits = opts.repeat;
  2515. }
  2516. opts.repeat = 0;
  2517. opts.autoGroup = opts.autoGroup && opts.groupSeparator != "";
  2518. if (opts.autoGroup && isFinite(opts.integerDigits)) {
  2519. var seps = Math.floor(opts.integerDigits / opts.groupSize);
  2520. var mod = opts.integerDigits % opts.groupSize;
  2521. opts.integerDigits += mod == 0 ? seps - 1 : seps;
  2522. }
  2523. opts.definitions[":"].placeholder = opts.radixPoint;
  2524. var mask = opts.prefix;
  2525. mask += "[+]";
  2526. mask += "~{1," + opts.integerDigits + "}";
  2527. if (opts.digits != undefined && (isNaN(opts.digits) || parseInt(opts.digits) > 0)) {
  2528. if (opts.digitsOptional)
  2529. mask += "[" + ":" + "~{" + opts.digits + "}]";
  2530. else mask += ":" + "~{" + opts.digits + "}";
  2531. }
  2532. mask += opts.suffix;
  2533. return mask;
  2534. },
  2535. placeholder: "",
  2536. greedy: false,
  2537. digits: "*", //number of fractionalDigits
  2538. digitsOptional: true,
  2539. groupSeparator: "",//",", // | "."
  2540. radixPoint: ".",
  2541. groupSize: 3,
  2542. autoGroup: false,
  2543. allowPlus: true,
  2544. allowMinus: true,
  2545. integerDigits: "+", //number of integerDigits
  2546. prefix: "",
  2547. suffix: "",
  2548. skipRadixDance: false, //disable radixpoint caret positioning
  2549. getLastValidPosition: function (maskset, closestTo, opts) {
  2550. var lastValidPosition = -1, valids = maskset["validPositions"];
  2551. for (var posNdx in valids) {
  2552. var psNdx = parseInt(posNdx);
  2553. if (psNdx > lastValidPosition) lastValidPosition = psNdx;
  2554. }
  2555. if (closestTo != undefined) {
  2556. var buffer = maskset["buffer"];
  2557. if (opts.skipRadixDance === false && opts.radixPoint != "" && $.inArray(opts.radixPoint, buffer) != -1)
  2558. lastValidPosition = $.inArray(opts.radixPoint, buffer);
  2559. }
  2560. return lastValidPosition;
  2561. },
  2562. rightAlign: true,
  2563. postFormat: function (buffer, pos, reformatOnly, opts) {
  2564. var needsRefresh = false;
  2565. if (opts.groupSeparator == "" || ($.inArray(opts.radixPoint, buffer) != -1 && pos > $.inArray(opts.radixPoint, buffer))) return { pos: pos };
  2566. var cbuf = buffer.slice();
  2567. if (!reformatOnly) {
  2568. cbuf.splice(pos, 0, "?"); //set position indicator
  2569. }
  2570. var bufVal = cbuf.join('');
  2571. if (opts.autoGroup || (reformatOnly && bufVal.indexOf(opts.groupSeparator) != -1)) {
  2572. var escapedGroupSeparator = $.inputmask.escapeRegex.call(this, opts.groupSeparator);
  2573. needsRefresh = bufVal.indexOf(opts.groupSeparator) == 0;
  2574. bufVal = bufVal.replace(new RegExp(escapedGroupSeparator, "g"), '');
  2575. var radixSplit = bufVal.split(opts.radixPoint);
  2576. bufVal = radixSplit[0];
  2577. if (bufVal != (opts.prefix + "?0") && bufVal.length > (opts.groupSize + opts.prefix.length)) {
  2578. needsRefresh = true;
  2579. var reg = new RegExp('([-\+]?[\\d\?]+)([\\d\?]{' + opts.groupSize + '})');
  2580. while (reg.test(bufVal)) {
  2581. bufVal = bufVal.replace(reg, '$1' + opts.groupSeparator + '$2');
  2582. bufVal = bufVal.replace(opts.groupSeparator + opts.groupSeparator, opts.groupSeparator);
  2583. }
  2584. }
  2585. if (radixSplit.length > 1)
  2586. bufVal += opts.radixPoint + radixSplit[1];
  2587. }
  2588. buffer.length = bufVal.length; //align the length
  2589. for (var i = 0, l = bufVal.length; i < l; i++) {
  2590. buffer[i] = bufVal.charAt(i);
  2591. }
  2592. var newPos = $.inArray("?", buffer);
  2593. if (!reformatOnly) buffer.splice(newPos, 1);
  2594. return { pos: reformatOnly ? pos : newPos, "refreshFromBuffer": needsRefresh };
  2595. },
  2596. onKeyDown: function (e, buffer, opts) {
  2597. if (opts.autoGroup && (e.keyCode == opts.keyCode.DELETE || e.keyCode == opts.keyCode.BACKSPACE)) {
  2598. return opts.postFormat(buffer, 0, true, opts);
  2599. }
  2600. },
  2601. onKeyPress: function (e, buffer, opts) {
  2602. var k = (e.which || e.charCode || e.keyCode);
  2603. if (k == 46 && e.shiftKey == false && opts.radixPoint == ",") k = 44;
  2604. if (opts.autoGroup && String.fromCharCode(k) == opts.radixPoint) {
  2605. var refresh = opts.postFormat(buffer, 0, true, opts);
  2606. refresh.caret = $.inArray(opts.radixPoint, buffer) + 1;
  2607. return refresh;
  2608. }
  2609. },
  2610. regex: {
  2611. integerPart: function (opts) { return new RegExp('[-\+]?\\d+'); }
  2612. },
  2613. negationhandler: function (chrs, buffer, pos, strict, opts) {
  2614. if (!strict && opts.allowMinus && chrs === "-") {
  2615. var matchRslt = buffer.join('').match(opts.regex.integerPart(opts));
  2616. if (matchRslt.length > 0) {
  2617. if (buffer[matchRslt.index] == "+") {
  2618. return { "pos": matchRslt.index, "c": "-", "remove": matchRslt.index, "caret": pos };
  2619. } else if (buffer[matchRslt.index] == "-") {
  2620. return { "remove": matchRslt.index, "caret": pos - 1 };
  2621. } else {
  2622. return { "pos": matchRslt.index, "c": "-", "caret": pos + 1 };
  2623. }
  2624. }
  2625. }
  2626. return false;
  2627. },
  2628. definitions: {
  2629. '~': {
  2630. validator: function (chrs, maskset, pos, strict, opts) {
  2631. var isValid = opts.negationhandler(chrs, maskset.buffer, pos, strict, opts);
  2632. if (!isValid) {
  2633. isValid = strict ? new RegExp("[0-9" + $.inputmask.escapeRegex.call(this, opts.groupSeparator) + "]").test(chrs) : new RegExp("[0-9]").test(chrs);
  2634. if (isValid === true) isValid = { pos: pos };
  2635. if (isValid != false && !strict) {
  2636. //handle 0 for integerpart
  2637. var matchRslt = maskset.buffer.join('').match(opts.regex.integerPart(opts)), radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
  2638. if (matchRslt) {
  2639. if (matchRslt["0"][0].indexOf("0") == 0 && pos >= opts.prefix.length) {
  2640. if (radixPosition == -1 || (pos <= radixPosition && maskset["validPositions"][radixPosition] == undefined)) {
  2641. maskset.buffer.splice(matchRslt.index, 1);
  2642. pos = pos > matchRslt.index ? pos - 1 : matchRslt.index;
  2643. $.extend(isValid, { "pos": pos, "remove": matchRslt.index });
  2644. } else if (pos > matchRslt.index && pos <= radixPosition) {
  2645. maskset.buffer.splice(matchRslt.index, 1);
  2646. pos = pos > matchRslt.index ? pos - 1 : matchRslt.index;
  2647. $.extend(isValid, { "pos": pos, "remove": matchRslt.index });
  2648. }
  2649. } else if (chrs == "0" && pos <= matchRslt.index) {
  2650. return false;
  2651. }
  2652. }
  2653. //handle overwrite when fixed precision
  2654. if (opts.digitsOptional === false && pos > radixPosition) {
  2655. return { "pos": pos, "remove": pos };
  2656. }
  2657. }
  2658. if (isValid != false && !strict && chrs != opts.radixPoint && opts.autoGroup === true) {
  2659. isValid = $.extend(isValid, opts.postFormat(maskset.buffer, pos, false, opts));
  2660. }
  2661. }
  2662. return isValid;
  2663. },
  2664. cardinality: 1,
  2665. prevalidator: null
  2666. },
  2667. '+': {
  2668. validator: function (chrs, maskset, pos, strict, opts) {
  2669. var signed = "[";
  2670. if (opts.allowMinus === true) signed += "-";
  2671. if (opts.allowPlus === true) signed += "\+";
  2672. signed += "]";
  2673. var isValid = new RegExp(signed).test(chrs);
  2674. return isValid;
  2675. },
  2676. cardinality: 1,
  2677. prevalidator: null
  2678. },
  2679. ':': {
  2680. validator: function (chrs, maskset, pos, strict, opts) {
  2681. var isValid = opts.negationhandler(chrs, maskset.buffer, pos, strict, opts);
  2682. if (!isValid) {
  2683. var radix = "[" + $.inputmask.escapeRegex.call(this, opts.radixPoint) + "]";
  2684. isValid = new RegExp(radix).test(chrs);
  2685. }
  2686. return isValid;
  2687. },
  2688. cardinality: 1,
  2689. prevalidator: null,
  2690. placeholder: "" //radixpoint will be set in the mask function
  2691. }
  2692. },
  2693. insertMode: true,
  2694. autoUnmask: false,
  2695. onUnMask: function (maskedValue, unmaskedValue, opts) {
  2696. var processValue = maskedValue.replace(opts.prefix, "");
  2697. processValue = processValue.replace(opts.suffix, "");
  2698. processValue = processValue.replace(new RegExp(opts.groupSeparator, "g"), "");
  2699. processValue = processValue.replace(opts.radixPoint, ".");
  2700. return Number(processValue);
  2701. },
  2702. isComplete: function (buffer, opts) {
  2703. var maskedValue = buffer.join('');
  2704. var processValue = maskedValue.replace(opts.prefix, "");
  2705. processValue = processValue.replace(opts.suffix, "");
  2706. processValue = processValue.replace(new RegExp(opts.groupSeparator, "g"), "");
  2707. processValue = processValue.replace(opts.radixPoint, ".");
  2708. return isFinite(processValue);
  2709. },
  2710. onBeforeMask: function (initialValue, opts) {
  2711. return isFinite(initialValue) ? initialValue.toString().replace(".", opts.radixPoint) : initialValue;
  2712. }
  2713. },
  2714. 'decimal': {
  2715. alias: "numeric"
  2716. },
  2717. 'integer': {
  2718. alias: "numeric",
  2719. digits: "0"
  2720. }
  2721. });
  2722. })(jQuery);
  2723. /*
  2724. Input Mask plugin extensions
  2725. http://github.com/RobinHerbots/jquery.inputmask
  2726. Copyright (c) 2010 - 2014 Robin Herbots
  2727. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  2728. Version: 3.0.46
  2729. Regex extensions on the jquery.inputmask base
  2730. Allows for using regular expressions as a mask
  2731. */
  2732. (function ($) {
  2733. $.extend($.inputmask.defaults.aliases, { // $(selector).inputmask("Regex", { regex: "[0-9]*"}
  2734. 'Regex': {
  2735. mask: "r",
  2736. greedy: false,
  2737. repeat: "*",
  2738. regex: null,
  2739. regexTokens: null,
  2740. //Thx to https://github.com/slevithan/regex-colorizer for the tokenizer regex
  2741. tokenizer: /\[\^?]?(?:[^\\\]]+|\\[\S\s]?)*]?|\\(?:0(?:[0-3][0-7]{0,2}|[4-7][0-7]?)?|[1-9][0-9]*|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|c[A-Za-z]|[\S\s]?)|\((?:\?[:=!]?)?|(?:[?*+]|\{[0-9]+(?:,[0-9]*)?\})\??|[^.?*+^${[()|\\]+|./g,
  2742. quantifierFilter: /[0-9]+[^,]/,
  2743. isComplete: function(buffer, opts){
  2744. return new RegExp(opts.regex).test(buffer.join(''));
  2745. },
  2746. definitions: {
  2747. 'r': {
  2748. validator: function (chrs, maskset, pos, strict, opts) {
  2749. function regexToken(isGroup, isQuantifier) {
  2750. this.matches = [];
  2751. this.isGroup = isGroup || false;
  2752. this.isQuantifier = isQuantifier || false;
  2753. this.quantifier = { min: 1, max: 1 };
  2754. this.repeaterPart = undefined;
  2755. }
  2756. function analyseRegex() {
  2757. var currentToken = new regexToken(), match, m, opengroups = [];
  2758. opts.regexTokens = [];
  2759. // The tokenizer regex does most of the tokenization grunt work
  2760. while (match = opts.tokenizer.exec(opts.regex)) {
  2761. m = match[0];
  2762. switch (m.charAt(0)) {
  2763. case "(": // Group opening
  2764. opengroups.push(new regexToken(true));
  2765. break;
  2766. case ")": // Group closing
  2767. var groupToken = opengroups.pop();
  2768. if (opengroups.length > 0) {
  2769. opengroups[opengroups.length - 1]["matches"].push(groupToken);
  2770. } else {
  2771. currentToken.matches.push(groupToken);
  2772. }
  2773. break;
  2774. case "{": case "+": case "*": //Quantifier
  2775. var quantifierToken = new regexToken(false, true);
  2776. m = m.replace(/[{}]/g, "");
  2777. var mq = m.split(","), mq0 = isNaN(mq[0]) ? mq[0] : parseInt(mq[0]), mq1 = mq.length == 1 ? mq0 : (isNaN(mq[1]) ? mq[1] : parseInt(mq[1]));
  2778. quantifierToken.quantifier = { min: mq0, max: mq1 };
  2779. if (opengroups.length > 0) {
  2780. var matches = opengroups[opengroups.length - 1]["matches"];
  2781. match = matches.pop();
  2782. if (!match["isGroup"]) {
  2783. var groupToken = new regexToken(true);
  2784. groupToken.matches.push(match);
  2785. match = groupToken;
  2786. }
  2787. matches.push(match);
  2788. matches.push(quantifierToken);
  2789. } else {
  2790. match = currentToken.matches.pop();
  2791. if (!match["isGroup"]) {
  2792. var groupToken = new regexToken(true);
  2793. groupToken.matches.push(match);
  2794. match = groupToken;
  2795. }
  2796. currentToken.matches.push(match);
  2797. currentToken.matches.push(quantifierToken);
  2798. }
  2799. break;
  2800. default:
  2801. if (opengroups.length > 0) {
  2802. opengroups[opengroups.length - 1]["matches"].push(m);
  2803. } else {
  2804. currentToken.matches.push(m);
  2805. }
  2806. break;
  2807. }
  2808. }
  2809. if (currentToken.matches.length > 0)
  2810. opts.regexTokens.push(currentToken);
  2811. };
  2812. function validateRegexToken(token, fromGroup) {
  2813. var isvalid = false;
  2814. if (fromGroup) {
  2815. regexPart += "(";
  2816. openGroupCount++;
  2817. }
  2818. for (var mndx = 0; mndx < token["matches"].length; mndx++) {
  2819. var matchToken = token["matches"][mndx];
  2820. if (matchToken["isGroup"] == true) {
  2821. isvalid = validateRegexToken(matchToken, true);
  2822. } else if (matchToken["isQuantifier"] == true) {
  2823. var crrntndx = $.inArray(matchToken, token["matches"]),
  2824. matchGroup = token["matches"][crrntndx - 1];
  2825. var regexPartBak = regexPart;
  2826. if (isNaN(matchToken.quantifier.max)) {
  2827. while (matchToken["repeaterPart"] && matchToken["repeaterPart"] != regexPart && matchToken["repeaterPart"].length > regexPart.length) {
  2828. isvalid = validateRegexToken(matchGroup, true);
  2829. if (isvalid) break;
  2830. }
  2831. isvalid = isvalid || validateRegexToken(matchGroup, true);
  2832. if (isvalid) matchToken["repeaterPart"] = regexPart;
  2833. regexPart = regexPartBak + matchToken.quantifier.max;
  2834. } else {
  2835. for (var i = 0, qm = matchToken.quantifier.max - 1; i < qm; i++) {
  2836. isvalid = validateRegexToken(matchGroup, true);
  2837. if (isvalid) break;
  2838. }
  2839. regexPart = regexPartBak + "{" + matchToken.quantifier.min + "," + matchToken.quantifier.max + "}";
  2840. }
  2841. } else if (matchToken["matches"] != undefined) {
  2842. for (var k = 0; k < matchToken.length; k++) {
  2843. isvalid = validateRegexToken(matchToken[k], fromGroup);
  2844. if (isvalid) break;
  2845. }
  2846. } else {
  2847. var testExp;
  2848. if (matchToken[0] == "[") {
  2849. testExp = regexPart;
  2850. testExp += matchToken;
  2851. for (var j = 0; j < openGroupCount; j++) {
  2852. testExp += ")";
  2853. }
  2854. var exp = new RegExp("^(" + testExp + ")$");
  2855. isvalid = exp.test(bufferStr);
  2856. } else {
  2857. for (var l = 0, tl = matchToken.length; l < tl; l++) {
  2858. if (matchToken[l] == "\\") continue;
  2859. testExp = regexPart;
  2860. testExp += matchToken.substr(0, l + 1);
  2861. testExp = testExp.replace(/\|$/, "");
  2862. for (var j = 0; j < openGroupCount; j++) {
  2863. testExp += ")";
  2864. }
  2865. var exp = new RegExp("^(" + testExp + ")$");
  2866. isvalid = exp.test(bufferStr);
  2867. if (isvalid) break;
  2868. }
  2869. }
  2870. regexPart += matchToken;
  2871. }
  2872. if (isvalid) break;
  2873. }
  2874. if (fromGroup) {
  2875. regexPart += ")";
  2876. openGroupCount--;
  2877. }
  2878. return isvalid;
  2879. }
  2880. if (opts.regexTokens == null) {
  2881. analyseRegex();
  2882. }
  2883. var cbuffer = maskset.buffer.slice(), regexPart = "", isValid = false, openGroupCount = 0;
  2884. cbuffer.splice(pos, 0, chrs);
  2885. var bufferStr = cbuffer.join('');
  2886. for (var i = 0; i < opts.regexTokens.length; i++) {
  2887. var regexToken = opts.regexTokens[i];
  2888. isValid = validateRegexToken(regexToken, regexToken["isGroup"]);
  2889. if (isValid) break;
  2890. }
  2891. return isValid;
  2892. },
  2893. cardinality: 1
  2894. }
  2895. }
  2896. }
  2897. });
  2898. })(jQuery);
  2899. /*
  2900. Input Mask plugin extensions
  2901. http://github.com/RobinHerbots/jquery.inputmask
  2902. Copyright (c) 2010 - 2014 Robin Herbots
  2903. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  2904. Version: 3.0.46
  2905. Phone extension.
  2906. When using this extension make sure you specify the correct url to get the masks
  2907. $(selector).inputmask("phone", {
  2908. url: "Scripts/jquery.inputmask/phone-codes/phone-codes.json",
  2909. onKeyValidation: function () { //show some metadata in the console
  2910. console.log($(this).inputmask("getmetadata")["name_en"]);
  2911. }
  2912. });
  2913. */
  2914. (function ($) {
  2915. $.extend($.inputmask.defaults.aliases, {
  2916. 'phone': {
  2917. url: "phone-codes/phone-codes.json",
  2918. mask: function (opts) {
  2919. opts.definitions = {
  2920. 'p': {
  2921. validator: function () { return false; },
  2922. cardinality: 1
  2923. },
  2924. '#': {
  2925. validator: "[0-9]",
  2926. cardinality: 1
  2927. }
  2928. };
  2929. var maskList = [];
  2930. $.ajax({
  2931. url: opts.url,
  2932. async: false,
  2933. dataType: 'json',
  2934. success: function (response) {
  2935. maskList = response;
  2936. }
  2937. });
  2938. maskList.splice(0, 0, "+p(ppp)ppp-pppp");
  2939. return maskList;
  2940. },
  2941. nojumps: true,
  2942. nojumpsThreshold: 1
  2943. },
  2944. 'phonebe': {
  2945. url: "phone-codes/phone-be.json",
  2946. mask: function (opts) {
  2947. opts.definitions = {
  2948. 'p': {
  2949. validator: function () { return false; },
  2950. cardinality: 1
  2951. },
  2952. '#': {
  2953. validator: "[0-9]",
  2954. cardinality: 1
  2955. }
  2956. };
  2957. var maskList = [];
  2958. $.ajax({
  2959. url: opts.url,
  2960. async: false,
  2961. dataType: 'json',
  2962. success: function (response) {
  2963. maskList = response;
  2964. }
  2965. });
  2966. maskList.splice(0, 0, "+32(ppp)ppp-pppp");
  2967. return maskList;
  2968. },
  2969. nojumps: true,
  2970. nojumpsThreshold: 4
  2971. }
  2972. });
  2973. })(jQuery);