jquery.inputmask.bundle.js 215 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863
  1. /*!
  2. * jquery.inputmask.bundle.js
  3. * https://github.com/RobinHerbots/Inputmask
  4. * Copyright (c) 2010 - 2018 Robin Herbots
  5. * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. * Version: 4.0.3-beta.4
  7. */
  8. (function(modules) {
  9. var installedModules = {};
  10. function __webpack_require__(moduleId) {
  11. if (installedModules[moduleId]) {
  12. return installedModules[moduleId].exports;
  13. }
  14. var module = installedModules[moduleId] = {
  15. i: moduleId,
  16. l: false,
  17. exports: {}
  18. };
  19. modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  20. module.l = true;
  21. return module.exports;
  22. }
  23. __webpack_require__.m = modules;
  24. __webpack_require__.c = installedModules;
  25. __webpack_require__.d = function(exports, name, getter) {
  26. if (!__webpack_require__.o(exports, name)) {
  27. Object.defineProperty(exports, name, {
  28. enumerable: true,
  29. get: getter
  30. });
  31. }
  32. };
  33. __webpack_require__.r = function(exports) {
  34. if (typeof Symbol !== "undefined" && Symbol.toStringTag) {
  35. Object.defineProperty(exports, Symbol.toStringTag, {
  36. value: "Module"
  37. });
  38. }
  39. Object.defineProperty(exports, "__esModule", {
  40. value: true
  41. });
  42. };
  43. __webpack_require__.t = function(value, mode) {
  44. if (mode & 1) value = __webpack_require__(value);
  45. if (mode & 8) return value;
  46. if (mode & 4 && typeof value === "object" && value && value.__esModule) return value;
  47. var ns = Object.create(null);
  48. __webpack_require__.r(ns);
  49. Object.defineProperty(ns, "default", {
  50. enumerable: true,
  51. value: value
  52. });
  53. if (mode & 2 && typeof value != "string") for (var key in value) __webpack_require__.d(ns, key, function(key) {
  54. return value[key];
  55. }.bind(null, key));
  56. return ns;
  57. };
  58. __webpack_require__.n = function(module) {
  59. var getter = module && module.__esModule ? function getDefault() {
  60. return module["default"];
  61. } : function getModuleExports() {
  62. return module;
  63. };
  64. __webpack_require__.d(getter, "a", getter);
  65. return getter;
  66. };
  67. __webpack_require__.o = function(object, property) {
  68. return Object.prototype.hasOwnProperty.call(object, property);
  69. };
  70. __webpack_require__.p = "";
  71. return __webpack_require__(__webpack_require__.s = 0);
  72. })([ function(module, exports, __webpack_require__) {
  73. "use strict";
  74. __webpack_require__(1);
  75. __webpack_require__(6);
  76. __webpack_require__(7);
  77. var _inputmask = __webpack_require__(2);
  78. var _inputmask2 = _interopRequireDefault(_inputmask);
  79. var _inputmask3 = __webpack_require__(3);
  80. var _inputmask4 = _interopRequireDefault(_inputmask3);
  81. var _jquery = __webpack_require__(4);
  82. var _jquery2 = _interopRequireDefault(_jquery);
  83. function _interopRequireDefault(obj) {
  84. return obj && obj.__esModule ? obj : {
  85. default: obj
  86. };
  87. }
  88. if (_inputmask4.default === _jquery2.default) {
  89. __webpack_require__(8);
  90. }
  91. window.Inputmask = _inputmask2.default;
  92. }, function(module, exports, __webpack_require__) {
  93. "use strict";
  94. var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;
  95. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function(obj) {
  96. return typeof obj;
  97. } : function(obj) {
  98. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  99. };
  100. (function(factory) {
  101. if (true) {
  102. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [ __webpack_require__(2) ], __WEBPACK_AMD_DEFINE_FACTORY__ = factory,
  103. __WEBPACK_AMD_DEFINE_RESULT__ = typeof __WEBPACK_AMD_DEFINE_FACTORY__ === "function" ? __WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__) : __WEBPACK_AMD_DEFINE_FACTORY__,
  104. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  105. } else {}
  106. })(function(Inputmask) {
  107. Inputmask.extendDefinitions({
  108. A: {
  109. validator: "[A-Za-z\u0410-\u044f\u0401\u0451\xc0-\xff\xb5]",
  110. casing: "upper"
  111. },
  112. "&": {
  113. validator: "[0-9A-Za-z\u0410-\u044f\u0401\u0451\xc0-\xff\xb5]",
  114. casing: "upper"
  115. },
  116. "#": {
  117. validator: "[0-9A-Fa-f]",
  118. casing: "upper"
  119. }
  120. });
  121. Inputmask.extendAliases({
  122. cssunit: {
  123. regex: "[+-]?[0-9]+\\.?([0-9]+)?(px|em|rem|ex|%|in|cm|mm|pt|pc)"
  124. },
  125. url: {
  126. regex: "(https?|ftp)//.*",
  127. autoUnmask: false
  128. },
  129. ip: {
  130. mask: "i[i[i]].i[i[i]].i[i[i]].i[i[i]]",
  131. definitions: {
  132. i: {
  133. validator: function validator(chrs, maskset, pos, strict, opts) {
  134. if (pos - 1 > -1 && maskset.buffer[pos - 1] !== ".") {
  135. chrs = maskset.buffer[pos - 1] + chrs;
  136. if (pos - 2 > -1 && maskset.buffer[pos - 2] !== ".") {
  137. chrs = maskset.buffer[pos - 2] + chrs;
  138. } else chrs = "0" + chrs;
  139. } else chrs = "00" + chrs;
  140. return new RegExp("25[0-5]|2[0-4][0-9]|[01][0-9][0-9]").test(chrs);
  141. }
  142. }
  143. },
  144. onUnMask: function onUnMask(maskedValue, unmaskedValue, opts) {
  145. return maskedValue;
  146. },
  147. inputmode: "numeric"
  148. },
  149. email: {
  150. mask: "*{1,64}[.*{1,64}][.*{1,64}][.*{1,63}]@-{1,63}.-{1,63}[.-{1,63}][.-{1,63}]",
  151. greedy: false,
  152. casing: "lower",
  153. onBeforePaste: function onBeforePaste(pastedValue, opts) {
  154. pastedValue = pastedValue.toLowerCase();
  155. return pastedValue.replace("mailto:", "");
  156. },
  157. definitions: {
  158. "*": {
  159. validator: "[0-9\uff11-\uff19A-Za-z\u0410-\u044f\u0401\u0451\xc0-\xff\xb5!#$%&'*+/=?^_`{|}~-]"
  160. },
  161. "-": {
  162. validator: "[0-9A-Za-z-]"
  163. }
  164. },
  165. onUnMask: function onUnMask(maskedValue, unmaskedValue, opts) {
  166. return maskedValue;
  167. },
  168. inputmode: "email"
  169. },
  170. mac: {
  171. mask: "##:##:##:##:##:##"
  172. },
  173. vin: {
  174. mask: "V{13}9{4}",
  175. definitions: {
  176. V: {
  177. validator: "[A-HJ-NPR-Za-hj-npr-z\\d]",
  178. casing: "upper"
  179. }
  180. },
  181. clearIncomplete: true,
  182. autoUnmask: true
  183. }
  184. });
  185. return Inputmask;
  186. });
  187. }, function(module, exports, __webpack_require__) {
  188. "use strict";
  189. var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;
  190. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function(obj) {
  191. return typeof obj;
  192. } : function(obj) {
  193. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  194. };
  195. (function(factory) {
  196. if (true) {
  197. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [ __webpack_require__(3), __webpack_require__(5) ],
  198. __WEBPACK_AMD_DEFINE_FACTORY__ = factory, __WEBPACK_AMD_DEFINE_RESULT__ = typeof __WEBPACK_AMD_DEFINE_FACTORY__ === "function" ? __WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__) : __WEBPACK_AMD_DEFINE_FACTORY__,
  199. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  200. } else {}
  201. })(function($, window, undefined) {
  202. var document = window.document, ua = navigator.userAgent, ie = ua.indexOf("MSIE ") > 0 || ua.indexOf("Trident/") > 0, mobile = isInputEventSupported("touchstart"), iemobile = /iemobile/i.test(ua), iphone = /iphone/i.test(ua) && !iemobile;
  203. function Inputmask(alias, options, internal) {
  204. if (!(this instanceof Inputmask)) {
  205. return new Inputmask(alias, options, internal);
  206. }
  207. this.el = undefined;
  208. this.events = {};
  209. this.maskset = undefined;
  210. this.refreshValue = false;
  211. if (internal !== true) {
  212. if ($.isPlainObject(alias)) {
  213. options = alias;
  214. } else {
  215. options = options || {};
  216. if (alias) options.alias = alias;
  217. }
  218. this.opts = $.extend(true, {}, this.defaults, options);
  219. this.noMasksCache = options && options.definitions !== undefined;
  220. this.userOptions = options || {};
  221. this.isRTL = this.opts.numericInput;
  222. resolveAlias(this.opts.alias, options, this.opts);
  223. }
  224. }
  225. Inputmask.prototype = {
  226. dataAttribute: "data-inputmask",
  227. defaults: {
  228. placeholder: "_",
  229. optionalmarker: [ "[", "]" ],
  230. quantifiermarker: [ "{", "}" ],
  231. groupmarker: [ "(", ")" ],
  232. alternatormarker: "|",
  233. escapeChar: "\\",
  234. mask: null,
  235. regex: null,
  236. oncomplete: $.noop,
  237. onincomplete: $.noop,
  238. oncleared: $.noop,
  239. repeat: 0,
  240. greedy: false,
  241. autoUnmask: false,
  242. removeMaskOnSubmit: false,
  243. clearMaskOnLostFocus: true,
  244. insertMode: true,
  245. clearIncomplete: false,
  246. alias: null,
  247. onKeyDown: $.noop,
  248. onBeforeMask: null,
  249. onBeforePaste: function onBeforePaste(pastedValue, opts) {
  250. return $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(this, pastedValue, opts) : pastedValue;
  251. },
  252. onBeforeWrite: null,
  253. onUnMask: null,
  254. showMaskOnFocus: true,
  255. showMaskOnHover: true,
  256. onKeyValidation: $.noop,
  257. skipOptionalPartCharacter: " ",
  258. numericInput: false,
  259. rightAlign: false,
  260. undoOnEscape: true,
  261. radixPoint: "",
  262. _radixDance: false,
  263. groupSeparator: "",
  264. keepStatic: null,
  265. positionCaretOnTab: true,
  266. tabThrough: false,
  267. supportsInputType: [ "text", "tel", "password", "search" ],
  268. 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, 0, 229 ],
  269. isComplete: null,
  270. preValidation: null,
  271. postValidation: null,
  272. staticDefinitionSymbol: undefined,
  273. jitMasking: false,
  274. nullable: true,
  275. inputEventOnly: false,
  276. noValuePatching: false,
  277. positionCaretOnClick: "lvp",
  278. casing: null,
  279. inputmode: "verbatim",
  280. colorMask: false,
  281. disablePredictiveText: false,
  282. importDataAttributes: true,
  283. shiftPositions: true
  284. },
  285. definitions: {
  286. 9: {
  287. validator: "[0-9\uff11-\uff19]",
  288. definitionSymbol: "*"
  289. },
  290. a: {
  291. validator: "[A-Za-z\u0410-\u044f\u0401\u0451\xc0-\xff\xb5]",
  292. definitionSymbol: "*"
  293. },
  294. "*": {
  295. validator: "[0-9\uff11-\uff19A-Za-z\u0410-\u044f\u0401\u0451\xc0-\xff\xb5]"
  296. }
  297. },
  298. aliases: {},
  299. masksCache: {},
  300. mask: function mask(elems) {
  301. var that = this;
  302. function importAttributeOptions(npt, opts, userOptions, dataAttribute) {
  303. if (opts.importDataAttributes === true) {
  304. var importOption = function importOption(option, optionData) {
  305. optionData = optionData !== undefined ? optionData : npt.getAttribute(dataAttribute + "-" + option);
  306. if (optionData !== null) {
  307. if (typeof optionData === "string") {
  308. if (option.indexOf("on") === 0) optionData = window[optionData]; else if (optionData === "false") optionData = false; else if (optionData === "true") optionData = true;
  309. }
  310. userOptions[option] = optionData;
  311. }
  312. };
  313. var attrOptions = npt.getAttribute(dataAttribute), option, dataoptions, optionData, p;
  314. if (attrOptions && attrOptions !== "") {
  315. attrOptions = attrOptions.replace(/'/g, '"');
  316. dataoptions = JSON.parse("{" + attrOptions + "}");
  317. }
  318. if (dataoptions) {
  319. optionData = undefined;
  320. for (p in dataoptions) {
  321. if (p.toLowerCase() === "alias") {
  322. optionData = dataoptions[p];
  323. break;
  324. }
  325. }
  326. }
  327. importOption("alias", optionData);
  328. if (userOptions.alias) {
  329. resolveAlias(userOptions.alias, userOptions, opts);
  330. }
  331. for (option in opts) {
  332. if (dataoptions) {
  333. optionData = undefined;
  334. for (p in dataoptions) {
  335. if (p.toLowerCase() === option.toLowerCase()) {
  336. optionData = dataoptions[p];
  337. break;
  338. }
  339. }
  340. }
  341. importOption(option, optionData);
  342. }
  343. }
  344. $.extend(true, opts, userOptions);
  345. if (npt.dir === "rtl" || opts.rightAlign) {
  346. npt.style.textAlign = "right";
  347. }
  348. if (npt.dir === "rtl" || opts.numericInput) {
  349. npt.dir = "ltr";
  350. npt.removeAttribute("dir");
  351. opts.isRTL = true;
  352. }
  353. return Object.keys(userOptions).length;
  354. }
  355. if (typeof elems === "string") {
  356. elems = document.getElementById(elems) || document.querySelectorAll(elems);
  357. }
  358. elems = elems.nodeName ? [ elems ] : elems;
  359. $.each(elems, function(ndx, el) {
  360. var scopedOpts = $.extend(true, {}, that.opts);
  361. if (importAttributeOptions(el, scopedOpts, $.extend(true, {}, that.userOptions), that.dataAttribute)) {
  362. var maskset = generateMaskSet(scopedOpts, that.noMasksCache);
  363. if (maskset !== undefined) {
  364. if (el.inputmask !== undefined) {
  365. el.inputmask.opts.autoUnmask = true;
  366. el.inputmask.remove();
  367. }
  368. el.inputmask = new Inputmask(undefined, undefined, true);
  369. el.inputmask.opts = scopedOpts;
  370. el.inputmask.noMasksCache = that.noMasksCache;
  371. el.inputmask.userOptions = $.extend(true, {}, that.userOptions);
  372. el.inputmask.isRTL = scopedOpts.isRTL || scopedOpts.numericInput;
  373. el.inputmask.el = el;
  374. el.inputmask.maskset = maskset;
  375. $.data(el, "_inputmask_opts", scopedOpts);
  376. maskScope.call(el.inputmask, {
  377. action: "mask"
  378. });
  379. }
  380. }
  381. });
  382. return elems && elems[0] ? elems[0].inputmask || this : this;
  383. },
  384. option: function option(options, noremask) {
  385. if (typeof options === "string") {
  386. return this.opts[options];
  387. } else if ((typeof options === "undefined" ? "undefined" : _typeof(options)) === "object") {
  388. $.extend(this.userOptions, options);
  389. if (this.el && noremask !== true) {
  390. this.mask(this.el);
  391. }
  392. return this;
  393. }
  394. },
  395. unmaskedvalue: function unmaskedvalue(value) {
  396. this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
  397. return maskScope.call(this, {
  398. action: "unmaskedvalue",
  399. value: value
  400. });
  401. },
  402. remove: function remove() {
  403. return maskScope.call(this, {
  404. action: "remove"
  405. });
  406. },
  407. getemptymask: function getemptymask() {
  408. this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
  409. return maskScope.call(this, {
  410. action: "getemptymask"
  411. });
  412. },
  413. hasMaskedValue: function hasMaskedValue() {
  414. return !this.opts.autoUnmask;
  415. },
  416. isComplete: function isComplete() {
  417. this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
  418. return maskScope.call(this, {
  419. action: "isComplete"
  420. });
  421. },
  422. getmetadata: function getmetadata() {
  423. this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
  424. return maskScope.call(this, {
  425. action: "getmetadata"
  426. });
  427. },
  428. isValid: function isValid(value) {
  429. this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
  430. return maskScope.call(this, {
  431. action: "isValid",
  432. value: value
  433. });
  434. },
  435. format: function format(value, metadata) {
  436. this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
  437. return maskScope.call(this, {
  438. action: "format",
  439. value: value,
  440. metadata: metadata
  441. });
  442. },
  443. setValue: function setValue(value) {
  444. if (this.el) {
  445. $(this.el).trigger("setvalue", [ value ]);
  446. }
  447. },
  448. analyseMask: function analyseMask(mask, regexMask, opts) {
  449. var tokenizer = /(?:[?*+]|\{[0-9\+\*]+(?:,[0-9\+\*]*)?(?:\|[0-9\+\*]*)?\})|[^.?*+^${[]()|\\]+|./g, regexTokenizer = /\[\^?]?(?:[^\\\]]+|\\[\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, escaped = false, currentToken = new MaskToken(), match, m, openenings = [], maskTokens = [], openingToken, currentOpeningToken, alternator, lastMatch, groupToken;
  450. function MaskToken(isGroup, isOptional, isQuantifier, isAlternator) {
  451. this.matches = [];
  452. this.openGroup = isGroup || false;
  453. this.alternatorGroup = false;
  454. this.isGroup = isGroup || false;
  455. this.isOptional = isOptional || false;
  456. this.isQuantifier = isQuantifier || false;
  457. this.isAlternator = isAlternator || false;
  458. this.quantifier = {
  459. min: 1,
  460. max: 1
  461. };
  462. }
  463. function insertTestDefinition(mtoken, element, position) {
  464. position = position !== undefined ? position : mtoken.matches.length;
  465. var prevMatch = mtoken.matches[position - 1];
  466. if (regexMask) {
  467. if (element.indexOf("[") === 0 || escaped && /\\d|\\s|\\w]/i.test(element) || element === ".") {
  468. mtoken.matches.splice(position++, 0, {
  469. fn: new RegExp(element, opts.casing ? "i" : ""),
  470. optionality: false,
  471. newBlockMarker: prevMatch === undefined ? "master" : prevMatch.def !== element,
  472. casing: null,
  473. def: element,
  474. placeholder: undefined,
  475. nativeDef: element
  476. });
  477. } else {
  478. if (escaped) element = element[element.length - 1];
  479. $.each(element.split(""), function(ndx, lmnt) {
  480. prevMatch = mtoken.matches[position - 1];
  481. mtoken.matches.splice(position++, 0, {
  482. fn: null,
  483. optionality: false,
  484. newBlockMarker: prevMatch === undefined ? "master" : prevMatch.def !== lmnt && prevMatch.fn !== null,
  485. casing: null,
  486. def: opts.staticDefinitionSymbol || lmnt,
  487. placeholder: opts.staticDefinitionSymbol !== undefined ? lmnt : undefined,
  488. nativeDef: (escaped ? "'" : "") + lmnt
  489. });
  490. });
  491. }
  492. escaped = false;
  493. } else {
  494. var maskdef = (opts.definitions ? opts.definitions[element] : undefined) || Inputmask.prototype.definitions[element];
  495. if (maskdef && !escaped) {
  496. mtoken.matches.splice(position++, 0, {
  497. fn: maskdef.validator ? typeof maskdef.validator == "string" ? new RegExp(maskdef.validator, opts.casing ? "i" : "") : new function() {
  498. this.test = maskdef.validator;
  499. }() : new RegExp("."),
  500. optionality: false,
  501. newBlockMarker: prevMatch === undefined ? "master" : prevMatch.def !== (maskdef.definitionSymbol || element),
  502. casing: maskdef.casing,
  503. def: maskdef.definitionSymbol || element,
  504. placeholder: maskdef.placeholder,
  505. nativeDef: element
  506. });
  507. } else {
  508. mtoken.matches.splice(position++, 0, {
  509. fn: null,
  510. optionality: false,
  511. newBlockMarker: prevMatch === undefined ? "master" : prevMatch.def !== element && prevMatch.fn !== null,
  512. casing: null,
  513. def: opts.staticDefinitionSymbol || element,
  514. placeholder: opts.staticDefinitionSymbol !== undefined ? element : undefined,
  515. nativeDef: (escaped ? "'" : "") + element
  516. });
  517. escaped = false;
  518. }
  519. }
  520. }
  521. function verifyGroupMarker(maskToken) {
  522. if (maskToken && maskToken.matches) {
  523. $.each(maskToken.matches, function(ndx, token) {
  524. var nextToken = maskToken.matches[ndx + 1];
  525. if ((nextToken === undefined || nextToken.matches === undefined || nextToken.isQuantifier === false) && token && token.isGroup) {
  526. token.isGroup = false;
  527. if (!regexMask) {
  528. insertTestDefinition(token, opts.groupmarker[0], 0);
  529. if (token.openGroup !== true) {
  530. insertTestDefinition(token, opts.groupmarker[1]);
  531. }
  532. }
  533. }
  534. verifyGroupMarker(token);
  535. });
  536. }
  537. }
  538. function defaultCase() {
  539. if (openenings.length > 0) {
  540. currentOpeningToken = openenings[openenings.length - 1];
  541. insertTestDefinition(currentOpeningToken, m);
  542. if (currentOpeningToken.isAlternator) {
  543. alternator = openenings.pop();
  544. for (var mndx = 0; mndx < alternator.matches.length; mndx++) {
  545. if (alternator.matches[mndx].isGroup) alternator.matches[mndx].isGroup = false;
  546. }
  547. if (openenings.length > 0) {
  548. currentOpeningToken = openenings[openenings.length - 1];
  549. currentOpeningToken.matches.push(alternator);
  550. } else {
  551. currentToken.matches.push(alternator);
  552. }
  553. }
  554. } else {
  555. insertTestDefinition(currentToken, m);
  556. }
  557. }
  558. function reverseTokens(maskToken) {
  559. function reverseStatic(st) {
  560. if (st === opts.optionalmarker[0]) st = opts.optionalmarker[1]; else if (st === opts.optionalmarker[1]) st = opts.optionalmarker[0]; else if (st === opts.groupmarker[0]) st = opts.groupmarker[1]; else if (st === opts.groupmarker[1]) st = opts.groupmarker[0];
  561. return st;
  562. }
  563. maskToken.matches = maskToken.matches.reverse();
  564. for (var match in maskToken.matches) {
  565. if (maskToken.matches.hasOwnProperty(match)) {
  566. var intMatch = parseInt(match);
  567. if (maskToken.matches[match].isQuantifier && maskToken.matches[intMatch + 1] && maskToken.matches[intMatch + 1].isGroup) {
  568. var qt = maskToken.matches[match];
  569. maskToken.matches.splice(match, 1);
  570. maskToken.matches.splice(intMatch + 1, 0, qt);
  571. }
  572. if (maskToken.matches[match].matches !== undefined) {
  573. maskToken.matches[match] = reverseTokens(maskToken.matches[match]);
  574. } else {
  575. maskToken.matches[match] = reverseStatic(maskToken.matches[match]);
  576. }
  577. }
  578. }
  579. return maskToken;
  580. }
  581. function groupify(matches) {
  582. var groupToken = new MaskToken(true);
  583. groupToken.openGroup = false;
  584. groupToken.matches = matches;
  585. return groupToken;
  586. }
  587. if (regexMask) {
  588. opts.optionalmarker[0] = undefined;
  589. opts.optionalmarker[1] = undefined;
  590. }
  591. while (match = regexMask ? regexTokenizer.exec(mask) : tokenizer.exec(mask)) {
  592. m = match[0];
  593. if (regexMask) {
  594. switch (m.charAt(0)) {
  595. case "?":
  596. m = "{0,1}";
  597. break;
  598. case "+":
  599. case "*":
  600. m = "{" + m + "}";
  601. break;
  602. }
  603. }
  604. if (escaped) {
  605. defaultCase();
  606. continue;
  607. }
  608. switch (m.charAt(0)) {
  609. case "(?=":
  610. break;
  611. case "(?!":
  612. break;
  613. case "(?<=":
  614. break;
  615. case "(?<!":
  616. break;
  617. case opts.escapeChar:
  618. escaped = true;
  619. if (regexMask) {
  620. defaultCase();
  621. }
  622. break;
  623. case opts.optionalmarker[1]:
  624. case opts.groupmarker[1]:
  625. openingToken = openenings.pop();
  626. openingToken.openGroup = false;
  627. if (openingToken !== undefined) {
  628. if (openenings.length > 0) {
  629. currentOpeningToken = openenings[openenings.length - 1];
  630. currentOpeningToken.matches.push(openingToken);
  631. if (currentOpeningToken.isAlternator) {
  632. alternator = openenings.pop();
  633. for (var mndx = 0; mndx < alternator.matches.length; mndx++) {
  634. alternator.matches[mndx].isGroup = false;
  635. alternator.matches[mndx].alternatorGroup = false;
  636. }
  637. if (openenings.length > 0) {
  638. currentOpeningToken = openenings[openenings.length - 1];
  639. currentOpeningToken.matches.push(alternator);
  640. } else {
  641. currentToken.matches.push(alternator);
  642. }
  643. }
  644. } else {
  645. currentToken.matches.push(openingToken);
  646. }
  647. } else defaultCase();
  648. break;
  649. case opts.optionalmarker[0]:
  650. openenings.push(new MaskToken(false, true));
  651. break;
  652. case opts.groupmarker[0]:
  653. openenings.push(new MaskToken(true));
  654. break;
  655. case opts.quantifiermarker[0]:
  656. var quantifier = new MaskToken(false, false, true);
  657. m = m.replace(/[{}]/g, "");
  658. var mqj = m.split("|"), mq = mqj[0].split(","), mq0 = isNaN(mq[0]) ? mq[0] : parseInt(mq[0]), mq1 = mq.length === 1 ? mq0 : isNaN(mq[1]) ? mq[1] : parseInt(mq[1]);
  659. if (mq0 === "*" || mq0 === "+") {
  660. mq0 = mq1 === "*" ? 0 : 1;
  661. }
  662. quantifier.quantifier = {
  663. min: mq0,
  664. max: mq1,
  665. jit: mqj[1]
  666. };
  667. var matches = openenings.length > 0 ? openenings[openenings.length - 1].matches : currentToken.matches;
  668. match = matches.pop();
  669. if (match.isAlternator) {
  670. matches.push(match);
  671. matches = match.matches;
  672. var groupToken = new MaskToken(true);
  673. var tmpMatch = matches.pop();
  674. matches.push(groupToken);
  675. matches = groupToken.matches;
  676. match = tmpMatch;
  677. }
  678. if (!match.isGroup) {
  679. match = groupify([ match ]);
  680. }
  681. matches.push(match);
  682. matches.push(quantifier);
  683. break;
  684. case opts.alternatormarker:
  685. var groupQuantifier = function groupQuantifier(matches) {
  686. var lastMatch = matches.pop();
  687. if (lastMatch.isQuantifier) {
  688. lastMatch = groupify([ matches.pop(), lastMatch ]);
  689. }
  690. return lastMatch;
  691. };
  692. if (openenings.length > 0) {
  693. currentOpeningToken = openenings[openenings.length - 1];
  694. var subToken = currentOpeningToken.matches[currentOpeningToken.matches.length - 1];
  695. if (currentOpeningToken.openGroup && (subToken.matches === undefined || subToken.isGroup === false && subToken.isAlternator === false)) {
  696. lastMatch = openenings.pop();
  697. } else {
  698. lastMatch = groupQuantifier(currentOpeningToken.matches);
  699. }
  700. } else {
  701. lastMatch = groupQuantifier(currentToken.matches);
  702. }
  703. if (lastMatch.isAlternator) {
  704. openenings.push(lastMatch);
  705. } else {
  706. if (lastMatch.alternatorGroup) {
  707. alternator = openenings.pop();
  708. lastMatch.alternatorGroup = false;
  709. } else {
  710. alternator = new MaskToken(false, false, false, true);
  711. }
  712. alternator.matches.push(lastMatch);
  713. openenings.push(alternator);
  714. if (lastMatch.openGroup) {
  715. lastMatch.openGroup = false;
  716. var alternatorGroup = new MaskToken(true);
  717. alternatorGroup.alternatorGroup = true;
  718. openenings.push(alternatorGroup);
  719. }
  720. }
  721. break;
  722. default:
  723. defaultCase();
  724. }
  725. }
  726. while (openenings.length > 0) {
  727. openingToken = openenings.pop();
  728. currentToken.matches.push(openingToken);
  729. }
  730. if (currentToken.matches.length > 0) {
  731. verifyGroupMarker(currentToken);
  732. maskTokens.push(currentToken);
  733. }
  734. if (opts.numericInput || opts.isRTL) {
  735. reverseTokens(maskTokens[0]);
  736. }
  737. return maskTokens;
  738. }
  739. };
  740. Inputmask.extendDefaults = function(options) {
  741. $.extend(true, Inputmask.prototype.defaults, options);
  742. };
  743. Inputmask.extendDefinitions = function(definition) {
  744. $.extend(true, Inputmask.prototype.definitions, definition);
  745. };
  746. Inputmask.extendAliases = function(alias) {
  747. $.extend(true, Inputmask.prototype.aliases, alias);
  748. };
  749. Inputmask.format = function(value, options, metadata) {
  750. return Inputmask(options).format(value, metadata);
  751. };
  752. Inputmask.unmask = function(value, options) {
  753. return Inputmask(options).unmaskedvalue(value);
  754. };
  755. Inputmask.isValid = function(value, options) {
  756. return Inputmask(options).isValid(value);
  757. };
  758. Inputmask.remove = function(elems) {
  759. if (typeof elems === "string") {
  760. elems = document.getElementById(elems) || document.querySelectorAll(elems);
  761. }
  762. elems = elems.nodeName ? [ elems ] : elems;
  763. $.each(elems, function(ndx, el) {
  764. if (el.inputmask) el.inputmask.remove();
  765. });
  766. };
  767. Inputmask.setValue = function(elems, value) {
  768. if (typeof elems === "string") {
  769. elems = document.getElementById(elems) || document.querySelectorAll(elems);
  770. }
  771. elems = elems.nodeName ? [ elems ] : elems;
  772. $.each(elems, function(ndx, el) {
  773. if (el.inputmask) el.inputmask.setValue(value); else $(el).trigger("setvalue", [ value ]);
  774. });
  775. };
  776. Inputmask.escapeRegex = function(str) {
  777. var specials = [ "/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\", "$", "^" ];
  778. return str.replace(new RegExp("(\\" + specials.join("|\\") + ")", "gim"), "\\$1");
  779. };
  780. Inputmask.keyCode = {
  781. BACKSPACE: 8,
  782. BACKSPACE_SAFARI: 127,
  783. DELETE: 46,
  784. DOWN: 40,
  785. END: 35,
  786. ENTER: 13,
  787. ESCAPE: 27,
  788. HOME: 36,
  789. INSERT: 45,
  790. LEFT: 37,
  791. PAGE_DOWN: 34,
  792. PAGE_UP: 33,
  793. RIGHT: 39,
  794. SPACE: 32,
  795. TAB: 9,
  796. UP: 38,
  797. X: 88,
  798. CONTROL: 17
  799. };
  800. Inputmask.dependencyLib = $;
  801. function resolveAlias(aliasStr, options, opts) {
  802. var aliasDefinition = Inputmask.prototype.aliases[aliasStr];
  803. if (aliasDefinition) {
  804. if (aliasDefinition.alias) resolveAlias(aliasDefinition.alias, undefined, opts);
  805. $.extend(true, opts, aliasDefinition);
  806. $.extend(true, opts, options);
  807. return true;
  808. } else if (opts.mask === null) {
  809. opts.mask = aliasStr;
  810. }
  811. return false;
  812. }
  813. function generateMaskSet(opts, nocache) {
  814. function generateMask(mask, metadata, opts) {
  815. var regexMask = false;
  816. if (mask === null || mask === "") {
  817. regexMask = opts.regex !== null;
  818. if (regexMask) {
  819. mask = opts.regex;
  820. mask = mask.replace(/^(\^)(.*)(\$)$/, "$2");
  821. } else {
  822. regexMask = true;
  823. mask = ".*";
  824. }
  825. }
  826. if (mask.length === 1 && opts.greedy === false && opts.repeat !== 0) {
  827. opts.placeholder = "";
  828. }
  829. if (opts.repeat > 0 || opts.repeat === "*" || opts.repeat === "+") {
  830. var repeatStart = opts.repeat === "*" ? 0 : opts.repeat === "+" ? 1 : opts.repeat;
  831. mask = opts.groupmarker[0] + mask + opts.groupmarker[1] + opts.quantifiermarker[0] + repeatStart + "," + opts.repeat + opts.quantifiermarker[1];
  832. }
  833. var masksetDefinition, maskdefKey = regexMask ? "regex_" + opts.regex : opts.numericInput ? mask.split("").reverse().join("") : mask;
  834. if (Inputmask.prototype.masksCache[maskdefKey] === undefined || nocache === true) {
  835. masksetDefinition = {
  836. mask: mask,
  837. maskToken: Inputmask.prototype.analyseMask(mask, regexMask, opts),
  838. validPositions: {},
  839. _buffer: undefined,
  840. buffer: undefined,
  841. tests: {},
  842. excludes: {},
  843. metadata: metadata,
  844. maskLength: undefined
  845. };
  846. if (nocache !== true) {
  847. Inputmask.prototype.masksCache[maskdefKey] = masksetDefinition;
  848. masksetDefinition = $.extend(true, {}, Inputmask.prototype.masksCache[maskdefKey]);
  849. }
  850. } else masksetDefinition = $.extend(true, {}, Inputmask.prototype.masksCache[maskdefKey]);
  851. return masksetDefinition;
  852. }
  853. var ms;
  854. if ($.isFunction(opts.mask)) {
  855. opts.mask = opts.mask(opts);
  856. }
  857. if ($.isArray(opts.mask)) {
  858. if (opts.mask.length > 1) {
  859. if (opts.keepStatic === null) {
  860. opts.keepStatic = "auto";
  861. for (var i = 0; i < opts.mask.length; i++) {
  862. if (opts.mask[i].charAt(0) !== opts.mask[0].charAt(0)) {
  863. opts.keepStatic = true;
  864. break;
  865. }
  866. }
  867. }
  868. var altMask = opts.groupmarker[0];
  869. $.each(opts.isRTL ? opts.mask.reverse() : opts.mask, function(ndx, msk) {
  870. if (altMask.length > 1) {
  871. altMask += opts.groupmarker[1] + opts.alternatormarker + opts.groupmarker[0];
  872. }
  873. if (msk.mask !== undefined && !$.isFunction(msk.mask)) {
  874. altMask += msk.mask;
  875. } else {
  876. altMask += msk;
  877. }
  878. });
  879. altMask += opts.groupmarker[1];
  880. return generateMask(altMask, opts.mask, opts);
  881. } else opts.mask = opts.mask.pop();
  882. }
  883. if (opts.mask && opts.mask.mask !== undefined && !$.isFunction(opts.mask.mask)) {
  884. ms = generateMask(opts.mask.mask, opts.mask, opts);
  885. } else {
  886. ms = generateMask(opts.mask, opts.mask, opts);
  887. }
  888. return ms;
  889. }
  890. function isInputEventSupported(eventName) {
  891. var el = document.createElement("input"), evName = "on" + eventName, isSupported = evName in el;
  892. if (!isSupported) {
  893. el.setAttribute(evName, "return;");
  894. isSupported = typeof el[evName] === "function";
  895. }
  896. el = null;
  897. return isSupported;
  898. }
  899. function maskScope(actionObj, maskset, opts) {
  900. maskset = maskset || this.maskset;
  901. opts = opts || this.opts;
  902. var inputmask = this, el = this.el, isRTL = this.isRTL, undoValue, $el, skipKeyPressEvent = false, skipInputEvent = false, ignorable = false, maxLength, mouseEnter = false, colorMask, originalPlaceholder;
  903. function getMaskTemplate(baseOnInput, minimalPos, includeMode, noJit, clearOptionalTail) {
  904. var greedy = opts.greedy;
  905. if (clearOptionalTail) opts.greedy = false;
  906. minimalPos = minimalPos || 0;
  907. var maskTemplate = [], ndxIntlzr, pos = 0, test, testPos, lvp = getLastValidPosition();
  908. do {
  909. if (baseOnInput === true && getMaskSet().validPositions[pos]) {
  910. testPos = clearOptionalTail && getMaskSet().validPositions[pos].match.optionality === true && getMaskSet().validPositions[pos + 1] === undefined && (getMaskSet().validPositions[pos].generatedInput === true || getMaskSet().validPositions[pos].input == opts.skipOptionalPartCharacter && pos > 0) ? determineTestTemplate(pos, getTests(pos, ndxIntlzr, pos - 1)) : getMaskSet().validPositions[pos];
  911. test = testPos.match;
  912. ndxIntlzr = testPos.locator.slice();
  913. maskTemplate.push(includeMode === true ? testPos.input : includeMode === false ? test.nativeDef : getPlaceholder(pos, test));
  914. } else {
  915. testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
  916. test = testPos.match;
  917. ndxIntlzr = testPos.locator.slice();
  918. var jitMasking = noJit === true ? false : opts.jitMasking !== false ? opts.jitMasking : test.jit;
  919. if (jitMasking === false || jitMasking === undefined || typeof jitMasking === "number" && isFinite(jitMasking) && jitMasking > pos) {
  920. maskTemplate.push(includeMode === false ? test.nativeDef : getPlaceholder(pos, test));
  921. }
  922. }
  923. if (opts.keepStatic === "auto") {
  924. if (test.newBlockMarker && test.fn !== null) {
  925. opts.keepStatic = pos - 1;
  926. }
  927. }
  928. pos++;
  929. } while ((maxLength === undefined || pos < maxLength) && (test.fn !== null || test.def !== "") || minimalPos > pos);
  930. if (maskTemplate[maskTemplate.length - 1] === "") {
  931. maskTemplate.pop();
  932. }
  933. if (includeMode !== false || getMaskSet().maskLength === undefined) getMaskSet().maskLength = pos - 1;
  934. opts.greedy = greedy;
  935. return maskTemplate;
  936. }
  937. function getMaskSet() {
  938. return maskset;
  939. }
  940. function resetMaskSet(soft) {
  941. var maskset = getMaskSet();
  942. maskset.buffer = undefined;
  943. if (soft !== true) {
  944. maskset.validPositions = {};
  945. maskset.p = 0;
  946. }
  947. }
  948. function getLastValidPosition(closestTo, strict, validPositions) {
  949. var before = -1, after = -1, valids = validPositions || getMaskSet().validPositions;
  950. if (closestTo === undefined) closestTo = -1;
  951. for (var posNdx in valids) {
  952. var psNdx = parseInt(posNdx);
  953. if (valids[psNdx] && (strict || valids[psNdx].generatedInput !== true)) {
  954. if (psNdx <= closestTo) before = psNdx;
  955. if (psNdx >= closestTo) after = psNdx;
  956. }
  957. }
  958. return before === -1 || before == closestTo ? after : after == -1 ? before : closestTo - before < after - closestTo ? before : after;
  959. }
  960. function getDecisionTaker(tst) {
  961. var decisionTaker = tst.locator[tst.alternation];
  962. if (typeof decisionTaker == "string" && decisionTaker.length > 0) {
  963. decisionTaker = decisionTaker.split(",")[0];
  964. }
  965. return decisionTaker !== undefined ? decisionTaker.toString() : "";
  966. }
  967. function getLocator(tst, align) {
  968. var locator = (tst.alternation != undefined ? tst.mloc[getDecisionTaker(tst)] : tst.locator).join("");
  969. if (locator !== "") while (locator.length < align) {
  970. locator += "0";
  971. }
  972. return locator;
  973. }
  974. function determineTestTemplate(pos, tests) {
  975. pos = pos > 0 ? pos - 1 : 0;
  976. var altTest = getTest(pos), targetLocator = getLocator(altTest), tstLocator, closest, bestMatch;
  977. for (var ndx = 0; ndx < tests.length; ndx++) {
  978. var tst = tests[ndx];
  979. tstLocator = getLocator(tst, targetLocator.length);
  980. var distance = Math.abs(tstLocator - targetLocator);
  981. if (closest === undefined || tstLocator !== "" && distance < closest || bestMatch && bestMatch.match.optionality && bestMatch.match.newBlockMarker === "master" && (!tst.match.optionality || !tst.match.newBlockMarker) || bestMatch && bestMatch.match.optionalQuantifier && !tst.match.optionalQuantifier) {
  982. closest = distance;
  983. bestMatch = tst;
  984. }
  985. }
  986. return bestMatch;
  987. }
  988. function getTestTemplate(pos, ndxIntlzr, tstPs) {
  989. return getMaskSet().validPositions[pos] || determineTestTemplate(pos, getTests(pos, ndxIntlzr ? ndxIntlzr.slice() : ndxIntlzr, tstPs));
  990. }
  991. function getTest(pos, tests) {
  992. if (getMaskSet().validPositions[pos]) {
  993. return getMaskSet().validPositions[pos];
  994. }
  995. return (tests || getTests(pos))[0];
  996. }
  997. function positionCanMatchDefinition(pos, def) {
  998. var valid = false, tests = getTests(pos);
  999. for (var tndx = 0; tndx < tests.length; tndx++) {
  1000. if (tests[tndx].match && tests[tndx].match.def === def) {
  1001. valid = true;
  1002. break;
  1003. }
  1004. }
  1005. return valid;
  1006. }
  1007. function getTests(pos, ndxIntlzr, tstPs) {
  1008. var maskTokens = getMaskSet().maskToken, testPos = ndxIntlzr ? tstPs : 0, ndxInitializer = ndxIntlzr ? ndxIntlzr.slice() : [ 0 ], matches = [], insertStop = false, latestMatch, cacheDependency = ndxIntlzr ? ndxIntlzr.join("") : "", offset = 0;
  1009. function resolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) {
  1010. function handleMatch(match, loopNdx, quantifierRecurse) {
  1011. function isFirstMatch(latestMatch, tokenGroup) {
  1012. var firstMatch = $.inArray(latestMatch, tokenGroup.matches) === 0;
  1013. if (!firstMatch) {
  1014. $.each(tokenGroup.matches, function(ndx, match) {
  1015. if (match.isQuantifier === true) firstMatch = isFirstMatch(latestMatch, tokenGroup.matches[ndx - 1]); else if (match.hasOwnProperty("matches")) firstMatch = isFirstMatch(latestMatch, match);
  1016. if (firstMatch) return false;
  1017. });
  1018. }
  1019. return firstMatch;
  1020. }
  1021. function resolveNdxInitializer(pos, alternateNdx, targetAlternation) {
  1022. var bestMatch, indexPos;
  1023. if (getMaskSet().tests[pos] || getMaskSet().validPositions[pos]) {
  1024. $.each(getMaskSet().tests[pos] || [ getMaskSet().validPositions[pos] ], function(ndx, lmnt) {
  1025. if (lmnt.mloc[alternateNdx]) {
  1026. bestMatch = lmnt;
  1027. return false;
  1028. }
  1029. var alternation = targetAlternation !== undefined ? targetAlternation : lmnt.alternation, ndxPos = lmnt.locator[alternation] !== undefined ? lmnt.locator[alternation].toString().indexOf(alternateNdx) : -1;
  1030. if ((indexPos === undefined || ndxPos < indexPos) && ndxPos !== -1) {
  1031. bestMatch = lmnt;
  1032. indexPos = ndxPos;
  1033. }
  1034. });
  1035. }
  1036. if (bestMatch) {
  1037. var bestMatchAltIndex = bestMatch.locator[bestMatch.alternation];
  1038. var locator = bestMatch.mloc[alternateNdx] || bestMatch.mloc[bestMatchAltIndex] || bestMatch.locator;
  1039. return locator.slice((targetAlternation !== undefined ? targetAlternation : bestMatch.alternation) + 1);
  1040. } else {
  1041. return targetAlternation !== undefined ? resolveNdxInitializer(pos, alternateNdx) : undefined;
  1042. }
  1043. }
  1044. function isSubsetOf(source, target) {
  1045. function expand(pattern) {
  1046. var expanded = [], start, end;
  1047. for (var i = 0, l = pattern.length; i < l; i++) {
  1048. if (pattern.charAt(i) === "-") {
  1049. end = pattern.charCodeAt(i + 1);
  1050. while (++start < end) {
  1051. expanded.push(String.fromCharCode(start));
  1052. }
  1053. } else {
  1054. start = pattern.charCodeAt(i);
  1055. expanded.push(pattern.charAt(i));
  1056. }
  1057. }
  1058. return expanded.join("");
  1059. }
  1060. if (opts.regex && source.match.fn !== null && target.match.fn !== null) {
  1061. return expand(target.match.def.replace(/[\[\]]/g, "")).indexOf(expand(source.match.def.replace(/[\[\]]/g, ""))) !== -1;
  1062. }
  1063. return source.match.def === target.match.nativeDef;
  1064. }
  1065. function staticCanMatchDefinition(source, target) {
  1066. var sloc = source.locator.slice(source.alternation).join(""), tloc = target.locator.slice(target.alternation).join(""), canMatch = sloc == tloc, canMatch = canMatch && source.match.fn === null && target.match.fn !== null ? target.match.fn.test(source.match.def, getMaskSet(), pos, false, opts, false) : false;
  1067. return canMatch;
  1068. }
  1069. function setMergeLocators(targetMatch, altMatch) {
  1070. if (altMatch === undefined || targetMatch.alternation === altMatch.alternation && targetMatch.locator[targetMatch.alternation].toString().indexOf(altMatch.locator[altMatch.alternation]) === -1) {
  1071. targetMatch.mloc = targetMatch.mloc || {};
  1072. var locNdx = targetMatch.locator[targetMatch.alternation];
  1073. if (locNdx === undefined) targetMatch.alternation = undefined; else {
  1074. if (typeof locNdx === "string") locNdx = locNdx.split(",")[0];
  1075. if (targetMatch.mloc[locNdx] === undefined) targetMatch.mloc[locNdx] = targetMatch.locator.slice();
  1076. if (altMatch !== undefined) {
  1077. for (var ndx in altMatch.mloc) {
  1078. if (typeof ndx === "string") ndx = ndx.split(",")[0];
  1079. if (targetMatch.mloc[ndx] === undefined) targetMatch.mloc[ndx] = altMatch.mloc[ndx];
  1080. }
  1081. targetMatch.locator[targetMatch.alternation] = Object.keys(targetMatch.mloc).join(",");
  1082. }
  1083. return true;
  1084. }
  1085. }
  1086. return false;
  1087. }
  1088. if (testPos > 500 && quantifierRecurse !== undefined) {
  1089. throw "Inputmask: There is probably an error in your mask definition or in the code. Create an issue on github with an example of the mask you are using. " + getMaskSet().mask;
  1090. }
  1091. if (testPos === pos && match.matches === undefined) {
  1092. matches.push({
  1093. match: match,
  1094. locator: loopNdx.reverse(),
  1095. cd: cacheDependency,
  1096. mloc: {}
  1097. });
  1098. return true;
  1099. } else if (match.matches !== undefined) {
  1100. if (match.isGroup && quantifierRecurse !== match) {
  1101. match = handleMatch(maskToken.matches[$.inArray(match, maskToken.matches) + 1], loopNdx, quantifierRecurse);
  1102. if (match) return true;
  1103. } else if (match.isOptional) {
  1104. var optionalToken = match;
  1105. match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse);
  1106. if (match) {
  1107. $.each(matches, function(ndx, mtch) {
  1108. mtch.match.optionality = true;
  1109. });
  1110. latestMatch = matches[matches.length - 1].match;
  1111. if (quantifierRecurse === undefined && isFirstMatch(latestMatch, optionalToken)) {
  1112. insertStop = true;
  1113. testPos = pos;
  1114. } else return true;
  1115. }
  1116. } else if (match.isAlternator) {
  1117. var alternateToken = match, malternateMatches = [], maltMatches, currentMatches = matches.slice(), loopNdxCnt = loopNdx.length;
  1118. var altIndex = ndxInitializer.length > 0 ? ndxInitializer.shift() : -1;
  1119. if (altIndex === -1 || typeof altIndex === "string") {
  1120. var currentPos = testPos, ndxInitializerClone = ndxInitializer.slice(), altIndexArr = [], amndx;
  1121. if (typeof altIndex == "string") {
  1122. altIndexArr = altIndex.split(",");
  1123. } else {
  1124. for (amndx = 0; amndx < alternateToken.matches.length; amndx++) {
  1125. altIndexArr.push(amndx.toString());
  1126. }
  1127. }
  1128. if (getMaskSet().excludes[pos]) {
  1129. var altIndexArrClone = altIndexArr.slice();
  1130. for (var i = 0, el = getMaskSet().excludes[pos].length; i < el; i++) {
  1131. altIndexArr.splice(altIndexArr.indexOf(getMaskSet().excludes[pos][i].toString()), 1);
  1132. }
  1133. if (altIndexArr.length === 0) {
  1134. getMaskSet().excludes[pos] = undefined;
  1135. altIndexArr = altIndexArrClone;
  1136. }
  1137. }
  1138. if (opts.keepStatic === true || isFinite(parseInt(opts.keepStatic)) && currentPos >= opts.keepStatic) altIndexArr = altIndexArr.slice(0, 1);
  1139. var unMatchedAlternation = false;
  1140. for (var ndx = 0; ndx < altIndexArr.length; ndx++) {
  1141. amndx = parseInt(altIndexArr[ndx]);
  1142. matches = [];
  1143. ndxInitializer = typeof altIndex === "string" ? resolveNdxInitializer(testPos, amndx, loopNdxCnt) || ndxInitializerClone.slice() : ndxInitializerClone.slice();
  1144. if (alternateToken.matches[amndx] && handleMatch(alternateToken.matches[amndx], [ amndx ].concat(loopNdx), quantifierRecurse)) match = true; else if (ndx === 0) {
  1145. unMatchedAlternation = true;
  1146. }
  1147. maltMatches = matches.slice();
  1148. testPos = currentPos;
  1149. matches = [];
  1150. for (var ndx1 = 0; ndx1 < maltMatches.length; ndx1++) {
  1151. var altMatch = maltMatches[ndx1], dropMatch = false;
  1152. altMatch.match.jit = altMatch.match.jit || unMatchedAlternation;
  1153. altMatch.alternation = altMatch.alternation || loopNdxCnt;
  1154. setMergeLocators(altMatch);
  1155. for (var ndx2 = 0; ndx2 < malternateMatches.length; ndx2++) {
  1156. var altMatch2 = malternateMatches[ndx2];
  1157. if (typeof altIndex !== "string" || altMatch.alternation !== undefined && $.inArray(altMatch.locator[altMatch.alternation].toString(), altIndexArr) !== -1) {
  1158. if (altMatch.match.nativeDef === altMatch2.match.nativeDef) {
  1159. dropMatch = true;
  1160. setMergeLocators(altMatch2, altMatch);
  1161. break;
  1162. } else if (isSubsetOf(altMatch, altMatch2)) {
  1163. if (setMergeLocators(altMatch, altMatch2)) {
  1164. dropMatch = true;
  1165. malternateMatches.splice(malternateMatches.indexOf(altMatch2), 0, altMatch);
  1166. }
  1167. break;
  1168. } else if (isSubsetOf(altMatch2, altMatch)) {
  1169. setMergeLocators(altMatch2, altMatch);
  1170. break;
  1171. } else if (staticCanMatchDefinition(altMatch, altMatch2)) {
  1172. if (setMergeLocators(altMatch, altMatch2)) {
  1173. dropMatch = true;
  1174. malternateMatches.splice(malternateMatches.indexOf(altMatch2), 0, altMatch);
  1175. }
  1176. break;
  1177. }
  1178. }
  1179. }
  1180. if (!dropMatch) {
  1181. malternateMatches.push(altMatch);
  1182. }
  1183. }
  1184. }
  1185. matches = currentMatches.concat(malternateMatches);
  1186. testPos = pos;
  1187. insertStop = matches.length > 0;
  1188. match = malternateMatches.length > 0;
  1189. ndxInitializer = ndxInitializerClone.slice();
  1190. } else match = handleMatch(alternateToken.matches[altIndex] || maskToken.matches[altIndex], [ altIndex ].concat(loopNdx), quantifierRecurse);
  1191. if (match) return true;
  1192. } else if (match.isQuantifier && quantifierRecurse !== maskToken.matches[$.inArray(match, maskToken.matches) - 1]) {
  1193. var qt = match;
  1194. for (var qndx = ndxInitializer.length > 0 ? ndxInitializer.shift() : 0; qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max) && testPos <= pos; qndx++) {
  1195. var tokenGroup = maskToken.matches[$.inArray(qt, maskToken.matches) - 1];
  1196. match = handleMatch(tokenGroup, [ qndx ].concat(loopNdx), tokenGroup);
  1197. if (match) {
  1198. latestMatch = matches[matches.length - 1].match;
  1199. latestMatch.optionalQuantifier = qndx > qt.quantifier.min - 1;
  1200. latestMatch.jit = (qndx || 1) * tokenGroup.matches.indexOf(latestMatch) >= qt.quantifier.jit;
  1201. if (latestMatch.optionalQuantifier && isFirstMatch(latestMatch, tokenGroup)) {
  1202. insertStop = true;
  1203. testPos = pos;
  1204. break;
  1205. }
  1206. if (latestMatch.jit && !latestMatch.optionalQuantifier) {
  1207. offset = tokenGroup.matches.indexOf(latestMatch);
  1208. testPos = pos;
  1209. insertStop = true;
  1210. break;
  1211. }
  1212. return true;
  1213. }
  1214. }
  1215. } else {
  1216. match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse);
  1217. if (match) return true;
  1218. }
  1219. } else {
  1220. testPos++;
  1221. }
  1222. }
  1223. for (var tndx = ndxInitializer.length > 0 ? ndxInitializer.shift() : 0; tndx < maskToken.matches.length; tndx = tndx + 1 + offset) {
  1224. offset = 0;
  1225. if (maskToken.matches[tndx].isQuantifier !== true) {
  1226. var match = handleMatch(maskToken.matches[tndx], [ tndx ].concat(loopNdx), quantifierRecurse);
  1227. if (match && testPos === pos) {
  1228. return match;
  1229. } else if (testPos > pos) {
  1230. break;
  1231. }
  1232. }
  1233. }
  1234. }
  1235. function mergeLocators(pos, tests) {
  1236. var locator = [];
  1237. if (!$.isArray(tests)) tests = [ tests ];
  1238. if (tests.length > 0) {
  1239. if (tests[0].alternation === undefined) {
  1240. locator = determineTestTemplate(pos, tests.slice()).locator.slice();
  1241. if (locator.length === 0) locator = tests[0].locator.slice();
  1242. } else {
  1243. $.each(tests, function(ndx, tst) {
  1244. if (tst.def !== "") {
  1245. if (locator.length === 0) locator = tst.locator.slice(); else {
  1246. for (var i = 0; i < locator.length; i++) {
  1247. if (tst.locator[i] && locator[i].toString().indexOf(tst.locator[i]) === -1) {
  1248. locator[i] += "," + tst.locator[i];
  1249. }
  1250. }
  1251. }
  1252. }
  1253. });
  1254. }
  1255. }
  1256. return locator;
  1257. }
  1258. if (pos > -1) {
  1259. if (ndxIntlzr === undefined) {
  1260. var previousPos = pos - 1, test;
  1261. while ((test = getMaskSet().validPositions[previousPos] || getMaskSet().tests[previousPos]) === undefined && previousPos > -1) {
  1262. previousPos--;
  1263. }
  1264. if (test !== undefined && previousPos > -1) {
  1265. ndxInitializer = mergeLocators(previousPos, test);
  1266. cacheDependency = ndxInitializer.join("");
  1267. testPos = previousPos;
  1268. }
  1269. }
  1270. if (getMaskSet().tests[pos] && getMaskSet().tests[pos][0].cd === cacheDependency) {
  1271. return getMaskSet().tests[pos];
  1272. }
  1273. for (var mtndx = ndxInitializer.shift(); mtndx < maskTokens.length; mtndx++) {
  1274. var match = resolveTestFromToken(maskTokens[mtndx], ndxInitializer, [ mtndx ]);
  1275. if (match && testPos === pos || testPos > pos) {
  1276. break;
  1277. }
  1278. }
  1279. }
  1280. if (matches.length === 0 || insertStop) {
  1281. matches.push({
  1282. match: {
  1283. fn: null,
  1284. optionality: false,
  1285. casing: null,
  1286. def: "",
  1287. placeholder: ""
  1288. },
  1289. locator: [],
  1290. mloc: {},
  1291. cd: cacheDependency
  1292. });
  1293. }
  1294. if (ndxIntlzr !== undefined && getMaskSet().tests[pos]) {
  1295. return $.extend(true, [], matches);
  1296. }
  1297. getMaskSet().tests[pos] = $.extend(true, [], matches);
  1298. return getMaskSet().tests[pos];
  1299. }
  1300. function getBufferTemplate() {
  1301. if (getMaskSet()._buffer === undefined) {
  1302. getMaskSet()._buffer = getMaskTemplate(false, 1);
  1303. if (getMaskSet().buffer === undefined) getMaskSet().buffer = getMaskSet()._buffer.slice();
  1304. }
  1305. return getMaskSet()._buffer;
  1306. }
  1307. function getBuffer(noCache) {
  1308. if (getMaskSet().buffer === undefined || noCache === true) {
  1309. getMaskSet().buffer = getMaskTemplate(true, getLastValidPosition(), true);
  1310. if (getMaskSet()._buffer === undefined) getMaskSet()._buffer = getMaskSet().buffer.slice();
  1311. }
  1312. return getMaskSet().buffer;
  1313. }
  1314. function refreshFromBuffer(start, end, buffer) {
  1315. var i, p;
  1316. if (start === true) {
  1317. resetMaskSet();
  1318. start = 0;
  1319. end = buffer.length;
  1320. } else {
  1321. for (i = start; i < end; i++) {
  1322. delete getMaskSet().validPositions[i];
  1323. }
  1324. }
  1325. p = start;
  1326. for (i = start; i < end; i++) {
  1327. resetMaskSet(true);
  1328. if (buffer[i] !== opts.skipOptionalPartCharacter) {
  1329. var valResult = isValid(p, buffer[i], true, true);
  1330. if (valResult !== false) {
  1331. resetMaskSet(true);
  1332. p = valResult.caret !== undefined ? valResult.caret : valResult.pos + 1;
  1333. }
  1334. }
  1335. }
  1336. }
  1337. function casing(elem, test, pos) {
  1338. switch (opts.casing || test.casing) {
  1339. case "upper":
  1340. elem = elem.toUpperCase();
  1341. break;
  1342. case "lower":
  1343. elem = elem.toLowerCase();
  1344. break;
  1345. case "title":
  1346. var posBefore = getMaskSet().validPositions[pos - 1];
  1347. if (pos === 0 || posBefore && posBefore.input === String.fromCharCode(Inputmask.keyCode.SPACE)) {
  1348. elem = elem.toUpperCase();
  1349. } else {
  1350. elem = elem.toLowerCase();
  1351. }
  1352. break;
  1353. default:
  1354. if ($.isFunction(opts.casing)) {
  1355. var args = Array.prototype.slice.call(arguments);
  1356. args.push(getMaskSet().validPositions);
  1357. elem = opts.casing.apply(this, args);
  1358. }
  1359. }
  1360. return elem;
  1361. }
  1362. function checkAlternationMatch(altArr1, altArr2, na) {
  1363. var altArrC = opts.greedy ? altArr2 : altArr2.slice(0, 1), isMatch = false, naArr = na !== undefined ? na.split(",") : [], naNdx;
  1364. for (var i = 0; i < naArr.length; i++) {
  1365. if ((naNdx = altArr1.indexOf(naArr[i])) !== -1) {
  1366. altArr1.splice(naNdx, 1);
  1367. }
  1368. }
  1369. for (var alndx = 0; alndx < altArr1.length; alndx++) {
  1370. if ($.inArray(altArr1[alndx], altArrC) !== -1) {
  1371. isMatch = true;
  1372. break;
  1373. }
  1374. }
  1375. return isMatch;
  1376. }
  1377. function alternate(pos, c, strict, fromSetValid, rAltPos) {
  1378. var validPsClone = $.extend(true, {}, getMaskSet().validPositions), lastAlt, alternation, isValidRslt = false, altPos, prevAltPos, i, validPos, decisionPos, lAltPos = rAltPos !== undefined ? rAltPos : getLastValidPosition();
  1379. if (lAltPos === -1 && rAltPos === undefined) {
  1380. lastAlt = 0;
  1381. prevAltPos = getTest(lastAlt);
  1382. alternation = prevAltPos.alternation;
  1383. } else {
  1384. for (;lAltPos >= 0; lAltPos--) {
  1385. altPos = getMaskSet().validPositions[lAltPos];
  1386. if (altPos && altPos.alternation !== undefined) {
  1387. if (prevAltPos && prevAltPos.locator[altPos.alternation] !== altPos.locator[altPos.alternation]) {
  1388. break;
  1389. }
  1390. lastAlt = lAltPos;
  1391. alternation = getMaskSet().validPositions[lastAlt].alternation;
  1392. prevAltPos = altPos;
  1393. }
  1394. }
  1395. }
  1396. if (alternation !== undefined) {
  1397. decisionPos = parseInt(lastAlt);
  1398. getMaskSet().excludes[decisionPos] = getMaskSet().excludes[decisionPos] || [];
  1399. if (pos !== true) {
  1400. getMaskSet().excludes[decisionPos].push(getDecisionTaker(prevAltPos));
  1401. }
  1402. var validInputsClone = [], staticInputsBeforePos = 0;
  1403. for (i = decisionPos; i < getLastValidPosition(undefined, true) + 1; i++) {
  1404. validPos = getMaskSet().validPositions[i];
  1405. if (validPos && validPos.generatedInput !== true) {
  1406. validInputsClone.push(validPos.input);
  1407. } else if (i < pos) staticInputsBeforePos++;
  1408. delete getMaskSet().validPositions[i];
  1409. }
  1410. while (getMaskSet().excludes[decisionPos] && getMaskSet().excludes[decisionPos].length < 10) {
  1411. var posOffset = staticInputsBeforePos * -1, validInputs = validInputsClone.slice();
  1412. getMaskSet().tests[decisionPos] = undefined;
  1413. resetMaskSet(true);
  1414. isValidRslt = true;
  1415. while (validInputs.length > 0) {
  1416. var input = validInputs.shift();
  1417. if (!(isValidRslt = isValid(getLastValidPosition(undefined, true) + 1, input, false, fromSetValid, true))) {
  1418. break;
  1419. }
  1420. }
  1421. if (isValidRslt && c !== undefined) {
  1422. var targetLvp = getLastValidPosition(pos) + 1;
  1423. for (i = decisionPos; i < getLastValidPosition() + 1; i++) {
  1424. validPos = getMaskSet().validPositions[i];
  1425. if ((validPos === undefined || validPos.match.fn == null) && i < pos + posOffset) {
  1426. posOffset++;
  1427. }
  1428. }
  1429. pos = pos + posOffset;
  1430. isValidRslt = isValid(pos > targetLvp ? targetLvp : pos, c, strict, fromSetValid, true);
  1431. }
  1432. if (!isValidRslt) {
  1433. resetMaskSet();
  1434. prevAltPos = getTest(decisionPos);
  1435. getMaskSet().validPositions = $.extend(true, {}, validPsClone);
  1436. if (getMaskSet().excludes[decisionPos]) {
  1437. var decisionTaker = getDecisionTaker(prevAltPos);
  1438. if (getMaskSet().excludes[decisionPos].indexOf(decisionTaker) !== -1) {
  1439. isValidRslt = alternate(pos, c, strict, fromSetValid, decisionPos - 1);
  1440. break;
  1441. }
  1442. getMaskSet().excludes[decisionPos].push(decisionTaker);
  1443. for (i = decisionPos; i < getLastValidPosition(undefined, true) + 1; i++) {
  1444. delete getMaskSet().validPositions[i];
  1445. }
  1446. } else {
  1447. isValidRslt = alternate(pos, c, strict, fromSetValid, decisionPos - 1);
  1448. break;
  1449. }
  1450. } else break;
  1451. }
  1452. }
  1453. getMaskSet().excludes[decisionPos] = undefined;
  1454. return isValidRslt;
  1455. }
  1456. function isValid(pos, c, strict, fromSetValid, fromAlternate, validateOnly) {
  1457. function isSelection(posObj) {
  1458. return isRTL ? posObj.begin - posObj.end > 1 || posObj.begin - posObj.end === 1 : posObj.end - posObj.begin > 1 || posObj.end - posObj.begin === 1;
  1459. }
  1460. strict = strict === true;
  1461. var maskPos = pos;
  1462. if (pos.begin !== undefined) {
  1463. maskPos = isRTL ? pos.end : pos.begin;
  1464. }
  1465. function _isValid(position, c, strict) {
  1466. var rslt = false;
  1467. $.each(getTests(position), function(ndx, tst) {
  1468. var test = tst.match;
  1469. getBuffer(true);
  1470. rslt = test.fn != null ? test.fn.test(c, getMaskSet(), position, strict, opts, isSelection(pos)) : (c === test.def || c === opts.skipOptionalPartCharacter) && test.def !== "" ? {
  1471. c: getPlaceholder(position, test, true) || test.def,
  1472. pos: position
  1473. } : false;
  1474. if (rslt !== false) {
  1475. var elem = rslt.c !== undefined ? rslt.c : c, validatedPos = position;
  1476. elem = elem === opts.skipOptionalPartCharacter && test.fn === null ? getPlaceholder(position, test, true) || test.def : elem;
  1477. if (rslt.remove !== undefined) {
  1478. if (!$.isArray(rslt.remove)) rslt.remove = [ rslt.remove ];
  1479. $.each(rslt.remove.sort(function(a, b) {
  1480. return b - a;
  1481. }), function(ndx, lmnt) {
  1482. revalidateMask({
  1483. begin: lmnt,
  1484. end: lmnt + 1
  1485. });
  1486. });
  1487. }
  1488. if (rslt.insert !== undefined) {
  1489. if (!$.isArray(rslt.insert)) rslt.insert = [ rslt.insert ];
  1490. $.each(rslt.insert.sort(function(a, b) {
  1491. return a - b;
  1492. }), function(ndx, lmnt) {
  1493. isValid(lmnt.pos, lmnt.c, true, fromSetValid);
  1494. });
  1495. }
  1496. if (rslt !== true && rslt.pos !== undefined && rslt.pos !== position) {
  1497. validatedPos = rslt.pos;
  1498. }
  1499. if (rslt !== true && rslt.pos === undefined && rslt.c === undefined) {
  1500. return false;
  1501. }
  1502. if (!revalidateMask(pos, $.extend({}, tst, {
  1503. input: casing(elem, test, validatedPos)
  1504. }), fromSetValid, validatedPos)) {
  1505. rslt = false;
  1506. }
  1507. return false;
  1508. }
  1509. });
  1510. return rslt;
  1511. }
  1512. var result = true, positionsClone = $.extend(true, {}, getMaskSet().validPositions);
  1513. if ($.isFunction(opts.preValidation) && !strict && fromSetValid !== true && validateOnly !== true) {
  1514. result = opts.preValidation(getBuffer(), maskPos, c, isSelection(pos), opts, getMaskSet());
  1515. }
  1516. if (result === true) {
  1517. trackbackPositions(undefined, maskPos, true);
  1518. if (maxLength === undefined || maskPos < maxLength) {
  1519. result = _isValid(maskPos, c, strict);
  1520. if ((!strict || fromSetValid === true) && result === false && validateOnly !== true) {
  1521. var currentPosValid = getMaskSet().validPositions[maskPos];
  1522. if (currentPosValid && currentPosValid.match.fn === null && (currentPosValid.match.def === c || c === opts.skipOptionalPartCharacter)) {
  1523. result = {
  1524. caret: seekNext(maskPos)
  1525. };
  1526. } else if ((opts.insertMode || getMaskSet().validPositions[seekNext(maskPos)] === undefined) && !isMask(maskPos, true)) {
  1527. for (var nPos = maskPos + 1, snPos = seekNext(maskPos); nPos <= snPos; nPos++) {
  1528. result = _isValid(nPos, c, strict);
  1529. if (result !== false) {
  1530. result = trackbackPositions(maskPos, result.pos !== undefined ? result.pos : nPos) || result;
  1531. maskPos = nPos;
  1532. break;
  1533. }
  1534. }
  1535. }
  1536. }
  1537. }
  1538. if (result === false && opts.keepStatic !== false && (opts.regex == null || isComplete(getBuffer())) && !strict && fromAlternate !== true) {
  1539. result = alternate(maskPos, c, strict, fromSetValid);
  1540. }
  1541. if (result === true) {
  1542. result = {
  1543. pos: maskPos
  1544. };
  1545. }
  1546. }
  1547. if ($.isFunction(opts.postValidation) && result !== false && !strict && fromSetValid !== true && validateOnly !== true) {
  1548. var postResult = opts.postValidation(getBuffer(true), pos.begin !== undefined ? isRTL ? pos.end : pos.begin : pos, result, opts);
  1549. if (postResult !== undefined) {
  1550. if (postResult.refreshFromBuffer && postResult.buffer) {
  1551. var refresh = postResult.refreshFromBuffer;
  1552. refreshFromBuffer(refresh === true ? refresh : refresh.start, refresh.end, postResult.buffer);
  1553. }
  1554. result = postResult === true ? result : postResult;
  1555. }
  1556. }
  1557. if (result && result.pos === undefined) {
  1558. result.pos = maskPos;
  1559. }
  1560. if (result === false || validateOnly === true) {
  1561. resetMaskSet(true);
  1562. getMaskSet().validPositions = $.extend(true, {}, positionsClone);
  1563. }
  1564. return result;
  1565. }
  1566. function trackbackPositions(originalPos, newPos, fillOnly) {
  1567. console.log("trackbackPositions");
  1568. var result;
  1569. if (originalPos === undefined) {
  1570. for (originalPos = newPos - 1; originalPos > 0; originalPos--) {
  1571. if (getMaskSet().validPositions[originalPos]) break;
  1572. }
  1573. }
  1574. for (var ps = originalPos; ps < newPos; ps++) {
  1575. if (getMaskSet().validPositions[ps] === undefined && !isMask(ps, true)) {
  1576. var vp = ps == 0 ? getTest(ps) : getMaskSet().validPositions[ps - 1];
  1577. if (vp) {
  1578. var tests = getTests(ps).slice();
  1579. if (tests[tests.length - 1].match.def === "") tests.pop();
  1580. var bestMatch = determineTestTemplate(ps, tests);
  1581. bestMatch = $.extend({}, bestMatch, {
  1582. input: getPlaceholder(ps, bestMatch.match, true) || bestMatch.match.def
  1583. });
  1584. bestMatch.generatedInput = true;
  1585. revalidateMask(ps, bestMatch, true);
  1586. if (fillOnly !== true) {
  1587. var cvpInput = getMaskSet().validPositions[newPos].input;
  1588. getMaskSet().validPositions[newPos] = undefined;
  1589. result = isValid(newPos, cvpInput, true, true);
  1590. }
  1591. }
  1592. }
  1593. }
  1594. return result;
  1595. }
  1596. function revalidateMask(pos, validTest, fromSetValid, validatedPos) {
  1597. function IsEnclosedStatic(pos, valids, selection) {
  1598. var posMatch = valids[pos];
  1599. if (posMatch !== undefined && (posMatch.match.fn === null && posMatch.match.optionality !== true || posMatch.input === opts.radixPoint)) {
  1600. var prevMatch = selection.begin <= pos - 1 ? valids[pos - 1] && valids[pos - 1].match.fn === null && valids[pos - 1] : valids[pos - 1], nextMatch = selection.end > pos + 1 ? valids[pos + 1] && valids[pos + 1].match.fn === null && valids[pos + 1] : valids[pos + 1];
  1601. return prevMatch && nextMatch;
  1602. }
  1603. return false;
  1604. }
  1605. var begin = pos.begin !== undefined ? pos.begin : pos, end = pos.end !== undefined ? pos.end : pos;
  1606. if (pos.begin > pos.end) {
  1607. begin = pos.end;
  1608. end = pos.begin;
  1609. }
  1610. validatedPos = validatedPos !== undefined ? validatedPos : begin;
  1611. if (begin !== end || opts.insertMode && getMaskSet().validPositions[validatedPos] !== undefined && fromSetValid === undefined) {
  1612. var positionsClone = $.extend(true, {}, getMaskSet().validPositions), lvp = getLastValidPosition(undefined, true), i;
  1613. getMaskSet().p = begin;
  1614. for (i = lvp; i >= begin; i--) {
  1615. if (getMaskSet().validPositions[i] && getMaskSet().validPositions[i].match.nativeDef === "+") {
  1616. opts.isNegative = false;
  1617. }
  1618. delete getMaskSet().validPositions[i];
  1619. }
  1620. var valid = true, j = validatedPos, vps = getMaskSet().validPositions, needsValidation = false, posMatch = j, i = j;
  1621. if (validTest) {
  1622. getMaskSet().validPositions[validatedPos] = $.extend(true, {}, validTest);
  1623. posMatch++;
  1624. j++;
  1625. if (begin < end) i++;
  1626. }
  1627. for (;i <= lvp; i++) {
  1628. var t = positionsClone[i];
  1629. if (t !== undefined && (i >= end || i >= begin && t.generatedInput !== true && IsEnclosedStatic(i, positionsClone, {
  1630. begin: begin,
  1631. end: end
  1632. }))) {
  1633. while (getTest(posMatch).match.def !== "") {
  1634. if (needsValidation === false && positionsClone[posMatch] && positionsClone[posMatch].match.nativeDef === t.match.nativeDef) {
  1635. getMaskSet().validPositions[posMatch] = $.extend(true, {}, positionsClone[posMatch]);
  1636. getMaskSet().validPositions[posMatch].input = t.input;
  1637. trackbackPositions(undefined, posMatch, true);
  1638. j = posMatch + 1;
  1639. valid = true;
  1640. } else if (opts.shiftPositions && positionCanMatchDefinition(posMatch, t.match.def)) {
  1641. var result = isValid(posMatch, t.input, true, true);
  1642. valid = result !== false;
  1643. j = result.caret || result.insert ? getLastValidPosition() : posMatch + 1;
  1644. needsValidation = true;
  1645. } else {
  1646. valid = t.generatedInput === true || t.input === opts.radixPoint && opts.numericInput === true;
  1647. }
  1648. if (valid) break;
  1649. if (!valid && posMatch > end && isMask(posMatch, true) && (t.match.fn !== null || posMatch > getMaskSet().maskLength)) {
  1650. break;
  1651. }
  1652. posMatch++;
  1653. }
  1654. if (getTest(posMatch).match.def == "") valid = false;
  1655. posMatch = j;
  1656. }
  1657. if (!valid) break;
  1658. }
  1659. if (!valid) {
  1660. getMaskSet().validPositions = $.extend(true, {}, positionsClone);
  1661. resetMaskSet(true);
  1662. return false;
  1663. }
  1664. } else if (validTest) {
  1665. getMaskSet().validPositions[validatedPos] = $.extend(true, {}, validTest);
  1666. }
  1667. resetMaskSet(true);
  1668. return true;
  1669. }
  1670. function isMask(pos, strict) {
  1671. var test = getTestTemplate(pos).match;
  1672. if (test.def === "") test = getTest(pos).match;
  1673. if (test.fn != null) {
  1674. return test.fn;
  1675. }
  1676. if (strict !== true && pos > -1) {
  1677. var tests = getTests(pos);
  1678. return tests.length > 1 + (tests[tests.length - 1].match.def === "" ? 1 : 0);
  1679. }
  1680. return false;
  1681. }
  1682. function seekNext(pos, newBlock) {
  1683. var position = pos + 1;
  1684. while (getTest(position).match.def !== "" && (newBlock === true && (getTest(position).match.newBlockMarker !== true || !isMask(position)) || newBlock !== true && !isMask(position))) {
  1685. position++;
  1686. }
  1687. return position;
  1688. }
  1689. function seekPrevious(pos, newBlock) {
  1690. var position = pos, tests;
  1691. if (position <= 0) return 0;
  1692. while (--position > 0 && (newBlock === true && getTest(position).match.newBlockMarker !== true || newBlock !== true && !isMask(position) && (tests = getTests(position),
  1693. tests.length < 2 || tests.length === 2 && tests[1].match.def === ""))) {}
  1694. return position;
  1695. }
  1696. function writeBuffer(input, buffer, caretPos, event, triggerEvents) {
  1697. if (event && $.isFunction(opts.onBeforeWrite)) {
  1698. var result = opts.onBeforeWrite.call(inputmask, event, buffer, caretPos, opts);
  1699. if (result) {
  1700. if (result.refreshFromBuffer) {
  1701. var refresh = result.refreshFromBuffer;
  1702. refreshFromBuffer(refresh === true ? refresh : refresh.start, refresh.end, result.buffer || buffer);
  1703. buffer = getBuffer(true);
  1704. }
  1705. if (caretPos !== undefined) caretPos = result.caret !== undefined ? result.caret : caretPos;
  1706. }
  1707. }
  1708. if (input !== undefined) {
  1709. input.inputmask._valueSet(buffer.join(""));
  1710. if (caretPos !== undefined && (event === undefined || event.type !== "blur")) {
  1711. caret(input, caretPos);
  1712. } else renderColorMask(input, caretPos, buffer.length === 0);
  1713. if (triggerEvents === true) {
  1714. var $input = $(input), nptVal = input.inputmask._valueGet();
  1715. skipInputEvent = true;
  1716. $input.trigger("input");
  1717. setTimeout(function() {
  1718. if (nptVal === getBufferTemplate().join("")) {
  1719. $input.trigger("cleared");
  1720. } else if (isComplete(buffer) === true) {
  1721. $input.trigger("complete");
  1722. }
  1723. }, 0);
  1724. }
  1725. }
  1726. }
  1727. function getPlaceholder(pos, test, returnPL) {
  1728. test = test || getTest(pos).match;
  1729. if (test.placeholder !== undefined || returnPL === true) {
  1730. return $.isFunction(test.placeholder) ? test.placeholder(opts) : test.placeholder;
  1731. } else if (test.fn === null) {
  1732. if (pos > -1 && getMaskSet().validPositions[pos] === undefined) {
  1733. var tests = getTests(pos), staticAlternations = [], prevTest;
  1734. if (tests.length > 1 + (tests[tests.length - 1].match.def === "" ? 1 : 0)) {
  1735. for (var i = 0; i < tests.length; i++) {
  1736. if (tests[i].match.optionality !== true && tests[i].match.optionalQuantifier !== true && (tests[i].match.fn === null || prevTest === undefined || tests[i].match.fn.test(prevTest.match.def, getMaskSet(), pos, true, opts) !== false)) {
  1737. staticAlternations.push(tests[i]);
  1738. if (tests[i].match.fn === null) prevTest = tests[i];
  1739. if (staticAlternations.length > 1) {
  1740. if (/[0-9a-bA-Z]/.test(staticAlternations[0].match.def)) {
  1741. return opts.placeholder.charAt(pos % opts.placeholder.length);
  1742. }
  1743. }
  1744. }
  1745. }
  1746. }
  1747. }
  1748. return test.def;
  1749. }
  1750. return opts.placeholder.charAt(pos % opts.placeholder.length);
  1751. }
  1752. function HandleNativePlaceholder(npt, value) {
  1753. if (ie && npt.inputmask._valueGet() !== value) {
  1754. var buffer = getBuffer().slice(), nptValue = npt.inputmask._valueGet();
  1755. if (nptValue !== value) {
  1756. if (getLastValidPosition() === -1 && nptValue === getBufferTemplate().join("")) {
  1757. buffer = [];
  1758. } else {
  1759. clearOptionalTail(buffer);
  1760. }
  1761. writeBuffer(npt, buffer);
  1762. }
  1763. } else if (npt.placeholder !== value) {
  1764. npt.placeholder = value;
  1765. if (npt.placeholder === "") npt.removeAttribute("placeholder");
  1766. }
  1767. }
  1768. var EventRuler = {
  1769. on: function on(input, eventName, eventHandler) {
  1770. var ev = function ev(e) {
  1771. var that = this;
  1772. if (that.inputmask === undefined && this.nodeName !== "FORM") {
  1773. var imOpts = $.data(that, "_inputmask_opts");
  1774. if (imOpts) new Inputmask(imOpts).mask(that); else EventRuler.off(that);
  1775. } else if (e.type !== "setvalue" && this.nodeName !== "FORM" && (that.disabled || that.readOnly && !(e.type === "keydown" && e.ctrlKey && e.keyCode === 67 || opts.tabThrough === false && e.keyCode === Inputmask.keyCode.TAB))) {
  1776. e.preventDefault();
  1777. } else {
  1778. switch (e.type) {
  1779. case "input":
  1780. if (skipInputEvent === true) {
  1781. skipInputEvent = false;
  1782. return e.preventDefault();
  1783. }
  1784. if (mobile) {
  1785. var args = arguments;
  1786. setTimeout(function() {
  1787. eventHandler.apply(that, args);
  1788. caret(that, that.inputmask.caretPos, undefined, true);
  1789. }, 0);
  1790. return false;
  1791. }
  1792. break;
  1793. case "keydown":
  1794. skipKeyPressEvent = false;
  1795. skipInputEvent = false;
  1796. break;
  1797. case "keypress":
  1798. if (skipKeyPressEvent === true) {
  1799. return e.preventDefault();
  1800. }
  1801. skipKeyPressEvent = true;
  1802. break;
  1803. case "click":
  1804. if (iemobile || iphone) {
  1805. var args = arguments;
  1806. setTimeout(function() {
  1807. eventHandler.apply(that, args);
  1808. }, 0);
  1809. return false;
  1810. }
  1811. break;
  1812. }
  1813. var returnVal = eventHandler.apply(that, arguments);
  1814. if (returnVal === false) {
  1815. e.preventDefault();
  1816. e.stopPropagation();
  1817. }
  1818. return returnVal;
  1819. }
  1820. };
  1821. input.inputmask.events[eventName] = input.inputmask.events[eventName] || [];
  1822. input.inputmask.events[eventName].push(ev);
  1823. if ($.inArray(eventName, [ "submit", "reset" ]) !== -1) {
  1824. if (input.form !== null) $(input.form).on(eventName, ev);
  1825. } else {
  1826. $(input).on(eventName, ev);
  1827. }
  1828. },
  1829. off: function off(input, event) {
  1830. if (input.inputmask && input.inputmask.events) {
  1831. var events;
  1832. if (event) {
  1833. events = [];
  1834. events[event] = input.inputmask.events[event];
  1835. } else {
  1836. events = input.inputmask.events;
  1837. }
  1838. $.each(events, function(eventName, evArr) {
  1839. while (evArr.length > 0) {
  1840. var ev = evArr.pop();
  1841. if ($.inArray(eventName, [ "submit", "reset" ]) !== -1) {
  1842. if (input.form !== null) $(input.form).off(eventName, ev);
  1843. } else {
  1844. $(input).off(eventName, ev);
  1845. }
  1846. }
  1847. delete input.inputmask.events[eventName];
  1848. });
  1849. }
  1850. }
  1851. };
  1852. var EventHandlers = {
  1853. keydownEvent: function keydownEvent(e) {
  1854. var input = this, $input = $(input), k = e.keyCode, pos = caret(input);
  1855. if (k === Inputmask.keyCode.BACKSPACE || k === Inputmask.keyCode.DELETE || iphone && k === Inputmask.keyCode.BACKSPACE_SAFARI || e.ctrlKey && k === Inputmask.keyCode.X && !isInputEventSupported("cut")) {
  1856. e.preventDefault();
  1857. handleRemove(input, k, pos);
  1858. writeBuffer(input, getBuffer(true), getMaskSet().p, e, input.inputmask._valueGet() !== getBuffer().join(""));
  1859. } else if (k === Inputmask.keyCode.END || k === Inputmask.keyCode.PAGE_DOWN) {
  1860. e.preventDefault();
  1861. var caretPos = seekNext(getLastValidPosition());
  1862. caret(input, e.shiftKey ? pos.begin : caretPos, caretPos, true);
  1863. } else if (k === Inputmask.keyCode.HOME && !e.shiftKey || k === Inputmask.keyCode.PAGE_UP) {
  1864. e.preventDefault();
  1865. caret(input, 0, e.shiftKey ? pos.begin : 0, true);
  1866. } else if ((opts.undoOnEscape && k === Inputmask.keyCode.ESCAPE || k === 90 && e.ctrlKey) && e.altKey !== true) {
  1867. checkVal(input, true, false, undoValue.split(""));
  1868. $input.trigger("click");
  1869. } else if (k === Inputmask.keyCode.INSERT && !(e.shiftKey || e.ctrlKey)) {
  1870. opts.insertMode = !opts.insertMode;
  1871. input.setAttribute("im-insert", opts.insertMode);
  1872. } else if (opts.tabThrough === true && k === Inputmask.keyCode.TAB) {
  1873. if (e.shiftKey === true) {
  1874. if (getTest(pos.begin).match.fn === null) {
  1875. pos.begin = seekNext(pos.begin);
  1876. }
  1877. pos.end = seekPrevious(pos.begin, true);
  1878. pos.begin = seekPrevious(pos.end, true);
  1879. } else {
  1880. pos.begin = seekNext(pos.begin, true);
  1881. pos.end = seekNext(pos.begin, true);
  1882. if (pos.end < getMaskSet().maskLength) pos.end--;
  1883. }
  1884. if (pos.begin < getMaskSet().maskLength) {
  1885. e.preventDefault();
  1886. caret(input, pos.begin, pos.end);
  1887. }
  1888. }
  1889. opts.onKeyDown.call(this, e, getBuffer(), caret(input).begin, opts);
  1890. ignorable = $.inArray(k, opts.ignorables) !== -1;
  1891. },
  1892. keypressEvent: function keypressEvent(e, checkval, writeOut, strict, ndx) {
  1893. var input = this, $input = $(input), k = e.which || e.charCode || e.keyCode;
  1894. if (checkval !== true && !(e.ctrlKey && e.altKey) && (e.ctrlKey || e.metaKey || ignorable)) {
  1895. if (k === Inputmask.keyCode.ENTER && undoValue !== getBuffer().join("")) {
  1896. undoValue = getBuffer().join("");
  1897. setTimeout(function() {
  1898. $input.trigger("change");
  1899. }, 0);
  1900. }
  1901. return true;
  1902. } else {
  1903. if (k) {
  1904. if (k === 46 && e.shiftKey === false && opts.radixPoint !== "") k = opts.radixPoint.charCodeAt(0);
  1905. var pos = checkval ? {
  1906. begin: ndx,
  1907. end: ndx
  1908. } : caret(input), forwardPosition, c = String.fromCharCode(k), offset = 0;
  1909. if (opts._radixDance && opts.numericInput) {
  1910. var caretPos = getBuffer().indexOf(opts.radixPoint.charAt(0)) + 1;
  1911. if (pos.begin <= caretPos) {
  1912. if (k === opts.radixPoint.charCodeAt(0)) offset = 1;
  1913. pos.begin -= 1;
  1914. pos.end -= 1;
  1915. }
  1916. }
  1917. getMaskSet().writeOutBuffer = true;
  1918. var valResult = isValid(pos, c, strict);
  1919. if (valResult !== false) {
  1920. resetMaskSet(true);
  1921. forwardPosition = valResult.caret !== undefined ? valResult.caret : seekNext(valResult.pos.begin ? valResult.pos.begin : valResult.pos);
  1922. getMaskSet().p = forwardPosition;
  1923. }
  1924. forwardPosition = (opts.numericInput && valResult.caret === undefined ? seekPrevious(forwardPosition) : forwardPosition) + offset;
  1925. if (writeOut !== false) {
  1926. setTimeout(function() {
  1927. opts.onKeyValidation.call(input, k, valResult, opts);
  1928. }, 0);
  1929. if (getMaskSet().writeOutBuffer && valResult !== false) {
  1930. var buffer = getBuffer();
  1931. writeBuffer(input, buffer, forwardPosition, e, checkval !== true);
  1932. }
  1933. }
  1934. e.preventDefault();
  1935. if (checkval) {
  1936. if (valResult !== false) valResult.forwardPosition = forwardPosition;
  1937. return valResult;
  1938. }
  1939. }
  1940. }
  1941. },
  1942. pasteEvent: function pasteEvent(e) {
  1943. var input = this, ev = e.originalEvent || e, $input = $(input), inputValue = input.inputmask._valueGet(true), caretPos = caret(input), tempValue;
  1944. if (isRTL) {
  1945. tempValue = caretPos.end;
  1946. caretPos.end = caretPos.begin;
  1947. caretPos.begin = tempValue;
  1948. }
  1949. var valueBeforeCaret = inputValue.substr(0, caretPos.begin), valueAfterCaret = inputValue.substr(caretPos.end, inputValue.length);
  1950. if (valueBeforeCaret === (isRTL ? getBufferTemplate().reverse() : getBufferTemplate()).slice(0, caretPos.begin).join("")) valueBeforeCaret = "";
  1951. if (valueAfterCaret === (isRTL ? getBufferTemplate().reverse() : getBufferTemplate()).slice(caretPos.end).join("")) valueAfterCaret = "";
  1952. if (window.clipboardData && window.clipboardData.getData) {
  1953. inputValue = valueBeforeCaret + window.clipboardData.getData("Text") + valueAfterCaret;
  1954. } else if (ev.clipboardData && ev.clipboardData.getData) {
  1955. inputValue = valueBeforeCaret + ev.clipboardData.getData("text/plain") + valueAfterCaret;
  1956. } else return true;
  1957. var pasteValue = inputValue;
  1958. if ($.isFunction(opts.onBeforePaste)) {
  1959. pasteValue = opts.onBeforePaste.call(inputmask, inputValue, opts);
  1960. if (pasteValue === false) {
  1961. return e.preventDefault();
  1962. }
  1963. if (!pasteValue) {
  1964. pasteValue = inputValue;
  1965. }
  1966. }
  1967. checkVal(input, false, false, pasteValue.toString().split(""));
  1968. writeBuffer(input, getBuffer(), seekNext(getLastValidPosition()), e, undoValue !== getBuffer().join(""));
  1969. return e.preventDefault();
  1970. },
  1971. inputFallBackEvent: function inputFallBackEvent(e) {
  1972. function radixPointHandler(input, inputValue, caretPos) {
  1973. if (inputValue.charAt(caretPos.begin - 1) === "." && opts.radixPoint !== "") {
  1974. inputValue = inputValue.split("");
  1975. inputValue[caretPos.begin - 1] = opts.radixPoint.charAt(0);
  1976. inputValue = inputValue.join("");
  1977. }
  1978. return inputValue;
  1979. }
  1980. function ieMobileHandler(input, inputValue, caretPos) {
  1981. if (iemobile) {
  1982. var inputChar = inputValue.replace(getBuffer().join(""), "");
  1983. if (inputChar.length === 1) {
  1984. var iv = inputValue.split("");
  1985. iv.splice(caretPos.begin, 0, inputChar);
  1986. inputValue = iv.join("");
  1987. }
  1988. }
  1989. return inputValue;
  1990. }
  1991. var input = this, inputValue = input.inputmask._valueGet();
  1992. if (getBuffer().join("") !== inputValue) {
  1993. var caretPos = caret(input);
  1994. inputValue = radixPointHandler(input, inputValue, caretPos);
  1995. inputValue = ieMobileHandler(input, inputValue, caretPos);
  1996. if (getBuffer().join("") !== inputValue) {
  1997. var buffer = getBuffer().join(""), offset = !opts.numericInput && inputValue.length > buffer.length ? -1 : 0, frontPart = inputValue.substr(0, caretPos.begin), backPart = inputValue.substr(caretPos.begin), frontBufferPart = buffer.substr(0, caretPos.begin + offset), backBufferPart = buffer.substr(caretPos.begin + offset);
  1998. var selection = caretPos, entries = "", isEntry = false;
  1999. if (frontPart !== frontBufferPart) {
  2000. var fpl = (isEntry = frontPart.length >= frontBufferPart.length) ? frontPart.length : frontBufferPart.length, i;
  2001. for (i = 0; frontPart.charAt(i) === frontBufferPart.charAt(i) && i < fpl; i++) {}
  2002. if (isEntry) {
  2003. selection.begin = i - offset;
  2004. entries += frontPart.slice(i, selection.end);
  2005. }
  2006. }
  2007. if (backPart !== backBufferPart) {
  2008. if (backPart.length > backBufferPart.length) {
  2009. entries += backPart.slice(0, 1);
  2010. } else {
  2011. if (backPart.length < backBufferPart.length) {
  2012. selection.end += backBufferPart.length - backPart.length;
  2013. if (!isEntry && opts.radixPoint !== "" && backPart === "" && frontPart.charAt(selection.begin + offset - 1) === opts.radixPoint) {
  2014. selection.begin--;
  2015. entries = opts.radixPoint;
  2016. }
  2017. }
  2018. }
  2019. }
  2020. writeBuffer(input, getBuffer(), {
  2021. begin: selection.begin + offset,
  2022. end: selection.end + offset
  2023. });
  2024. if (entries.length > 0) {
  2025. $.each(entries.split(""), function(ndx, entry) {
  2026. var keypress = new $.Event("keypress");
  2027. keypress.which = entry.charCodeAt(0);
  2028. ignorable = false;
  2029. EventHandlers.keypressEvent.call(input, keypress);
  2030. });
  2031. } else {
  2032. if (selection.begin === selection.end - 1) {
  2033. selection.begin = seekPrevious(selection.begin + 1);
  2034. if (selection.begin === selection.end - 1) {
  2035. caret(input, selection.begin);
  2036. } else {
  2037. caret(input, selection.begin, selection.end);
  2038. }
  2039. }
  2040. var keydown = new $.Event("keydown");
  2041. keydown.keyCode = opts.numericInput ? Inputmask.keyCode.BACKSPACE : Inputmask.keyCode.DELETE;
  2042. EventHandlers.keydownEvent.call(input, keydown);
  2043. }
  2044. e.preventDefault();
  2045. }
  2046. }
  2047. },
  2048. beforeInputEvent: function beforeInputEvent(e) {
  2049. if (e.cancelable) {
  2050. var input = this;
  2051. switch (e.inputType) {
  2052. case "insertText":
  2053. $.each(e.data.split(""), function(ndx, entry) {
  2054. var keypress = new $.Event("keypress");
  2055. keypress.which = entry.charCodeAt(0);
  2056. ignorable = false;
  2057. EventHandlers.keypressEvent.call(input, keypress);
  2058. });
  2059. return e.preventDefault();
  2060. case "deleteContentBackward":
  2061. var keydown = new $.Event("keydown");
  2062. keydown.keyCode = Inputmask.keyCode.BACKSPACE;
  2063. EventHandlers.keydownEvent.call(input, keydown);
  2064. return e.preventDefault();
  2065. case "deleteContentForward":
  2066. var keydown = new $.Event("keydown");
  2067. keydown.keyCode = Inputmask.keyCode.DELETE;
  2068. EventHandlers.keydownEvent.call(input, keydown);
  2069. return e.preventDefault();
  2070. }
  2071. }
  2072. },
  2073. setValueEvent: function setValueEvent(e) {
  2074. this.inputmask.refreshValue = false;
  2075. var input = this, value = e && e.detail ? e.detail[0] : arguments[1], value = value || input.inputmask._valueGet(true);
  2076. if ($.isFunction(opts.onBeforeMask)) value = opts.onBeforeMask.call(inputmask, value, opts) || value;
  2077. value = value.split("");
  2078. checkVal(input, true, false, value);
  2079. undoValue = getBuffer().join("");
  2080. if ((opts.clearMaskOnLostFocus || opts.clearIncomplete) && input.inputmask._valueGet() === getBufferTemplate().join("")) {
  2081. input.inputmask._valueSet("");
  2082. }
  2083. },
  2084. focusEvent: function focusEvent(e) {
  2085. var input = this, nptValue = input.inputmask._valueGet();
  2086. if (opts.showMaskOnFocus && (!opts.showMaskOnHover || opts.showMaskOnHover && nptValue === "")) {
  2087. if (input.inputmask._valueGet() !== getBuffer().join("")) {
  2088. writeBuffer(input, getBuffer(), seekNext(getLastValidPosition()));
  2089. } else if (mouseEnter === false) {
  2090. caret(input, seekNext(getLastValidPosition()));
  2091. }
  2092. }
  2093. if (opts.positionCaretOnTab === true && mouseEnter === false) {
  2094. EventHandlers.clickEvent.apply(input, [ e, true ]);
  2095. }
  2096. undoValue = getBuffer().join("");
  2097. },
  2098. mouseleaveEvent: function mouseleaveEvent(e) {
  2099. var input = this;
  2100. mouseEnter = false;
  2101. if (opts.clearMaskOnLostFocus && document.activeElement !== input) {
  2102. HandleNativePlaceholder(input, originalPlaceholder);
  2103. }
  2104. },
  2105. clickEvent: function clickEvent(e, tabbed) {
  2106. function doRadixFocus(clickPos) {
  2107. if (opts.radixPoint !== "") {
  2108. var vps = getMaskSet().validPositions;
  2109. if (vps[clickPos] === undefined || vps[clickPos].input === getPlaceholder(clickPos)) {
  2110. if (clickPos < seekNext(-1)) return true;
  2111. var radixPos = $.inArray(opts.radixPoint, getBuffer());
  2112. if (radixPos !== -1) {
  2113. for (var vp in vps) {
  2114. if (radixPos < vp && vps[vp].input !== getPlaceholder(vp)) {
  2115. return false;
  2116. }
  2117. }
  2118. return true;
  2119. }
  2120. }
  2121. }
  2122. return false;
  2123. }
  2124. var input = this;
  2125. setTimeout(function() {
  2126. if (document.activeElement === input) {
  2127. var selectedCaret = caret(input);
  2128. if (tabbed) {
  2129. if (isRTL) {
  2130. selectedCaret.end = selectedCaret.begin;
  2131. } else {
  2132. selectedCaret.begin = selectedCaret.end;
  2133. }
  2134. }
  2135. if (selectedCaret.begin === selectedCaret.end) {
  2136. switch (opts.positionCaretOnClick) {
  2137. case "none":
  2138. break;
  2139. case "select":
  2140. caret(input, 0, getBuffer().length);
  2141. break;
  2142. case "ignore":
  2143. caret(input, seekNext(getLastValidPosition()));
  2144. break;
  2145. case "radixFocus":
  2146. if (doRadixFocus(selectedCaret.begin)) {
  2147. var radixPos = getBuffer().join("").indexOf(opts.radixPoint);
  2148. caret(input, opts.numericInput ? seekNext(radixPos) : radixPos);
  2149. break;
  2150. }
  2151. default:
  2152. var clickPosition = selectedCaret.begin, lvclickPosition = getLastValidPosition(clickPosition, true), lastPosition = seekNext(lvclickPosition);
  2153. if (clickPosition < lastPosition) {
  2154. caret(input, !isMask(clickPosition, true) && !isMask(clickPosition - 1, true) ? seekNext(clickPosition) : clickPosition);
  2155. } else {
  2156. var lvp = getMaskSet().validPositions[lvclickPosition], tt = getTestTemplate(lastPosition, lvp ? lvp.match.locator : undefined, lvp), placeholder = getPlaceholder(lastPosition, tt.match);
  2157. if (placeholder !== "" && getBuffer()[lastPosition] !== placeholder && tt.match.optionalQuantifier !== true && tt.match.newBlockMarker !== true || !isMask(lastPosition, opts.keepStatic) && tt.match.def === placeholder) {
  2158. var newPos = seekNext(lastPosition);
  2159. if (clickPosition >= newPos || clickPosition === lastPosition) {
  2160. lastPosition = newPos;
  2161. }
  2162. }
  2163. caret(input, lastPosition);
  2164. }
  2165. break;
  2166. }
  2167. }
  2168. }
  2169. }, 0);
  2170. },
  2171. cutEvent: function cutEvent(e) {
  2172. var input = this, $input = $(input), pos = caret(input), ev = e.originalEvent || e;
  2173. var clipboardData = window.clipboardData || ev.clipboardData, clipData = isRTL ? getBuffer().slice(pos.end, pos.begin) : getBuffer().slice(pos.begin, pos.end);
  2174. clipboardData.setData("text", isRTL ? clipData.reverse().join("") : clipData.join(""));
  2175. if (document.execCommand) document.execCommand("copy");
  2176. handleRemove(input, Inputmask.keyCode.DELETE, pos);
  2177. writeBuffer(input, getBuffer(), getMaskSet().p, e, undoValue !== getBuffer().join(""));
  2178. },
  2179. blurEvent: function blurEvent(e) {
  2180. var $input = $(this), input = this;
  2181. if (input.inputmask) {
  2182. HandleNativePlaceholder(input, originalPlaceholder);
  2183. var nptValue = input.inputmask._valueGet(), buffer = getBuffer().slice();
  2184. if (nptValue !== "" || colorMask !== undefined) {
  2185. if (opts.clearMaskOnLostFocus) {
  2186. if (getLastValidPosition() === -1 && nptValue === getBufferTemplate().join("")) {
  2187. buffer = [];
  2188. } else {
  2189. clearOptionalTail(buffer);
  2190. }
  2191. }
  2192. if (isComplete(buffer) === false) {
  2193. setTimeout(function() {
  2194. $input.trigger("incomplete");
  2195. }, 0);
  2196. if (opts.clearIncomplete) {
  2197. resetMaskSet();
  2198. if (opts.clearMaskOnLostFocus) {
  2199. buffer = [];
  2200. } else {
  2201. buffer = getBufferTemplate().slice();
  2202. }
  2203. }
  2204. }
  2205. writeBuffer(input, buffer, undefined, e);
  2206. }
  2207. if (undoValue !== getBuffer().join("")) {
  2208. undoValue = buffer.join("");
  2209. $input.trigger("change");
  2210. }
  2211. }
  2212. },
  2213. mouseenterEvent: function mouseenterEvent(e) {
  2214. var input = this;
  2215. mouseEnter = true;
  2216. if (document.activeElement !== input && opts.showMaskOnHover) {
  2217. HandleNativePlaceholder(input, (isRTL ? getBuffer().slice().reverse() : getBuffer()).join(""));
  2218. }
  2219. },
  2220. submitEvent: function submitEvent(e) {
  2221. if (undoValue !== getBuffer().join("")) {
  2222. $el.trigger("change");
  2223. }
  2224. if (opts.clearMaskOnLostFocus && getLastValidPosition() === -1 && el.inputmask._valueGet && el.inputmask._valueGet() === getBufferTemplate().join("")) {
  2225. el.inputmask._valueSet("");
  2226. }
  2227. if (opts.clearIncomplete && isComplete(getBuffer()) === false) {
  2228. el.inputmask._valueSet("");
  2229. }
  2230. if (opts.removeMaskOnSubmit) {
  2231. el.inputmask._valueSet(el.inputmask.unmaskedvalue(), true);
  2232. setTimeout(function() {
  2233. writeBuffer(el, getBuffer());
  2234. }, 0);
  2235. }
  2236. },
  2237. resetEvent: function resetEvent(e) {
  2238. el.inputmask.refreshValue = true;
  2239. setTimeout(function() {
  2240. $el.trigger("setvalue");
  2241. }, 0);
  2242. }
  2243. };
  2244. function checkVal(input, writeOut, strict, nptvl, initiatingEvent) {
  2245. var inputmask = this || input.inputmask, inputValue = nptvl.slice(), charCodes = "", initialNdx = -1, result = undefined;
  2246. function isTemplateMatch(ndx, charCodes) {
  2247. var charCodeNdx = getMaskTemplate(true, 0, false).slice(ndx, seekNext(ndx)).join("").replace(/'/g, "").indexOf(charCodes);
  2248. return charCodeNdx !== -1 && !isMask(ndx) && (getTest(ndx).match.nativeDef === charCodes.charAt(0) || getTest(ndx).match.fn === null && getTest(ndx).match.nativeDef === "'" + charCodes.charAt(0) || getTest(ndx).match.nativeDef === " " && (getTest(ndx + 1).match.nativeDef === charCodes.charAt(0) || getTest(ndx + 1).match.fn === null && getTest(ndx + 1).match.nativeDef === "'" + charCodes.charAt(0)));
  2249. }
  2250. resetMaskSet();
  2251. if (!strict && opts.autoUnmask !== true) {
  2252. var staticInput = getBufferTemplate().slice(0, seekNext(-1)).join(""), matches = inputValue.join("").match(new RegExp("^" + Inputmask.escapeRegex(staticInput), "g"));
  2253. if (matches && matches.length > 0) {
  2254. inputValue.splice(0, matches.length * staticInput.length);
  2255. initialNdx = seekNext(initialNdx);
  2256. }
  2257. } else {
  2258. initialNdx = seekNext(initialNdx);
  2259. }
  2260. if (initialNdx === -1) {
  2261. getMaskSet().p = seekNext(initialNdx);
  2262. initialNdx = 0;
  2263. } else getMaskSet().p = initialNdx;
  2264. inputmask.caretPos = {
  2265. begin: initialNdx
  2266. };
  2267. $.each(inputValue, function(ndx, charCode) {
  2268. if (charCode !== undefined) {
  2269. if (getMaskSet().validPositions[ndx] === undefined && inputValue[ndx] === getPlaceholder(ndx) && isMask(ndx, true) && isValid(ndx, inputValue[ndx], true, undefined, undefined, true) === false) {
  2270. getMaskSet().p++;
  2271. } else {
  2272. var keypress = new $.Event("_checkval");
  2273. keypress.which = charCode.charCodeAt(0);
  2274. charCodes += charCode;
  2275. var lvp = getLastValidPosition(undefined, true);
  2276. if (!isTemplateMatch(initialNdx, charCodes)) {
  2277. result = EventHandlers.keypressEvent.call(input, keypress, true, false, strict, inputmask.caretPos.begin);
  2278. if (result) {
  2279. initialNdx = inputmask.caretPos.begin + 1;
  2280. charCodes = "";
  2281. }
  2282. } else {
  2283. result = EventHandlers.keypressEvent.call(input, keypress, true, false, strict, lvp + 1);
  2284. }
  2285. if (result) {
  2286. writeBuffer(undefined, getBuffer(), result.forwardPosition, keypress, false);
  2287. inputmask.caretPos = {
  2288. begin: result.forwardPosition,
  2289. end: result.forwardPosition
  2290. };
  2291. }
  2292. }
  2293. }
  2294. });
  2295. if (writeOut) writeBuffer(input, getBuffer(), result ? result.forwardPosition : undefined, initiatingEvent || new $.Event("checkval"), initiatingEvent && initiatingEvent.type === "input");
  2296. }
  2297. function unmaskedvalue(input) {
  2298. if (input) {
  2299. if (input.inputmask === undefined) {
  2300. return input.value;
  2301. }
  2302. if (input.inputmask && input.inputmask.refreshValue) {
  2303. EventHandlers.setValueEvent.call(input);
  2304. }
  2305. }
  2306. var umValue = [], vps = getMaskSet().validPositions;
  2307. for (var pndx in vps) {
  2308. if (vps[pndx].match && vps[pndx].match.fn != null) {
  2309. umValue.push(vps[pndx].input);
  2310. }
  2311. }
  2312. var unmaskedValue = umValue.length === 0 ? "" : (isRTL ? umValue.reverse() : umValue).join("");
  2313. if ($.isFunction(opts.onUnMask)) {
  2314. var bufferValue = (isRTL ? getBuffer().slice().reverse() : getBuffer()).join("");
  2315. unmaskedValue = opts.onUnMask.call(inputmask, bufferValue, unmaskedValue, opts);
  2316. }
  2317. return unmaskedValue;
  2318. }
  2319. function caret(input, begin, end, notranslate) {
  2320. function translatePosition(pos) {
  2321. if (isRTL && typeof pos === "number" && (!opts.greedy || opts.placeholder !== "") && el) {
  2322. pos = el.inputmask._valueGet().length - pos;
  2323. }
  2324. return pos;
  2325. }
  2326. var range;
  2327. if (begin !== undefined) {
  2328. if ($.isArray(begin)) {
  2329. end = isRTL ? begin[0] : begin[1];
  2330. begin = isRTL ? begin[1] : begin[0];
  2331. }
  2332. if (begin.begin !== undefined) {
  2333. end = isRTL ? begin.begin : begin.end;
  2334. begin = isRTL ? begin.end : begin.begin;
  2335. }
  2336. if (typeof begin === "number") {
  2337. begin = notranslate ? begin : translatePosition(begin);
  2338. end = notranslate ? end : translatePosition(end);
  2339. end = typeof end == "number" ? end : begin;
  2340. var scrollCalc = parseInt(((input.ownerDocument.defaultView || window).getComputedStyle ? (input.ownerDocument.defaultView || window).getComputedStyle(input, null) : input.currentStyle).fontSize) * end;
  2341. input.scrollLeft = scrollCalc > input.scrollWidth ? scrollCalc : 0;
  2342. input.inputmask.caretPos = {
  2343. begin: begin,
  2344. end: end
  2345. };
  2346. if (input === document.activeElement) {
  2347. if ("selectionStart" in input) {
  2348. input.selectionStart = begin;
  2349. input.selectionEnd = end;
  2350. } else if (window.getSelection) {
  2351. range = document.createRange();
  2352. if (input.firstChild === undefined || input.firstChild === null) {
  2353. var textNode = document.createTextNode("");
  2354. input.appendChild(textNode);
  2355. }
  2356. range.setStart(input.firstChild, begin < input.inputmask._valueGet().length ? begin : input.inputmask._valueGet().length);
  2357. range.setEnd(input.firstChild, end < input.inputmask._valueGet().length ? end : input.inputmask._valueGet().length);
  2358. range.collapse(true);
  2359. var sel = window.getSelection();
  2360. sel.removeAllRanges();
  2361. sel.addRange(range);
  2362. } else if (input.createTextRange) {
  2363. range = input.createTextRange();
  2364. range.collapse(true);
  2365. range.moveEnd("character", end);
  2366. range.moveStart("character", begin);
  2367. range.select();
  2368. }
  2369. renderColorMask(input, {
  2370. begin: begin,
  2371. end: end
  2372. });
  2373. }
  2374. }
  2375. } else {
  2376. if ("selectionStart" in input) {
  2377. begin = input.selectionStart;
  2378. end = input.selectionEnd;
  2379. } else if (window.getSelection) {
  2380. range = window.getSelection().getRangeAt(0);
  2381. if (range.commonAncestorContainer.parentNode === input || range.commonAncestorContainer === input) {
  2382. begin = range.startOffset;
  2383. end = range.endOffset;
  2384. }
  2385. } else if (document.selection && document.selection.createRange) {
  2386. range = document.selection.createRange();
  2387. begin = 0 - range.duplicate().moveStart("character", -input.inputmask._valueGet().length);
  2388. end = begin + range.text.length;
  2389. }
  2390. return {
  2391. begin: notranslate ? begin : translatePosition(begin),
  2392. end: notranslate ? end : translatePosition(end)
  2393. };
  2394. }
  2395. }
  2396. function determineLastRequiredPosition(returnDefinition) {
  2397. var buffer = getMaskTemplate(true, getLastValidPosition(), true, true), bl = buffer.length, pos, lvp = getLastValidPosition(), positions = {}, lvTest = getMaskSet().validPositions[lvp], ndxIntlzr = lvTest !== undefined ? lvTest.locator.slice() : undefined, testPos;
  2398. for (pos = lvp + 1; pos < buffer.length; pos++) {
  2399. testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
  2400. ndxIntlzr = testPos.locator.slice();
  2401. positions[pos] = $.extend(true, {}, testPos);
  2402. }
  2403. var lvTestAlt = lvTest && lvTest.alternation !== undefined ? lvTest.locator[lvTest.alternation] : undefined;
  2404. for (pos = bl - 1; pos > lvp; pos--) {
  2405. testPos = positions[pos];
  2406. if ((testPos.match.optionality || testPos.match.optionalQuantifier && testPos.match.newBlockMarker || lvTestAlt && (lvTestAlt !== positions[pos].locator[lvTest.alternation] && testPos.match.fn != null || testPos.match.fn === null && testPos.locator[lvTest.alternation] && checkAlternationMatch(testPos.locator[lvTest.alternation].toString().split(","), lvTestAlt.toString().split(",")) && getTests(pos)[0].def !== "")) && buffer[pos] === getPlaceholder(pos, testPos.match)) {
  2407. bl--;
  2408. } else break;
  2409. }
  2410. return returnDefinition ? {
  2411. l: bl,
  2412. def: positions[bl] ? positions[bl].match : undefined
  2413. } : bl;
  2414. }
  2415. function clearOptionalTail(buffer) {
  2416. buffer.length = 0;
  2417. var template = getMaskTemplate(true, 0, true, undefined, true), lmnt, validPos;
  2418. while (lmnt = template.shift(), lmnt !== undefined) {
  2419. buffer.push(lmnt);
  2420. }
  2421. return buffer;
  2422. }
  2423. function isComplete(buffer) {
  2424. if ($.isFunction(opts.isComplete)) return opts.isComplete(buffer, opts);
  2425. if (opts.repeat === "*") return undefined;
  2426. var complete = false, lrp = determineLastRequiredPosition(true), aml = seekPrevious(lrp.l);
  2427. if (lrp.def === undefined || lrp.def.newBlockMarker || lrp.def.optionality || lrp.def.optionalQuantifier) {
  2428. complete = true;
  2429. for (var i = 0; i <= aml; i++) {
  2430. var test = getTestTemplate(i).match;
  2431. if (test.fn !== null && getMaskSet().validPositions[i] === undefined && test.optionality !== true && test.optionalQuantifier !== true || test.fn === null && buffer[i] !== getPlaceholder(i, test)) {
  2432. complete = false;
  2433. break;
  2434. }
  2435. }
  2436. }
  2437. return complete;
  2438. }
  2439. function handleRemove(input, k, pos, strict, fromIsValid) {
  2440. if (opts.numericInput || isRTL) {
  2441. if (k === Inputmask.keyCode.BACKSPACE) {
  2442. k = Inputmask.keyCode.DELETE;
  2443. } else if (k === Inputmask.keyCode.DELETE) {
  2444. k = Inputmask.keyCode.BACKSPACE;
  2445. }
  2446. if (isRTL) {
  2447. var pend = pos.end;
  2448. pos.end = pos.begin;
  2449. pos.begin = pend;
  2450. }
  2451. }
  2452. if (k === Inputmask.keyCode.BACKSPACE && pos.end - pos.begin < 1) {
  2453. pos.begin = seekPrevious(pos.begin);
  2454. if (getMaskSet().validPositions[pos.begin] !== undefined && getMaskSet().validPositions[pos.begin].input === opts.groupSeparator) {
  2455. pos.begin--;
  2456. }
  2457. } else if (k === Inputmask.keyCode.DELETE && pos.begin === pos.end) {
  2458. pos.end = isMask(pos.end, true) && getMaskSet().validPositions[pos.end] && getMaskSet().validPositions[pos.end].input !== opts.radixPoint ? pos.end + 1 : seekNext(pos.end) + 1;
  2459. if (getMaskSet().validPositions[pos.begin] !== undefined && getMaskSet().validPositions[pos.begin].input === opts.groupSeparator) {
  2460. pos.end++;
  2461. }
  2462. }
  2463. revalidateMask(pos);
  2464. if (strict !== true && opts.keepStatic !== false || opts.regex !== null) {
  2465. var result = alternate(true);
  2466. if (result) {
  2467. var newPos = result.caret !== undefined ? result.caret : result.pos ? seekNext(result.pos.begin ? result.pos.begin : result.pos) : getLastValidPosition(-1, true);
  2468. if (k !== Inputmask.keyCode.DELETE || pos.begin > newPos) {
  2469. pos.begin == newPos;
  2470. }
  2471. }
  2472. }
  2473. var lvp = getLastValidPosition(pos.begin, true);
  2474. if (lvp < pos.begin || pos.begin === -1) {
  2475. getMaskSet().p = seekNext(lvp);
  2476. } else if (strict !== true) {
  2477. getMaskSet().p = pos.begin;
  2478. if (fromIsValid !== true) {
  2479. while (getMaskSet().p < lvp && getMaskSet().validPositions[getMaskSet().p] === undefined) {
  2480. getMaskSet().p++;
  2481. }
  2482. }
  2483. }
  2484. }
  2485. function initializeColorMask(input) {
  2486. var computedStyle = (input.ownerDocument.defaultView || window).getComputedStyle(input, null);
  2487. function findCaretPos(clientx) {
  2488. var e = document.createElement("span"), caretPos;
  2489. for (var style in computedStyle) {
  2490. if (isNaN(style) && style.indexOf("font") !== -1) {
  2491. e.style[style] = computedStyle[style];
  2492. }
  2493. }
  2494. e.style.textTransform = computedStyle.textTransform;
  2495. e.style.letterSpacing = computedStyle.letterSpacing;
  2496. e.style.position = "absolute";
  2497. e.style.height = "auto";
  2498. e.style.width = "auto";
  2499. e.style.visibility = "hidden";
  2500. e.style.whiteSpace = "nowrap";
  2501. document.body.appendChild(e);
  2502. var inputText = input.inputmask._valueGet(), previousWidth = 0, itl;
  2503. for (caretPos = 0, itl = inputText.length; caretPos <= itl; caretPos++) {
  2504. e.innerHTML += inputText.charAt(caretPos) || "_";
  2505. if (e.offsetWidth >= clientx) {
  2506. var offset1 = clientx - previousWidth;
  2507. var offset2 = e.offsetWidth - clientx;
  2508. e.innerHTML = inputText.charAt(caretPos);
  2509. offset1 -= e.offsetWidth / 3;
  2510. caretPos = offset1 < offset2 ? caretPos - 1 : caretPos;
  2511. break;
  2512. }
  2513. previousWidth = e.offsetWidth;
  2514. }
  2515. document.body.removeChild(e);
  2516. return caretPos;
  2517. }
  2518. var template = document.createElement("div");
  2519. template.style.width = computedStyle.width;
  2520. template.style.textAlign = computedStyle.textAlign;
  2521. colorMask = document.createElement("div");
  2522. input.inputmask.colorMask = colorMask;
  2523. colorMask.className = "im-colormask";
  2524. input.parentNode.insertBefore(colorMask, input);
  2525. input.parentNode.removeChild(input);
  2526. colorMask.appendChild(input);
  2527. colorMask.appendChild(template);
  2528. input.style.left = template.offsetLeft + "px";
  2529. $(colorMask).on("mouseleave", function(e) {
  2530. return EventHandlers.mouseleaveEvent.call(input, [ e ]);
  2531. });
  2532. $(colorMask).on("mouseenter", function(e) {
  2533. return EventHandlers.mouseenterEvent.call(input, [ e ]);
  2534. });
  2535. $(colorMask).on("click", function(e) {
  2536. caret(input, findCaretPos(e.clientX));
  2537. return EventHandlers.clickEvent.call(input, [ e ]);
  2538. });
  2539. }
  2540. Inputmask.prototype.positionColorMask = function(input, template) {
  2541. input.style.left = template.offsetLeft + "px";
  2542. };
  2543. function renderColorMask(input, caretPos, clear) {
  2544. var maskTemplate = [], isStatic = false, test, testPos, ndxIntlzr, pos = 0;
  2545. function setEntry(entry) {
  2546. if (entry === undefined) entry = "";
  2547. if (!isStatic && (test.fn === null || testPos.input === undefined)) {
  2548. isStatic = true;
  2549. maskTemplate.push("<span class='im-static'>" + entry);
  2550. } else if (isStatic && (test.fn !== null && testPos.input !== undefined || test.def === "")) {
  2551. isStatic = false;
  2552. var mtl = maskTemplate.length;
  2553. maskTemplate[mtl - 1] = maskTemplate[mtl - 1] + "</span>";
  2554. maskTemplate.push(entry);
  2555. } else maskTemplate.push(entry);
  2556. }
  2557. function setCaret() {
  2558. if (document.activeElement === input) {
  2559. maskTemplate.splice(caretPos.begin, 0, caretPos.begin === caretPos.end || caretPos.end > getMaskSet().maskLength ? '<mark class="im-caret" style="border-right-width: 1px;border-right-style: solid;">' : '<mark class="im-caret-select">');
  2560. maskTemplate.splice(caretPos.end + 1, 0, "</mark>");
  2561. }
  2562. }
  2563. if (colorMask !== undefined) {
  2564. var buffer = getBuffer();
  2565. if (caretPos === undefined) {
  2566. caretPos = caret(input);
  2567. } else if (caretPos.begin === undefined) {
  2568. caretPos = {
  2569. begin: caretPos,
  2570. end: caretPos
  2571. };
  2572. }
  2573. if (clear !== true) {
  2574. var lvp = getLastValidPosition();
  2575. do {
  2576. if (getMaskSet().validPositions[pos]) {
  2577. testPos = getMaskSet().validPositions[pos];
  2578. test = testPos.match;
  2579. ndxIntlzr = testPos.locator.slice();
  2580. setEntry(buffer[pos]);
  2581. } else {
  2582. testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
  2583. test = testPos.match;
  2584. ndxIntlzr = testPos.locator.slice();
  2585. if (opts.jitMasking === false || pos < lvp || typeof opts.jitMasking === "number" && isFinite(opts.jitMasking) && opts.jitMasking > pos) {
  2586. setEntry(getPlaceholder(pos, test));
  2587. } else isStatic = false;
  2588. }
  2589. pos++;
  2590. } while ((maxLength === undefined || pos < maxLength) && (test.fn !== null || test.def !== "") || lvp > pos || isStatic);
  2591. if (isStatic) setEntry();
  2592. setCaret();
  2593. }
  2594. var template = colorMask.getElementsByTagName("div")[0];
  2595. template.innerHTML = maskTemplate.join("");
  2596. input.inputmask.positionColorMask(input, template);
  2597. }
  2598. }
  2599. function mask(elem) {
  2600. function isElementTypeSupported(input, opts) {
  2601. function patchValueProperty(npt) {
  2602. var valueGet;
  2603. var valueSet;
  2604. function patchValhook(type) {
  2605. if ($.valHooks && ($.valHooks[type] === undefined || $.valHooks[type].inputmaskpatch !== true)) {
  2606. var valhookGet = $.valHooks[type] && $.valHooks[type].get ? $.valHooks[type].get : function(elem) {
  2607. return elem.value;
  2608. };
  2609. var valhookSet = $.valHooks[type] && $.valHooks[type].set ? $.valHooks[type].set : function(elem, value) {
  2610. elem.value = value;
  2611. return elem;
  2612. };
  2613. $.valHooks[type] = {
  2614. get: function get(elem) {
  2615. if (elem.inputmask) {
  2616. if (elem.inputmask.opts.autoUnmask) {
  2617. return elem.inputmask.unmaskedvalue();
  2618. } else {
  2619. var result = valhookGet(elem);
  2620. return getLastValidPosition(undefined, undefined, elem.inputmask.maskset.validPositions) !== -1 || opts.nullable !== true ? result : "";
  2621. }
  2622. } else return valhookGet(elem);
  2623. },
  2624. set: function set(elem, value) {
  2625. var $elem = $(elem), result;
  2626. result = valhookSet(elem, value);
  2627. if (elem.inputmask) {
  2628. $elem.trigger("setvalue", [ value ]);
  2629. }
  2630. return result;
  2631. },
  2632. inputmaskpatch: true
  2633. };
  2634. }
  2635. }
  2636. function getter() {
  2637. if (this.inputmask) {
  2638. return this.inputmask.opts.autoUnmask ? this.inputmask.unmaskedvalue() : getLastValidPosition() !== -1 || opts.nullable !== true ? document.activeElement === this && opts.clearMaskOnLostFocus ? (isRTL ? clearOptionalTail(getBuffer().slice()).reverse() : clearOptionalTail(getBuffer().slice())).join("") : valueGet.call(this) : "";
  2639. } else return valueGet.call(this);
  2640. }
  2641. function setter(value) {
  2642. valueSet.call(this, value);
  2643. if (this.inputmask) {
  2644. $(this).trigger("setvalue", [ value ]);
  2645. }
  2646. }
  2647. function installNativeValueSetFallback(npt) {
  2648. EventRuler.on(npt, "mouseenter", function(event) {
  2649. var $input = $(this), input = this, value = input.inputmask._valueGet();
  2650. if (value !== getBuffer().join("")) {
  2651. $input.trigger("setvalue");
  2652. }
  2653. });
  2654. }
  2655. if (!npt.inputmask.__valueGet) {
  2656. if (opts.noValuePatching !== true) {
  2657. if (Object.getOwnPropertyDescriptor) {
  2658. if (typeof Object.getPrototypeOf !== "function") {
  2659. Object.getPrototypeOf = _typeof("test".__proto__) === "object" ? function(object) {
  2660. return object.__proto__;
  2661. } : function(object) {
  2662. return object.constructor.prototype;
  2663. };
  2664. }
  2665. var valueProperty = Object.getPrototypeOf ? Object.getOwnPropertyDescriptor(Object.getPrototypeOf(npt), "value") : undefined;
  2666. if (valueProperty && valueProperty.get && valueProperty.set) {
  2667. valueGet = valueProperty.get;
  2668. valueSet = valueProperty.set;
  2669. Object.defineProperty(npt, "value", {
  2670. get: getter,
  2671. set: setter,
  2672. configurable: true
  2673. });
  2674. } else if (npt.tagName !== "INPUT") {
  2675. valueGet = function valueGet() {
  2676. return this.textContent;
  2677. };
  2678. valueSet = function valueSet(value) {
  2679. this.textContent = value;
  2680. };
  2681. Object.defineProperty(npt, "value", {
  2682. get: getter,
  2683. set: setter,
  2684. configurable: true
  2685. });
  2686. }
  2687. } else if (document.__lookupGetter__ && npt.__lookupGetter__("value")) {
  2688. valueGet = npt.__lookupGetter__("value");
  2689. valueSet = npt.__lookupSetter__("value");
  2690. npt.__defineGetter__("value", getter);
  2691. npt.__defineSetter__("value", setter);
  2692. }
  2693. npt.inputmask.__valueGet = valueGet;
  2694. npt.inputmask.__valueSet = valueSet;
  2695. }
  2696. npt.inputmask._valueGet = function(overruleRTL) {
  2697. return isRTL && overruleRTL !== true ? valueGet.call(this.el).split("").reverse().join("") : valueGet.call(this.el);
  2698. };
  2699. npt.inputmask._valueSet = function(value, overruleRTL) {
  2700. valueSet.call(this.el, value === null || value === undefined ? "" : overruleRTL !== true && isRTL ? value.split("").reverse().join("") : value);
  2701. };
  2702. if (valueGet === undefined) {
  2703. valueGet = function valueGet() {
  2704. return this.value;
  2705. };
  2706. valueSet = function valueSet(value) {
  2707. this.value = value;
  2708. };
  2709. patchValhook(npt.type);
  2710. installNativeValueSetFallback(npt);
  2711. }
  2712. }
  2713. }
  2714. var elementType = input.getAttribute("type");
  2715. var isSupported = input.tagName === "INPUT" && $.inArray(elementType, opts.supportsInputType) !== -1 || input.isContentEditable || input.tagName === "TEXTAREA";
  2716. if (!isSupported) {
  2717. if (input.tagName === "INPUT") {
  2718. var el = document.createElement("input");
  2719. el.setAttribute("type", elementType);
  2720. isSupported = el.type === "text";
  2721. el = null;
  2722. } else isSupported = "partial";
  2723. }
  2724. if (isSupported !== false) {
  2725. patchValueProperty(input);
  2726. } else input.inputmask = undefined;
  2727. return isSupported;
  2728. }
  2729. EventRuler.off(elem);
  2730. var isSupported = isElementTypeSupported(elem, opts);
  2731. if (isSupported !== false) {
  2732. el = elem;
  2733. $el = $(el);
  2734. originalPlaceholder = el.placeholder;
  2735. maxLength = el !== undefined ? el.maxLength : undefined;
  2736. if (maxLength === -1) maxLength = undefined;
  2737. if (opts.colorMask === true) {
  2738. initializeColorMask(el);
  2739. }
  2740. if (mobile) {
  2741. if ("inputmode" in el) {
  2742. el.inputmode = opts.inputmode;
  2743. el.setAttribute("inputmode", opts.inputmode);
  2744. }
  2745. if (opts.disablePredictiveText === true) {
  2746. if ("autocorrect" in el) {
  2747. el.autocorrect = false;
  2748. } else {
  2749. if (opts.colorMask !== true) {
  2750. initializeColorMask(el);
  2751. }
  2752. el.type = "password";
  2753. }
  2754. }
  2755. }
  2756. if (isSupported === true) {
  2757. el.setAttribute("im-insert", opts.insertMode);
  2758. EventRuler.on(el, "submit", EventHandlers.submitEvent);
  2759. EventRuler.on(el, "reset", EventHandlers.resetEvent);
  2760. EventRuler.on(el, "blur", EventHandlers.blurEvent);
  2761. EventRuler.on(el, "focus", EventHandlers.focusEvent);
  2762. if (opts.colorMask !== true) {
  2763. EventRuler.on(el, "click", EventHandlers.clickEvent);
  2764. EventRuler.on(el, "mouseleave", EventHandlers.mouseleaveEvent);
  2765. EventRuler.on(el, "mouseenter", EventHandlers.mouseenterEvent);
  2766. }
  2767. EventRuler.on(el, "paste", EventHandlers.pasteEvent);
  2768. EventRuler.on(el, "cut", EventHandlers.cutEvent);
  2769. EventRuler.on(el, "complete", opts.oncomplete);
  2770. EventRuler.on(el, "incomplete", opts.onincomplete);
  2771. EventRuler.on(el, "cleared", opts.oncleared);
  2772. if (!mobile && opts.inputEventOnly !== true) {
  2773. EventRuler.on(el, "keydown", EventHandlers.keydownEvent);
  2774. EventRuler.on(el, "keypress", EventHandlers.keypressEvent);
  2775. } else {
  2776. el.removeAttribute("maxLength");
  2777. }
  2778. EventRuler.on(el, "input", EventHandlers.inputFallBackEvent);
  2779. EventRuler.on(el, "beforeinput", EventHandlers.beforeInputEvent);
  2780. }
  2781. EventRuler.on(el, "setvalue", EventHandlers.setValueEvent);
  2782. undoValue = getBufferTemplate().join("");
  2783. if (el.inputmask._valueGet(true) !== "" || opts.clearMaskOnLostFocus === false || document.activeElement === el) {
  2784. var initialValue = $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(inputmask, el.inputmask._valueGet(true), opts) || el.inputmask._valueGet(true) : el.inputmask._valueGet(true);
  2785. if (initialValue !== "") checkVal(el, true, false, initialValue.split(""));
  2786. var buffer = getBuffer().slice();
  2787. undoValue = buffer.join("");
  2788. if (isComplete(buffer) === false) {
  2789. if (opts.clearIncomplete) {
  2790. resetMaskSet();
  2791. }
  2792. }
  2793. if (opts.clearMaskOnLostFocus && document.activeElement !== el) {
  2794. if (getLastValidPosition() === -1) {
  2795. buffer = [];
  2796. } else {
  2797. clearOptionalTail(buffer);
  2798. }
  2799. }
  2800. if (opts.clearMaskOnLostFocus === false || opts.showMaskOnFocus && document.activeElement === el || el.inputmask._valueGet(true) !== "") writeBuffer(el, buffer);
  2801. if (document.activeElement === el) {
  2802. caret(el, seekNext(getLastValidPosition()));
  2803. }
  2804. }
  2805. }
  2806. }
  2807. var valueBuffer;
  2808. if (actionObj !== undefined) {
  2809. switch (actionObj.action) {
  2810. case "isComplete":
  2811. el = actionObj.el;
  2812. return isComplete(getBuffer());
  2813. case "unmaskedvalue":
  2814. if (el === undefined || actionObj.value !== undefined) {
  2815. valueBuffer = actionObj.value;
  2816. valueBuffer = ($.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(inputmask, valueBuffer, opts) || valueBuffer : valueBuffer).split("");
  2817. checkVal.call(this, undefined, false, false, valueBuffer);
  2818. if ($.isFunction(opts.onBeforeWrite)) opts.onBeforeWrite.call(inputmask, undefined, getBuffer(), 0, opts);
  2819. }
  2820. return unmaskedvalue(el);
  2821. case "mask":
  2822. mask(el);
  2823. break;
  2824. case "format":
  2825. valueBuffer = ($.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(inputmask, actionObj.value, opts) || actionObj.value : actionObj.value).split("");
  2826. checkVal.call(this, undefined, true, false, valueBuffer);
  2827. if (actionObj.metadata) {
  2828. return {
  2829. value: isRTL ? getBuffer().slice().reverse().join("") : getBuffer().join(""),
  2830. metadata: maskScope.call(this, {
  2831. action: "getmetadata"
  2832. }, maskset, opts)
  2833. };
  2834. }
  2835. return isRTL ? getBuffer().slice().reverse().join("") : getBuffer().join("");
  2836. case "isValid":
  2837. if (actionObj.value) {
  2838. valueBuffer = actionObj.value.split("");
  2839. checkVal.call(this, undefined, true, true, valueBuffer);
  2840. } else {
  2841. actionObj.value = getBuffer().join("");
  2842. }
  2843. var buffer = getBuffer();
  2844. var rl = determineLastRequiredPosition(), lmib = buffer.length - 1;
  2845. for (;lmib > rl; lmib--) {
  2846. if (isMask(lmib)) break;
  2847. }
  2848. buffer.splice(rl, lmib + 1 - rl);
  2849. return isComplete(buffer) && actionObj.value === getBuffer().join("");
  2850. case "getemptymask":
  2851. return getBufferTemplate().join("");
  2852. case "remove":
  2853. if (el && el.inputmask) {
  2854. $.data(el, "_inputmask_opts", null);
  2855. $el = $(el);
  2856. el.inputmask._valueSet(opts.autoUnmask ? unmaskedvalue(el) : el.inputmask._valueGet(true));
  2857. EventRuler.off(el);
  2858. if (el.inputmask.colorMask) {
  2859. colorMask = el.inputmask.colorMask;
  2860. colorMask.removeChild(el);
  2861. colorMask.parentNode.insertBefore(el, colorMask);
  2862. colorMask.parentNode.removeChild(colorMask);
  2863. }
  2864. var valueProperty;
  2865. if (Object.getOwnPropertyDescriptor && Object.getPrototypeOf) {
  2866. valueProperty = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(el), "value");
  2867. if (valueProperty) {
  2868. if (el.inputmask.__valueGet) {
  2869. Object.defineProperty(el, "value", {
  2870. get: el.inputmask.__valueGet,
  2871. set: el.inputmask.__valueSet,
  2872. configurable: true
  2873. });
  2874. }
  2875. }
  2876. } else if (document.__lookupGetter__ && el.__lookupGetter__("value")) {
  2877. if (el.inputmask.__valueGet) {
  2878. el.__defineGetter__("value", el.inputmask.__valueGet);
  2879. el.__defineSetter__("value", el.inputmask.__valueSet);
  2880. }
  2881. }
  2882. el.inputmask = undefined;
  2883. }
  2884. return el;
  2885. break;
  2886. case "getmetadata":
  2887. if ($.isArray(maskset.metadata)) {
  2888. var maskTarget = getMaskTemplate(true, 0, false).join("");
  2889. $.each(maskset.metadata, function(ndx, mtdt) {
  2890. if (mtdt.mask === maskTarget) {
  2891. maskTarget = mtdt;
  2892. return false;
  2893. }
  2894. });
  2895. return maskTarget;
  2896. }
  2897. return maskset.metadata;
  2898. }
  2899. }
  2900. }
  2901. return Inputmask;
  2902. });
  2903. }, function(module, exports, __webpack_require__) {
  2904. "use strict";
  2905. var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;
  2906. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function(obj) {
  2907. return typeof obj;
  2908. } : function(obj) {
  2909. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  2910. };
  2911. (function(factory) {
  2912. if (true) {
  2913. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [ __webpack_require__(4) ], __WEBPACK_AMD_DEFINE_FACTORY__ = factory,
  2914. __WEBPACK_AMD_DEFINE_RESULT__ = typeof __WEBPACK_AMD_DEFINE_FACTORY__ === "function" ? __WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__) : __WEBPACK_AMD_DEFINE_FACTORY__,
  2915. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  2916. } else {}
  2917. })(function($) {
  2918. return $;
  2919. });
  2920. }, function(module, exports) {
  2921. module.exports = jQuery;
  2922. }, function(module, exports, __webpack_require__) {
  2923. "use strict";
  2924. var __WEBPACK_AMD_DEFINE_RESULT__;
  2925. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function(obj) {
  2926. return typeof obj;
  2927. } : function(obj) {
  2928. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  2929. };
  2930. if (true) !(__WEBPACK_AMD_DEFINE_RESULT__ = function() {
  2931. return window || new (eval("require('jsdom')")("").window)();
  2932. }.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); else {}
  2933. }, function(module, exports, __webpack_require__) {
  2934. "use strict";
  2935. var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;
  2936. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function(obj) {
  2937. return typeof obj;
  2938. } : function(obj) {
  2939. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  2940. };
  2941. (function(factory) {
  2942. if (true) {
  2943. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [ __webpack_require__(2) ], __WEBPACK_AMD_DEFINE_FACTORY__ = factory,
  2944. __WEBPACK_AMD_DEFINE_RESULT__ = typeof __WEBPACK_AMD_DEFINE_FACTORY__ === "function" ? __WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__) : __WEBPACK_AMD_DEFINE_FACTORY__,
  2945. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  2946. } else {}
  2947. })(function(Inputmask) {
  2948. var $ = Inputmask.dependencyLib;
  2949. var formatCode = {
  2950. d: [ "[1-9]|[12][0-9]|3[01]", Date.prototype.setDate, "day", Date.prototype.getDate ],
  2951. dd: [ "0[1-9]|[12][0-9]|3[01]", Date.prototype.setDate, "day", function() {
  2952. return pad(Date.prototype.getDate.call(this), 2);
  2953. } ],
  2954. ddd: [ "" ],
  2955. dddd: [ "" ],
  2956. m: [ "[1-9]|1[012]", Date.prototype.setMonth, "month", function() {
  2957. return Date.prototype.getMonth.call(this) + 1;
  2958. } ],
  2959. mm: [ "0[1-9]|1[012]", Date.prototype.setMonth, "month", function() {
  2960. return pad(Date.prototype.getMonth.call(this) + 1, 2);
  2961. } ],
  2962. mmm: [ "" ],
  2963. mmmm: [ "" ],
  2964. yy: [ "[0-9]{2}", Date.prototype.setFullYear, "year", function() {
  2965. return pad(Date.prototype.getFullYear.call(this), 2);
  2966. } ],
  2967. yyyy: [ "[0-9]{4}", Date.prototype.setFullYear, "year", function() {
  2968. return pad(Date.prototype.getFullYear.call(this), 4);
  2969. } ],
  2970. h: [ "[1-9]|1[0-2]", Date.prototype.setHours, "hours", Date.prototype.getHours ],
  2971. hh: [ "0[1-9]|1[0-2]", Date.prototype.setHours, "hours", function() {
  2972. return pad(Date.prototype.getHours.call(this), 2);
  2973. } ],
  2974. hhh: [ "[0-9]+", Date.prototype.setHours, "hours", Date.prototype.getHours ],
  2975. H: [ "1?[0-9]|2[0-3]", Date.prototype.setHours, "hours", Date.prototype.getHours ],
  2976. HH: [ "[01][0-9]|2[0-3]", Date.prototype.setHours, "hours", function() {
  2977. return pad(Date.prototype.getHours.call(this), 2);
  2978. } ],
  2979. HHH: [ "[0-9]+", Date.prototype.setHours, "hours", Date.prototype.getHours ],
  2980. M: [ "[1-5]?[0-9]", Date.prototype.setMinutes, "minutes", Date.prototype.getMinutes ],
  2981. MM: [ "[0-5][0-9]", Date.prototype.setMinutes, "minutes", function() {
  2982. return pad(Date.prototype.getMinutes.call(this), 2);
  2983. } ],
  2984. s: [ "[1-5]?[0-9]", Date.prototype.setSeconds, "seconds", Date.prototype.getSeconds ],
  2985. ss: [ "[0-5][0-9]", Date.prototype.setSeconds, "seconds", function() {
  2986. return pad(Date.prototype.getSeconds.call(this), 2);
  2987. } ],
  2988. l: [ "[0-9]{3}", Date.prototype.setMilliseconds, "milliseconds", function() {
  2989. return pad(Date.prototype.getMilliseconds.call(this), 3);
  2990. } ],
  2991. L: [ "[0-9]{2}", Date.prototype.setMilliseconds, "milliseconds", function() {
  2992. return pad(Date.prototype.getMilliseconds.call(this), 2);
  2993. } ],
  2994. t: [ "[ap]" ],
  2995. tt: [ "[ap]m" ],
  2996. T: [ "[AP]" ],
  2997. TT: [ "[AP]M" ],
  2998. Z: [ "" ],
  2999. o: [ "" ],
  3000. S: [ "" ]
  3001. }, formatAlias = {
  3002. isoDate: "yyyy-mm-dd",
  3003. isoTime: "HH:MM:ss",
  3004. isoDateTime: "yyyy-mm-dd'T'HH:MM:ss",
  3005. isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
  3006. };
  3007. function getTokenizer(opts) {
  3008. if (!opts.tokenizer) {
  3009. var tokens = [];
  3010. for (var ndx in formatCode) {
  3011. if (tokens.indexOf(ndx[0]) === -1) tokens.push(ndx[0]);
  3012. }
  3013. opts.tokenizer = "(" + tokens.join("+|") + ")+?|.";
  3014. opts.tokenizer = new RegExp(opts.tokenizer, "g");
  3015. }
  3016. return opts.tokenizer;
  3017. }
  3018. function isValidDate(dateParts, currentResult) {
  3019. return !isFinite(dateParts.rawday) || dateParts.day == "29" && !isFinite(dateParts.rawyear) || new Date(dateParts.date.getFullYear(), isFinite(dateParts.rawmonth) ? dateParts.month : dateParts.date.getMonth() + 1, 0).getDate() >= dateParts.day ? currentResult : false;
  3020. }
  3021. function isDateInRange(dateParts, opts) {
  3022. var result = true;
  3023. if (opts.min) {
  3024. if (dateParts["rawyear"]) {
  3025. var rawYear = dateParts["rawyear"].replace(/[^0-9]/g, ""), minYear = opts.min.year.substr(0, rawYear.length);
  3026. result = minYear <= rawYear;
  3027. }
  3028. if (dateParts["year"] === dateParts["rawyear"]) {
  3029. if (opts.min.date.getTime() === opts.min.date.getTime()) {
  3030. result = opts.min.date.getTime() <= dateParts.date.getTime();
  3031. }
  3032. }
  3033. }
  3034. if (result && opts.max && opts.max.date.getTime() === opts.max.date.getTime()) {
  3035. result = opts.max.date.getTime() >= dateParts.date.getTime();
  3036. }
  3037. return result;
  3038. }
  3039. function parse(format, dateObjValue, opts, raw) {
  3040. var mask = "", match;
  3041. while (match = getTokenizer(opts).exec(format)) {
  3042. if (dateObjValue === undefined) {
  3043. if (formatCode[match[0]]) {
  3044. mask += "(" + formatCode[match[0]][0] + ")";
  3045. } else {
  3046. switch (match[0]) {
  3047. case "[":
  3048. mask += "(";
  3049. break;
  3050. case "]":
  3051. mask += ")?";
  3052. break;
  3053. default:
  3054. mask += Inputmask.escapeRegex(match[0]);
  3055. }
  3056. }
  3057. } else {
  3058. if (formatCode[match[0]]) {
  3059. if (raw !== true && formatCode[match[0]][3]) {
  3060. var getFn = formatCode[match[0]][3];
  3061. mask += getFn.call(dateObjValue.date);
  3062. } else if (formatCode[match[0]][2]) mask += dateObjValue["raw" + formatCode[match[0]][2]]; else mask += match[0];
  3063. } else mask += match[0];
  3064. }
  3065. }
  3066. return mask;
  3067. }
  3068. function pad(val, len) {
  3069. val = String(val);
  3070. len = len || 2;
  3071. while (val.length < len) {
  3072. val = "0" + val;
  3073. }
  3074. return val;
  3075. }
  3076. function analyseMask(maskString, format, opts) {
  3077. var dateObj = {
  3078. date: new Date(1, 0, 1)
  3079. }, targetProp, mask = maskString, match, dateOperation, targetValidator;
  3080. function extendProperty(value) {
  3081. var correctedValue = value.replace(/[^0-9]/g, "0");
  3082. if (correctedValue != value) {
  3083. var enteredPart = value.replace(/[^0-9]/g, ""), min = (opts.min && opts.min[targetProp] || value).toString(), max = (opts.max && opts.max[targetProp] || value).toString();
  3084. correctedValue = enteredPart + (enteredPart < min.slice(0, enteredPart.length) ? min.slice(enteredPart.length) : enteredPart > max.slice(0, enteredPart.length) ? max.slice(enteredPart.length) : correctedValue.toString().slice(enteredPart.length));
  3085. }
  3086. return correctedValue;
  3087. }
  3088. function setValue(dateObj, value, opts) {
  3089. dateObj[targetProp] = extendProperty(value);
  3090. dateObj["raw" + targetProp] = value;
  3091. if (dateOperation !== undefined) dateOperation.call(dateObj.date, targetProp == "month" ? parseInt(dateObj[targetProp]) - 1 : dateObj[targetProp]);
  3092. }
  3093. if (typeof mask === "string") {
  3094. while (match = getTokenizer(opts).exec(format)) {
  3095. var value = mask.slice(0, match[0].length);
  3096. if (formatCode.hasOwnProperty(match[0])) {
  3097. targetValidator = formatCode[match[0]][0];
  3098. targetProp = formatCode[match[0]][2];
  3099. dateOperation = formatCode[match[0]][1];
  3100. setValue(dateObj, value, opts);
  3101. }
  3102. mask = mask.slice(value.length);
  3103. }
  3104. return dateObj;
  3105. } else if (mask && (typeof mask === "undefined" ? "undefined" : _typeof(mask)) === "object" && mask.hasOwnProperty("date")) {
  3106. return mask;
  3107. }
  3108. return undefined;
  3109. }
  3110. Inputmask.extendAliases({
  3111. datetime: {
  3112. mask: function mask(opts) {
  3113. formatCode.S = opts.i18n.ordinalSuffix.join("|");
  3114. opts.inputFormat = formatAlias[opts.inputFormat] || opts.inputFormat;
  3115. opts.displayFormat = formatAlias[opts.displayFormat] || opts.displayFormat || opts.inputFormat;
  3116. opts.outputFormat = formatAlias[opts.outputFormat] || opts.outputFormat || opts.inputFormat;
  3117. opts.placeholder = opts.placeholder !== "" ? opts.placeholder : opts.inputFormat.replace(/[\[\]]/, "");
  3118. opts.regex = parse(opts.inputFormat, undefined, opts);
  3119. return null;
  3120. },
  3121. placeholder: "",
  3122. inputFormat: "isoDateTime",
  3123. displayFormat: undefined,
  3124. outputFormat: undefined,
  3125. min: null,
  3126. max: null,
  3127. i18n: {
  3128. dayNames: [ "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ],
  3129. monthNames: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
  3130. ordinalSuffix: [ "st", "nd", "rd", "th" ]
  3131. },
  3132. postValidation: function postValidation(buffer, pos, currentResult, opts) {
  3133. opts.min = analyseMask(opts.min, opts.inputFormat, opts);
  3134. opts.max = analyseMask(opts.max, opts.inputFormat, opts);
  3135. var result = currentResult, dateParts = analyseMask(buffer.join(""), opts.inputFormat, opts);
  3136. if (result && dateParts.date.getTime() === dateParts.date.getTime()) {
  3137. result = isValidDate(dateParts, result);
  3138. result = result && isDateInRange(dateParts, opts);
  3139. }
  3140. if (pos && result && currentResult.pos !== pos) {
  3141. return {
  3142. buffer: parse(opts.inputFormat, dateParts, opts),
  3143. refreshFromBuffer: {
  3144. start: pos,
  3145. end: currentResult.pos
  3146. }
  3147. };
  3148. }
  3149. return result;
  3150. },
  3151. onKeyDown: function onKeyDown(e, buffer, caretPos, opts) {
  3152. var input = this;
  3153. if (e.ctrlKey && e.keyCode === Inputmask.keyCode.RIGHT) {
  3154. var today = new Date(), match, date = "";
  3155. while (match = getTokenizer(opts).exec(opts.inputFormat)) {
  3156. if (match[0].charAt(0) === "d") {
  3157. date += pad(today.getDate(), match[0].length);
  3158. } else if (match[0].charAt(0) === "m") {
  3159. date += pad(today.getMonth() + 1, match[0].length);
  3160. } else if (match[0] === "yyyy") {
  3161. date += today.getFullYear().toString();
  3162. } else if (match[0].charAt(0) === "y") {
  3163. date += pad(today.getYear(), match[0].length);
  3164. }
  3165. }
  3166. input.inputmask._valueSet(date);
  3167. $(input).trigger("setvalue");
  3168. }
  3169. },
  3170. onUnMask: function onUnMask(maskedValue, unmaskedValue, opts) {
  3171. return parse(opts.outputFormat, analyseMask(maskedValue, opts.inputFormat, opts), opts, true);
  3172. },
  3173. casing: function casing(elem, test, pos, validPositions) {
  3174. if (test.nativeDef.indexOf("[ap]") == 0) return elem.toLowerCase();
  3175. if (test.nativeDef.indexOf("[AP]") == 0) return elem.toUpperCase();
  3176. return elem;
  3177. },
  3178. insertMode: false,
  3179. shiftPositions: false
  3180. }
  3181. });
  3182. return Inputmask;
  3183. });
  3184. }, function(module, exports, __webpack_require__) {
  3185. "use strict";
  3186. var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;
  3187. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function(obj) {
  3188. return typeof obj;
  3189. } : function(obj) {
  3190. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  3191. };
  3192. (function(factory) {
  3193. if (true) {
  3194. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [ __webpack_require__(2) ], __WEBPACK_AMD_DEFINE_FACTORY__ = factory,
  3195. __WEBPACK_AMD_DEFINE_RESULT__ = typeof __WEBPACK_AMD_DEFINE_FACTORY__ === "function" ? __WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__) : __WEBPACK_AMD_DEFINE_FACTORY__,
  3196. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  3197. } else {}
  3198. })(function(Inputmask) {
  3199. var $ = Inputmask.dependencyLib;
  3200. function autoEscape(txt, opts) {
  3201. var escapedTxt = "";
  3202. for (var i = 0; i < txt.length; i++) {
  3203. if (Inputmask.prototype.definitions[txt.charAt(i)] || opts.definitions[txt.charAt(i)] || opts.optionalmarker.start === txt.charAt(i) || opts.optionalmarker.end === txt.charAt(i) || opts.quantifiermarker.start === txt.charAt(i) || opts.quantifiermarker.end === txt.charAt(i) || opts.groupmarker.start === txt.charAt(i) || opts.groupmarker.end === txt.charAt(i) || opts.alternatormarker === txt.charAt(i)) {
  3204. escapedTxt += "\\" + txt.charAt(i);
  3205. } else escapedTxt += txt.charAt(i);
  3206. }
  3207. return escapedTxt;
  3208. }
  3209. function alignDigits(buffer, digits, opts) {
  3210. if (digits > 0) {
  3211. var radixPosition = $.inArray(opts.radixPoint, buffer);
  3212. if (radixPosition === -1) {
  3213. buffer.push(opts.radixPoint);
  3214. radixPosition = buffer.length - 1;
  3215. }
  3216. for (var i = 1; i <= digits; i++) {
  3217. buffer[radixPosition + i] = buffer[radixPosition + i] || "0";
  3218. }
  3219. }
  3220. return buffer;
  3221. }
  3222. Inputmask.extendAliases({
  3223. numeric: {
  3224. mask: function mask(opts) {
  3225. if (opts.repeat !== 0 && isNaN(opts.integerDigits)) {
  3226. opts.integerDigits = opts.repeat;
  3227. }
  3228. opts.repeat = 0;
  3229. if (opts.groupSeparator === opts.radixPoint && opts.digits && opts.digits !== "0") {
  3230. if (opts.radixPoint === ".") {
  3231. opts.groupSeparator = ",";
  3232. } else if (opts.radixPoint === ",") {
  3233. opts.groupSeparator = ".";
  3234. } else opts.groupSeparator = "";
  3235. }
  3236. if (opts.groupSeparator === " ") {
  3237. opts.skipOptionalPartCharacter = undefined;
  3238. }
  3239. opts.autoGroup = opts.autoGroup && opts.groupSeparator !== "";
  3240. if (opts.autoGroup) {
  3241. if (typeof opts.groupSize == "string" && isFinite(opts.groupSize)) opts.groupSize = parseInt(opts.groupSize);
  3242. if (isFinite(opts.integerDigits)) {
  3243. var seps = Math.floor(opts.integerDigits / opts.groupSize);
  3244. var mod = opts.integerDigits % opts.groupSize;
  3245. opts.integerDigits = parseInt(opts.integerDigits) + (mod === 0 ? seps - 1 : seps);
  3246. if (opts.integerDigits < 1) {
  3247. opts.integerDigits = "*";
  3248. }
  3249. }
  3250. }
  3251. if (opts.placeholder.length > 1) {
  3252. opts.placeholder = opts.placeholder.charAt(0);
  3253. }
  3254. if (opts.positionCaretOnClick === "radixFocus" && opts.placeholder === "" && opts.integerOptional === false) {
  3255. opts.positionCaretOnClick = "lvp";
  3256. }
  3257. opts.definitions[";"] = opts.definitions["~"];
  3258. opts.definitions[";"].definitionSymbol = "~";
  3259. if (opts.numericInput === true) {
  3260. opts.positionCaretOnClick = opts.positionCaretOnClick === "radixFocus" ? "lvp" : opts.positionCaretOnClick;
  3261. opts.digitsOptional = false;
  3262. if (isNaN(opts.digits)) opts.digits = 2;
  3263. opts.decimalProtect = false;
  3264. }
  3265. var mask = "[+]";
  3266. mask += autoEscape(opts.prefix, opts);
  3267. if (opts.integerOptional === true) {
  3268. mask += "~{1," + opts.integerDigits + "}";
  3269. } else mask += "~{" + opts.integerDigits + "}";
  3270. if (opts.digits !== undefined) {
  3271. var radixDef = opts.decimalProtect ? ":" : opts.radixPoint;
  3272. var dq = opts.digits.toString().split(",");
  3273. if (isFinite(dq[0]) && dq[1] && isFinite(dq[1])) {
  3274. mask += radixDef + ";{" + opts.digits + "}";
  3275. } else if (isNaN(opts.digits) || parseInt(opts.digits) > 0) {
  3276. if (opts.digitsOptional) {
  3277. mask += "[" + radixDef + ";{1," + opts.digits + "}]";
  3278. } else mask += radixDef + ";{" + opts.digits + "}";
  3279. }
  3280. }
  3281. mask += autoEscape(opts.suffix, opts);
  3282. mask += "[-]";
  3283. opts.greedy = false;
  3284. return mask;
  3285. },
  3286. placeholder: "",
  3287. greedy: false,
  3288. digits: "*",
  3289. digitsOptional: true,
  3290. enforceDigitsOnBlur: false,
  3291. radixPoint: ".",
  3292. positionCaretOnClick: "radixFocus",
  3293. groupSize: 3,
  3294. groupSeparator: "",
  3295. autoGroup: false,
  3296. allowMinus: true,
  3297. negationSymbol: {
  3298. front: "-",
  3299. back: ""
  3300. },
  3301. integerDigits: "+",
  3302. integerOptional: true,
  3303. prefix: "",
  3304. suffix: "",
  3305. rightAlign: true,
  3306. decimalProtect: true,
  3307. min: null,
  3308. max: null,
  3309. step: 1,
  3310. insertMode: true,
  3311. autoUnmask: false,
  3312. unmaskAsNumber: false,
  3313. inputType: "text",
  3314. inputmode: "numeric",
  3315. preValidation: function preValidation(buffer, pos, c, isSelection, opts, maskset) {
  3316. if (c === "-" || c === opts.negationSymbol.front) {
  3317. if (opts.allowMinus !== true) return false;
  3318. opts.isNegative = opts.isNegative === undefined ? true : !opts.isNegative;
  3319. if (buffer.join("") === "") return true;
  3320. return {
  3321. caret: maskset.validPositions[pos] ? pos : undefined,
  3322. dopost: true
  3323. };
  3324. }
  3325. if (isSelection === false && c === opts.radixPoint && opts.digits !== undefined && (isNaN(opts.digits) || parseInt(opts.digits) > 0)) {
  3326. var radixPos = $.inArray(opts.radixPoint, buffer);
  3327. if (radixPos !== -1 && maskset.validPositions[radixPos] !== undefined) {
  3328. if (opts.numericInput === true) {
  3329. return pos === radixPos;
  3330. }
  3331. return {
  3332. caret: radixPos + 1
  3333. };
  3334. }
  3335. }
  3336. return true;
  3337. },
  3338. postValidation: function postValidation(buffer, pos, currentResult, opts) {
  3339. function buildPostMask(buffer, opts) {
  3340. var postMask = "";
  3341. postMask += "(" + opts.groupSeparator + "*{" + opts.groupSize + "}){*}";
  3342. if (opts.radixPoint !== "") {
  3343. var radixSplit = buffer.join("").split(opts.radixPoint);
  3344. if (radixSplit[1]) {
  3345. postMask += opts.radixPoint + "*{" + radixSplit[1].match(/^\d*\??\d*/)[0].length + "}";
  3346. }
  3347. }
  3348. return postMask;
  3349. }
  3350. var suffix = opts.suffix.split(""), prefix = opts.prefix.split("");
  3351. if (currentResult.pos === undefined && currentResult.caret !== undefined && currentResult.dopost !== true) return currentResult;
  3352. var caretPos = currentResult.caret !== undefined ? currentResult.caret : currentResult.pos;
  3353. var maskedValue = buffer.slice();
  3354. if (opts.numericInput) {
  3355. caretPos = maskedValue.length - caretPos - 1;
  3356. maskedValue = maskedValue.reverse();
  3357. }
  3358. var charAtPos = maskedValue[caretPos];
  3359. if (charAtPos === opts.groupSeparator) {
  3360. caretPos += 1;
  3361. charAtPos = maskedValue[caretPos];
  3362. }
  3363. if (caretPos === maskedValue.length - opts.suffix.length - 1 && charAtPos === opts.radixPoint) return currentResult;
  3364. if (charAtPos !== undefined) {
  3365. if (charAtPos !== opts.radixPoint && charAtPos !== opts.negationSymbol.front && charAtPos !== opts.negationSymbol.back) {
  3366. maskedValue[caretPos] = "?";
  3367. if (opts.prefix.length > 0 && caretPos >= (opts.isNegative === false ? 1 : 0) && caretPos < opts.prefix.length - 1 + (opts.isNegative === false ? 1 : 0)) {
  3368. prefix[caretPos - (opts.isNegative === false ? 1 : 0)] = "?";
  3369. } else if (opts.suffix.length > 0 && caretPos >= maskedValue.length - opts.suffix.length - (opts.isNegative === false ? 1 : 0)) {
  3370. suffix[caretPos - (maskedValue.length - opts.suffix.length - (opts.isNegative === false ? 1 : 0))] = "?";
  3371. }
  3372. }
  3373. }
  3374. prefix = prefix.join("");
  3375. suffix = suffix.join("");
  3376. var processValue = maskedValue.join("").replace(prefix, "");
  3377. processValue = processValue.replace(suffix, "");
  3378. processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
  3379. processValue = processValue.replace(new RegExp("[-" + Inputmask.escapeRegex(opts.negationSymbol.front) + "]", "g"), "");
  3380. processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.negationSymbol.back) + "$"), "");
  3381. if (isNaN(opts.placeholder)) {
  3382. processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.placeholder), "g"), "");
  3383. }
  3384. if (processValue.length > 1 && processValue.indexOf(opts.radixPoint) !== 1) {
  3385. if (charAtPos === "0") {
  3386. processValue = processValue.replace(/^\?/g, "");
  3387. }
  3388. processValue = processValue.replace(/^0/g, "");
  3389. }
  3390. if (processValue.charAt(0) === opts.radixPoint && opts.radixPoint !== "" && opts.numericInput !== true) {
  3391. processValue = "0" + processValue;
  3392. }
  3393. if (processValue !== "") {
  3394. processValue = processValue.split("");
  3395. if ((!opts.digitsOptional || opts.enforceDigitsOnBlur && currentResult.event === "blur") && isFinite(opts.digits)) {
  3396. var radixPosition = $.inArray(opts.radixPoint, processValue);
  3397. var rpb = $.inArray(opts.radixPoint, maskedValue);
  3398. if (radixPosition === -1) {
  3399. processValue.push(opts.radixPoint);
  3400. radixPosition = processValue.length - 1;
  3401. }
  3402. for (var i = 1; i <= opts.digits; i++) {
  3403. if ((!opts.digitsOptional || opts.enforceDigitsOnBlur && currentResult.event === "blur") && (processValue[radixPosition + i] === undefined || processValue[radixPosition + i] === opts.placeholder.charAt(0))) {
  3404. processValue[radixPosition + i] = currentResult.placeholder || opts.placeholder.charAt(0);
  3405. } else if (rpb !== -1 && maskedValue[rpb + i] !== undefined) {
  3406. processValue[radixPosition + i] = processValue[radixPosition + i] || maskedValue[rpb + i];
  3407. }
  3408. }
  3409. }
  3410. if (opts.autoGroup === true && opts.groupSeparator !== "" && (charAtPos !== opts.radixPoint || currentResult.pos !== undefined || currentResult.dopost)) {
  3411. var addRadix = processValue[processValue.length - 1] === opts.radixPoint && currentResult.c === opts.radixPoint;
  3412. processValue = Inputmask(buildPostMask(processValue, opts), {
  3413. numericInput: true,
  3414. jitMasking: true,
  3415. definitions: {
  3416. "*": {
  3417. validator: "[0-9?]",
  3418. cardinality: 1
  3419. }
  3420. }
  3421. }).format(processValue.join(""));
  3422. if (addRadix) processValue += opts.radixPoint;
  3423. if (processValue.charAt(0) === opts.groupSeparator) {
  3424. processValue.substr(1);
  3425. }
  3426. } else processValue = processValue.join("");
  3427. }
  3428. if (opts.isNegative && currentResult.event === "blur") {
  3429. opts.isNegative = processValue !== "0";
  3430. }
  3431. processValue = prefix + processValue;
  3432. processValue += suffix;
  3433. if (opts.isNegative) {
  3434. processValue = opts.negationSymbol.front + processValue;
  3435. processValue += opts.negationSymbol.back;
  3436. }
  3437. processValue = processValue.split("");
  3438. if (charAtPos !== undefined) {
  3439. if (charAtPos !== opts.radixPoint && charAtPos !== opts.negationSymbol.front && charAtPos !== opts.negationSymbol.back) {
  3440. caretPos = $.inArray("?", processValue);
  3441. if (caretPos > -1) {
  3442. processValue[caretPos] = charAtPos;
  3443. } else caretPos = currentResult.caret || 0;
  3444. } else if (charAtPos === opts.radixPoint || charAtPos === opts.negationSymbol.front || charAtPos === opts.negationSymbol.back) {
  3445. var newCaretPos = $.inArray(charAtPos, processValue);
  3446. if (newCaretPos !== -1) caretPos = newCaretPos;
  3447. }
  3448. }
  3449. if (opts.numericInput) {
  3450. caretPos = processValue.length - caretPos - 1;
  3451. processValue = processValue.reverse();
  3452. }
  3453. var rslt = {
  3454. caret: (charAtPos === undefined || currentResult.pos !== undefined) && caretPos !== undefined ? caretPos + (opts.numericInput ? -1 : 1) : caretPos,
  3455. buffer: processValue,
  3456. refreshFromBuffer: currentResult.dopost || buffer.join("") !== processValue.join("")
  3457. };
  3458. return rslt.refreshFromBuffer ? rslt : currentResult;
  3459. },
  3460. onBeforeWrite: function onBeforeWrite(e, buffer, caretPos, opts) {
  3461. function parseMinMaxOptions(opts) {
  3462. if (opts.parseMinMaxOptions === undefined) {
  3463. if (opts.min !== null) {
  3464. opts.min = opts.min.toString().replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
  3465. if (opts.radixPoint === ",") opts.min = opts.min.replace(opts.radixPoint, ".");
  3466. opts.min = isFinite(opts.min) ? parseFloat(opts.min) : NaN;
  3467. if (isNaN(opts.min)) opts.min = Number.MIN_VALUE;
  3468. }
  3469. if (opts.max !== null) {
  3470. opts.max = opts.max.toString().replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
  3471. if (opts.radixPoint === ",") opts.max = opts.max.replace(opts.radixPoint, ".");
  3472. opts.max = isFinite(opts.max) ? parseFloat(opts.max) : NaN;
  3473. if (isNaN(opts.max)) opts.max = Number.MAX_VALUE;
  3474. }
  3475. opts.parseMinMaxOptions = "done";
  3476. }
  3477. }
  3478. if (e) {
  3479. switch (e.type) {
  3480. case "keydown":
  3481. return opts.postValidation(buffer, caretPos, {
  3482. caret: caretPos,
  3483. dopost: true
  3484. }, opts);
  3485. case "blur":
  3486. case "checkval":
  3487. var unmasked;
  3488. parseMinMaxOptions(opts);
  3489. if (opts.min !== null || opts.max !== null) {
  3490. unmasked = opts.onUnMask(buffer.join(""), undefined, $.extend({}, opts, {
  3491. unmaskAsNumber: true
  3492. }));
  3493. if (opts.min !== null && unmasked < opts.min) {
  3494. opts.isNegative = opts.min < 0;
  3495. return opts.postValidation(opts.min.toString().replace(".", opts.radixPoint).split(""), caretPos, {
  3496. caret: caretPos,
  3497. dopost: true,
  3498. placeholder: "0"
  3499. }, opts);
  3500. } else if (opts.max !== null && unmasked > opts.max) {
  3501. opts.isNegative = opts.max < 0;
  3502. return opts.postValidation(opts.max.toString().replace(".", opts.radixPoint).split(""), caretPos, {
  3503. caret: caretPos,
  3504. dopost: true,
  3505. placeholder: "0"
  3506. }, opts);
  3507. }
  3508. }
  3509. return opts.postValidation(buffer, caretPos, {
  3510. caret: caretPos,
  3511. placeholder: "0",
  3512. event: "blur"
  3513. }, opts);
  3514. case "_checkval":
  3515. return {
  3516. caret: caretPos
  3517. };
  3518. default:
  3519. break;
  3520. }
  3521. }
  3522. },
  3523. regex: {
  3524. integerPart: function integerPart(opts, emptyCheck) {
  3525. return emptyCheck ? new RegExp("[" + Inputmask.escapeRegex(opts.negationSymbol.front) + "+]?") : new RegExp("[" + Inputmask.escapeRegex(opts.negationSymbol.front) + "+]?\\d+");
  3526. },
  3527. integerNPart: function integerNPart(opts) {
  3528. return new RegExp("[\\d" + Inputmask.escapeRegex(opts.groupSeparator) + Inputmask.escapeRegex(opts.placeholder.charAt(0)) + "]+");
  3529. }
  3530. },
  3531. definitions: {
  3532. "~": {
  3533. validator: function validator(chrs, maskset, pos, strict, opts, isSelection) {
  3534. var isValid, l;
  3535. if (chrs === "k" || chrs === "m") {
  3536. isValid = {
  3537. insert: [],
  3538. c: 0
  3539. };
  3540. for (var i = 0, l = chrs === "k" ? 2 : 5; i < l; i++) {
  3541. isValid.insert.push({
  3542. pos: pos + i,
  3543. c: 0
  3544. });
  3545. }
  3546. isValid.pos = pos + l;
  3547. return isValid;
  3548. }
  3549. isValid = strict ? new RegExp("[0-9" + Inputmask.escapeRegex(opts.groupSeparator) + "]").test(chrs) : new RegExp("[0-9]").test(chrs);
  3550. if (isValid === true) {
  3551. if (opts.numericInput !== true && maskset.validPositions[pos] !== undefined && maskset.validPositions[pos].match.def === "~" && !isSelection) {
  3552. var processValue = maskset.buffer.join("");
  3553. processValue = processValue.replace(new RegExp("[-" + Inputmask.escapeRegex(opts.negationSymbol.front) + "]", "g"), "");
  3554. processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.negationSymbol.back) + "$"), "");
  3555. var pvRadixSplit = processValue.split(opts.radixPoint);
  3556. if (pvRadixSplit.length > 1) {
  3557. pvRadixSplit[1] = pvRadixSplit[1].replace(/0/g, opts.placeholder.charAt(0));
  3558. }
  3559. if (pvRadixSplit[0] === "0") {
  3560. pvRadixSplit[0] = pvRadixSplit[0].replace(/0/g, opts.placeholder.charAt(0));
  3561. }
  3562. processValue = pvRadixSplit[0] + opts.radixPoint + pvRadixSplit[1] || "";
  3563. var bufferTemplate = maskset._buffer.join("");
  3564. if (processValue === opts.radixPoint) {
  3565. processValue = bufferTemplate;
  3566. }
  3567. while (processValue.match(Inputmask.escapeRegex(bufferTemplate) + "$") === null) {
  3568. bufferTemplate = bufferTemplate.slice(1);
  3569. }
  3570. processValue = processValue.replace(bufferTemplate, "");
  3571. processValue = processValue.split("");
  3572. if (processValue[pos] === undefined) {
  3573. isValid = {
  3574. pos: pos,
  3575. remove: pos
  3576. };
  3577. } else {
  3578. isValid = {
  3579. pos: pos
  3580. };
  3581. }
  3582. }
  3583. } else if (!strict && chrs === opts.radixPoint && maskset.validPositions[pos - 1] === undefined) {
  3584. isValid = {
  3585. insert: {
  3586. pos: pos,
  3587. c: 0
  3588. },
  3589. pos: pos + 1
  3590. };
  3591. }
  3592. return isValid;
  3593. },
  3594. cardinality: 1
  3595. },
  3596. "+": {
  3597. validator: function validator(chrs, maskset, pos, strict, opts) {
  3598. return opts.allowMinus && (chrs === "-" || chrs === opts.negationSymbol.front);
  3599. },
  3600. cardinality: 1,
  3601. placeholder: ""
  3602. },
  3603. "-": {
  3604. validator: function validator(chrs, maskset, pos, strict, opts) {
  3605. return opts.allowMinus && chrs === opts.negationSymbol.back;
  3606. },
  3607. cardinality: 1,
  3608. placeholder: ""
  3609. },
  3610. ":": {
  3611. validator: function validator(chrs, maskset, pos, strict, opts) {
  3612. var radix = "[" + Inputmask.escapeRegex(opts.radixPoint) + "]";
  3613. var isValid = new RegExp(radix).test(chrs);
  3614. if (isValid && maskset.validPositions[pos] && maskset.validPositions[pos].match.placeholder === opts.radixPoint) {
  3615. isValid = {
  3616. caret: pos + 1
  3617. };
  3618. }
  3619. return isValid;
  3620. },
  3621. cardinality: 1,
  3622. placeholder: function placeholder(opts) {
  3623. return opts.radixPoint;
  3624. }
  3625. }
  3626. },
  3627. onUnMask: function onUnMask(maskedValue, unmaskedValue, opts) {
  3628. if (unmaskedValue === "" && opts.nullable === true) {
  3629. return unmaskedValue;
  3630. }
  3631. var processValue = maskedValue.replace(opts.prefix, "");
  3632. processValue = processValue.replace(opts.suffix, "");
  3633. processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
  3634. if (opts.placeholder.charAt(0) !== "") {
  3635. processValue = processValue.replace(new RegExp(opts.placeholder.charAt(0), "g"), "0");
  3636. }
  3637. if (opts.unmaskAsNumber) {
  3638. if (opts.radixPoint !== "" && processValue.indexOf(opts.radixPoint) !== -1) processValue = processValue.replace(Inputmask.escapeRegex.call(this, opts.radixPoint), ".");
  3639. processValue = processValue.replace(new RegExp("^" + Inputmask.escapeRegex(opts.negationSymbol.front)), "-");
  3640. processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.negationSymbol.back) + "$"), "");
  3641. return Number(processValue);
  3642. }
  3643. return processValue;
  3644. },
  3645. isComplete: function isComplete(buffer, opts) {
  3646. var maskedValue = (opts.numericInput ? buffer.slice().reverse() : buffer).join("");
  3647. maskedValue = maskedValue.replace(new RegExp("^" + Inputmask.escapeRegex(opts.negationSymbol.front)), "-");
  3648. maskedValue = maskedValue.replace(new RegExp(Inputmask.escapeRegex(opts.negationSymbol.back) + "$"), "");
  3649. maskedValue = maskedValue.replace(opts.prefix, "");
  3650. maskedValue = maskedValue.replace(opts.suffix, "");
  3651. maskedValue = maskedValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator) + "([0-9]{3})", "g"), "$1");
  3652. if (opts.radixPoint === ",") maskedValue = maskedValue.replace(Inputmask.escapeRegex(opts.radixPoint), ".");
  3653. return isFinite(maskedValue);
  3654. },
  3655. onBeforeMask: function onBeforeMask(initialValue, opts) {
  3656. opts.isNegative = undefined;
  3657. var radixPoint = opts.radixPoint || ",";
  3658. if ((typeof initialValue == "number" || opts.inputType === "number") && radixPoint !== "") {
  3659. initialValue = initialValue.toString().replace(".", radixPoint);
  3660. }
  3661. var valueParts = initialValue.split(radixPoint), integerPart = valueParts[0].replace(/[^\-0-9]/g, ""), decimalPart = valueParts.length > 1 ? valueParts[1].replace(/[^0-9]/g, "") : "";
  3662. initialValue = integerPart + (decimalPart !== "" ? radixPoint + decimalPart : decimalPart);
  3663. var digits = 0;
  3664. if (radixPoint !== "") {
  3665. digits = decimalPart.length;
  3666. if (decimalPart !== "") {
  3667. var digitsFactor = Math.pow(10, digits || 1);
  3668. if (isFinite(opts.digits)) {
  3669. digits = parseInt(opts.digits);
  3670. digitsFactor = Math.pow(10, digits);
  3671. }
  3672. initialValue = initialValue.replace(Inputmask.escapeRegex(radixPoint), ".");
  3673. if (isFinite(initialValue)) initialValue = Math.round(parseFloat(initialValue) * digitsFactor) / digitsFactor;
  3674. initialValue = initialValue.toString().replace(".", radixPoint);
  3675. }
  3676. }
  3677. if (opts.digits === 0 && initialValue.indexOf(Inputmask.escapeRegex(radixPoint)) !== -1) {
  3678. initialValue = initialValue.substring(0, initialValue.indexOf(Inputmask.escapeRegex(radixPoint)));
  3679. }
  3680. return alignDigits(initialValue.toString().split(""), digits, opts).join("");
  3681. },
  3682. onKeyDown: function onKeyDown(e, buffer, caretPos, opts) {
  3683. var $input = $(this);
  3684. if (e.ctrlKey) {
  3685. switch (e.keyCode) {
  3686. case Inputmask.keyCode.UP:
  3687. $input.val(parseFloat(this.inputmask.unmaskedvalue()) + parseInt(opts.step));
  3688. $input.trigger("setvalue");
  3689. break;
  3690. case Inputmask.keyCode.DOWN:
  3691. $input.val(parseFloat(this.inputmask.unmaskedvalue()) - parseInt(opts.step));
  3692. $input.trigger("setvalue");
  3693. break;
  3694. }
  3695. }
  3696. }
  3697. },
  3698. currency: {
  3699. prefix: "$ ",
  3700. groupSeparator: ",",
  3701. alias: "numeric",
  3702. placeholder: "0",
  3703. autoGroup: true,
  3704. digits: 2,
  3705. digitsOptional: false,
  3706. clearMaskOnLostFocus: false
  3707. },
  3708. decimal: {
  3709. alias: "numeric"
  3710. },
  3711. integer: {
  3712. alias: "numeric",
  3713. digits: 0,
  3714. radixPoint: ""
  3715. },
  3716. percentage: {
  3717. alias: "numeric",
  3718. digits: 2,
  3719. digitsOptional: true,
  3720. radixPoint: ".",
  3721. placeholder: "0",
  3722. autoGroup: false,
  3723. min: 0,
  3724. max: 100,
  3725. suffix: " %",
  3726. allowMinus: false
  3727. }
  3728. });
  3729. return Inputmask;
  3730. });
  3731. }, function(module, exports, __webpack_require__) {
  3732. "use strict";
  3733. var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;
  3734. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function(obj) {
  3735. return typeof obj;
  3736. } : function(obj) {
  3737. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  3738. };
  3739. (function(factory) {
  3740. if (true) {
  3741. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [ __webpack_require__(4), __webpack_require__(2) ],
  3742. __WEBPACK_AMD_DEFINE_FACTORY__ = factory, __WEBPACK_AMD_DEFINE_RESULT__ = typeof __WEBPACK_AMD_DEFINE_FACTORY__ === "function" ? __WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__) : __WEBPACK_AMD_DEFINE_FACTORY__,
  3743. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  3744. } else {}
  3745. })(function($, Inputmask) {
  3746. if ($.fn.inputmask === undefined) {
  3747. $.fn.inputmask = function(fn, options) {
  3748. var nptmask, input = this[0];
  3749. if (options === undefined) options = {};
  3750. if (typeof fn === "string") {
  3751. switch (fn) {
  3752. case "unmaskedvalue":
  3753. return input && input.inputmask ? input.inputmask.unmaskedvalue() : $(input).val();
  3754. case "remove":
  3755. return this.each(function() {
  3756. if (this.inputmask) this.inputmask.remove();
  3757. });
  3758. case "getemptymask":
  3759. return input && input.inputmask ? input.inputmask.getemptymask() : "";
  3760. case "hasMaskedValue":
  3761. return input && input.inputmask ? input.inputmask.hasMaskedValue() : false;
  3762. case "isComplete":
  3763. return input && input.inputmask ? input.inputmask.isComplete() : true;
  3764. case "getmetadata":
  3765. return input && input.inputmask ? input.inputmask.getmetadata() : undefined;
  3766. case "setvalue":
  3767. Inputmask.setValue(input, options);
  3768. break;
  3769. case "option":
  3770. if (typeof options === "string") {
  3771. if (input && input.inputmask !== undefined) {
  3772. return input.inputmask.option(options);
  3773. }
  3774. } else {
  3775. return this.each(function() {
  3776. if (this.inputmask !== undefined) {
  3777. return this.inputmask.option(options);
  3778. }
  3779. });
  3780. }
  3781. break;
  3782. default:
  3783. options.alias = fn;
  3784. nptmask = new Inputmask(options);
  3785. return this.each(function() {
  3786. nptmask.mask(this);
  3787. });
  3788. }
  3789. } else if (Array.isArray(fn)) {
  3790. options.alias = fn;
  3791. nptmask = new Inputmask(options);
  3792. return this.each(function() {
  3793. nptmask.mask(this);
  3794. });
  3795. } else if ((typeof fn === "undefined" ? "undefined" : _typeof(fn)) == "object") {
  3796. nptmask = new Inputmask(fn);
  3797. if (fn.mask === undefined && fn.alias === undefined) {
  3798. return this.each(function() {
  3799. if (this.inputmask !== undefined) {
  3800. return this.inputmask.option(fn);
  3801. } else nptmask.mask(this);
  3802. });
  3803. } else {
  3804. return this.each(function() {
  3805. nptmask.mask(this);
  3806. });
  3807. }
  3808. } else if (fn === undefined) {
  3809. return this.each(function() {
  3810. nptmask = new Inputmask(options);
  3811. nptmask.mask(this);
  3812. });
  3813. }
  3814. };
  3815. }
  3816. return $.fn.inputmask;
  3817. });
  3818. } ]);