1/*! 2* dependencyLibs/inputmask.dependencyLib.js 3* https://github.com/RobinHerbots/Inputmask 4* Copyright (c) 2010 - 2019 Robin Herbots 5* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php) 6* Version: 4.0.9 7*/ 8 9(function(factory) { 10 if (typeof define === "function" && define.amd) { 11 define([ "../global/window" ], factory); 12 } else if (typeof exports === "object") { 13 module.exports = factory(require("../global/window")); 14 } else { 15 window.dependencyLib = factory(window); 16 } 17})(function(window) { 18 var document = window.document; 19 function indexOf(list, elem) { 20 var i = 0, len = list.length; 21 for (;i < len; i++) { 22 if (list[i] === elem) { 23 return i; 24 } 25 } 26 return -1; 27 } 28 function isWindow(obj) { 29 return obj != null && obj === obj.window; 30 } 31 function isArraylike(obj) { 32 var length = "length" in obj && obj.length, ltype = typeof obj; 33 if (ltype === "function" || isWindow(obj)) { 34 return false; 35 } 36 if (obj.nodeType === 1 && length) { 37 return true; 38 } 39 return ltype === "array" || length === 0 || typeof length === "number" && length > 0 && length - 1 in obj; 40 } 41 function isValidElement(elem) { 42 return elem instanceof Element; 43 } 44 function DependencyLib(elem) { 45 if (elem instanceof DependencyLib) { 46 return elem; 47 } 48 if (!(this instanceof DependencyLib)) { 49 return new DependencyLib(elem); 50 } 51 if (elem !== undefined && elem !== null && elem !== window) { 52 this[0] = elem.nodeName ? elem : elem[0] !== undefined && elem[0].nodeName ? elem[0] : document.querySelector(elem); 53 if (this[0] !== undefined && this[0] !== null) { 54 this[0].eventRegistry = this[0].eventRegistry || {}; 55 } 56 } 57 } 58 function getWindow(elem) { 59 return isWindow(elem) ? elem : elem.nodeType === 9 ? elem.defaultView || elem.parentWindow : false; 60 } 61 DependencyLib.prototype = { 62 on: function(events, handler) { 63 if (isValidElement(this[0])) { 64 var eventRegistry = this[0].eventRegistry, elem = this[0]; 65 var addEvent = function(ev, namespace) { 66 if (elem.addEventListener) { 67 elem.addEventListener(ev, handler, false); 68 } else if (elem.attachEvent) { 69 elem.attachEvent("on" + ev, handler); 70 } 71 eventRegistry[ev] = eventRegistry[ev] || {}; 72 eventRegistry[ev][namespace] = eventRegistry[ev][namespace] || []; 73 eventRegistry[ev][namespace].push(handler); 74 }; 75 var _events = events.split(" "); 76 for (var endx = 0; endx < _events.length; endx++) { 77 var nsEvent = _events[endx].split("."), ev = nsEvent[0], namespace = nsEvent[1] || "global"; 78 addEvent(ev, namespace); 79 } 80 } 81 return this; 82 }, 83 off: function(events, handler) { 84 if (isValidElement(this[0])) { 85 var eventRegistry = this[0].eventRegistry, elem = this[0]; 86 var removeEvent = function(ev, namespace, handler) { 87 if (ev in eventRegistry === true) { 88 if (elem.removeEventListener) { 89 elem.removeEventListener(ev, handler, false); 90 } else if (elem.detachEvent) { 91 elem.detachEvent("on" + ev, handler); 92 } 93 if (namespace === "global") { 94 for (var nmsp in eventRegistry[ev]) { 95 eventRegistry[ev][nmsp].splice(eventRegistry[ev][nmsp].indexOf(handler), 1); 96 } 97 } else { 98 eventRegistry[ev][namespace].splice(eventRegistry[ev][namespace].indexOf(handler), 1); 99 } 100 } 101 }; 102 var resolveNamespace = function(ev, namespace) { 103 var evts = [], hndx, hndL; 104 if (ev.length > 0) { 105 if (handler === undefined) { 106 for (hndx = 0, hndL = eventRegistry[ev][namespace].length;
106 hndx < hndL; hndx++) { 107 evts.push({ 108 ev: ev, 109 namespace: namespace && namespace.length > 0 ? namespace : "global", 110 handler: eventRegistry[ev][namespace][hndx] 111 }); 112 } 113 } else { 114 evts.push({ 115 ev: ev, 116 namespace: namespace && namespace.length > 0 ? namespace : "global", 117 handler: handler 118 }); 119 } 120 } else if (namespace.length > 0) { 121 for (var evNdx in eventRegistry) { 122 for (var nmsp in eventRegistry[evNdx]) { 123 if (nmsp === namespace) { 124 if (handler === undefined) { 125 for (hndx = 0, hndL = eventRegistry[evNdx][nmsp].length; hndx < hndL; hndx++) { 126 evts.push({ 127 ev: evNdx, 128 namespace: nmsp, 129 handler: eventRegistry[evNdx][nmsp][hndx] 130 }); 131 } 132 } else { 133 evts.push({ 134 ev: evNdx, 135 namespace: nmsp, 136 handler: handler 137 }); 138 } 139 } 140 } 141 } 142 } 143 return evts; 144 }; 145 var _events = events.split(" "); 146 for (var endx = 0; endx < _events.length; endx++) { 147 var nsEvent = _events[endx].split("."), offEvents = resolveNamespace(nsEvent[0], nsEvent[1]); 148 for (var i = 0, offEventsL = offEvents.length; i < offEventsL; i++) { 149 removeEvent(offEvents[i].ev, offEvents[i].namespace, offEvents[i].handler); 150 } 151 } 152 } 153 return this; 154 }, 155 trigger: function(events) { 156 if (isValidElement(this[0])) { 157 var eventRegistry = this[0].eventRegistry, elem = this[0]; 158 var _events = typeof events === "string" ? events.split(" ") : [ events.type ]; 159 for (var endx = 0; endx < _events.length; endx++) { 160 var nsEvent = _events[endx].split("."), ev = nsEvent[0], namespace = nsEvent[1] || "global"; 161 if (document !== undefined && namespace === "global") { 162 var evnt, i, params = { 163 bubbles: true, 164 cancelable: true, 165 detail: arguments[1] 166 }; 167 if (document.createEvent) { 168 try { 169 evnt = new CustomEvent(ev, params); 170 } catch (e) { 171 evnt = document.createEvent("CustomEvent"); 172 evnt.initCustomEvent(ev, params.bubbles, params.cancelable, params.detail); 173 } 174 if (events.type) DependencyLib.extend(evnt, events); 175 elem.dispatchEvent(evnt); 176 } else { 177 evnt = document.createEventObject(); 178 evnt.eventType = ev; 179 evnt.detail = arguments[1]; 180 if (events.type) DependencyLib.extend(evnt, events); 181 elem.fireEvent("on" + evnt.eventType, evnt); 182 } 183 } else if (eventRegistry[ev] !== undefined) { 184 arguments[0] = arguments[0].type ? arguments[0] : DependencyLib.Event(arguments[0]); 185 if (namespace === "global") { 186 for (var nmsp in eventRegistry[ev]) { 187 for (i = 0; i < eventRegistry[ev][nmsp].length; i++) { 188 eventRegistry[ev][nmsp][i].apply(elem, arguments); 189 } 190 } 191 } else { 192 for (i = 0; i < eventRegistry[ev][namespace].length; i++) { 193 eventRegistry[ev][namespace][i].apply(elem, arguments); 194 } 195 } 196 } 197 } 198 } 199 return this; 200 } 201 }; 202 DependencyLib.isFunction = function(obj) { 203 return typeof obj === "function"; 204 }; 205 DependencyLib.noop = function() {}; 206 DependencyLib.isArray = Array.isArray; 207 DependencyLib.inArray = function(elem, arr, i) { 208 return arr == null ? -1 : indexOf(arr, elem, i); 209 }; 210 DependencyLib.valHooks = undefined; 211 DependencyLib.isPlainObject = function(obj) { 212 if (typeof obj !== "object" || obj.nodeType || isWindow(obj)) { 213 return false; 214 } 215 if (obj.constructor && !Object.hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf")) { 216 return false; 217 } 218 return true; 219 }; 220 DependencyLib.extend = function() { 221 var options, name, src, copy, copyIsArray, clone, target = arguments[0] || {}, i = 1, length = arguments.length, deep = false; 222 if (typeof target === "boolean") { 223 deep = target; 224 target = arguments[i] || {}; 225 i++; 226 } 227 if (typeof target !== "object" && !DependencyLib.isFunction(target)) { 228 target = {}; 229 } 230 if (i === length) { 231 target = this; 232 i--; 233 } 234 for (;i < length; i++) { 235 if ((options = arguments[i]) != null) { 236 for (name in options) { 237 src = target[name]; 238 copy = options[name]; 239 if (target === copy) { 240 continue; 241 } 242 if (deep && copy && (DependencyLib.isPlainObject(copy) || (copyIsArray = DependencyLib.isArray(copy)))) { 243 if (copyIsArray) { 244 copyIsArray = false; 245 clone = src && DependencyLib.isArray(src) ? src : []; 246 } else { 247 clone = src && DependencyLib.isPlainObject(src) ? src : {}; 248 } 249 target[name] = DependencyLib.extend(deep, clone, copy); 250 } else if (copy !== undefined) { 251 target[name] = copy; 252 } 253 } 254 } 255 } 256 return target; 257 }; 258 DependencyLib.each = function(obj, callback) { 259 var value, i = 0; 260 if (isArraylike(obj)) { 261 for (var length = obj.length; i < length; i++) { 262 value = callback.call(obj[i], i, obj[i]); 263 if (value === false) { 264 break; 265 } 266 } 267 } else { 268 for (i in obj) { 269 value = callback.call(obj[i], i, obj[i]); 270 if (value === false) { 271 break; 272 } 273 } 274 } 275 return obj;
276 }; 277 DependencyLib.data = function(owner, key, value) { 278 if (value === undefined) { 279 return owner.__data ? owner.__data[key] : null; 280 } else { 281 owner.__data = owner.__data || {}; 282 owner.__data[key] = value; 283 } 284 }; 285 if (typeof window.CustomEvent === "function") { 286 DependencyLib.Event = window.CustomEvent; 287 } else { 288 DependencyLib.Event = function(event, params) { 289 params = params || { 290 bubbles: false, 291 cancelable: false, 292 detail: undefined 293 }; 294 var evt = document.createEvent("CustomEvent"); 295 evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); 296 return evt; 297 }; 298 DependencyLib.Event.prototype = window.Event.prototype; 299 } 300 return DependencyLib; 301}); 302/*! 303* inputmask.js 304* https://github.com/RobinHerbots/Inputmask 305* Copyright (c) 2010 - 2019 Robin Herbots 306* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php) 307* Version: 4.0.9 308*/ 309 310(function(factory) { 311 if (typeof define === "function" && define.amd) { 312 define([ "./dependencyLibs/inputmask.dependencyLib", "./global/window" ], factory); 313 } else if (typeof exports === "object") { 314 module.exports = factory(require("./dependencyLibs/inputmask.dependencyLib"), require("./global/window")); 315 } else { 316 window.Inputmask = factory(window.dependencyLib || jQuery, window); 317 } 318})(function($, window, undefined) { 319 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; 320 function Inputmask(alias, options, internal) { 321 if (!(this instanceof Inputmask)) { 322 return new Inputmask(alias, options, internal); 323 } 324 this.el = undefined; 325 this.events = {}; 326 this.maskset = undefined; 327 this.refreshValue = false; 328 if (internal !== true) { 329 if ($.isPlainObject(alias)) { 330 options = alias; 331 } else { 332 options = options || {}; 333 if (alias) options.alias = alias; 334 } 335 this.opts = $.extend(true, {}, this.defaults, options); 336 this.noMasksCache = options && options.definitions !== undefined; 337 this.userOptions = options || {}; 338 this.isRTL = this.opts.numericInput; 339 resolveAlias(this.opts.alias, options, this.opts); 340 } 341 } 342 Inputmask.prototype = { 343 dataAttribute: "data-inputmask", 344 defaults: { 345 placeholder: "_", 346 optionalmarker: [ "[", "]" ], 347 quantifiermarker: [ "{", "}" ], 348 groupmarker: [ "(", ")" ], 349 alternatormarker: "|", 350 escapeChar: "\\", 351 mask: null, 352 regex: null, 353 oncomplete: $.noop, 354 onincomplete: $.noop, 355 oncleared: $.noop, 356 repeat: 0, 357 greedy: false, 358 autoUnmask: false, 359 removeMaskOnSubmit: false, 360 clearMaskOnLostFocus: true, 361 insertMode: true, 362 clearIncomplete: false, 363 alias: null, 364 onKeyDown: $.noop, 365 onBeforeMask: null, 366 onBeforePaste: function(pastedValue, opts) { 367 return $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(this, pastedValue, opts) : pastedValue; 368 }, 369 onBeforeWrite: null, 370 onUnMask: null, 371 showMaskOnFocus: true, 372 showMaskOnHover: true, 373 onKeyValidation: $.noop, 374 skipOptionalPartCharacter: " ", 375 numericInput: false, 376 rightAlign: false, 377 undoOnEscape: true, 378 radixPoint: "", 379 _radixDance: false, 380 groupSeparator: "", 381 keepStatic: null, 382 positionCaretOnTab: true, 383 tabThrough: false, 384 supportsInputType: [ "text", "tel", "url", "password", "search" ], 385 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 ], 386 isComplete: null, 387 preValidation: null, 388 postValidation: null, 389 staticDefinitionSymbol: undefined, 390 jitMasking: false, 391 nullable: true, 392 inputEventOnly: false, 393 noValuePatching: false, 394 positionCaretOnClick: "lvp", 395 casing: null, 396 inputmode: "verbatim", 397 colorMask: false, 398 disablePredictiveText: false, 399 importDataAttributes: true, 400 shiftPositions: true 401 }, 402 definitions: { 403 9: { 404 validator: "[0-9\uff11-\uff19]", 405 definitionSymbol: "*" 406 }, 407 a: { 408 validator: "[A-Za-z\u0410-\u044f\u0401\u0451\xc0-\xff\xb5]", 409 definitionSymbol: "*" 410 }, 411 "*": { 412 validator: "[0-9\uff11-\uff19A-Za-z\u0410-\u044f\u0401\u0451\xc0-\xff\xb5]" 413 } 414 }, 415 aliases: {}, 416 masksCache: {}, 417 mask: function(elems) { 418 var that = this; 419 function importAttributeOptions(npt, opts, userOptions, dataAttribute) { 420 if (opts.importDataAttributes === true) { 421 var attrOptions = npt.getAttribute(dataAttribute), option, dataoptions, optionData, p; 422 var importOption = function(option, optionData) { 423 optionData = optionData !== undefined ? optionData : npt.getAttribute(dataAttribute + "-" + option); 424 if (optionData !== null) { 425 if (typeof optionData === "string") { 426 if (option.indexOf("on") === 0) optionData = window[optionData];
426 else if (optionData === "false") optionData = false; else if (optionData === "true") optionData = true; 427 } 428 userOptions[option] = optionData; 429 } 430 }; 431 if (attrOptions && attrOptions !== "") { 432 attrOptions = attrOptions.replace(/'/g, '"'); 433 dataoptions = JSON.parse("{" + attrOptions + "}"); 434 } 435 if (dataoptions) { 436 optionData = undefined; 437 for (p in dataoptions) { 438 if (p.toLowerCase() === "alias") { 439 optionData = dataoptions[p]; 440 break; 441 } 442 } 443 } 444 importOption("alias", optionData); 445 if (userOptions.alias) { 446 resolveAlias(userOptions.alias, userOptions, opts); 447 } 448 for (option in opts) { 449 if (dataoptions) { 450 optionData = undefined; 451 for (p in dataoptions) { 452 if (p.toLowerCase() === option.toLowerCase()) { 453 optionData = dataoptions[p]; 454 break; 455 } 456 } 457 } 458 importOption(option, optionData); 459 } 460 } 461 $.extend(true, opts, userOptions); 462 if (npt.dir === "rtl" || opts.rightAlign) { 463 npt.style.textAlign = "right"; 464 } 465 if (npt.dir === "rtl" || opts.numericInput) { 466 npt.dir = "ltr"; 467 npt.removeAttribute("dir"); 468 opts.isRTL = true; 469 } 470 return Object.keys(userOptions).length; 471 } 472 if (typeof elems === "string") { 473 elems = document.getElementById(elems) || document.querySelectorAll(elems); 474 } 475 elems = elems.nodeName ? [ elems ] : elems; 476 $.each(elems, function(ndx, el) { 477 var scopedOpts = $.extend(true, {}, that.opts); 478 if (importAttributeOptions(el, scopedOpts, $.extend(true, {}, that.userOptions), that.dataAttribute)) { 479 var maskset = generateMaskSet(scopedOpts, that.noMasksCache); 480 if (maskset !== undefined) { 481 if (el.inputmask !== undefined) { 482 el.inputmask.opts.autoUnmask = true; 483 el.inputmask.remove(); 484 } 485 el.inputmask = new Inputmask(undefined, undefined, true); 486 el.inputmask.opts = scopedOpts; 487 el.inputmask.noMasksCache = that.noMasksCache; 488 el.inputmask.userOptions = $.extend(true, {}, that.userOptions); 489 el.inputmask.isRTL = scopedOpts.isRTL || scopedOpts.numericInput; 490 el.inputmask.el = el; 491 el.inputmask.maskset = maskset; 492 $.data(el, "_inputmask_opts", scopedOpts); 493 maskScope.call(el.inputmask, { 494 action: "mask" 495 }); 496 } 497 } 498 }); 499 return elems && elems[0] ? elems[0].inputmask || this : this; 500 }, 501 option: function(options, noremask) { 502 if (typeof options === "string") { 503 return this.opts[options]; 504 } else if (typeof options === "object") { 505 $.extend(this.userOptions, options); 506 if (this.el && noremask !== true) { 507 this.mask(this.el); 508 } 509 return this; 510 } 511 }, 512 unmaskedvalue: function(value) { 513 this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache); 514 return maskScope.call(this, { 515 action: "unmaskedvalue", 516 value: value 517 }); 518 }, 519 remove: function() { 520 return maskScope.call(this, { 521 action: "remove" 522 }); 523 }, 524 getemptymask: function() { 525 this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache); 526 return maskScope.call(this, { 527 action: "getemptymask" 528 }); 529 }, 530 hasMaskedValue: function() { 531 return !this.opts.autoUnmask; 532 }, 533 isComplete: function() { 534 this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache); 535 return maskScope.call(this, { 536 action: "isComplete" 537 }); 538 }, 539 getmetadata: function() { 540 this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache); 541 return maskScope.call(this, { 542 action: "getmetadata" 543 }); 544 }, 545 isValid: function(value) { 546 this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache); 547 return maskScope.call(this, { 548 action: "isValid", 549 value: value 550 }); 551 }, 552 format: function(value, metadata) { 553 this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache); 554 return maskScope.call(this, { 555 action: "format", 556 value: value, 557 metadata: metadata 558 }); 559 }, 560 setValue: function(value) { 561 if (this.el) { 562 $(this.el).trigger("setvalue", [ value ]); 563 } 564 }, 565 analyseMask: function(mask, regexMask, opts) { 566 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; 567 function MaskToken(isGroup, isOptional, isQuantifier, isAlternator) { 568 this.matches = []; 569 this.openGroup = isGroup || false; 570 this.alternatorGroup = false; 571 this.isGroup = isGroup || false; 572 this.isOptional = isOptional || false;
573 this.isQuantifier = isQuantifier || false; 574 this.isAlternator = isAlternator || false; 575 this.quantifier = { 576 min: 1, 577 max: 1 578 }; 579 } 580 function insertTestDefinition(mtoken, element, position) { 581 position = position !== undefined ? position : mtoken.matches.length; 582 var prevMatch = mtoken.matches[position - 1]; 583 if (regexMask) { 584 if (element.indexOf("[") === 0 || escaped && /\\d|\\s|\\w]/i.test(element) || element === ".") { 585 mtoken.matches.splice(position++, 0, { 586 fn: new RegExp(element, opts.casing ? "i" : ""), 587 optionality: false, 588 newBlockMarker: prevMatch === undefined ? "master" : prevMatch.def !== element, 589 casing: null, 590 def: element, 591 placeholder: undefined, 592 nativeDef: element 593 }); 594 } else { 595 if (escaped) element = element[element.length - 1]; 596 $.each(element.split(""), function(ndx, lmnt) { 597 prevMatch = mtoken.matches[position - 1]; 598 mtoken.matches.splice(position++, 0, { 599 fn: null, 600 optionality: false, 601 newBlockMarker: prevMatch === undefined ? "master" : prevMatch.def !== lmnt && prevMatch.fn !== null, 602 casing: null, 603 def: opts.staticDefinitionSymbol || lmnt, 604 placeholder: opts.staticDefinitionSymbol !== undefined ? lmnt : undefined, 605 nativeDef: (escaped ? "'" : "") + lmnt 606 }); 607 }); 608 } 609 escaped = false; 610 } else { 611 var maskdef = (opts.definitions ? opts.definitions[element] : undefined) || Inputmask.prototype.definitions[element]; 612 if (maskdef && !escaped) { 613 mtoken.matches.splice(position++, 0, { 614 fn: maskdef.validator ? typeof maskdef.validator == "string" ? new RegExp(maskdef.validator, opts.casing ? "i" : "") : new function() { 615 this.test = maskdef.validator; 616 }() : new RegExp("."), 617 optionality: false, 618 newBlockMarker: prevMatch === undefined ? "master" : prevMatch.def !== (maskdef.definitionSymbol || element), 619 casing: maskdef.casing, 620 def: maskdef.definitionSymbol || element, 621 placeholder: maskdef.placeholder, 622 nativeDef: element 623 }); 624 } else { 625 mtoken.matches.splice(position++, 0, { 626 fn: null, 627 optionality: false, 628 newBlockMarker: prevMatch === undefined ? "master" : prevMatch.def !== element && prevMatch.fn !== null, 629 casing: null, 630 def: opts.staticDefinitionSymbol || element, 631 placeholder: opts.staticDefinitionSymbol !== undefined ? element : undefined, 632 nativeDef: (escaped ? "'" : "") + element 633 }); 634 escaped = false; 635 } 636 } 637 } 638 function verifyGroupMarker(maskToken) { 639 if (maskToken && maskToken.matches) { 640 $.each(maskToken.matches, function(ndx, token) { 641 var nextToken = maskToken.matches[ndx + 1];
642 if ((nextToken === undefined || (nextToken.matches === undefined || nextToken.isQuantifier === false)) && token && token.isGroup) { 643 token.isGroup = false; 644 if (!regexMask) { 645 insertTestDefinition(token, opts.groupmarker[0], 0); 646 if (token.openGroup !== true) { 647 insertTestDefinition(token, opts.groupmarker[1]); 648 } 649 } 650 } 651 verifyGroupMarker(token); 652 }); 653 } 654 } 655 function defaultCase() { 656 if (openenings.length > 0) { 657 currentOpeningToken = openenings[openenings.length - 1]; 658 insertTestDefinition(currentOpeningToken, m); 659 if (currentOpeningToken.isAlternator) { 660 alternator = openenings.pop(); 661 for (var mndx = 0; mndx < alternator.matches.length; mndx++) { 662 if (alternator.matches[mndx].isGroup) alternator.matches[mndx].isGroup = false; 663 } 664 if (openenings.length > 0) { 665 currentOpeningToken = openenings[openenings.length - 1]; 666 currentOpeningToken.matches.push(alternator); 667 } else { 668 currentToken.matches.push(alternator); 669 } 670 } 671 } else { 672 insertTestDefinition(currentToken, m); 673 } 674 } 675 function reverseTokens(maskToken) { 676 function reverseStatic(st) { 677 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]; 678 return st; 679 } 680 maskToken.matches = maskToken.matches.reverse(); 681 for (var match in maskToken.matches) { 682 if (maskToken.matches.hasOwnProperty(match)) { 683 var intMatch = parseInt(match); 684 if (maskToken.matches[match].isQuantifier && maskToken.matches[intMatch + 1] && maskToken.matches[intMatch + 1].isGroup) { 685 var qt = maskToken.matches[match]; 686 maskToken.matches.splice(match, 1); 687 maskToken.matches.splice(intMatch + 1, 0, qt); 688 } 689 if (maskToken.matches[match].matches !== undefined) { 690 maskToken.matches[match] = reverseTokens(maskToken.matches[match]); 691 } else { 692 maskToken.matches[match] = reverseStatic(maskToken.matches[match]); 693 } 694 } 695 } 696 return maskToken; 697 } 698 function groupify(matches) { 699 var groupToken = new MaskToken(true); 700 groupToken.openGroup = false; 701 groupToken.matches = matches; 702 return groupToken; 703 } 704 if (regexMask) { 705 opts.optionalmarker[0] = undefined; 706 opts.optionalmarker[1] = undefined; 707 } 708 while (match = regexMask ? regexTokenizer.exec(mask) : tokenizer.exec(mask)) { 709 m = match[0]; 710 if (regexMask) { 711 switch (m.charAt(0)) { 712 case "?": 713 m = "{0,1}"; 714 break; 715 716 case "+": 717 case "*": 718 m = "{" + m + "}"; 719 break; 720 } 721 } 722 if (escaped) { 723 defaultCase(); 724 continue; 725 } 726 switch (m.charAt(0)) { 727 case "(?=": 728 break; 729 730 case "(?!": 731 break; 732 733 case "(?<=": 734 break; 735 736 case "(?<!": 737 break; 738 739 case opts.escapeChar: 740 escaped = true; 741 if (regexMask) { 742 defaultCase(); 743 } 744 break; 745 746 case opts.optionalmarker[1]: 747 case opts.groupmarker[1]: 748 openingToken = openenings.pop(); 749 openingToken.openGroup = false; 750 if (openingToken !== undefined) { 751 if (openenings.length > 0) { 752 currentOpeningToken = openenings[openenings.length - 1]; 753 currentOpeningToken.matches.push(openingToken); 754 if (currentOpeningToken.isAlternator) { 755 alternator = openenings.pop(); 756 for (var mndx = 0; mndx < alternator.matches.length; mndx++) { 757 alternator.matches[mndx].isGroup = false; 758 alternator.matches[mndx].alternatorGroup = false; 759 } 760 if (openenings.length > 0) { 761 currentOpeningToken = openenings[openenings.length - 1]; 762 currentOpeningToken.matches.push(alternator); 763 } else { 764 currentToken.matches.push(alternator); 765 } 766 } 767 } else { 768 currentToken.matches.push(openingToken); 769 } 770 } else defaultCase(); 771 break; 772 773 case opts.optionalmarker[0]: 774 openenings.push(new MaskToken(false, true)); 775 break; 776 777 case opts.groupmarker[0]: 778 openenings.push(new MaskToken(true)); 779 break; 780 781 case opts.quantifiermarker[0]: 782 var quantifier = new MaskToken(false, false, true); 783 m = m.replace(/[{}]/g, ""); 784 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]); 785 if (mq0 === "*" || mq0 === "+") { 786 mq0 = mq1 === "*" ? 0 : 1; 787 } 788 quantifier.quantifier = { 789 min: mq0, 790 max: mq1, 791 jit: mqj[1] 792 }; 793 var matches = openenings.length > 0 ? openenings[openenings.length - 1].matches : currentToken.matches; 794 match = matches.pop(); 795 if (match.isAlternator) { 796 matches.push(match); 797 matches = match.matches; 798 var groupToken = new MaskToken(true); 799 var tmpMatch = matches.pop(); 800 matches.push(groupToken); 801 matches = groupToken.matches; 802 match = tmpMatch; 803 } 804 if (!match.isGroup) { 805 match = groupify([ match ]); 806 } 807 matches.push(match); 808 matches.push(quantifier); 809 break; 810 811 case opts.alternatormarker: 812 var groupQuantifier = function(matches) { 813 var lastMatch = matches.pop(); 814 if (lastMatch.isQuantifier) { 815 lastMatch = groupify([ matches.pop(), lastMatch ]); 816 } 817 return lastMatch; 818 }; 819 if (openenings.length > 0) { 820 currentOpeningToken = openenings[openenings.length - 1]; 821 var subToken = currentOpeningToken.matches[currentOpeningToken.matches.length - 1]; 822 if (currentOpeningToken.openGroup && (subToken.matches === undefined || subToken.isGroup === false && subToken.isAlternator === false)) { 823 lastMatch = openenings.pop(); 824 } else { 825 lastMatch = groupQuantifier(currentOpeningToken.matches); 826 } 827 } else { 828 lastMatch = groupQuantifier(currentToken.matches); 829 } 830 if (lastMatch.isAlternator) { 831 openenings.push(lastMatch); 832 } else { 833 if (lastMatch.alternatorGroup) { 834 alternator = openenings.pop(); 835 lastMatch.alternatorGroup = false; 836 } else { 837 alternator = new MaskToken(false, false, false, true); 838 } 839 alternator.matches.push(lastMatch); 840 openenings.push(alternator); 841 if (lastMatch.openGroup) { 842 lastMatch.openGroup = false; 843 var alternatorGroup = new MaskToken(true); 844 alternatorGroup.alternatorGroup = true; 845 openenings.push(alternatorGroup); 846 } 847 } 848 break; 849 850 default: 851 defaultCase(); 852 } 853 } 854 while (openenings.length > 0) { 855 openingToken = openenings.pop(); 856 currentToken.matches.push(openingToken); 857 } 858 if (currentToken.matches.length > 0) { 859 verifyGroupMarker(currentToken); 860 maskTokens.push(currentToken); 861 } 862 if (opts.numericInput || opts.isRTL) { 863 reverseTokens(maskTokens[0]); 864 } 865 return maskTokens; 866 }, 867 positionColorMask: function(input, template) { 868 input.style.left = template.offsetLeft + "px"; 869 } 870 }; 871 Inputmask.extendDefaults = function(options) { 872 $.extend(true, Inputmask.prototype.defaults, options); 873 }; 874 Inputmask.extendDefinitions = function(definition) { 875 $.extend(true, Inputmask.prototype.definitions, definition); 876 }; 877 Inputmask.extendAliases = function(alias) { 878 $.extend(true, Inputmask.prototype.aliases, alias); 879 }; 880 Inputmask.format = function(value, options, metadata) { 881 return Inputmask(options).format(value, metadata); 882 }; 883 Inputmask.unmask = function(value, options) { 884 return Inputmask(options).unmaskedvalue(value); 885 }; 886 Inputmask.isValid = function(value, options) { 887 return Inputmask(options).isValid(value); 888 }; 889 Inputmask.remove = function(elems) { 890 if (typeof elems === "string") { 891 elems = document.getElementById(elems) || document.querySelectorAll(elems); 892 } 893 elems = elems.nodeName ? [ elems ] : elems; 894 $.each(elems, function(ndx, el) { 895 if (el.inputmask) el.inputmask.remove(); 896 }); 897 }; 898 Inputmask.setValue = function(elems, value) { 899 if (typeof elems === "string") { 900 elems = document.getElementById(elems) || document.querySelectorAll(elems); 901 } 902 elems = elems.nodeName ? [ elems ] : elems; 903 $.each(elems, function(ndx, el) { 904 if (el.inputmask) el.inputmask.setValue(value); else $(el).trigger("setvalue", [ value ]); 905 }); 906 }; 907 Inputmask.escapeRegex = function(str) { 908 var specials = [ "/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\", "$", "^" ]; 909 return str.replace(new RegExp("(\\" + specials.join("|\\") + ")", "gim"), "\\$1"); 910 }; 911 Inputmask.keyCode = { 912 BACKSPACE: 8, 913 BACKSPACE_SAFARI: 127, 914 DELETE: 46, 915 DOWN: 40, 916 END: 35, 917 ENTER: 13, 918 ESCAPE: 27, 919 HOME: 36, 920 INSERT: 45, 921 LEFT: 37, 922 PAGE_DOWN: 34, 923 PAGE_UP: 33, 924 RIGHT: 39, 925 SPACE: 32, 926 TAB: 9, 927 UP: 38, 928 X: 88, 929 CONTROL: 17 930 }; 931 Inputmask.dependencyLib = $; 932 function resolveAlias(aliasStr, options, opts) { 933 var aliasDefinition = Inputmask.prototype.aliases[aliasStr]; 934 if (aliasDefinition) { 935 if (aliasDefinition.alias) resolveAlias(aliasDefinition.alias, undefined, opts); 936 $.extend(true, opts, aliasDefinition); 937 $.extend(true, opts, options); 938 return true; 939 } else if (opts.mask === null) { 940 opts.mask = aliasStr; 941 } 942 return false; 943 } 944 function generateMaskSet(opts, nocache) { 945 function generateMask(mask, metadata, opts) { 946 var regexMask = false; 947 if (mask === null || mask === "") { 948 regexMask = opts.regex !== null; 949 if (regexMask) { 950 mask = opts.regex; 951 mask = mask.replace(/^(\^)(.*)(\$)$/, "$2"); 952 } else { 953 regexMask = true; 954 mask = ".*"; 955 } 956 } 957 if (mask.length === 1 && opts.greedy === false && opts.repeat !== 0) { 958 opts.placeholder = ""; 959 } 960 if (opts.repeat > 0 || opts.repeat === "*" || opts.repeat === "+") { 961 var repeatStart = opts.repeat === "*" ? 0 : opts.repeat === "+" ? 1 : opts.repeat; 962 mask = opts.groupmarker[0] + mask + opts.groupmarker[1] + opts.quantifiermarker[0] + repeatStart + "," + opts.repeat + opts.quantifiermarker[1]; 963 } 964 var masksetDefinition, maskdefKey = regexMask ? "regex_" + opts.regex : opts.numericInput ? mask.split("").reverse().join("") : mask; 965 if (Inputmask.prototype.masksCache[maskdefKey] === undefined || nocache === true) { 966 masksetDefinition = { 967 mask: mask,
968 maskToken: Inputmask.prototype.analyseMask(mask, regexMask, opts), 969 validPositions: {}, 970 _buffer: undefined, 971 buffer: undefined, 972 tests: {}, 973 excludes: {}, 974 metadata: metadata, 975 maskLength: undefined, 976 jitOffset: {} 977 }; 978 if (nocache !== true) { 979 Inputmask.prototype.masksCache[maskdefKey] = masksetDefinition; 980 masksetDefinition = $.extend(true, {}, Inputmask.prototype.masksCache[maskdefKey]); 981 } 982 } else masksetDefinition = $.extend(true, {}, Inputmask.prototype.masksCache[maskdefKey]); 983 return masksetDefinition; 984 } 985 var ms; 986 if ($.isFunction(opts.mask)) { 987 opts.mask = opts.mask(opts); 988 } 989 if ($.isArray(opts.mask)) { 990 if (opts.mask.length > 1) { 991 if (opts.keepStatic === null) { 992 opts.keepStatic = "auto"; 993 for (var i = 0; i < opts.mask.length; i++) { 994 if (opts.mask[i].charAt(0) !== opts.mask[0].charAt(0)) { 995 opts.keepStatic = true; 996 break; 997 } 998 } 999 } 1000 var altMask = opts.groupmarker[0]; 1001 $.each(opts.isRTL ? opts.mask.reverse() : opts.mask, function(ndx, msk) { 1002 if (altMask.length > 1) { 1003 altMask += opts.groupmarker[1] + opts.alternatormarker + opts.groupmarker[0]; 1004 } 1005 if (msk.mask !== undefined && !$.isFunction(msk.mask)) { 1006 altMask += msk.mask; 1007 } else { 1008 altMask += msk; 1009 } 1010 }); 1011 altMask += opts.groupmarker[1]; 1012 return generateMask(altMask, opts.mask, opts); 1013 } else opts.mask = opts.mask.pop(); 1014 } 1015 if (opts.mask && opts.mask.mask !== undefined && !$.isFunction(opts.mask.mask)) { 1016 ms = generateMask(opts.mask.mask, opts.mask, opts); 1017 } else { 1018 ms = generateMask(opts.mask, opts.mask, opts); 1019 } 1020 return ms; 1021 } 1022 function isInputEventSupported(eventName) { 1023 var el = document.createElement("input"), evName = "on" + eventName, isSupported = evName in el; 1024 if (!isSupported) { 1025 el.setAttribute(evName, "return;"); 1026 isSupported = typeof el[evName] === "function"; 1027 } 1028 el = null; 1029 return isSupported; 1030 } 1031 function maskScope(actionObj, maskset, opts) { 1032 maskset = maskset || this.maskset; 1033 opts = opts || this.opts; 1034 var inputmask = this, el = this.el, isRTL = this.isRTL, undoValue, $el, skipKeyPressEvent = false, skipInputEvent = false, ignorable = false, maxLength, mouseEnter = false, colorMask, originalPlaceholder; 1035 var getMaskTemplate = function(baseOnInput, minimalPos, includeMode, noJit, clearOptionalTail) { 1036 var greedy = opts.greedy; 1037 if (clearOptionalTail) opts.greedy = false; 1038 minimalPos = minimalPos || 0; 1039 var maskTemplate = [], ndxIntlzr, pos = 0, test, testPos, lvp = getLastValidPosition(); 1040 do { 1041 if (baseOnInput === true && getMaskSet().validPositions[pos]) { 1042 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]; 1043 test = testPos.match; 1044 ndxIntlzr = testPos.locator.slice(); 1045 maskTemplate.push(includeMode === true ? testPos.input : includeMode === false ? test.nativeDef : getPlaceholder(pos, test)); 1046 } else { 1047 testPos = getTestTemplate(pos, ndxIntlzr, pos - 1); 1048 test = testPos.match; 1049 ndxIntlzr = testPos.locator.slice(); 1050 var jitMasking = noJit === true ? false : opts.jitMasking !== false ? opts.jitMasking : test.jit; 1051 if (jitMasking === false || jitMasking === undefined || typeof jitMasking === "number" && isFinite(jitMasking) && jitMasking > pos) { 1052 maskTemplate.push(includeMode === false ? test.nativeDef : getPlaceholder(pos, test)); 1053 } 1054 } 1055 if (opts.keepStatic === "auto") { 1056 if (test.newBlockMarker && test.fn !== null) { 1057 opts.keepStatic = pos - 1; 1058 } 1059 } 1060 pos++; 1061 } while ((maxLength === undefined || pos < maxLength) && (test.fn !== null || test.def !== "") || minimalPos > pos); 1062 if (maskTemplate[maskTemplate.length - 1] === "") { 1063 maskTemplate.pop();
1064 } 1065 if (includeMode !== false || getMaskSet().maskLength === undefined) getMaskSet().maskLength = pos - 1; 1066 opts.greedy = greedy; 1067 return maskTemplate; 1068 }; 1069 function getMaskSet() { 1070 return maskset; 1071 } 1072 function resetMaskSet(soft) { 1073 var maskset = getMaskSet(); 1074 maskset.buffer = undefined; 1075 if (soft !== true) { 1076 maskset.validPositions = {}; 1077 maskset.p = 0; 1078 } 1079 } 1080 function getLastValidPosition(closestTo, strict, validPositions) { 1081 var before = -1, after = -1, valids = validPositions || getMaskSet().validPositions; 1082 if (closestTo === undefined) closestTo = -1; 1083 for (var posNdx in valids) { 1084 var psNdx = parseInt(posNdx); 1085 if (valids[psNdx] && (strict || valids[psNdx].generatedInput !== true)) { 1086 if (psNdx <= closestTo) before = psNdx; 1087 if (psNdx >= closestTo) after = psNdx; 1088 } 1089 } 1090 return before === -1 || before == closestTo ? after : after == -1 ? before : closestTo - before < after - closestTo ? before : after; 1091 } 1092 function getDecisionTaker(tst) { 1093 var decisionTaker = tst.locator[tst.alternation]; 1094 if (typeof decisionTaker == "string" && decisionTaker.length > 0) { 1095 decisionTaker = decisionTaker.split(",")[0]; 1096 } 1097 return decisionTaker !== undefined ? decisionTaker.toString() : ""; 1098 } 1099 function getLocator(tst, align) { 1100 var locator = (tst.alternation != undefined ? tst.mloc[getDecisionTaker(tst)] : tst.locator).join(""); 1101 if (locator !== "") while (locator.length < align) locator += "0"; 1102 return locator; 1103 } 1104 function determineTestTemplate(pos, tests) { 1105 pos = pos > 0 ? pos - 1 : 0; 1106 var altTest = getTest(pos), targetLocator = getLocator(altTest), tstLocator, closest, bestMatch; 1107 for (var ndx = 0; ndx < tests.length; ndx++) { 1108 var tst = tests[ndx]; 1109 tstLocator = getLocator(tst, targetLocator.length); 1110 var distance = Math.abs(tstLocator - targetLocator); 1111 if (closest === undefined || tstLocator !== "" && distance < closest || bestMatch && !opts.greedy && bestMatch.match.optionality && bestMatch.match.newBlockMarker === "master" && (!tst.match.optionality || !tst.match.newBlockMarker) || bestMatch && bestMatch.match.optionalQuantifier && !tst.match.optionalQuantifier) { 1112 closest = distance; 1113 bestMatch = tst; 1114 } 1115 } 1116 return bestMatch; 1117 } 1118 function getTestTemplate(pos, ndxIntlzr, tstPs) { 1119 return getMaskSet().validPositions[pos] || determineTestTemplate(pos, getTests(pos, ndxIntlzr ? ndxIntlzr.slice() : ndxIntlzr, tstPs)); 1120 } 1121 function getTest(pos, tests) { 1122 if (getMaskSet().validPositions[pos]) { 1123 return getMaskSet().validPositions[pos]; 1124 } 1125 return (tests || getTests(pos))[0]; 1126 } 1127 function positionCanMatchDefinition(pos, def) { 1128 var valid = false, tests = getTests(pos); 1129 for (var tndx = 0; tndx < tests.length; tndx++) { 1130 if (tests[tndx].match && tests[tndx].match.def === def) { 1131 valid = true; 1132 break; 1133 } 1134 } 1135 return valid; 1136 } 1137 function getTests(pos, ndxIntlzr, tstPs) { 1138 var maskTokens = getMaskSet().maskToken, testPos = ndxIntlzr ? tstPs : 0, ndxInitializer = ndxIntlzr ? ndxIntlzr.slice() : [ 0 ], matches = [], insertStop = false, latestMatch, cacheDependency = ndxIntlzr ? ndxIntlzr.join("") : ""; 1139 function resolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) { 1140 function handleMatch(match, loopNdx, quantifierRecurse) { 1141 function isFirstMatch(latestMatch, tokenGroup) { 1142 var firstMatch = $.inArray(latestMatch, tokenGroup.matches) === 0; 1143 if (!firstMatch) { 1144 $.each(tokenGroup.matches, function(ndx, match) { 1145 if (match.isQuantifier === true) firstMatch = isFirstMatch(latestMatch, tokenGroup.matches[ndx - 1]); else if (match.hasOwnProperty("matches")) firstMatch = isFirstMatch(latestMatch, match); 1146 if (firstMatch) return false; 1147 }); 1148 } 1149 return firstMatch; 1150 } 1151 function resolveNdxInitializer(pos, alternateNdx, targetAlternation) { 1152 var bestMatch, indexPos; 1153 if (getMaskSet().tests[pos] || getMaskSet().validPositions[pos]) { 1154 $.each(getMaskSet().tests[pos] || [ getMaskSet().validPositions[pos] ], function(ndx, lmnt) { 1155 if (lmnt.mloc[alternateNdx]) { 1156 bestMatch = lmnt; 1157 return false; 1158 } 1159 var alternation = targetAlternation !== undefined ? targetAlternation : lmnt.alternation, ndxPos = lmnt.locator[alternation] !== undefined ? lmnt.locator[alternation].toString().indexOf(alternateNdx) : -1; 1160 if ((indexPos === undefined || ndxPos < indexPos) && ndxPos !== -1) { 1161 bestMatch = lmnt; 1162 indexPos = ndxPos; 1163 } 1164 }); 1165 } 1166 if (bestMatch) { 1167 var bestMatchAltIndex = bestMatch.locator[bestMatch.alternation]; 1168 var locator = bestMatch.mloc[alternateNdx] || bestMatch.mloc[bestMatchAltIndex] || bestMatch.locator; 1169 return locator.slice((targetAlternation !== undefined ? targetAlternation : bestMatch.alternation) + 1); 1170 } else { 1171 return targetAlternation !== undefined ? resolveNdxInitializer(pos, alternateNdx) : undefined; 1172 } 1173 } 1174 function isSubsetOf(source, target) { 1175 function expand(pattern) { 1176 var expanded = [], start, end; 1177 for (var i = 0, l = pattern.length; i < l; i++) { 1178 if (pattern.charAt(i) === "-") {
1179 end = pattern.charCodeAt(i + 1); 1180 while (++start < end) expanded.push(String.fromCharCode(start)); 1181 } else { 1182 start = pattern.charCodeAt(i); 1183 expanded.push(pattern.charAt(i)); 1184 } 1185 } 1186 return expanded.join(""); 1187 } 1188 if (opts.regex && source.match.fn !== null && target.match.fn !== null) { 1189 return expand(target.match.def.replace(/[\[\]]/g, "")).indexOf(expand(source.match.def.replace(/[\[\]]/g, ""))) !== -1; 1190 } 1191 return source.match.def === target.match.nativeDef; 1192 } 1193 function staticCanMatchDefinition(source, target) { 1194 var sloc = source.locator.slice(source.alternation).join(""), tloc = target.locator.slice(target.alternation).join(""), canMatch = sloc == tloc; 1195 canMatch = canMatch && source.match.fn === null && target.match.fn !== null ? target.match.fn.test(source.match.def, getMaskSet(), pos, false, opts, false) : false; 1196 return canMatch; 1197 } 1198 function setMergeLocators(targetMatch, altMatch) { 1199 if (altMatch === undefined || targetMatch.alternation === altMatch.alternation && targetMatch.locator[targetMatch.alternation].toString().indexOf(altMatch.locator[altMatch.alternation]) === -1) { 1200 targetMatch.mloc = targetMatch.mloc || {}; 1201 var locNdx = targetMatch.locator[targetMatch.alternation]; 1202 if (locNdx === undefined) targetMatch.alternation = undefined; else { 1203 if (typeof locNdx === "string") locNdx = locNdx.split(",")[0]; 1204 if (targetMatch.mloc[locNdx] === undefined) targetMatch.mloc[locNdx] = targetMatch.locator.slice(); 1205 if (altMatch !== undefined) { 1206 for (var ndx in altMatch.mloc) { 1207 if (typeof ndx === "string") ndx = ndx.split(",")[0]; 1208 if (targetMatch.mloc[ndx] === undefined) targetMatch.mloc[ndx] = altMatch.mloc[ndx]; 1209 } 1210 targetMatch.locator[targetMatch.alternation] = Object.keys(targetMatch.mloc).join(","); 1211 } 1212 return true; 1213 } 1214 } 1215 return false; 1216 } 1217 if (testPos > 500 && quantifierRecurse !== undefined) { 1218 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; 1219 } 1220 if (testPos === pos && match.matches === undefined) { 1221 matches.push({ 1222 match: match, 1223 locator: loopNdx.reverse(), 1224 cd: cacheDependency, 1225 mloc: {} 1226 }); 1227 return true; 1228 } else if (match.matches !== undefined) { 1229 if (match.isGroup && quantifierRecurse !== match) { 1230 match = handleMatch(maskToken.matches[$.inArray(match, maskToken.matches) + 1], loopNdx, quantifierRecurse); 1231 if (match) return true; 1232 } else if (match.isOptional) { 1233 var optionalToken = match; 1234 match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse); 1235 if (match) { 1236 $.each(matches, function(ndx, mtch) { 1237 mtch.match.optionality = true; 1238 }); 1239 latestMatch = matches[matches.length - 1].match; 1240 if (quantifierRecurse === undefined && isFirstMatch(latestMatch, optionalToken)) { 1241 insertStop = true; 1242 testPos = pos; 1243 } else return true; 1244 } 1245 } else if (match.isAlternator) { 1246 var alternateToken = match, malternateMatches = [], maltMatches, currentMatches = matches.slice(), loopNdxCnt = loopNdx.length; 1247 var altIndex = ndxInitializer.length > 0 ? ndxInitializer.shift() : -1; 1248 if (altIndex === -1 || typeof altIndex === "string") { 1249 var currentPos = testPos, ndxInitializerClone = ndxInitializer.slice(), altIndexArr = [], amndx; 1250 if (typeof altIndex == "string") { 1251 altIndexArr = altIndex.split(","); 1252 } else { 1253 for (amndx = 0;
1253 amndx < alternateToken.matches.length; amndx++) { 1254 altIndexArr.push(amndx.toString()); 1255 } 1256 } 1257 if (getMaskSet().excludes[pos]) { 1258 var altIndexArrClone = altIndexArr.slice(); 1259 for (var i = 0, el = getMaskSet().excludes[pos].length; i < el; i++) { 1260 altIndexArr.splice(altIndexArr.indexOf(getMaskSet().excludes[pos][i].toString()), 1); 1261 } 1262 if (altIndexArr.length === 0) { 1263 getMaskSet().excludes[pos] = undefined; 1264 altIndexArr = altIndexArrClone; 1265 } 1266 } 1267 if (opts.keepStatic === true || isFinite(parseInt(opts.keepStatic)) && currentPos >= opts.keepStatic) altIndexArr = altIndexArr.slice(0, 1); 1268 var unMatchedAlternation = false; 1269 for (var ndx = 0; ndx < altIndexArr.length; ndx++) { 1270 amndx = parseInt(altIndexArr[ndx]); 1271 matches = []; 1272 ndxInitializer = typeof altIndex === "string" ? resolveNdxInitializer(testPos, amndx, loopNdxCnt) || ndxInitializerClone.slice() : ndxInitializerClone.slice(); 1273 if (alternateToken.matches[amndx] && handleMatch(alternateToken.matches[amndx], [ amndx ].concat(loopNdx), quantifierRecurse)) match = true; else if (ndx === 0) { 1274 unMatchedAlternation = true; 1275 } 1276 maltMatches = matches.slice(); 1277 testPos = currentPos; 1278 matches = []; 1279 for (var ndx1 = 0; ndx1 < maltMatches.length; ndx1++) { 1280 var altMatch = maltMatches[ndx1], dropMatch = false; 1281 altMatch.match.jit = altMatch.match.jit || unMatchedAlternation; 1282 altMatch.alternation = altMatch.alternation || loopNdxCnt; 1283 setMergeLocators(altMatch); 1284 for (var ndx2 = 0; ndx2 < malternateMatches.length; ndx2++) { 1285 var altMatch2 = malternateMatches[ndx2]; 1286 if (typeof altIndex !== "string" || altMatch.alternation !== undefined && $.inArray(altMatch.locator[altMatch.alternation].toString(), altIndexArr) !== -1) { 1287 if (altMatch.match.nativeDef === altMatch2.match.nativeDef) { 1288 dropMatch = true; 1289 setMergeLocators(altMatch2, altMatch); 1290 break; 1291 } else if (isSubsetOf(altMatch, altMatch2)) { 1292 if (setMergeLocators(altMatch, altMatch2)) { 1293 dropMatch = true; 1294 malternateMatches.splice(malternateMatches.indexOf(altMatch2), 0, altMatch); 1295 } 1296 break; 1297 } else if (isSubsetOf(altMatch2, altMatch)) { 1298 setMergeLocators(altMatch2, altMatch); 1299 break; 1300 } else if (staticCanMatchDefinition(altMatch, altMatch2)) { 1301 if (setMergeLocators(altMatch, altMatch2)) { 1302 dropMatch = true; 1303 malternateMatches.splice(malternateMatches.indexOf(altMatch2), 0, altMatch); 1304 } 1305 break; 1306 } 1307 } 1308 } 1309 if (!dropMatch) { 1310 malternateMatches.push(altMatch); 1311 } 1312 } 1313 } 1314 matches = currentMatches.concat(malternateMatches); 1315 testPos = pos; 1316 insertStop = matches.length > 0;
1317 match = malternateMatches.length > 0; 1318 ndxInitializer = ndxInitializerClone.slice(); 1319 } else match = handleMatch(alternateToken.matches[altIndex] || maskToken.matches[altIndex], [ altIndex ].concat(loopNdx), quantifierRecurse); 1320 if (match) return true; 1321 } else if (match.isQuantifier && quantifierRecurse !== maskToken.matches[$.inArray(match, maskToken.matches) - 1]) { 1322 var qt = match; 1323 for (var qndx = ndxInitializer.length > 0 ? ndxInitializer.shift() : 0; qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max) && testPos <= pos; qndx++) { 1324 var tokenGroup = maskToken.matches[$.inArray(qt, maskToken.matches) - 1]; 1325 match = handleMatch(tokenGroup, [ qndx ].concat(loopNdx), tokenGroup); 1326 if (match) { 1327 latestMatch = matches[matches.length - 1].match; 1328 latestMatch.optionalQuantifier = qndx >= qt.quantifier.min; 1329 latestMatch.jit = (qndx || 1) * tokenGroup.matches.indexOf(latestMatch) >= qt.quantifier.jit; 1330 if (latestMatch.optionalQuantifier && isFirstMatch(latestMatch, tokenGroup)) { 1331 insertStop = true; 1332 testPos = pos; 1333 break; 1334 } 1335 if (latestMatch.jit) { 1336 getMaskSet().jitOffset[pos] = tokenGroup.matches.indexOf(latestMatch); 1337 } 1338 return true; 1339 } 1340 } 1341 } else { 1342 match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse); 1343 if (match) return true; 1344 } 1345 } else { 1346 testPos++; 1347 } 1348 } 1349 for (var tndx = ndxInitializer.length > 0 ? ndxInitializer.shift() : 0; tndx < maskToken.matches.length; tndx++) { 1350 if (maskToken.matches[tndx].isQuantifier !== true) { 1351 var match = handleMatch(maskToken.matches[tndx], [ tndx ].concat(loopNdx), quantifierRecurse); 1352 if (match && testPos === pos) { 1353 return match; 1354 } else if (testPos > pos) { 1355 break; 1356 } 1357 } 1358 } 1359 } 1360 function mergeLocators(pos, tests) { 1361 var locator = []; 1362 if (!$.isArray(tests)) tests = [ tests ]; 1363 if (tests.length > 0) { 1364 if (tests[0].alternation === undefined) { 1365 locator = determineTestTemplate(pos, tests.slice()).locator.slice(); 1366 if (locator.length === 0) locator = tests[0].locator.slice(); 1367 } else { 1368 $.each(tests, function(ndx, tst) { 1369 if (tst.def !== "") { 1370 if (locator.length === 0) locator = tst.locator.slice(); else { 1371 for (var i = 0; i < locator.length; i++) { 1372 if (tst.locator[i] && locator[i].toString().indexOf(tst.locator[i]) === -1) { 1373 locator[i] += "," + tst.locator[i]; 1374 } 1375 } 1376 } 1377 } 1378 }); 1379 } 1380 } 1381 return locator; 1382 } 1383 if (pos > -1) { 1384 if (ndxIntlzr === undefined) { 1385 var previousPos = pos - 1, test; 1386 while ((test = getMaskSet().validPositions[previousPos] || getMaskSet().tests[previousPos]) === undefined && previousPos > -1) { 1387 previousPos--; 1388 } 1389 if (test !== undefined && previousPos > -1) { 1390 ndxInitializer = mergeLocators(previousPos, test); 1391 cacheDependency = ndxInitializer.join(""); 1392 testPos = previousPos; 1393 } 1394 } 1395 if (getMaskSet().tests[pos] && getMaskSet().tests[pos][0].cd === cacheDependency) { 1396 return getMaskSet().tests[pos]; 1397 } 1398 for (var mtndx = ndxInitializer.shift(); mtndx < maskTokens.length; mtndx++) { 1399 var match = resolveTestFromToken(maskTokens[mtndx], ndxInitializer, [ mtndx ]); 1400 if (match && testPos === pos || testPos > pos) { 1401 break; 1402 } 1403 } 1404 } 1405 if (matches.length === 0 || insertStop) { 1406 matches.push({ 1407 match: { 1408 fn: null, 1409 optionality: false, 1410 casing: null, 1411 def: "", 1412 placeholder: "" 1413 }, 1414 locator: [], 1415 mloc: {}, 1416 cd: cacheDependency 1417 }); 1418 } 1419 if (ndxIntlzr !== undefined && getMaskSet().tests[pos]) { 1420 return $.extend(true, [], matches); 1421 } 1422 getMaskSet().tests[pos] = $.extend(true, [], matches); 1423 return getMaskSet().tests[pos]; 1424 } 1425 function getBufferTemplate() { 1426 if (getMaskSet()._buffer === undefined) { 1427 getMaskSet()._buffer = getMaskTemplate(false, 1); 1428 if (getMaskSet().buffer === undefined) getMaskSet().buffer = getMaskSet()._buffer.slice(); 1429 } 1430 return getMaskSet()._buffer; 1431 } 1432 function getBuffer(noCache) { 1433 if (getMaskSet().buffer === undefined || noCache === true) { 1434 getMaskSet().buffer = getMaskTemplate(true, getLastValidPosition(), true); 1435 if (getMaskSet()._buffer === undefined) getMaskSet()._buffer = getMaskSet().buffer.slice(); 1436 } 1437 return getMaskSet().buffer; 1438 } 1439 function refreshFromBuffer(start, end, buffer) { 1440 var i, p; 1441 if (start === true) { 1442 resetMaskSet(); 1443 start = 0; 1444 end = buffer.length; 1445 } else { 1446 for (i = start; i < end; i++) { 1447 delete getMaskSet().validPositions[i]; 1448 } 1449 } 1450 p = start; 1451 for (i = start; i < end; i++) { 1452 resetMaskSet(true); 1453 if (buffer[i] !== opts.skipOptionalPartCharacter) { 1454 var valResult = isValid(p, buffer[i], true, true); 1455 if (valResult !== false) { 1456 resetMaskSet(true); 1457 p = valResult.caret !== undefined ? valResult.caret : valResult.pos + 1; 1458 } 1459 } 1460 } 1461 } 1462 function casing(elem, test, pos) { 1463 switch (opts.casing || test.casing) { 1464 case "upper": 1465 elem = elem.toUpperCase(); 1466 break; 1467 1468 case "lower": 1469 elem = elem.toLowerCase(); 1470 break; 1471 1472 case "title": 1473 var posBefore = getMaskSet().validPositions[pos - 1]; 1474 if (pos === 0 || posBefore && posBefore.input === String.fromCharCode(Inputmask.keyCode.SPACE)) { 1475 elem = elem.toUpperCase(); 1476 } else { 1477 elem = elem.toLowerCase(); 1478 } 1479 break; 1480 1481 default: 1482 if ($.isFunction(opts.casing)) { 1483 var args = Array.prototype.slice.call(arguments); 1484 args.push(getMaskSet().validPositions); 1485 elem = opts.casing.apply(this, args); 1486 } 1487 } 1488 return elem; 1489 } 1490 function checkAlternationMatch(altArr1, altArr2, na) { 1491 var altArrC = opts.greedy ? altArr2 : altArr2.slice(0, 1), isMatch = false, naArr = na !== undefined ? na.split(",") : [], naNdx; 1492 for (var i = 0; i < naArr.length; i++) { 1493 if ((naNdx = altArr1.indexOf(naArr[i])) !== -1) { 1494 altArr1.splice(naNdx, 1); 1495 } 1496 } 1497 for (var alndx = 0; alndx < altArr1.length; alndx++) { 1498 if ($.inArray(altArr1[alndx], altArrC) !== -1) { 1499 isMatch = true; 1500 break; 1501 } 1502 } 1503 return isMatch; 1504 } 1505 function alternate(pos, c, strict, fromSetValid, rAltPos) {
1506 var validPsClone = $.extend(true, {}, getMaskSet().validPositions), lastAlt, alternation, isValidRslt = false, altPos, prevAltPos, i, validPos, decisionPos, lAltPos = rAltPos !== undefined ? rAltPos : getLastValidPosition(); 1507 if (lAltPos === -1 && rAltPos === undefined) { 1508 lastAlt = 0; 1509 prevAltPos = getTest(lastAlt); 1510 alternation = prevAltPos.alternation; 1511 } else { 1512 for (;lAltPos >= 0; lAltPos--) { 1513 altPos = getMaskSet().validPositions[lAltPos]; 1514 if (altPos && altPos.alternation !== undefined) { 1515 if (prevAltPos && prevAltPos.locator[altPos.alternation] !== altPos.locator[altPos.alternation]) { 1516 break; 1517 } 1518 lastAlt = lAltPos; 1519 alternation = getMaskSet().validPositions[lastAlt].alternation; 1520 prevAltPos = altPos; 1521 } 1522 } 1523 } 1524 if (alternation !== undefined) { 1525 decisionPos = parseInt(lastAlt); 1526 getMaskSet().excludes[decisionPos] = getMaskSet().excludes[decisionPos] || []; 1527 if (pos !== true) { 1528 getMaskSet().excludes[decisionPos].push(getDecisionTaker(prevAltPos)); 1529 } 1530 var validInputsClone = [], staticInputsBeforePos = 0; 1531 for (i = decisionPos; i < getLastValidPosition(undefined, true) + 1; i++) { 1532 validPos = getMaskSet().validPositions[i]; 1533 if (validPos && validPos.generatedInput !== true) { 1534 validInputsClone.push(validPos.input); 1535 } else if (i < pos) staticInputsBeforePos++; 1536 delete getMaskSet().validPositions[i]; 1537 } 1538 while (getMaskSet().excludes[decisionPos] && getMaskSet().excludes[decisionPos].length < 10) { 1539 var posOffset = staticInputsBeforePos * -1, validInputs = validInputsClone.slice(); 1540 getMaskSet().tests[decisionPos] = undefined; 1541 resetMaskSet(true); 1542 isValidRslt = true; 1543 while (validInputs.length > 0) { 1544 var input = validInputs.shift(); 1545 if (!(isValidRslt = isValid(getLastValidPosition(undefined, true) + 1, input, false, fromSetValid, true))) { 1546 break; 1547 } 1548 } 1549 if (isValidRslt && c !== undefined) { 1550 var targetLvp = getLastValidPosition(pos) + 1; 1551 for (i = decisionPos; i < getLastValidPosition() + 1; i++) { 1552 validPos = getMaskSet().validPositions[i]; 1553 if ((validPos === undefined || validPos.match.fn == null) && i < pos + posOffset) { 1554 posOffset++; 1555 } 1556 } 1557 pos = pos + posOffset; 1558 isValidRslt = isValid(pos > targetLvp ? targetLvp : pos, c, strict, fromSetValid, true); 1559 } 1560 if (!isValidRslt) { 1561 resetMaskSet(); 1562 prevAltPos = getTest(decisionPos); 1563 getMaskSet().validPositions = $.extend(true, {}, validPsClone); 1564 if (getMaskSet().excludes[decisionPos]) { 1565 var decisionTaker = getDecisionTaker(prevAltPos); 1566 if (getMaskSet().excludes[decisionPos].indexOf(decisionTaker) !== -1) { 1567 isValidRslt = alternate(pos, c, strict, fromSetValid, decisionPos - 1); 1568 break; 1569 } 1570 getMaskSet().excludes[decisionPos].push(decisionTaker); 1571 for (i = decisionPos; i < getLastValidPosition(undefined, true) + 1; i++) delete getMaskSet().validPositions[i]; 1572 } else { 1573 isValidRslt = alternate(pos, c, strict, fromSetValid, decisionPos - 1); 1574 break; 1575 } 1576 } else break; 1577 } 1578 } 1579 getMaskSet().excludes[decisionPos] = undefined; 1580 return isValidRslt; 1581 } 1582 function isValid(pos, c, strict, fromSetValid, fromAlternate, validateOnly) { 1583 function isSelection(posObj) { 1584 return isRTL ? posObj.begin - posObj.end > 1 || posObj.begin - posObj.end === 1 : posObj.end - posObj.begin > 1 || posObj.end - posObj.begin === 1; 1585 }
1586 strict = strict === true; 1587 var maskPos = pos; 1588 if (pos.begin !== undefined) { 1589 maskPos = isRTL ? pos.end : pos.begin; 1590 } 1591 function _isValid(position, c, strict) { 1592 var rslt = false; 1593 $.each(getTests(position), function(ndx, tst) { 1594 var test = tst.match; 1595 getBuffer(true); 1596 rslt = test.fn != null ? test.fn.test(c, getMaskSet(), position, strict, opts, isSelection(pos)) : (c === test.def || c === opts.skipOptionalPartCharacter) && test.def !== "" ? { 1597 c: getPlaceholder(position, test, true) || test.def, 1598 pos: position 1599 } : false; 1600 if (rslt !== false) { 1601 var elem = rslt.c !== undefined ? rslt.c : c, validatedPos = position; 1602 elem = elem === opts.skipOptionalPartCharacter && test.fn === null ? getPlaceholder(position, test, true) || test.def : elem; 1603 if (rslt.remove !== undefined) { 1604 if (!$.isArray(rslt.remove)) rslt.remove = [ rslt.remove ]; 1605 $.each(rslt.remove.sort(function(a, b) { 1606 return b - a; 1607 }), function(ndx, lmnt) { 1608 revalidateMask({ 1609 begin: lmnt, 1610 end: lmnt + 1 1611 }); 1612 }); 1613 } 1614 if (rslt.insert !== undefined) { 1615 if (!$.isArray(rslt.insert)) rslt.insert = [ rslt.insert ]; 1616 $.each(rslt.insert.sort(function(a, b) { 1617 return a - b; 1618 }), function(ndx, lmnt) { 1619 isValid(lmnt.pos, lmnt.c, true, fromSetValid); 1620 }); 1621 } 1622 if (rslt !== true && rslt.pos !== undefined && rslt.pos !== position) { 1623 validatedPos = rslt.pos; 1624 } 1625 if (rslt !== true && rslt.pos === undefined && rslt.c === undefined) { 1626 return false; 1627 } 1628 if (!revalidateMask(pos, $.extend({}, tst, { 1629 input: casing(elem, test, validatedPos) 1630 }), fromSetValid, validatedPos)) { 1631 rslt = false; 1632 } 1633 return false; 1634 } 1635 }); 1636 return rslt; 1637 } 1638 var result = true, positionsClone = $.extend(true, {}, getMaskSet().validPositions); 1639 if ($.isFunction(opts.preValidation) && !strict && fromSetValid !== true && validateOnly !== true) { 1640 result = opts.preValidation(getBuffer(), maskPos, c, isSelection(pos), opts, getMaskSet()); 1641 } 1642 if (result === true) { 1643 trackbackPositions(undefined, maskPos, true); 1644 if (maxLength === undefined || maskPos < maxLength) { 1645 result = _isValid(maskPos, c, strict); 1646 if ((!strict || fromSetValid === true) && result === false && validateOnly !== true) { 1647 var currentPosValid = getMaskSet().validPositions[maskPos]; 1648 if (currentPosValid && currentPosValid.match.fn === null && (currentPosValid.match.def === c || c === opts.skipOptionalPartCharacter)) { 1649 result = { 1650 caret: seekNext(maskPos) 1651 }; 1652 } else { 1653 if ((opts.insertMode || getMaskSet().validPositions[seekNext(maskPos)] === undefined) && (!isMask(maskPos, true) || getMaskSet().jitOffset[maskPos])) { 1654 if (getMaskSet().jitOffset[maskPos] && getMaskSet().validPositions[seekNext(maskPos)] === undefined) { 1655 result = isValid(maskPos + getMaskSet().jitOffset[maskPos], c, strict); 1656 if (result !== false) result.caret = maskPos; 1657 } else for (var nPos = maskPos + 1, snPos = seekNext(maskPos); nPos <= snPos; nPos++) { 1658 result = _isValid(nPos, c, strict); 1659 if (result !== false) { 1660 result = trackbackPositions(maskPos, result.pos !== undefined ? result.pos : nPos) || result; 1661 maskPos = nPos; 1662 break; 1663 } 1664 } 1665 } 1666 } 1667 } 1668 } 1669 if (result === false && opts.keepStatic !== false && (opts.regex == null || isComplete(getBuffer())) && !strict && fromAlternate !== true) { 1670 result = alternate(maskPos, c, strict, fromSetValid); 1671 } 1672 if (result === true) { 1673 result = { 1674 pos: maskPos 1675 }; 1676 } 1677 } 1678 if ($.isFunction(opts.postValidation) && result !== false && !strict && fromSetValid !== true && validateOnly !== true) { 1679 var postResult = opts.postValidation(getBuffer(true), pos.begin !== undefined ? isRTL ? pos.end : pos.begin : pos, result, opts); 1680 if (postResult !== undefined) { 1681 if (postResult.refreshFromBuffer && postResult.buffer) { 1682 var refresh = postResult.refreshFromBuffer; 1683 refreshFromBuffer(refresh === true ? refresh : refresh.start, refresh.end, postResult.buffer); 1684 } 1685 result = postResult === true ? result : postResult; 1686 } 1687 } 1688 if (result && result.pos === undefined) { 1689 result.pos = maskPos; 1690 } 1691 if (result === false || validateOnly === true) { 1692 resetMaskSet(true); 1693 getMaskSet().validPositions = $.extend(true, {}, positionsClone); 1694 } 1695 return result; 1696 } 1697 function trackbackPositions(originalPos, newPos, fillOnly) { 1698 var result; 1699 if (originalPos === undefined) { 1700 for (originalPos = newPos - 1; originalPos > 0; originalPos--) { 1701 if (getMaskSet().validPositions[originalPos]) break; 1702 } 1703 } 1704 for (var ps = originalPos; ps < newPos; ps++) { 1705 if (getMaskSet().validPositions[ps] === undefined && !isMask(ps, true)) { 1706 var vp = ps == 0 ? getTest(ps) : getMaskSet().validPositions[ps - 1]; 1707 if (vp) { 1708 var tests = getTests(ps).slice(); 1709 if (tests[tests.length - 1].match.def === "") tests.pop(); 1710 var bestMatch = determineTestTemplate(ps, tests); 1711 bestMatch = $.extend({}, bestMatch, { 1712 input: getPlaceholder(ps, bestMatch.match, true) || bestMatch.match.def 1713 }); 1714 bestMatch.generatedInput = true; 1715 revalidateMask(ps, bestMatch, true); 1716 if (fillOnly !== true) { 1717 var cvpInput = getMaskSet().validPositions[newPos].input; 1718 getMaskSet().validPositions[newPos] = undefined; 1719 result = isValid(newPos, cvpInput, true, true); 1720 } 1721 } 1722 } 1723 } 1724 return result; 1725 } 1726 function revalidateMask(pos, validTest, fromSetValid, validatedPos) { 1727 function IsEnclosedStatic(pos, valids, selection) { 1728 var posMatch = valids[pos]; 1729 if (posMatch !== undefined && (posMatch.match.fn === null && posMatch.match.optionality !== true || posMatch.input === opts.radixPoint)) { 1730 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]; 1731 return prevMatch && nextMatch; 1732 } 1733 return false; 1734 } 1735 var begin = pos.begin !== undefined ? pos.begin : pos, end = pos.end !== undefined ? pos.end : pos; 1736 if (pos.begin > pos.end) { 1737 begin = pos.end; 1738 end = pos.begin; 1739 } 1740 validatedPos = validatedPos !== undefined ? validatedPos : begin; 1741 if (begin !== end || opts.insertMode && getMaskSet().validPositions[validatedPos] !== undefined && fromSetValid === undefined) { 1742 var positionsClone = $.extend(true, {}, getMaskSet().validPositions), lvp = getLastValidPosition(undefined, true), i; 1743 getMaskSet().p = begin; 1744 for (i = lvp; i >= begin; i--) { 1745 if (getMaskSet().validPositions[i] && getMaskSet().validPositions[i].match.nativeDef === "+") { 1746 opts.isNegative = false; 1747 } 1748 delete getMaskSet().validPositions[i]; 1749 }
1750 var valid = true, j = validatedPos, vps = getMaskSet().validPositions, needsValidation = false, posMatch = j, i = j; 1751 if (validTest) { 1752 getMaskSet().validPositions[validatedPos] = $.extend(true, {}, validTest); 1753 posMatch++; 1754 j++; 1755 if (begin < end) i++; 1756 } 1757 for (;i <= lvp; i++) { 1758 var t = positionsClone[i]; 1759 if (t !== undefined && (i >= end || i >= begin && t.generatedInput !== true && IsEnclosedStatic(i, positionsClone, { 1760 begin: begin, 1761 end: end 1762 }))) { 1763 while (getTest(posMatch).match.def !== "") { 1764 if (needsValidation === false && positionsClone[posMatch] && positionsClone[posMatch].match.nativeDef === t.match.nativeDef) { 1765 getMaskSet().validPositions[posMatch] = $.extend(true, {}, positionsClone[posMatch]); 1766 getMaskSet().validPositions[posMatch].input = t.input; 1767 trackbackPositions(undefined, posMatch, true); 1768 j = posMatch + 1; 1769 valid = true; 1770 } else if (opts.shiftPositions && positionCanMatchDefinition(posMatch, t.match.def)) { 1771 var result = isValid(posMatch, t.input, true, true); 1772 valid = result !== false; 1773 j = result.caret || result.insert ? getLastValidPosition() : posMatch + 1; 1774 needsValidation = true; 1775 } else { 1776 valid = t.generatedInput === true || t.input === opts.radixPoint && opts.numericInput === true; 1777 } 1778 if (valid) break; 1779 if (!valid && posMatch > end && isMask(posMatch, true) && (t.match.fn !== null || posMatch > getMaskSet().maskLength)) { 1780 break; 1781 } 1782 posMatch++; 1783 } 1784 if (getTest(posMatch).match.def == "") valid = false; 1785 posMatch = j; 1786 } 1787 if (!valid) break; 1788 } 1789 if (!valid) { 1790 getMaskSet().validPositions = $.extend(true, {}, positionsClone); 1791 resetMaskSet(true); 1792 return false; 1793 } 1794 } else if (validTest) { 1795 getMaskSet().validPositions[validatedPos] = $.extend(true, {}, validTest); 1796 } 1797 resetMaskSet(true); 1798 return true; 1799 } 1800 function isMask(pos, strict) { 1801 var test = getTestTemplate(pos).match; 1802 if (test.def === "") test = getTest(pos).match; 1803 if (test.fn != null) { 1804 return test.fn; 1805 } 1806 if (strict !== true && pos > -1) { 1807 var tests = getTests(pos); 1808 return tests.length > 1 + (tests[tests.length - 1].match.def === "" ? 1 : 0); 1809 } 1810 return false; 1811 } 1812 function seekNext(pos, newBlock) { 1813 var position = pos + 1; 1814 while (getTest(position).match.def !== "" && (newBlock === true && (getTest(position).match.newBlockMarker !== true || !isMask(position)) || newBlock !== true && !isMask(position))) { 1815 position++; 1816 } 1817 return position; 1818 } 1819 function seekPrevious(pos, newBlock) { 1820 var position = pos, tests; 1821 if (position <= 0) return 0; 1822 while (--position > 0 && (newBlock === true && getTest(position).match.newBlockMarker !== true || newBlock !== true && !isMask(position) && (tests = getTests(position), 1823 tests.length < 2 || tests.length === 2 && tests[1].match.def === ""))) {} 1824 return position; 1825 } 1826 function writeBuffer(input, buffer, caretPos, event, triggerEvents) { 1827 if (event && $.isFunction(opts.onBeforeWrite)) { 1828 var result = opts.onBeforeWrite.call(inputmask, event, buffer, caretPos, opts); 1829 if (result) { 1830 if (result.refreshFromBuffer) { 1831 var refresh = result.refreshFromBuffer; 1832 refreshFromBuffer(refresh === true ? refresh : refresh.start, refresh.end, result.buffer || buffer); 1833 buffer = getBuffer(true); 1834 } 1835 if (caretPos !== undefined) caretPos = result.caret !== undefined ? result.caret : caretPos; 1836 } 1837 } 1838 if (input !== undefined) { 1839 input.inputmask._valueSet(buffer.join("")); 1840 if (caretPos !== undefined && (event === undefined || event.type !== "blur")) { 1841 caret(input, caretPos); 1842 } else renderColorMask(input, caretPos, buffer.length === 0); 1843 if (triggerEvents === true) { 1844 var $input = $(input), nptVal = input.inputmask._valueGet(); 1845 skipInputEvent = true; 1846 $input.trigger("input"); 1847 setTimeout(function() { 1848 if (nptVal === getBufferTemplate().join("")) { 1849 $input.trigger("cleared"); 1850 } else if (isComplete(buffer) === true) { 1851 $input.trigger("complete"); 1852 } 1853 }, 0); 1854 } 1855 } 1856 } 1857 function getPlaceholder(pos, test, returnPL) { 1858 test = test || getTest(pos).match; 1859 if (test.placeholder !== undefined || returnPL === true) { 1860 return $.isFunction(test.placeholder) ? test.placeholder(opts) : test.placeholder; 1861 } else if (test.fn === null) { 1862 if (pos > -1 && getMaskSet().validPositions[pos] === undefined) { 1863 var tests = getTests(pos), staticAlternations = [], prevTest; 1864 if (tests.length > 1 + (tests[tests.length - 1].match.def === "" ? 1 : 0)) { 1865 for (var i = 0; i < tests.length; i++) { 1866 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))) { 1867 staticAlternations.push(tests[i]); 1868 if (tests[i].match.fn === null) prevTest = tests[i]; 1869 if (staticAlternations.length > 1) { 1870 if (/[0-9a-bA-Z]/.test(staticAlternations[0].match.def)) { 1871 return opts.placeholder.charAt(pos % opts.placeholder.length); 1872 } 1873 } 1874 } 1875 } 1876 } 1877 } 1878 return test.def; 1879 } 1880 return opts.placeholder.charAt(pos % opts.placeholder.length); 1881 } 1882 function HandleNativePlaceholder(npt, value) { 1883 if (ie) { 1884 if (npt.inputmask._valueGet() !== value && (npt.placeholder !== value || npt.placeholder === "")) { 1885 var buffer = getBuffer().slice(), nptValue = npt.inputmask._valueGet(); 1886 if (nptValue !== value) { 1887 var lvp = getLastValidPosition(); 1888 if (lvp === -1 && nptValue === getBufferTemplate().join("")) { 1889 buffer = []; 1890 } else if (lvp !== -1) { 1891 clearOptionalTail(buffer); 1892 } 1893 writeBuffer(npt, buffer); 1894 } 1895 } 1896 } else if (npt.placeholder !== value) { 1897 npt.placeholder = value; 1898 if (npt.placeholder === "") npt.removeAttribute("placeholder"); 1899 } 1900 } 1901 var EventRuler = { 1902 on: function(input, eventName, eventHandler) { 1903 var ev = function(e) { 1904 var that = this; 1905 if (that.inputmask === undefined && this.nodeName !== "FORM") { 1906 var imOpts = $.data(that, "_inputmask_opts"); 1907 if (imOpts) new Inputmask(imOpts).mask(that); else EventRuler.off(that); 1908 } 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))) { 1909 e.preventDefault(); 1910 } else { 1911 switch (e.type) { 1912 case "input": 1913 if (skipInputEvent === true) { 1914 skipInputEvent = false; 1915 return e.preventDefault(); 1916 } 1917 if (mobile) { 1918 var args = arguments; 1919 setTimeout(function() { 1920 eventHandler.apply(that, args); 1921 caret(that, that.inputmask.caretPos, undefined, true); 1922 }, 0); 1923 return false; 1924 } 1925 break; 1926 1927 case "keydown": 1928 skipKeyPressEvent = false; 1929 skipInputEvent = false; 1930 break; 1931 1932 case "keypress": 1933 if (skipKeyPressEvent === true) { 1934 return e.preventDefault(); 1935 } 1936 skipKeyPressEvent = true; 1937 break; 1938 1939 case "click": 1940 if (iemobile || iphone) { 1941 var args = arguments; 1942 setTimeout(function() { 1943 eventHandler.apply(that, args); 1944 }, 0); 1945 return false; 1946 } 1947 break; 1948 } 1949 var returnVal = eventHandler.apply(that, arguments); 1950 if (returnVal === false) { 1951 e.preventDefault(); 1952 e.stopPropagation(); 1953 } 1954 return returnVal; 1955 } 1956 }; 1957 input.inputmask.events[eventName] = input.inputmask.events[eventName] || []; 1958 input.inputmask.events[eventName].push(ev); 1959 if ($.inArray(eventName, [ "submit", "reset" ]) !== -1) { 1960 if (input.form !== null) $(input.form).on(eventName, ev); 1961 } else { 1962 $(input).on(eventName, ev); 1963 } 1964 }, 1965 off: function(input, event) { 1966 if (input.inputmask && input.inputmask.events) { 1967 var events; 1968 if (event) { 1969 events = []; 1970 events[event] = input.inputmask.events[event]; 1971 } else { 1972 events = input.inputmask.events; 1973 } 1974 $.each(events, function(eventName, evArr) { 1975 while (evArr.length > 0) { 1976 var ev = evArr.pop();
1977 if ($.inArray(eventName, [ "submit", "reset" ]) !== -1) { 1978 if (input.form !== null) $(input.form).off(eventName, ev); 1979 } else { 1980 $(input).off(eventName, ev); 1981 } 1982 } 1983 delete input.inputmask.events[eventName]; 1984 }); 1985 } 1986 } 1987 }; 1988 var EventHandlers = { 1989 keydownEvent: function(e) { 1990 var input = this, $input = $(input), k = e.keyCode, pos = caret(input); 1991 if (k === Inputmask.keyCode.BACKSPACE || k === Inputmask.keyCode.DELETE || iphone && k === Inputmask.keyCode.BACKSPACE_SAFARI || e.ctrlKey && k === Inputmask.keyCode.X && !isInputEventSupported("cut")) { 1992 e.preventDefault(); 1993 handleRemove(input, k, pos); 1994 writeBuffer(input, getBuffer(true), getMaskSet().p, e, input.inputmask._valueGet() !== getBuffer().join("")); 1995 } else if (k === Inputmask.keyCode.END || k === Inputmask.keyCode.PAGE_DOWN) { 1996 e.preventDefault(); 1997 var caretPos = seekNext(getLastValidPosition()); 1998 caret(input, e.shiftKey ? pos.begin : caretPos, caretPos, true); 1999 } else if (k === Inputmask.keyCode.HOME && !e.shiftKey || k === Inputmask.keyCode.PAGE_UP) { 2000 e.preventDefault(); 2001 caret(input, 0, e.shiftKey ? pos.begin : 0, true); 2002 } else if ((opts.undoOnEscape && k === Inputmask.keyCode.ESCAPE || k === 90 && e.ctrlKey) && e.altKey !== true) { 2003 checkVal(input, true, false, undoValue.split("")); 2004 $input.trigger("click"); 2005 } else if (k === Inputmask.keyCode.INSERT && !(e.shiftKey || e.ctrlKey)) { 2006 opts.insertMode = !opts.insertMode; 2007 input.setAttribute("im-insert", opts.insertMode); 2008 } else if (opts.tabThrough === true && k === Inputmask.keyCode.TAB) { 2009 if (e.shiftKey === true) { 2010 if (getTest(pos.begin).match.fn === null) { 2011 pos.begin = seekNext(pos.begin); 2012 } 2013 pos.end = seekPrevious(pos.begin, true); 2014 pos.begin = seekPrevious(pos.end, true); 2015 } else { 2016 pos.begin = seekNext(pos.begin, true); 2017 pos.end = seekNext(pos.begin, true); 2018 if (pos.end < getMaskSet().maskLength) pos.end--; 2019 } 2020 if (pos.begin < getMaskSet().maskLength) { 2021 e.preventDefault(); 2022 caret(input, pos.begin, pos.end); 2023 } 2024 } 2025 opts.onKeyDown.call(this, e, getBuffer(), caret(input).begin, opts); 2026 ignorable = $.inArray(k, opts.ignorables) !== -1; 2027 }, 2028 keypressEvent: function(e, checkval, writeOut, strict, ndx) { 2029 var input = this, $input = $(input), k = e.which || e.charCode || e.keyCode; 2030 if (checkval !== true && (!(e.ctrlKey && e.altKey) && (e.ctrlKey || e.metaKey || ignorable))) { 2031 if (k === Inputmask.keyCode.ENTER && undoValue !== getBuffer().join("")) { 2032 undoValue = getBuffer().join(""); 2033 setTimeout(function() { 2034 $input.trigger("change"); 2035 }, 0); 2036 } 2037 return true; 2038 } else { 2039 if (k) { 2040 if (k === 46 && e.shiftKey === false && opts.radixPoint !== "") k = opts.radixPoint.charCodeAt(0); 2041 var pos = checkval ? { 2042 begin: ndx, 2043 end: ndx 2044 } : caret(input), forwardPosition, c = String.fromCharCode(k), offset = 0; 2045 if (opts._radixDance && opts.numericInput) { 2046 var caretPos = getBuffer().indexOf(opts.radixPoint.charAt(0)) + 1; 2047 if (pos.begin <= caretPos) { 2048 if (k === opts.radixPoint.charCodeAt(0)) offset = 1; 2049 pos.begin -= 1; 2050 pos.end -= 1; 2051 } 2052 } 2053 getMaskSet().writeOutBuffer = true; 2054 var valResult = isValid(pos, c, strict); 2055 if (valResult !== false) { 2056 resetMaskSet(true); 2057 forwardPosition = valResult.caret !== undefined ? valResult.caret : seekNext(valResult.pos.begin ? valResult.pos.begin : valResult.pos); 2058 getMaskSet().p = forwardPosition; 2059 } 2060 forwardPosition = (opts.numericInput && valResult.caret === undefined ? seekPrevious(forwardPosition) : forwardPosition) + offset; 2061 if (writeOut !== false) { 2062 setTimeout(function() { 2063 opts.onKeyValidation.call(input, k, valResult, opts); 2064 }, 0); 2065 if (getMaskSet().writeOutBuffer && valResult !== false) { 2066 var buffer = getBuffer(); 2067 writeBuffer(input, buffer, forwardPosition, e, checkval !== true); 2068 } 2069 } 2070 e.preventDefault(); 2071 if (checkval) { 2072 if (valResult !== false) valResult.forwardPosition = forwardPosition; 2073 return valResult; 2074 } 2075 } 2076 } 2077 }, 2078 pasteEvent: function(e) { 2079 var input = this, ev = e.originalEvent || e, $input = $(input), inputValue = input.inputmask._valueGet(true), caretPos = caret(input), tempValue; 2080 if (isRTL) { 2081 tempValue = caretPos.end; 2082 caretPos.end = caretPos.begin; 2083 caretPos.begin = tempValue; 2084 } 2085 var valueBeforeCaret = inputValue.substr(0, caretPos.begin), valueAfterCaret = inputValue.substr(caretPos.end, inputValue.length); 2086 if (valueBeforeCaret === (isRTL ? getBufferTemplate().reverse() : getBufferTemplate()).slice(0, caretPos.begin).join("")) valueBeforeCaret = ""; 2087 if (valueAfterCaret === (isRTL ? getBufferTemplate().reverse() : getBufferTemplate()).slice(caretPos.end).join("")) valueAfterCaret = ""; 2088 if (window.clipboardData && window.clipboardData.getData) { 2089 inputValue = valueBeforeCaret + window.clipboardData.getData("Text") + valueAfterCaret; 2090 } else if (ev.clipboardData && ev.clipboardData.getData) { 2091 inputValue = valueBeforeCaret + ev.clipboardData.getData("text/plain") + valueAfterCaret; 2092 } else return true; 2093 var pasteValue = inputValue; 2094 if ($.isFunction(opts.onBeforePaste)) { 2095 pasteValue = opts.onBeforePaste.call(inputmask, inputValue, opts); 2096 if (pasteValue === false) { 2097 return e.preventDefault(); 2098 } 2099 if (!pasteValue) { 2100 pasteValue = inputValue; 2101 } 2102 } 2103 checkVal(input, false, false, pasteValue.toString().split("")); 2104 writeBuffer(input, getBuffer(), seekNext(getLastValidPosition()), e, undoValue !== getBuffer().join("")); 2105 return e.preventDefault(); 2106 }, 2107 inputFallBackEvent: function(e) { 2108 function radixPointHandler(input, inputValue, caretPos) { 2109 if (inputValue.charAt(caretPos.begin - 1) === "." && opts.radixPoint !== "") { 2110 inputValue = inputValue.split(""); 2111 inputValue[caretPos.begin - 1] = opts.radixPoint.charAt(0);
2112 inputValue = inputValue.join(""); 2113 } 2114 return inputValue; 2115 } 2116 function ieMobileHandler(input, inputValue, caretPos) { 2117 if (iemobile) { 2118 var inputChar = inputValue.replace(getBuffer().join(""), ""); 2119 if (inputChar.length === 1) { 2120 var iv = inputValue.split(""); 2121 iv.splice(caretPos.begin, 0, inputChar); 2122 inputValue = iv.join(""); 2123 } 2124 } 2125 return inputValue; 2126 } 2127 var input = this, inputValue = input.inputmask._valueGet(); 2128 if (getBuffer().join("") !== inputValue) { 2129 var caretPos = caret(input); 2130 inputValue = radixPointHandler(input, inputValue, caretPos); 2131 inputValue = ieMobileHandler(input, inputValue, caretPos); 2132 if (getBuffer().join("") !== inputValue) { 2133 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); 2134 var selection = caretPos, entries = "", isEntry = false; 2135 if (frontPart !== frontBufferPart) { 2136 var fpl = (isEntry = frontPart.length >= frontBufferPart.length) ? frontPart.length : frontBufferPart.length, i; 2137 for (i = 0; frontPart.charAt(i) === frontBufferPart.charAt(i) && i < fpl; i++) ; 2138 if (isEntry) { 2139 selection.begin = i - offset; 2140 entries += frontPart.slice(i, selection.end); 2141 } 2142 } 2143 if (backPart !== backBufferPart) { 2144 if (backPart.length > backBufferPart.length) { 2145 entries += backPart.slice(0, 1); 2146 } else { 2147 if (backPart.length < backBufferPart.length) { 2148 selection.end += backBufferPart.length - backPart.length; 2149 if (!isEntry && opts.radixPoint !== "" && backPart === "" && frontPart.charAt(selection.begin + offset - 1) === opts.radixPoint) { 2150 selection.begin--; 2151 entries = opts.radixPoint; 2152 } 2153 } 2154 } 2155 } 2156 writeBuffer(input, getBuffer(), { 2157 begin: selection.begin + offset, 2158 end: selection.end + offset 2159 }); 2160 if (entries.length > 0) { 2161 $.each(entries.split(""), function(ndx, entry) { 2162 var keypress = new $.Event("keypress"); 2163 keypress.which = entry.charCodeAt(0); 2164 ignorable = false; 2165 EventHandlers.keypressEvent.call(input, keypress); 2166 }); 2167 } else { 2168 if (selection.begin === selection.end - 1) { 2169 selection.begin = seekPrevious(selection.begin + 1); 2170 if (selection.begin === selection.end - 1) { 2171 caret(input, selection.begin); 2172 } else { 2173 caret(input, selection.begin, selection.end); 2174 } 2175 }
2176 var keydown = new $.Event("keydown"); 2177 keydown.keyCode = opts.numericInput ? Inputmask.keyCode.BACKSPACE : Inputmask.keyCode.DELETE; 2178 EventHandlers.keydownEvent.call(input, keydown); 2179 } 2180 e.preventDefault(); 2181 } 2182 } 2183 }, 2184 beforeInputEvent: function(e) { 2185 if (e.cancelable) { 2186 var input = this; 2187 switch (e.inputType) { 2188 case "insertText": 2189 $.each(e.data.split(""), function(ndx, entry) { 2190 var keypress = new $.Event("keypress"); 2191 keypress.which = entry.charCodeAt(0); 2192 ignorable = false; 2193 EventHandlers.keypressEvent.call(input, keypress); 2194 }); 2195 return e.preventDefault(); 2196 2197 case "deleteContentBackward": 2198 var keydown = new $.Event("keydown"); 2199 keydown.keyCode = Inputmask.keyCode.BACKSPACE; 2200 EventHandlers.keydownEvent.call(input, keydown); 2201 return e.preventDefault(); 2202 2203 case "deleteContentForward": 2204 var keydown = new $.Event("keydown"); 2205 keydown.keyCode = Inputmask.keyCode.DELETE; 2206 EventHandlers.keydownEvent.call(input, keydown); 2207 return e.preventDefault(); 2208 } 2209 } 2210 }, 2211 setValueEvent: function(e) { 2212 this.inputmask.refreshValue = false; 2213 var input = this, value = e && e.detail ? e.detail[0] : arguments[1], value = value || input.inputmask._valueGet(true); 2214 if ($.isFunction(opts.onBeforeMask)) value = opts.onBeforeMask.call(inputmask, value, opts) || value; 2215 value = value.toString().split(""); 2216 checkVal(input, true, false, value); 2217 undoValue = getBuffer().join(""); 2218 if ((opts.clearMaskOnLostFocus || opts.clearIncomplete) && input.inputmask._valueGet() === getBufferTemplate().join("")) { 2219 input.inputmask._valueSet(""); 2220 } 2221 }, 2222 focusEvent: function(e) { 2223 var input = this, nptValue = input.inputmask._valueGet(); 2224 if (opts.showMaskOnFocus) { 2225 if (nptValue !== getBuffer().join("")) { 2226 writeBuffer(input, getBuffer(), seekNext(getLastValidPosition())); 2227 } else if (mouseEnter === false) { 2228 caret(input, seekNext(getLastValidPosition())); 2229 } 2230 } 2231 if (opts.positionCaretOnTab === true && mouseEnter === false) { 2232 EventHandlers.clickEvent.apply(input, [ e, true ]); 2233 } 2234 undoValue = getBuffer().join(""); 2235 }, 2236 mouseleaveEvent: function(e) { 2237 var input = this; 2238 mouseEnter = false; 2239 if (opts.clearMaskOnLostFocus && document.activeElement !== input) { 2240 HandleNativePlaceholder(input, originalPlaceholder); 2241 } 2242 }, 2243 clickEvent: function(e, tabbed) { 2244 function doRadixFocus(clickPos) { 2245 if (opts.radixPoint !== "") { 2246 var vps = getMaskSet().validPositions; 2247 if (vps[clickPos] === undefined || vps[clickPos].input === getPlaceholder(clickPos)) { 2248 if (clickPos < seekNext(-1)) return true; 2249 var radixPos = $.inArray(opts.radixPoint, getBuffer()); 2250 if (radixPos !== -1) { 2251 for (var vp in vps) { 2252 if (radixPos < vp && vps[vp].input !== getPlaceholder(vp)) { 2253 return false; 2254 } 2255 } 2256 return true; 2257 } 2258 } 2259 } 2260 return false; 2261 } 2262 var input = this; 2263 setTimeout(function() { 2264 if (document.activeElement === input) { 2265 var selectedCaret = caret(input); 2266 if (tabbed) { 2267 if (isRTL) { 2268 selectedCaret.end = selectedCaret.begin; 2269 } else { 2270 selectedCaret.begin = selectedCaret.end; 2271 } 2272 } 2273 if (selectedCaret.begin === selectedCaret.end) { 2274 switch (opts.positionCaretOnClick) { 2275 case "none": 2276 break; 2277 2278 case "select": 2279 caret(input, 0, getBuffer().length); 2280 break; 2281 2282 case "ignore": 2283 caret(input, seekNext(getLastValidPosition())); 2284 break; 2285 2286 case "radixFocus": 2287 if (doRadixFocus(selectedCaret.begin)) { 2288 var radixPos = getBuffer().join("").indexOf(opts.radixPoint); 2289 caret(input, opts.numericInput ? seekNext(radixPos) : radixPos); 2290 break; 2291 } 2292 2293 default: 2294 var clickPosition = selectedCaret.begin, lvclickPosition = getLastValidPosition(clickPosition, true), lastPosition = seekNext(lvclickPosition); 2295 if (clickPosition < lastPosition) { 2296 caret(input, !isMask(clickPosition, true) && !isMask(clickPosition - 1, true) ? seekNext(clickPosition) : clickPosition); 2297 } else { 2298 var lvp = getMaskSet().validPositions[lvclickPosition], tt = getTestTemplate(lastPosition, lvp ? lvp.match.locator : undefined, lvp), placeholder = getPlaceholder(lastPosition, tt.match); 2299 if (placeholder !== "" && getBuffer()[lastPosition] !== placeholder && tt.match.optionalQuantifier !== true && tt.match.newBlockMarker !== true || !isMask(lastPosition, opts.keepStatic) && tt.match.def === placeholder) { 2300 var newPos = seekNext(lastPosition); 2301 if (clickPosition >= newPos || clickPosition === lastPosition) { 2302 lastPosition = newPos; 2303 } 2304 } 2305 caret(input, lastPosition); 2306 } 2307 break; 2308 } 2309 } 2310 } 2311 }, 0); 2312 }, 2313 cutEvent: function(e) { 2314 var input = this, $input = $(input), pos = caret(input), ev = e.originalEvent || e; 2315 var clipboardData = window.clipboardData || ev.clipboardData, clipData = isRTL ? getBuffer().slice(pos.end, pos.begin) : getBuffer().slice(pos.begin, pos.end); 2316 clipboardData.setData("text", isRTL ? clipData.reverse().join("") : clip
2316Data.join("")); 2317 if (document.execCommand) document.execCommand("copy"); 2318 handleRemove(input, Inputmask.keyCode.DELETE, pos); 2319 writeBuffer(input, getBuffer(), getMaskSet().p, e, undoValue !== getBuffer().join("")); 2320 }, 2321 blurEvent: function(e) { 2322 var $input = $(this), input = this; 2323 if (input.inputmask) { 2324 HandleNativePlaceholder(input, originalPlaceholder); 2325 var nptValue = input.inputmask._valueGet(), buffer = getBuffer().slice(); 2326 if (nptValue !== "" || colorMask !== undefined) { 2327 if (opts.clearMaskOnLostFocus) { 2328 if (getLastValidPosition() === -1 && nptValue === getBufferTemplate().join("")) { 2329 buffer = []; 2330 } else { 2331 clearOptionalTail(buffer); 2332 } 2333 } 2334 if (isComplete(buffer) === false) { 2335 setTimeout(function() { 2336 $input.trigger("incomplete"); 2337 }, 0); 2338 if (opts.clearIncomplete) { 2339 resetMaskSet(); 2340 if (opts.clearMaskOnLostFocus) { 2341 buffer = []; 2342 } else { 2343 buffer = getBufferTemplate().slice(); 2344 } 2345 } 2346 } 2347 writeBuffer(input, buffer, undefined, e); 2348 } 2349 if (undoValue !== getBuffer().join("")) { 2350 undoValue = buffer.join(""); 2351 $input.trigger("change"); 2352 } 2353 } 2354 }, 2355 mouseenterEvent: function(e) { 2356 var input = this; 2357 mouseEnter = true; 2358 if (document.activeElement !== input && opts.showMaskOnHover) { 2359 HandleNativePlaceholder(input, (isRTL ? getBuffer().slice().reverse() : getBuffer()).join("")); 2360 } 2361 }, 2362 submitEvent: function(e) { 2363 if (undoValue !== getBuffer().join("")) { 2364 $el.trigger("change"); 2365 } 2366 if (opts.clearMaskOnLostFocus && getLastValidPosition() === -1 && el.inputmask._valueGet && el.inputmask._valueGet() === getBufferTemplate().join("")) { 2367 el.inputmask._valueSet(""); 2368 } 2369 if (opts.clearIncomplete && isComplete(getBuffer()) === false) { 2370 el.inputmask._valueSet(""); 2371 } 2372 if (opts.removeMaskOnSubmit) { 2373 el.inputmask._valueSet(el.inputmask.unmaskedvalue(), true); 2374 setTimeout(function() { 2375 writeBuffer(el, getBuffer()); 2376 }, 0); 2377 } 2378 }, 2379 resetEvent: function(e) { 2380 el.inputmask.refreshValue = true; 2381 setTimeout(function() { 2382 $el.trigger("setvalue"); 2383 }, 0); 2384 } 2385 }; 2386 function checkVal(input, writeOut, strict, nptvl, initiatingEvent) { 2387 var inputmask = this || input.inputmask, inputValue = nptvl.slice(), charCodes = "", initialNdx = -1, result = undefined; 2388 function isTemplateMatch(ndx, charCodes) { 2389 var charCodeNdx = getMaskTemplate(true, 0, false).slice(ndx, seekNext(ndx)).join("").replace(/'/g, "").indexOf(charCodes); 2390 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))); 2391 } 2392 resetMaskSet(); 2393 if (!strict && opts.autoUnmask !== true) { 2394 var staticInput = getBufferTemplate().slice(0, seekNext(-1)).join(""), matches = inputValue.join("").match(new RegExp("^" + Inputmask.escapeRegex(staticInput), "g")); 2395 if (matches && matches.length > 0) { 2396 inputValue.splice(0, matches.length * staticInput.length); 2397 initialNdx = seekNext(initialNdx); 2398 } 2399 } else { 2400 initialNdx = seekNext(initialNdx); 2401 } 2402 if (initialNdx === -1) { 2403 getMaskSet().p = seekNext(initialNdx); 2404 initialNdx = 0; 2405 } else getMaskSet().p = initialNdx; 2406 inputmask.caretPos = { 2407 begin: initialNdx 2408 };
2409 $.each(inputValue, function(ndx, charCode) { 2410 if (charCode !== undefined) { 2411 if (getMaskSet().validPositions[ndx] === undefined && inputValue[ndx] === getPlaceholder(ndx) && isMask(ndx, true) && isValid(ndx, inputValue[ndx], true, undefined, undefined, true) === false) { 2412 getMaskSet().p++; 2413 } else { 2414 var keypress = new $.Event("_checkval"); 2415 keypress.which = charCode.charCodeAt(0); 2416 charCodes += charCode; 2417 var lvp = getLastValidPosition(undefined, true); 2418 if (!isTemplateMatch(initialNdx, charCodes)) { 2419 result = EventHandlers.keypressEvent.call(input, keypress, true, false, strict, inputmask.caretPos.begin); 2420 if (result) { 2421 initialNdx = inputmask.caretPos.begin + 1; 2422 charCodes = ""; 2423 } 2424 } else { 2425 result = EventHandlers.keypressEvent.call(input, keypress, true, false, strict, lvp + 1); 2426 } 2427 if (result) { 2428 writeBuffer(undefined, getBuffer(), result.forwardPosition, keypress, false); 2429 inputmask.caretPos = { 2430 begin: result.forwardPosition, 2431 end: result.forwardPosition 2432 }; 2433 } 2434 } 2435 } 2436 }); 2437 if (writeOut) writeBuffer(input, getBuffer(), result ? result.forwardPosition : undefined, initiatingEvent || new $.Event("checkval"), initiatingEvent && initiatingEvent.type === "input"); 2438 } 2439 function unmaskedvalue(input) { 2440 if (input) { 2441 if (input.inputmask === undefined) { 2442 return input.value; 2443 } 2444 if (input.inputmask && input.inputmask.refreshValue) { 2445 EventHandlers.setValueEvent.call(input); 2446 } 2447 } 2448 var umValue = [], vps = getMaskSet().validPositions; 2449 for (var pndx in vps) { 2450 if (vps[pndx].match && vps[pndx].match.fn != null) { 2451 umValue.push(vps[pndx].input); 2452 } 2453 } 2454 var unmaskedValue = umValue.length === 0 ? "" : (isRTL ? umValue.reverse() : umValue).join(""); 2455 if ($.isFunction(opts.onUnMask)) { 2456 var bufferValue = (isRTL ? getBuffer().slice().reverse() : getBuffer()).join(""); 2457 unmaskedValue = opts.onUnMask.call(inputmask, bufferValue, unmaskedValue, opts); 2458 } 2459 return unmaskedValue; 2460 } 2461 function caret(input, begin, end, notranslate) { 2462 function translatePosition(pos) { 2463 if (isRTL && typeof pos === "number" && (!opts.greedy || opts.placeholder !== "") && el) { 2464 pos = el.inputmask._valueGet().length - pos; 2465 } 2466 return pos; 2467 } 2468 var range; 2469 if (begin !== undefined) { 2470 if ($.isArray(begin)) { 2471 end = isRTL ? begin[0] : begin[1]; 2472 begin = isRTL ? begin[1] : begin[0]; 2473 } 2474 if (begin.begin !== undefined) { 2475 end = isRTL ? begin.begin : begin.end; 2476 begin = isRTL ? begin.end : begin.begin; 2477 } 2478 if (typeof begin === "number") { 2479 begin = notranslate ? begin : translatePosition(begin); 2480 end = notranslate ? end : translatePosition(end); 2481 end = typeof end == "number" ? end : begin; 2482 var scrollCalc = parseInt(((input.ownerDocument.defaultView || window).getComputedStyle ? (input.ownerDocument.defaultView || window).getComputedStyle(input, null) : input.currentStyle).fontSize) * end; 2483 input.scrollLeft = scrollCalc > input.scrollWidth ? scrollCalc : 0; 2484 input.inputmask.caretPos = { 2485 begin: begin, 2486 end: end 2487 }; 2488 if (input === document.activeElement) { 2489 if ("selectionStart" in input) { 2490 input.selectionStart = begin; 2491 input.selectionEnd = end; 2492 } else if (window.getSelection) { 2493 range = document.createRange(); 2494 if (input.firstChild === undefined || input.firstChild === null) { 2495 var textNode = document.createTextNode(""); 2496 input.appendChild(textNode); 2497 } 2498 range.setStart(input.firstChild, begin < input.inputmask._valueGet().length ? begin : input.inputmask._valueGet().length); 2499 range.setEnd(input.firstChild, end < input.inputmask._valueGet().length ? end : input.inputmask._valueGet().length); 2500 range.collapse(true); 2501 var sel = window.getSelection(); 2502 sel.removeAllRanges(); 2503 sel.addRange(range); 2504 } else if (input.createTextRange) { 2505 range = input.createTextRange(); 2506 range.collapse(true); 2507 range.moveEnd("character", end); 2508 range.moveStart("character", begin); 2509 range.select(); 2510 } 2511 renderColorMask(input, { 2512 begin: begin, 2513 end: end 2514 }); 2515 } 2516 } 2517 } else { 2518 if ("selectionStart" in input) { 2519 begin = input.selectionStart; 2520 end = input.selectionEnd; 2521 } else if (window.getSelection) { 2522 range = window.getSelection().getRangeAt(0);
2523 if (range.commonAncestorContainer.parentNode === input || range.commonAncestorContainer === input) { 2524 begin = range.startOffset; 2525 end = range.endOffset; 2526 } 2527 } else if (document.selection && document.selection.createRange) { 2528 range = document.selection.createRange(); 2529 begin = 0 - range.duplicate().moveStart("character", -input.inputmask._valueGet().length); 2530 end = begin + range.text.length; 2531 } 2532 return { 2533 begin: notranslate ? begin : translatePosition(begin), 2534 end: notranslate ? end : translatePosition(end) 2535 }; 2536 } 2537 } 2538 function determineLastRequiredPosition(returnDefinition) { 2539 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; 2540 for (pos = lvp + 1; pos < buffer.length; pos++) { 2541 testPos = getTestTemplate(pos, ndxIntlzr, pos - 1); 2542 ndxIntlzr = testPos.locator.slice(); 2543 positions[pos] = $.extend(true, {}, testPos); 2544 } 2545 var lvTestAlt = lvTest && lvTest.alternation !== undefined ? lvTest.locator[lvTest.alternation] : undefined; 2546 for (pos = bl - 1; pos > lvp; pos--) { 2547 testPos = positions[pos]; 2548 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)) { 2549 bl--; 2550 } else break; 2551 } 2552 return returnDefinition ? { 2553 l: bl, 2554 def: positions[bl] ? positions[bl].match : undefined 2555 } : bl; 2556 } 2557 function clearOptionalTail(buffer) { 2558 buffer.length = 0; 2559 var template = getMaskTemplate(true, 0, true, undefined, true), lmnt, validPos; 2560 while (lmnt = template.shift(), lmnt !== undefined) buffer.push(lmnt); 2561 return buffer; 2562 } 2563 function isComplete(buffer) { 2564 if ($.isFunction(opts.isComplete)) return opts.isComplete(buffer, opts); 2565 if (opts.repeat === "*") return undefined; 2566 var complete = false, lrp = determineLastRequiredPosition(true), aml = seekPrevious(lrp.l); 2567 if (lrp.def === undefined || lrp.def.newBlockMarker || lrp.def.optionality || lrp.def.optionalQuantifier) { 2568 complete = true; 2569 for (var i = 0; i <= aml; i++) { 2570 var test = getTestTemplate(i).match; 2571 if (test.fn !== null && getMaskSet().validPositions[i] === undefined && test.optionality !== true && test.optionalQuantifier !== true || test.fn === null && buffer[i] !== getPlaceholder(i, test)) { 2572 complete = false; 2573 break; 2574 } 2575 } 2576 } 2577 return complete; 2578 } 2579 function handleRemove(input, k, pos, strict, fromIsValid) { 2580 if (opts.numericInput || isRTL) { 2581 if (k === Inputmask.keyCode.BACKSPACE) { 2582 k = Inputmask.keyCode.DELETE; 2583 } else if (k === Inputmask.keyCode.DELETE) { 2584 k = Inputmask.keyCode.BACKSPACE; 2585 } 2586 if (isRTL) { 2587 var pend = pos.end; 2588 pos.end = pos.begin; 2589 pos.begin = pend; 2590 } 2591 } 2592 if (k === Inputmask.keyCode.BACKSPACE && pos.end - pos.begin < 1) { 2593 pos.begin = seekPrevious(pos.begin); 2594 if (getMaskSet().validPositions[pos.begin] !== undefined && getMaskSet().validPositions[pos.begin].input === opts.groupSeparator) { 2595 pos.begin--; 2596 } 2597 } else if (k === Inputmask.keyCode.DELETE && pos.begin === pos.end) { 2598 pos.end = isMask(pos.end, true) && (getMaskSet().validPositions[pos.end] && getMaskSet().validPositions[pos.end].input !== opts.radixPoint) ? pos.end + 1 : seekNext(pos.end) + 1; 2599 if (getMaskSet().validPositions[pos.begin] !== undefined && getMaskSet().validPositions[pos.begin].input === opts.groupSeparator) { 2600 pos.end++; 2601 } 2602 } 2603 revalidateMask(pos); 2604 if (strict !== true && opts.keepStatic !== false || opts.regex !== null) { 2605 var result = alternate(true); 2606 if (result) { 2607 var newPos = result.caret !== undefined ? result.caret : result.pos ? seekNext(result.pos.begin ? result.pos.begin : result.pos) : getLastValidPosition(-1, true); 2608 if (k !== Inputmask.keyCode.DELETE || pos.begin > newPos) { 2609 pos.begin == newPos; 2610 } 2611 } 2612 } 2613 var lvp = getLastValidPosition(pos.begin, true); 2614 if (lvp < pos.begin || pos.begin === -1) { 2615 getMaskSet().p = seekNext(lvp);
2616 } else if (strict !== true) { 2617 getMaskSet().p = pos.begin; 2618 if (fromIsValid !== true) { 2619 while (getMaskSet().p < lvp && getMaskSet().validPositions[getMaskSet().p] === undefined) { 2620 getMaskSet().p++; 2621 } 2622 } 2623 } 2624 } 2625 function initializeColorMask(input) { 2626 var computedStyle = (input.ownerDocument.defaultView || window).getComputedStyle(input, null); 2627 function findCaretPos(clientx) { 2628 var e = document.createElement("span"), caretPos; 2629 for (var style in computedStyle) { 2630 if (isNaN(style) && style.indexOf("font") !== -1) { 2631 e.style[style] = computedStyle[style]; 2632 } 2633 } 2634 e.style.textTransform = computedStyle.textTransform; 2635 e.style.letterSpacing = computedStyle.letterSpacing; 2636 e.style.position = "absolute"; 2637 e.style.height = "auto"; 2638 e.style.width = "auto"; 2639 e.style.visibility = "hidden"; 2640 e.style.whiteSpace = "nowrap"; 2641 document.body.appendChild(e); 2642 var inputText = input.inputmask._valueGet(), previousWidth = 0, itl; 2643 for (caretPos = 0, itl = inputText.length; caretPos <= itl; caretPos++) { 2644 e.innerHTML += inputText.charAt(caretPos) || "_"; 2645 if (e.offsetWidth >= clientx) { 2646 var offset1 = clientx - previousWidth; 2647 var offset2 = e.offsetWidth - clientx; 2648 e.innerHTML = inputText.charAt(caretPos); 2649 offset1 -= e.offsetWidth / 3; 2650 caretPos = offset1 < offset2 ? caretPos - 1 : caretPos; 2651 break; 2652 } 2653 previousWidth = e.offsetWidth; 2654 } 2655 document.body.removeChild(e); 2656 return caretPos; 2657 } 2658 var template = document.createElement("div"); 2659 template.style.width = computedStyle.width; 2660 template.style.textAlign = computedStyle.textAlign; 2661 colorMask = document.createElement("div"); 2662 input.inputmask.colorMask = colorMask; 2663 colorMask.className = "im-colormask"; 2664 input.parentNode.insertBefore(colorMask, input); 2665 input.parentNode.removeChild(input); 2666 colorMask.appendChild(input); 2667 colorMask.appendChild(template); 2668 input.style.left = template.offsetLeft + "px"; 2669 $(colorMask).on("mouseleave", function(e) { 2670 return EventHandlers.mouseleaveEvent.call(input, [ e ]); 2671 }); 2672 $(colorMask).on("mouseenter", function(e) { 2673 return EventHandlers.mouseenterEvent.call(input, [ e ]); 2674 }); 2675 $(colorMask).on("click", function(e) { 2676 caret(input, findCaretPos(e.clientX)); 2677 return EventHandlers.clickEvent.call(input, [ e ]); 2678 }); 2679 } 2680 function renderColorMask(input, caretPos, clear) { 2681 var maskTemplate = [], isStatic = false, test, testPos, ndxIntlzr, pos = 0; 2682 function setEntry(entry) { 2683 if (entry === undefined) entry = ""; 2684 if (!isStatic && (test.fn === null || testPos.input === undefined)) { 2685 isStatic = true; 2686 maskTemplate.push("<span class='im-static'>" + entry); 2687 } else if (isStatic && (test.fn !== null && testPos.input !== undefined || test.def === "")) { 2688 isStatic = false; 2689 var mtl = maskTemplate.length; 2690 maskTemplate[mtl - 1] = maskTemplate[mtl - 1] + "</span>"; 2691 maskTemplate.push(entry); 2692 } else maskTemplate.push(entry); 2693 } 2694 function setCaret() { 2695 if (document.activeElement === input) { 2696 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">'); 2697 maskTemplate.splice(caretPos.end + 1, 0, "</mark>"); 2698 } 2699 } 2700 if (colorMask !== undefined) { 2701 var buffer = getBuffer(); 2702 if (caretPos === undefined) { 2703 caretPos = caret(input); 2704 } else if (caretPos.begin === undefined) { 2705 caretPos = { 2706 begin: caretPos, 2707 end: caretPos 2708 }; 2709 } 2710 if (clear !== true) { 2711 var lvp = getLastValidPosition(); 2712 do { 2713 if (getMaskSet().validPositions[pos]) { 2714 testPos = getMaskSet().validPositions[pos]; 2715 test = testPos.match; 2716 ndxIntlzr = testPos.locator.slice(); 2717 setEntry(buffer[pos]); 2718 } else { 2719 testPos = getTestTemplate(pos, ndxIntlzr, pos - 1); 2720 test = testPos.match; 2721 ndxIntlzr = testPos.locator.slice(); 2722 if (opts.jitMasking === false || pos < lvp || typeof opts.jitMasking === "number" && isFinite(opts.jitMasking) && opts.jitMasking > pos) { 2723 setEntry(getPlaceholder(pos, test)); 2724 } else isStatic = false; 2725 } 2726 pos++; 2727 } while ((maxLength === undefined || pos < maxLength) && (test.fn !== null || test.def !== "") || lvp > pos || isStatic); 2728 if (isStatic) setEntry(); 2729 setCaret(); 2730 } 2731 var template = colorMask.getElementsByTagName("div")[0]; 2732 template.innerHTML = maskTemplate.join(""); 2733 input.inputmask.positionColorMask(input, template); 2734 } 2735 } 2736 function mask(elem) { 2737 function isElementTypeSupported(input, opts) { 2738 function patchValueProperty(npt) { 2739 var valueGet; 2740 var valueSet; 2741 function patchValhook(type) { 2742 if ($.valHooks && ($.valHooks[type] === undefined || $.valHooks[type].inputmaskpatch !== true)) { 2743 var valhookGet = $.valHooks[type] && $.valHooks[type].get ? $.valHooks[type].get : function(elem) { 2744 return elem.value; 2745 }; 2746 var valhookSet = $.valHooks[type] && $.valHooks[type].set ? $.valHooks[type].set : function(elem, value) { 2747 elem.value = value; 2748 return elem; 2749 }; 2750 $.valHooks[type] = { 2751 get: function(elem) { 2752 if (elem.inputmask) { 2753 if (elem.inputmask.opts.autoUnmask) { 2754 return elem.inputmask.unmaskedvalue(); 2755 } else { 2756 var result = valhookGet(elem); 2757 return getLastValidPosition(undefined, undefined, elem.inputmask.maskset.validPositions) !== -1 || opts.nullable !== true ? result : ""; 2758 } 2759 } else return valhookGet(elem); 2760 }, 2761 set: function(elem, value) { 2762 var $elem = $(elem), result; 2763 result = valhookSet(elem, value); 2764 if (elem.inputmask) { 2765 $elem.trigger("setvalue", [ value ]); 2766 } 2767 return result; 2768 }, 2769 inputmaskpatch: true 2770 }; 2771 } 2772 } 2773 function getter() { 2774 if (this.inputmask) { 2775 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) : ""; 2776 } else return valueGet.call(this); 2777 } 2778 function setter(value) { 2779 valueSet.call(this, value); 2780 if (this.inputmask) { 2781 $(this).trigger("setvalue", [ value ]); 2782 } 2783 } 2784 function installNativeValueSetFallback(npt) { 2785 EventRuler.on(npt, "mouseenter", function(event) { 2786 var $input = $(this), input = this, value = input.inputmask._valueGet(); 2787 if (value !== getBuffer().join("")) { 2788 $input.trigger("setvalue"); 2789 } 2790 }); 2791 } 2792 if (!npt.inputmask.__valueGet) { 2793 if (opts.noValuePatching !== true) { 2794 if (Object.getOwnPropertyDescriptor) { 2795 if (typeof Object.getPrototypeOf
2795!== "function") { 2796 Object.getPrototypeOf = typeof "test".__proto__ === "object" ? function(object) { 2797 return object.__proto__; 2798 } : function(object) { 2799 return object.constructor.prototype; 2800 }; 2801 } 2802 var valueProperty = Object.getPrototypeOf ? Object.getOwnPropertyDescriptor(Object.getPrototypeOf(npt), "value") : undefined; 2803 if (valueProperty && valueProperty.get && valueProperty.set) { 2804 valueGet = valueProperty.get; 2805 valueSet = valueProperty.set; 2806 Object.defineProperty(npt, "value", { 2807 get: getter, 2808 set: setter, 2809 configurable: true 2810 }); 2811 } else if (npt.tagName !== "INPUT") { 2812 valueGet = function() { 2813 return this.textContent; 2814 }; 2815 valueSet = function(value) { 2816 this.textContent = value; 2817 }; 2818 Object.defineProperty(npt, "value", { 2819 get: getter, 2820 set: setter, 2821 configurable: true 2822 }); 2823 } 2824 } else if (document.__lookupGetter__ && npt.__lookupGetter__("value")) { 2825 valueGet = npt.__lookupGetter__("value"); 2826 valueSet = npt.__lookupSetter__("value"); 2827 npt.__defineGetter__("value", getter); 2828 npt.__defineSetter__("value", setter); 2829 } 2830 npt.inputmask.__valueGet = valueGet; 2831 npt.inputmask.__valueSet = valueSet; 2832 } 2833 npt.inputmask._valueGet = function(overruleRTL) { 2834 return isRTL && overruleRTL !== true ? valueGet.call(this.el).split("").reverse().join("") : valueGet.call(this.el); 2835 }; 2836 npt.inputmask._valueSet = function(value, overruleRTL) { 2837 valueSet.call(this.el, value === null || value === undefined ? "" : overruleRTL !== true && isRTL ? value.split("").reverse().join("") : value); 2838 }; 2839 if (valueGet === undefined) { 2840 valueGet = function() { 2841 return this.value; 2842 }; 2843 valueSet = function(value) { 2844 this.value = value; 2845 }; 2846 patchValhook(npt.type); 2847 installNativeValueSetFallback(npt); 2848 } 2849 } 2850 } 2851 var elementType = input.getAttribute("type"); 2852 var isSupported = input.tagName === "INPUT" && $.inArray(elementType, opts.supportsInputType) !== -1 || input.isContentEditable || input.tagName === "TEXTAREA"; 2853 if (!isSupported) { 2854 if (input.tagName === "INPUT") { 2855 var el = document.createElement("input"); 2856 el.setAttribute("type", elementType); 2857 isSupported = el.type === "text"; 2858 el = null; 2859 } else isSupported = "partial"; 2860 } 2861 if (isSupported !== false) { 2862 patchValueProperty(input); 2863 } else input.inputmask = undefined; 2864 return isSupported; 2865 } 2866 EventRuler.off(elem); 2867 var isSupported = isElementTypeSupported(elem, opts); 2868 if (isSupported !== false) { 2869 el = elem; 2870 $el = $(el); 2871 originalPlaceholder = el.placeholder; 2872 maxLength = el !== undefined ? el.maxLength : undefined; 2873 if (maxLength === -1) maxLength = undefined; 2874 if (opts.colorMask === true) { 2875 initializeColorMask(el); 2876 } 2877 if (mobile) { 2878 if ("inputMode" in el) { 2879 el.inputmode = opts.inputmode; 2880 el.setAttribute("inputmode", opts.inputmode); 2881 } 2882 if (opts.disablePredictiveText === true) { 2883 if ("autocorrect" in el) { 2884 el.autocorrect = false; 2885 } else { 2886 if (opts.colorMask !== true) { 2887 initializeColorMask(el); 2888 } 2889 el.type = "password"; 2890 } 2891 } 2892 } 2893 if (isSupported === true) { 2894 el.setAttribute("im-insert", opts.insertMode); 2895 EventRuler.on(el, "submit", EventHandlers.submitEvent); 2896 EventRuler.on(el, "reset", EventHandlers.resetEvent); 2897 EventRuler.on(el, "blur", EventHandlers.blurEvent); 2898 EventRuler.on(el, "focus", EventHandlers.focusEvent); 2899 if (opts.colorMask !== true) { 2900 EventRuler.on(el, "click", EventHandlers.clickEvent); 2901 EventRuler.on(el, "mouseleave", EventHandlers.mouseleaveEvent); 2902 EventRuler.on(el, "mouseenter", EventHandlers.mouseenterEvent); 2903 } 2904 EventRuler.on(el, "paste", EventHandlers.pasteEvent); 2905 EventRuler.on(el, "cut", EventHandlers.cutEvent); 2906 EventRuler.on(el, "complete", opts.oncomplete); 2907 EventRuler.on(el, "incomplete", opts.onincomplete); 2908 EventRuler.on(el, "cleared", opts.oncleared); 2909 if (!mobile && opts.inputEventOnly !== true) { 2910 EventRuler.on(el, "keydown", EventHandlers.keydownEvent); 2911 EventRuler.on(el, "keypress", EventHandlers.keypressEvent); 2912 } else { 2913 el.removeAttribute("maxLength"); 2914 } 2915 EventRuler.on(el, "input", EventHandlers.inputFallBackEvent); 2916 EventRuler.on(el, "beforeinput", EventHandlers.beforeInputEvent); 2917 } 2918 EventRuler.on(el, "setvalue", EventHandlers.setValueEvent); 2919 undoValue = getBufferTemplate().join(""); 2920 if (el.inputmask._valueGet(true) !== "" || opts.clearMaskOnLostFocus === false || document.activeElement === el) { 2921 var initialValue = $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(inputmask, el.inputmask._valueGet(true), opts) || el.inputmask._valueGet(true) : el.inputmask._valueGet(true); 2922 if (initialValue !== "") checkVal(el, true, false, initialValue.split("")); 2923 var buffer = getBuffer().slice(); 2924 undoValue = buffer.join(""); 2925 if (isComplete(buffer) === false) { 2926 if (opts.clearIncomplete) { 2927 resetMaskSet(); 2928 } 2929 } 2930 if (opts.clearMaskOnLostFocus && document.activeElement !== el) { 2931 if (getLastValidPosition() === -1) { 2932 buffer = []; 2933 } else { 2934 clearOptionalTail(buffer); 2935 } 2936 } 2937 if (opts.clearMaskOnLostFocus === false || opts.showMaskOnFocus && document.activeElement === el || el.inputmask._valueGet(true) !== "") writeBuffer(el, buffer); 2938 if (document.activeElement === el) { 2939 caret(el, seekNext(getLastValidPosition())); 2940 } 2941 } 2942 } 2943 } 2944 var valueBuffer; 2945 if (actionObj !== undefined) { 2946 switch (actionObj.action) { 2947 case "isComplete": 2948 el = actionObj.el; 2949 return isComplete(getBuffer()); 2950 2951 case "unmaskedvalue": 2952 if (el === undefined || actionObj.value !== undefined) { 2953 valueBuffer = actionObj.value; 2954 valueBuffer = ($.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(inputmask, valueBuffer, opts) || valueBuffer : valueBuffer).split(""); 2955 checkVal.call(this, undefined, false, false, valueBuffer); 2956 if ($.isFunction(opts.onBeforeWrite)) opts.onBeforeWrite.call(inputmask, undefined, getBuffer(), 0, opts); 2957 } 2958 return unmaskedvalue(el); 2959 2960 case "mask": 2961 mask(el); 2962 break; 2963 2964 case "format": 2965 valueBuffer = ($.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(inputmask, actionObj.value, opts) || actionObj.value : actionObj.value).split(""); 2966 checkVal.call(this, undefined, true, false, valueBuffer); 2967 if (actionObj.metadata) { 2968 return { 2969 value: isRTL ? getBuffer().slice().reverse().join("") : getBuffer().join(""), 2970 metadata: maskScope.call(this, { 2971 action: "getmetadata" 2972 }, maskset, opts) 2973 }; 2974 } 2975 return isRTL ? getBuffer().slice().reverse().join("") : getBuffer().join(""); 2976 2977 case "isValid": 2978 if (actionObj.value) { 2979 valueBuffer = actionObj.value.split(""); 2980 checkVal.call(this, undefined, true, true, valueBuffer); 2981 } else { 2982 actionObj.value = getBuffer().join(""); 2983 } 2984 var buffer = getBuffer(); 2985 var rl = determineLastRequiredPosition(), lmib = buffer.length - 1; 2986 for (;lmib > rl; lmib--) { 2987 if (isMask(lmib)) break; 2988 } 2989 buffer.splice(rl, lmib + 1 - rl); 2990 return isComplete(buffer) && actionObj.value === getBuffer().join(""); 2991 2992 case "getemptymask": 2993 return getBufferTemplate().join(""); 2994 2995 case "remove": 2996 if (el && el.inputmask) { 2997 $.data(el, "_inputmask_opts", null); 2998 $el = $(el); 2999 el.inputmask._valueSet(opts.autoUnmask ? unmaskedvalue(el) : el.inputmask._valueGet(true)); 3000 EventRuler.off(el); 3001 if (el.inputmask.colorMask) { 3002 colorMask = el.inputmask.colorMask; 3003 colorMask.removeChild(el); 3004 colorMask.parentNode.insertBefore(el, colorMask); 3005 colorMask.parentNode.removeChild(colorMask); 3006 } 3007 var valueProperty;
3008 if (Object.getOwnPropertyDescriptor && Object.getPrototypeOf) { 3009 valueProperty = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(el), "value"); 3010 if (valueProperty) { 3011 if (el.inputmask.__valueGet) { 3012 Object.defineProperty(el, "value", { 3013 get: el.inputmask.__valueGet, 3014 set: el.inputmask.__valueSet, 3015 configurable: true 3016 }); 3017 } 3018 } 3019 } else if (document.__lookupGetter__ && el.__lookupGetter__("value")) { 3020 if (el.inputmask.__valueGet) { 3021 el.__defineGetter__("value", el.inputmask.__valueGet); 3022 el.__defineSetter__("value", el.inputmask.__valueSet); 3023 } 3024 } 3025 el.inputmask = undefined; 3026 } 3027 return el; 3028 break; 3029 3030 case "getmetadata": 3031 if ($.isArray(maskset.metadata)) { 3032 var maskTarget = getMaskTemplate(true, 0, false).join(""); 3033 $.each(maskset.metadata, function(ndx, mtdt) { 3034 if (mtdt.mask === maskTarget) { 3035 maskTarget = mtdt; 3036 return false; 3037 } 3038 }); 3039 return maskTarget; 3040 } 3041 return maskset.metadata; 3042 } 3043 } 3044 } 3045 return Inputmask; 3046});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.