PageSourceSearch

https://www.isa.org/kentico/bundles/forms/scripts?v=8ROjo-b7v0CsU9WtaE8WINT6U8_4lVUAMpaTWjvgxsY1

js isa.org collected 2026-09-24 08:28:10 UTC 183,955 bytes, 3,509 lines download raw bytes

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

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.