jquery.inputmask
Version:
jquery.inputmask is a jquery plugin which create an input mask.
614 lines (612 loc) • 112 kB
JavaScript
/*!
* inputmask.js
* https://github.com/RobinHerbots/jquery.inputmask
* Copyright (c) 2010 - 2016 Robin Herbots
* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
* Version: 3.3.4
*/
!function(factory) {
"function" == typeof define && define.amd ? define("inputmask", [ "inputmask.dependencyLib" ], factory) : "object" == typeof exports ? module.exports = factory(require("./inputmask.dependencyLib")) : factory(window.dependencyLib || jQuery);
}(function($) {
function Inputmask(alias, options) {
return this instanceof Inputmask ? ($.isPlainObject(alias) ? options = alias : (options = options || {},
options.alias = alias), this.el = void 0, this.opts = $.extend(!0, {}, this.defaults, options),
this.maskset = void 0, this.noMasksCache = options && void 0 !== options.definitions,
this.userOptions = options || {}, this.events = {}, this.dataAttribute = "data-inputmask",
this.isRTL = this.opts.numericInput, void resolveAlias(this.opts.alias, options, this.opts)) : new Inputmask(alias, options);
}
function resolveAlias(aliasStr, options, opts) {
var aliasDefinition = opts.aliases[aliasStr];
return aliasDefinition ? (aliasDefinition.alias && resolveAlias(aliasDefinition.alias, void 0, opts),
$.extend(!0, opts, aliasDefinition), $.extend(!0, opts, options), !0) : (null === opts.mask && (opts.mask = aliasStr),
!1);
}
function generateMaskSet(opts, nocache) {
function generateMask(mask, metadata, opts) {
if (null !== mask && "" !== mask) {
if (1 === mask.length && opts.greedy === !1 && 0 !== opts.repeat && (opts.placeholder = ""),
opts.repeat > 0 || "*" === opts.repeat || "+" === opts.repeat) {
var repeatStart = "*" === opts.repeat ? 0 : "+" === opts.repeat ? 1 : opts.repeat;
mask = opts.groupmarker.start + mask + opts.groupmarker.end + opts.quantifiermarker.start + repeatStart + "," + opts.repeat + opts.quantifiermarker.end;
}
var masksetDefinition;
return void 0 === Inputmask.prototype.masksCache[mask] || nocache === !0 ? (masksetDefinition = {
mask: mask,
maskToken: Inputmask.prototype.analyseMask(mask, opts),
validPositions: {},
_buffer: void 0,
buffer: void 0,
tests: {},
metadata: metadata,
maskLength: void 0
}, nocache !== !0 && (Inputmask.prototype.masksCache[opts.numericInput ? mask.split("").reverse().join("") : mask] = masksetDefinition,
masksetDefinition = $.extend(!0, {}, Inputmask.prototype.masksCache[opts.numericInput ? mask.split("").reverse().join("") : mask]))) : masksetDefinition = $.extend(!0, {}, Inputmask.prototype.masksCache[opts.numericInput ? mask.split("").reverse().join("") : mask]),
masksetDefinition;
}
}
var ms;
if ($.isFunction(opts.mask) && (opts.mask = opts.mask(opts)), $.isArray(opts.mask)) {
if (opts.mask.length > 1) {
opts.keepStatic = null === opts.keepStatic || opts.keepStatic;
var altMask = opts.groupmarker.start;
return $.each(opts.numericInput ? opts.mask.reverse() : opts.mask, function(ndx, msk) {
altMask.length > 1 && (altMask += opts.groupmarker.end + opts.alternatormarker + opts.groupmarker.start),
altMask += void 0 === msk.mask || $.isFunction(msk.mask) ? msk : msk.mask;
}), altMask += opts.groupmarker.end, generateMask(altMask, opts.mask, opts);
}
opts.mask = opts.mask.pop();
}
return opts.mask && (ms = void 0 === opts.mask.mask || $.isFunction(opts.mask.mask) ? generateMask(opts.mask, opts.mask, opts) : generateMask(opts.mask.mask, opts.mask, opts)),
ms;
}
function maskScope(actionObj, maskset, opts) {
function getMaskTemplate(baseOnInput, minimalPos, includeMode) {
minimalPos = minimalPos || 0;
var ndxIntlzr, test, testPos, maskTemplate = [], pos = 0, lvp = getLastValidPosition();
maxLength = void 0 !== el ? el.maxLength : void 0, maxLength === -1 && (maxLength = void 0);
do baseOnInput === !0 && getMaskSet().validPositions[pos] ? (testPos = getMaskSet().validPositions[pos],
test = testPos.match, ndxIntlzr = testPos.locator.slice(), maskTemplate.push(includeMode === !0 ? testPos.input : includeMode === !1 ? test.nativeDef : getPlaceholder(pos, test))) : (testPos = getTestTemplate(pos, ndxIntlzr, pos - 1),
test = testPos.match, ndxIntlzr = testPos.locator.slice(), (opts.jitMasking === !1 || pos < lvp || "number" == typeof opts.jitMasking && isFinite(opts.jitMasking) && opts.jitMasking > pos) && maskTemplate.push(includeMode === !1 ? test.nativeDef : getPlaceholder(pos, test))),
pos++; while ((void 0 === maxLength || pos < maxLength) && (null !== test.fn || "" !== test.def) || minimalPos > pos);
return "" === maskTemplate[maskTemplate.length - 1] && maskTemplate.pop(), getMaskSet().maskLength = pos + 1,
maskTemplate;
}
function getMaskSet() {
return maskset;
}
function resetMaskSet(soft) {
var maskset = getMaskSet();
maskset.buffer = void 0, soft !== !0 && (maskset._buffer = void 0, maskset.validPositions = {},
maskset.p = 0);
}
function getLastValidPosition(closestTo, strict, validPositions) {
var before = -1, after = -1, valids = validPositions || getMaskSet().validPositions;
void 0 === closestTo && (closestTo = -1);
for (var posNdx in valids) {
var psNdx = parseInt(posNdx);
valids[psNdx] && (strict || null !== valids[psNdx].match.fn) && (psNdx <= closestTo && (before = psNdx),
psNdx >= closestTo && (after = psNdx));
}
return before !== -1 && closestTo - before > 1 || after < closestTo ? before : after;
}
function stripValidPositions(start, end, nocheck, strict) {
function IsEnclosedStatic(pos) {
var posMatch = getMaskSet().validPositions[pos];
if (void 0 !== posMatch && null === posMatch.match.fn) {
var prevMatch = getMaskSet().validPositions[pos - 1], nextMatch = getMaskSet().validPositions[pos + 1];
return void 0 !== prevMatch && void 0 !== nextMatch;
}
return !1;
}
var i, startPos = start, positionsClone = $.extend(!0, {}, getMaskSet().validPositions), needsValidation = !1;
for (getMaskSet().p = start, i = end - 1; i >= startPos; i--) void 0 !== getMaskSet().validPositions[i] && (nocheck !== !0 && (!getMaskSet().validPositions[i].match.optionality && IsEnclosedStatic(i) || opts.canClearPosition(getMaskSet(), i, getLastValidPosition(), strict, opts) === !1) || delete getMaskSet().validPositions[i]);
for (resetMaskSet(!0), i = startPos + 1; i <= getLastValidPosition(); ) {
for (;void 0 !== getMaskSet().validPositions[startPos]; ) startPos++;
if (i < startPos && (i = startPos + 1), void 0 === getMaskSet().validPositions[i] && isMask(i)) i++; else {
var t = getTestTemplate(i);
needsValidation === !1 && positionsClone[startPos] && positionsClone[startPos].match.def === t.match.def ? (getMaskSet().validPositions[startPos] = $.extend(!0, {}, positionsClone[startPos]),
getMaskSet().validPositions[startPos].input = t.input, delete getMaskSet().validPositions[i],
i++) : positionCanMatchDefinition(startPos, t.match.def) ? isValid(startPos, t.input || getPlaceholder(i), !0) !== !1 && (delete getMaskSet().validPositions[i],
i++, needsValidation = !0) : isMask(i) || (i++, startPos--), startPos++;
}
}
resetMaskSet(!0);
}
function determineTestTemplate(tests, guessNextBest) {
for (var testPos, testPositions = tests, lvp = getLastValidPosition(), lvTest = getMaskSet().validPositions[lvp] || getTests(0)[0], lvTestAltArr = void 0 !== lvTest.alternation ? lvTest.locator[lvTest.alternation].toString().split(",") : [], ndx = 0; ndx < testPositions.length && (testPos = testPositions[ndx],
!(testPos.match && (opts.greedy && testPos.match.optionalQuantifier !== !0 || (testPos.match.optionality === !1 || testPos.match.newBlockMarker === !1) && testPos.match.optionalQuantifier !== !0) && (void 0 === lvTest.alternation || lvTest.alternation !== testPos.alternation || void 0 !== testPos.locator[lvTest.alternation] && checkAlternationMatch(testPos.locator[lvTest.alternation].toString().split(","), lvTestAltArr))) || guessNextBest === !0 && (null !== testPos.match.fn || /[0-9a-bA-Z]/.test(testPos.match.def))); ndx++) ;
return testPos;
}
function getTestTemplate(pos, ndxIntlzr, tstPs) {
return getMaskSet().validPositions[pos] || determineTestTemplate(getTests(pos, ndxIntlzr ? ndxIntlzr.slice() : ndxIntlzr, tstPs));
}
function getTest(pos) {
return getMaskSet().validPositions[pos] ? getMaskSet().validPositions[pos] : getTests(pos)[0];
}
function positionCanMatchDefinition(pos, def) {
for (var valid = !1, tests = getTests(pos), tndx = 0; tndx < tests.length; tndx++) if (tests[tndx].match && tests[tndx].match.def === def) {
valid = !0;
break;
}
return valid;
}
function getTests(pos, ndxIntlzr, tstPs) {
function resolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) {
function handleMatch(match, loopNdx, quantifierRecurse) {
function isFirstMatch(latestMatch, tokenGroup) {
var firstMatch = 0 === $.inArray(latestMatch, tokenGroup.matches);
return firstMatch || $.each(tokenGroup.matches, function(ndx, match) {
if (match.isQuantifier === !0 && (firstMatch = isFirstMatch(latestMatch, tokenGroup.matches[ndx - 1]))) return !1;
}), firstMatch;
}
function resolveNdxInitializer(pos, alternateNdx, targetAlternation) {
var bestMatch, indexPos;
return (getMaskSet().tests[pos] || getMaskSet().validPositions[pos]) && $.each(getMaskSet().tests[pos] || [ getMaskSet().validPositions[pos] ], function(ndx, lmnt) {
var alternation = void 0 !== targetAlternation ? targetAlternation : lmnt.alternation, ndxPos = void 0 !== lmnt.locator[alternation] ? lmnt.locator[alternation].toString().indexOf(alternateNdx) : -1;
(void 0 === indexPos || ndxPos < indexPos) && ndxPos !== -1 && (bestMatch = lmnt,
indexPos = ndxPos);
}), bestMatch ? bestMatch.locator.slice((void 0 !== targetAlternation ? targetAlternation : bestMatch.alternation) + 1) : void 0 !== targetAlternation ? resolveNdxInitializer(pos, alternateNdx) : void 0;
}
function staticCanMatchDefinition(source, target) {
return null === source.match.fn && null !== target.match.fn && target.match.fn.test(source.match.def, getMaskSet(), pos, !1, opts, !1);
}
if (testPos > 1e4) 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;
if (testPos === pos && void 0 === match.matches) return matches.push({
match: match,
locator: loopNdx.reverse(),
cd: cacheDependency
}), !0;
if (void 0 !== match.matches) {
if (match.isGroup && quantifierRecurse !== match) {
if (match = handleMatch(maskToken.matches[$.inArray(match, maskToken.matches) + 1], loopNdx)) return !0;
} else if (match.isOptional) {
var optionalToken = match;
if (match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse)) {
if (latestMatch = matches[matches.length - 1].match, !isFirstMatch(latestMatch, optionalToken)) return !0;
insertStop = !0, testPos = pos;
}
} else if (match.isAlternator) {
var maltMatches, alternateToken = match, malternateMatches = [], currentMatches = matches.slice(), loopNdxCnt = loopNdx.length, altIndex = ndxInitializer.length > 0 ? ndxInitializer.shift() : -1;
if (altIndex === -1 || "string" == typeof altIndex) {
var amndx, currentPos = testPos, ndxInitializerClone = ndxInitializer.slice(), altIndexArr = [];
if ("string" == typeof altIndex) altIndexArr = altIndex.split(","); else for (amndx = 0; amndx < alternateToken.matches.length; amndx++) altIndexArr.push(amndx);
for (var ndx = 0; ndx < altIndexArr.length; ndx++) {
if (amndx = parseInt(altIndexArr[ndx]), matches = [], ndxInitializer = resolveNdxInitializer(testPos, amndx, loopNdxCnt) || ndxInitializerClone.slice(),
match = handleMatch(alternateToken.matches[amndx] || maskToken.matches[amndx], [ amndx ].concat(loopNdx), quantifierRecurse) || match,
match !== !0 && void 0 !== match && altIndexArr[altIndexArr.length - 1] < alternateToken.matches.length) {
var ntndx = $.inArray(match, maskToken.matches) + 1;
maskToken.matches.length > ntndx && (match = handleMatch(maskToken.matches[ntndx], [ ntndx ].concat(loopNdx.slice(1, loopNdx.length)), quantifierRecurse),
match && (altIndexArr.push(ntndx.toString()), $.each(matches, function(ndx, lmnt) {
lmnt.alternation = loopNdx.length - 1;
})));
}
maltMatches = matches.slice(), testPos = currentPos, matches = [];
for (var ndx1 = 0; ndx1 < maltMatches.length; ndx1++) {
var altMatch = maltMatches[ndx1], hasMatch = !1;
altMatch.alternation = altMatch.alternation || loopNdxCnt;
for (var ndx2 = 0; ndx2 < malternateMatches.length; ndx2++) {
var altMatch2 = malternateMatches[ndx2];
if (("string" != typeof altIndex || $.inArray(altMatch.locator[altMatch.alternation].toString(), altIndexArr) !== -1) && (altMatch.match.def === altMatch2.match.def || staticCanMatchDefinition(altMatch, altMatch2))) {
hasMatch = altMatch.match.nativeDef === altMatch2.match.nativeDef, altMatch.alternation == altMatch2.alternation && altMatch2.locator[altMatch2.alternation].toString().indexOf(altMatch.locator[altMatch.alternation]) === -1 && (altMatch2.locator[altMatch2.alternation] = altMatch2.locator[altMatch2.alternation] + "," + altMatch.locator[altMatch.alternation],
altMatch2.alternation = altMatch.alternation, null == altMatch.match.fn && (altMatch2.na = altMatch2.na || altMatch.locator[altMatch.alternation].toString(),
altMatch2.na.indexOf(altMatch.locator[altMatch.alternation]) === -1 && (altMatch2.na = altMatch2.na + "," + altMatch.locator[altMatch.alternation])));
break;
}
}
hasMatch || malternateMatches.push(altMatch);
}
}
"string" == typeof altIndex && (malternateMatches = $.map(malternateMatches, function(lmnt, ndx) {
if (isFinite(ndx)) {
var mamatch, alternation = lmnt.alternation, altLocArr = lmnt.locator[alternation].toString().split(",");
lmnt.locator[alternation] = void 0, lmnt.alternation = void 0;
for (var alndx = 0; alndx < altLocArr.length; alndx++) mamatch = $.inArray(altLocArr[alndx], altIndexArr) !== -1,
mamatch && (void 0 !== lmnt.locator[alternation] ? (lmnt.locator[alternation] += ",",
lmnt.locator[alternation] += altLocArr[alndx]) : lmnt.locator[alternation] = parseInt(altLocArr[alndx]),
lmnt.alternation = alternation);
if (void 0 !== lmnt.locator[alternation]) return lmnt;
}
})), matches = currentMatches.concat(malternateMatches), testPos = pos, insertStop = matches.length > 0,
ndxInitializer = ndxInitializerClone.slice();
} else match = handleMatch(alternateToken.matches[altIndex] || maskToken.matches[altIndex], [ altIndex ].concat(loopNdx), quantifierRecurse);
if (match) return !0;
} else if (match.isQuantifier && quantifierRecurse !== maskToken.matches[$.inArray(match, maskToken.matches) - 1]) for (var qt = match, qndx = ndxInitializer.length > 0 ? ndxInitializer.shift() : 0; qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max) && testPos <= pos; qndx++) {
var tokenGroup = maskToken.matches[$.inArray(qt, maskToken.matches) - 1];
if (match = handleMatch(tokenGroup, [ qndx ].concat(loopNdx), tokenGroup)) {
if (latestMatch = matches[matches.length - 1].match, latestMatch.optionalQuantifier = qndx > qt.quantifier.min - 1,
isFirstMatch(latestMatch, tokenGroup)) {
if (qndx > qt.quantifier.min - 1) {
insertStop = !0, testPos = pos;
break;
}
return !0;
}
return !0;
}
} else if (match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse)) return !0;
} else testPos++;
}
for (var tndx = ndxInitializer.length > 0 ? ndxInitializer.shift() : 0; tndx < maskToken.matches.length; tndx++) if (maskToken.matches[tndx].isQuantifier !== !0) {
var match = handleMatch(maskToken.matches[tndx], [ tndx ].concat(loopNdx), quantifierRecurse);
if (match && testPos === pos) return match;
if (testPos > pos) break;
}
}
function mergeLocators(tests) {
var locator = [];
return $.isArray(tests) || (tests = [ tests ]), tests.length > 0 && (void 0 === tests[0].alternation ? (locator = determineTestTemplate(tests.slice()).locator.slice(),
0 === locator.length && (locator = tests[0].locator.slice())) : $.each(tests, function(ndx, tst) {
if ("" !== tst.def) if (0 === locator.length) locator = tst.locator.slice(); else for (var i = 0; i < locator.length; i++) tst.locator[i] && locator[i].toString().indexOf(tst.locator[i]) === -1 && (locator[i] += "," + tst.locator[i]);
})), locator;
}
function filterTests(tests) {
return opts.keepStatic && pos > 0 && tests.length > 1 + ("" === tests[tests.length - 1].match.def ? 1 : 0) && tests[0].match.optionality !== !0 && tests[0].match.optionalQuantifier !== !0 && null === tests[0].match.fn && !/[0-9a-bA-Z]/.test(tests[0].match.def) ? [ determineTestTemplate(tests) ] : tests;
}
var latestMatch, maskTokens = getMaskSet().maskToken, testPos = ndxIntlzr ? tstPs : 0, ndxInitializer = ndxIntlzr ? ndxIntlzr.slice() : [ 0 ], matches = [], insertStop = !1, cacheDependency = ndxIntlzr ? ndxIntlzr.join("") : "";
if (pos > -1) {
if (void 0 === ndxIntlzr) {
for (var test, previousPos = pos - 1; void 0 === (test = getMaskSet().validPositions[previousPos] || getMaskSet().tests[previousPos]) && previousPos > -1; ) previousPos--;
void 0 !== test && previousPos > -1 && (ndxInitializer = mergeLocators(test), cacheDependency = ndxInitializer.join(""),
testPos = previousPos);
}
if (getMaskSet().tests[pos] && getMaskSet().tests[pos][0].cd === cacheDependency) return filterTests(getMaskSet().tests[pos]);
for (var mtndx = ndxInitializer.shift(); mtndx < maskTokens.length; mtndx++) {
var match = resolveTestFromToken(maskTokens[mtndx], ndxInitializer, [ mtndx ]);
if (match && testPos === pos || testPos > pos) break;
}
}
return (0 === matches.length || insertStop) && matches.push({
match: {
fn: null,
cardinality: 0,
optionality: !0,
casing: null,
def: "",
placeholder: ""
},
locator: [],
cd: cacheDependency
}), void 0 !== ndxIntlzr && getMaskSet().tests[pos] ? filterTests($.extend(!0, [], matches)) : (getMaskSet().tests[pos] = $.extend(!0, [], matches),
filterTests(getMaskSet().tests[pos]));
}
function getBufferTemplate() {
return void 0 === getMaskSet()._buffer && (getMaskSet()._buffer = getMaskTemplate(!1, 1),
void 0 === getMaskSet().buffer && getMaskSet()._buffer.slice()), getMaskSet()._buffer;
}
function getBuffer(noCache) {
return void 0 !== getMaskSet().buffer && noCache !== !0 || (getMaskSet().buffer = getMaskTemplate(!0, getLastValidPosition(), !0)),
getMaskSet().buffer;
}
function refreshFromBuffer(start, end, buffer) {
var i;
if (start === !0) resetMaskSet(), start = 0, end = buffer.length; else for (i = start; i < end; i++) delete getMaskSet().validPositions[i];
for (i = start; i < end; i++) resetMaskSet(!0), buffer[i] !== opts.skipOptionalPartCharacter && isValid(i, buffer[i], !0, !0);
}
function casing(elem, test, pos) {
switch (opts.casing || test.casing) {
case "upper":
elem = elem.toUpperCase();
break;
case "lower":
elem = elem.toLowerCase();
break;
case "title":
var posBefore = getMaskSet().validPositions[pos - 1];
elem = 0 === pos || posBefore && posBefore.input === String.fromCharCode(Inputmask.keyCode.SPACE) ? elem.toUpperCase() : elem.toLowerCase();
}
return elem;
}
function checkAlternationMatch(altArr1, altArr2) {
for (var altArrC = opts.greedy ? altArr2 : altArr2.slice(0, 1), isMatch = !1, alndx = 0; alndx < altArr1.length; alndx++) if ($.inArray(altArr1[alndx], altArrC) !== -1) {
isMatch = !0;
break;
}
return isMatch;
}
function isValid(pos, c, strict, fromSetValid, fromAlternate) {
function isSelection(posObj) {
var selection = isRTL ? posObj.begin - posObj.end > 1 || posObj.begin - posObj.end === 1 && opts.insertMode : posObj.end - posObj.begin > 1 || posObj.end - posObj.begin === 1 && opts.insertMode;
return selection && 0 === posObj.begin && posObj.end === getMaskSet().maskLength ? "full" : selection;
}
function _isValid(position, c, strict) {
var rslt = !1;
return $.each(getTests(position), function(ndx, tst) {
for (var test = tst.match, loopend = c ? 1 : 0, chrs = "", i = test.cardinality; i > loopend; i--) chrs += getBufferElement(position - (i - 1));
if (c && (chrs += c), getBuffer(!0), rslt = null != test.fn ? test.fn.test(chrs, getMaskSet(), position, strict, opts, isSelection(pos)) : (c === test.def || c === opts.skipOptionalPartCharacter) && "" !== test.def && {
c: test.placeholder || test.def,
pos: position
}, rslt !== !1) {
var elem = void 0 !== rslt.c ? rslt.c : c;
elem = elem === opts.skipOptionalPartCharacter && null === test.fn ? test.placeholder || test.def : elem;
var validatedPos = position, possibleModifiedBuffer = getBuffer();
if (void 0 !== rslt.remove && ($.isArray(rslt.remove) || (rslt.remove = [ rslt.remove ]),
$.each(rslt.remove.sort(function(a, b) {
return b - a;
}), function(ndx, lmnt) {
stripValidPositions(lmnt, lmnt + 1, !0);
})), void 0 !== rslt.insert && ($.isArray(rslt.insert) || (rslt.insert = [ rslt.insert ]),
$.each(rslt.insert.sort(function(a, b) {
return a - b;
}), function(ndx, lmnt) {
isValid(lmnt.pos, lmnt.c, !0, fromSetValid);
})), rslt.refreshFromBuffer) {
var refresh = rslt.refreshFromBuffer;
if (strict = !0, refreshFromBuffer(refresh === !0 ? refresh : refresh.start, refresh.end, possibleModifiedBuffer),
void 0 === rslt.pos && void 0 === rslt.c) return rslt.pos = getLastValidPosition(),
!1;
if (validatedPos = void 0 !== rslt.pos ? rslt.pos : position, validatedPos !== position) return rslt = $.extend(rslt, isValid(validatedPos, elem, !0, fromSetValid)),
!1;
} else if (rslt !== !0 && void 0 !== rslt.pos && rslt.pos !== position && (validatedPos = rslt.pos,
refreshFromBuffer(position, validatedPos, getBuffer().slice()), validatedPos !== position)) return rslt = $.extend(rslt, isValid(validatedPos, elem, !0)),
!1;
return (rslt === !0 || void 0 !== rslt.pos || void 0 !== rslt.c) && (ndx > 0 && resetMaskSet(!0),
setValidPosition(validatedPos, $.extend({}, tst, {
input: casing(elem, test, validatedPos)
}), fromSetValid, isSelection(pos)) || (rslt = !1), !1);
}
}), rslt;
}
function alternate(pos, c, strict) {
var lastAlt, alternation, altPos, prevAltPos, i, validPos, altNdxs, decisionPos, validPsClone = $.extend(!0, {}, getMaskSet().validPositions), isValidRslt = !1, lAltPos = getLastValidPosition();
for (prevAltPos = getMaskSet().validPositions[lAltPos]; lAltPos >= 0; lAltPos--) if (altPos = getMaskSet().validPositions[lAltPos],
altPos && void 0 !== altPos.alternation) {
if (lastAlt = lAltPos, alternation = getMaskSet().validPositions[lastAlt].alternation,
prevAltPos.locator[altPos.alternation] !== altPos.locator[altPos.alternation]) break;
prevAltPos = altPos;
}
if (void 0 !== alternation) {
decisionPos = parseInt(lastAlt);
var decisionTaker = void 0 !== prevAltPos.locator[prevAltPos.alternation || alternation] ? prevAltPos.locator[prevAltPos.alternation || alternation] : altNdxs[0];
decisionTaker.length > 0 && (decisionTaker = decisionTaker.split(",")[0]);
var possibilityPos = getMaskSet().validPositions[decisionPos], prevPos = getMaskSet().validPositions[decisionPos - 1];
$.each(getTests(decisionPos, prevPos ? prevPos.locator : void 0, decisionPos - 1), function(ndx, test) {
altNdxs = test.locator[alternation] ? test.locator[alternation].toString().split(",") : [];
for (var mndx = 0; mndx < altNdxs.length; mndx++) {
var validInputs = [], staticInputsBeforePos = 0, staticInputsBeforePosAlternate = 0, verifyValidInput = !1;
if (decisionTaker < altNdxs[mndx] && (void 0 === test.na || $.inArray(altNdxs[mndx], test.na.split(",")) === -1)) {
getMaskSet().validPositions[decisionPos] = $.extend(!0, {}, test);
var possibilities = getMaskSet().validPositions[decisionPos].locator;
for (getMaskSet().validPositions[decisionPos].locator[alternation] = parseInt(altNdxs[mndx]),
null == test.match.fn ? (possibilityPos.input !== test.match.def && (verifyValidInput = !0,
possibilityPos.generatedInput !== !0 && validInputs.push(possibilityPos.input)),
staticInputsBeforePosAlternate++, getMaskSet().validPositions[decisionPos].generatedInput = !/[0-9a-bA-Z]/.test(test.match.def),
getMaskSet().validPositions[decisionPos].input = test.match.def) : getMaskSet().validPositions[decisionPos].input = possibilityPos.input,
i = decisionPos + 1; i < getLastValidPosition(void 0, !0) + 1; i++) validPos = getMaskSet().validPositions[i],
validPos && validPos.generatedInput !== !0 && /[0-9a-bA-Z]/.test(validPos.input) ? validInputs.push(validPos.input) : i < pos && staticInputsBeforePos++,
delete getMaskSet().validPositions[i];
for (verifyValidInput && validInputs[0] === test.match.def && validInputs.shift(),
resetMaskSet(!0), isValidRslt = !0; validInputs.length > 0; ) {
var input = validInputs.shift();
if (input !== opts.skipOptionalPartCharacter && !(isValidRslt = isValid(getLastValidPosition(void 0, !0) + 1, input, !1, fromSetValid, !0))) break;
}
if (isValidRslt) {
getMaskSet().validPositions[decisionPos].locator = possibilities;
var targetLvp = getLastValidPosition(pos) + 1;
for (i = decisionPos + 1; i < getLastValidPosition() + 1; i++) validPos = getMaskSet().validPositions[i],
(void 0 === validPos || null == validPos.match.fn) && i < pos + (staticInputsBeforePosAlternate - staticInputsBeforePos) && staticInputsBeforePosAlternate++;
pos += staticInputsBeforePosAlternate - staticInputsBeforePos, isValidRslt = isValid(pos > targetLvp ? targetLvp : pos, c, strict, fromSetValid, !0);
}
if (isValidRslt) return !1;
resetMaskSet(), getMaskSet().validPositions = $.extend(!0, {}, validPsClone);
}
}
});
}
return isValidRslt;
}
function trackbackAlternations(originalPos, newPos) {
var vp = getMaskSet().validPositions[newPos];
if (vp) for (var targetLocator = vp.locator, tll = targetLocator.length, ps = originalPos; ps < newPos; ps++) if (void 0 === getMaskSet().validPositions[ps] && !isMask(ps, !0)) {
var tests = getTests(ps), bestMatch = tests[0], equality = -1;
$.each(tests, function(ndx, tst) {
for (var i = 0; i < tll && (void 0 !== tst.locator[i] && checkAlternationMatch(tst.locator[i].toString().split(","), targetLocator[i].toString().split(","))); i++) equality < i && (equality = i,
bestMatch = tst);
}), setValidPosition(ps, $.extend({}, bestMatch, {
input: bestMatch.match.placeholder || bestMatch.match.def
}), !0);
}
}
function setValidPosition(pos, validTest, fromSetValid, isSelection) {
if (isSelection || opts.insertMode && void 0 !== getMaskSet().validPositions[pos] && void 0 === fromSetValid) {
var i, positionsClone = $.extend(!0, {}, getMaskSet().validPositions), lvp = getLastValidPosition(void 0, !0);
for (i = pos; i <= lvp; i++) delete getMaskSet().validPositions[i];
getMaskSet().validPositions[pos] = $.extend(!0, {}, validTest);
var j, valid = !0, vps = getMaskSet().validPositions, needsValidation = !1, initialLength = getMaskSet().maskLength;
for (i = j = pos; i <= lvp; i++) {
var t = positionsClone[i];
if (void 0 !== t) for (var posMatch = j; posMatch < getMaskSet().maskLength && (null === t.match.fn && vps[i] && (vps[i].match.optionalQuantifier === !0 || vps[i].match.optionality === !0) || null != t.match.fn); ) {
if (posMatch++, needsValidation === !1 && positionsClone[posMatch] && positionsClone[posMatch].match.def === t.match.def) getMaskSet().validPositions[posMatch] = $.extend(!0, {}, positionsClone[posMatch]),
getMaskSet().validPositions[posMatch].input = t.input, fillMissingNonMask(posMatch),
j = posMatch, valid = !0; else if (positionCanMatchDefinition(posMatch, t.match.def)) {
var result = isValid(posMatch, t.input, !0, !0);
valid = result !== !1, j = result.caret || result.insert ? getLastValidPosition() : posMatch,
needsValidation = !0;
} else valid = t.generatedInput === !0;
if (getMaskSet().maskLength < initialLength && (getMaskSet().maskLength = initialLength),
valid) break;
}
if (!valid) break;
}
if (!valid) return getMaskSet().validPositions = $.extend(!0, {}, positionsClone),
resetMaskSet(!0), !1;
} else getMaskSet().validPositions[pos] = $.extend(!0, {}, validTest);
return resetMaskSet(!0), !0;
}
function fillMissingNonMask(maskPos) {
for (var pndx = maskPos - 1; pndx > -1 && !getMaskSet().validPositions[pndx]; pndx--) ;
var testTemplate, testsFromPos;
for (pndx++; pndx < maskPos; pndx++) void 0 === getMaskSet().validPositions[pndx] && (opts.jitMasking === !1 || opts.jitMasking > pndx) && (testsFromPos = getTests(pndx, getTestTemplate(pndx - 1).locator, pndx - 1).slice(),
"" === testsFromPos[testsFromPos.length - 1].match.def && testsFromPos.pop(), testTemplate = determineTestTemplate(testsFromPos),
testTemplate && (testTemplate.match.def === opts.radixPointDefinitionSymbol || !isMask(pndx, !0) || $.inArray(opts.radixPoint, getBuffer()) < pndx && testTemplate.match.fn && testTemplate.match.fn.test(getPlaceholder(pndx), getMaskSet(), pndx, !1, opts)) && (result = _isValid(pndx, testTemplate.match.placeholder || (null == testTemplate.match.fn ? testTemplate.match.def : "" !== getPlaceholder(pndx) ? getPlaceholder(pndx) : getBuffer()[pndx]), !0),
result !== !1 && (getMaskSet().validPositions[result.pos || pndx].generatedInput = !0)));
}
strict = strict === !0;
var maskPos = pos;
void 0 !== pos.begin && (maskPos = isRTL && !isSelection(pos) ? pos.end : pos.begin);
var result = !1, positionsClone = $.extend(!0, {}, getMaskSet().validPositions);
if (fillMissingNonMask(maskPos), isSelection(pos) && (handleRemove(void 0, Inputmask.keyCode.DELETE, pos),
maskPos = getMaskSet().p), maskPos < getMaskSet().maskLength && (result = _isValid(maskPos, c, strict),
(!strict || fromSetValid === !0) && result === !1)) {
var currentPosValid = getMaskSet().validPositions[maskPos];
if (!currentPosValid || null !== currentPosValid.match.fn || currentPosValid.match.def !== c && c !== opts.skipOptionalPartCharacter) {
if ((opts.insertMode || void 0 === getMaskSet().validPositions[seekNext(maskPos)]) && !isMask(maskPos, !0)) {
var testsFromPos = getTests(maskPos).slice();
"" === testsFromPos[testsFromPos.length - 1].match.def && testsFromPos.pop();
var staticChar = determineTestTemplate(testsFromPos, !0);
staticChar && null === staticChar.match.fn && (staticChar = staticChar.match.placeholder || staticChar.match.def,
_isValid(maskPos, staticChar, strict), getMaskSet().validPositions[maskPos].generatedInput = !0);
for (var nPos = maskPos + 1, snPos = seekNext(maskPos); nPos <= snPos; nPos++) if (result = _isValid(nPos, c, strict),
result !== !1) {
trackbackAlternations(maskPos, void 0 !== result.pos ? result.pos : nPos), maskPos = nPos;
break;
}
}
} else result = {
caret: seekNext(maskPos)
};
}
return result === !1 && opts.keepStatic && !strict && fromAlternate !== !0 && (result = alternate(maskPos, c, strict)),
result === !0 && (result = {
pos: maskPos
}), $.isFunction(opts.postValidation) && result !== !1 && !strict && fromSetValid !== !0 && (result = !!opts.postValidation(getBuffer(!0), result, opts) && result),
void 0 === result.pos && (result.pos = maskPos), result === !1 && (resetMaskSet(!0),
getMaskSet().validPositions = $.extend(!0, {}, positionsClone)), result;
}
function isMask(pos, strict) {
var test;
if (strict ? (test = getTestTemplate(pos).match, "" === test.def && (test = getTest(pos).match)) : test = getTest(pos).match,
null != test.fn) return test.fn;
if (strict !== !0 && pos > -1) {
var tests = getTests(pos);
return tests.length > 1 + ("" === tests[tests.length - 1].match.def ? 1 : 0);
}
return !1;
}
function seekNext(pos, newBlock) {
var maskL = getMaskSet().maskLength;
if (pos >= maskL) return maskL;
for (var position = pos; ++position < maskL && (newBlock === !0 && (getTest(position).match.newBlockMarker !== !0 || !isMask(position)) || newBlock !== !0 && !isMask(position)); ) ;
return position;
}
function seekPrevious(pos, newBlock) {
var tests, position = pos;
if (position <= 0) return 0;
for (;--position > 0 && (newBlock === !0 && getTest(position).match.newBlockMarker !== !0 || newBlock !== !0 && !isMask(position) && (tests = getTests(position),
tests.length < 2 || 2 === tests.length && "" === tests[1].match.def)); ) ;
return position;
}
function getBufferElement(position) {
return void 0 === getMaskSet().validPositions[position] ? getPlaceholder(position) : getMaskSet().validPositions[position].input;
}
function writeBuffer(input, buffer, caretPos, event, triggerInputEvent) {
if (event && $.isFunction(opts.onBeforeWrite)) {
var result = opts.onBeforeWrite(event, buffer, caretPos, opts);
if (result) {
if (result.refreshFromBuffer) {
var refresh = result.refreshFromBuffer;
refreshFromBuffer(refresh === !0 ? refresh : refresh.start, refresh.end, result.buffer || buffer),
buffer = getBuffer(!0);
}
void 0 !== caretPos && (caretPos = void 0 !== result.caret ? result.caret : caretPos);
}
}
input.inputmask._valueSet(buffer.join("")), void 0 === caretPos || void 0 !== event && "blur" === event.type ? renderColorMask(input, buffer, caretPos) : caret(input, caretPos),
triggerInputEvent === !0 && (skipInputEvent = !0, $(input).trigger("input"));
}
function getPlaceholder(pos, test) {
if (test = test || getTest(pos).match, void 0 !== test.placeholder) return test.placeholder;
if (null === test.fn) {
if (pos > -1 && void 0 === getMaskSet().validPositions[pos]) {
var prevTest, tests = getTests(pos), staticAlternations = [];
if (tests.length > 1 + ("" === tests[tests.length - 1].match.def ? 1 : 0)) for (var i = 0; i < tests.length; i++) if (tests[i].match.optionality !== !0 && tests[i].match.optionalQuantifier !== !0 && (null === tests[i].match.fn || void 0 === prevTest || tests[i].match.fn.test(prevTest.match.def, getMaskSet(), pos, !0, opts) !== !1) && (staticAlternations.push(tests[i]),
null === tests[i].match.fn && (prevTest = tests[i]), staticAlternations.length > 1 && /[0-9a-bA-Z]/.test(staticAlternations[0].match.def))) return opts.placeholder.charAt(pos % opts.placeholder.length);
}
return test.def;
}
return opts.placeholder.charAt(pos % opts.placeholder.length);
}
function checkVal(input, writeOut, strict, nptvl, initiatingEvent, stickyCaret) {
function isTemplateMatch() {
var isMatch = !1, charCodeNdx = getBufferTemplate().slice(initialNdx, seekNext(initialNdx)).join("").indexOf(charCodes);
if (charCodeNdx !== -1 && !isMask(initialNdx)) {
isMatch = !0;
for (var bufferTemplateArr = getBufferTemplate().slice(initialNdx, initialNdx + charCodeNdx), i = 0; i < bufferTemplateArr.length; i++) if (" " !== bufferTemplateArr[i]) {
isMatch = !1;
break;
}
}
return isMatch;
}
var inputValue = nptvl.slice(), charCodes = "", initialNdx = 0, result = void 0;
if (resetMaskSet(), getMaskSet().p = seekNext(-1), !strict) if (opts.autoUnmask !== !0) {
var staticInput = getBufferTemplate().slice(0, seekNext(-1)).join(""), matches = inputValue.join("").match(new RegExp("^" + Inputmask.escapeRegex(staticInput), "g"));
matches && matches.length > 0 && (inputValue.splice(0, matches.length * staticInput.length),
initialNdx = seekNext(initialNdx));
} else initialNdx = seekNext(initialNdx);
if ($.each(inputValue, function(ndx, charCode) {
if (void 0 !== charCode) {
var keypress = new $.Event("keypress");
keypress.which = charCode.charCodeAt(0), charCodes += charCode;
var lvp = getLastValidPosition(void 0, !0), lvTest = getMaskSet().validPositions[lvp], nextTest = getTestTemplate(lvp + 1, lvTest ? lvTest.locator.slice() : void 0, lvp);
if (!isTemplateMatch() || strict || opts.autoUnmask) {
var pos = strict ? ndx : null == nextTest.match.fn && nextTest.match.optionality && lvp + 1 < getMaskSet().p ? lvp + 1 : getMaskSet().p;
result = EventHandlers.keypressEvent.call(input, keypress, !0, !1, strict, pos),
initialNdx = pos + 1, charCodes = "";
} else result = EventHandlers.keypressEvent.call(input, keypress, !0, !1, !0, lvp + 1);
if (!strict && $.isFunction(opts.onBeforeWrite) && (result = opts.onBeforeWrite(keypress, getBuffer(), result.forwardPosition, opts),
result && result.refreshFromBuffer)) {
var refresh = result.refreshFromBuffer;
refreshFromBuffer(refresh === !0 ? refresh : refresh.start, refresh.end, result.buffer),
resetMaskSet(!0), result.caret && (getMaskSet().p = result.caret);
}
}
}), writeOut) {
var caretPos = void 0, lvp = getLastValidPosition();
document.activeElement === input && (initiatingEvent || result) && (caretPos = caret(input).begin,
initiatingEvent && result === !1 && (caretPos = seekNext(getLastValidPosition(caretPos))),
result && stickyCaret !== !0 && (caretPos < lvp + 1 || lvp === -1) && (caretPos = opts.numericInput && void 0 === result.caret ? seekPrevious(result.forwardPosition) : result.forwardPosition)),
writeBuffer(input, getBuffer(), caretPos, initiatingEvent || new $.Event("checkval"));
}
}
function unmaskedvalue(input) {
if (input && void 0 === input.inputmask) return input.value;
var umValue = [], vps = getMaskSet().validPositions;
for (var pndx in vps) vps[pndx].match && null != vps[pndx].match.fn && umValue.push(vps[pndx].input);
var unmaskedValue = 0 === umValue.length ? "" : (isRTL ? umValue.reverse() : umValue).join("");
if ($.isFunction(opts.onUnMask)) {
var bufferValue = (isRTL ? getBuffer().slice().reverse() : getBuffer()).join("");
unmaskedValue = opts.onUnMask(bufferValue, unmaskedValue, opts) || unmaskedValue;
}
return unmaskedValue;
}
function caret(input, begin, end, notranslate) {
function translatePosition(pos) {
if (notranslate !== !0 && isRTL && "number" == typeof pos && (!opts.greedy || "" !== opts.placeholder)) {
var bffrLght = getBuffer().join("").length;
pos = bffrLght - pos;
}
return pos;
}
var range;
if ("number" != typeof begin) return input.setSelectionRange ? (begin = input.selectionStart,
end = input.selectionEnd) : window.getSelection ? (range = window.getSelection().getRangeAt(0),
range.commonAncestorContainer.parentNode !== input && range.commonAncestorContainer !== input || (begin = range.startOffset,
end = range.endOffset)) : document.selection && document.selection.createRange && (range = document.selection.createRange(),
begin = 0 - range.duplicate().moveStart("character", -input.inputmask._valueGet().length),
end = begin + range.text.length), {
begin: translatePosition(begin),
end: translatePosition(end)
};
begin = translatePosition(begin), end = translatePosition(end), end = "number" == typeof end ? end : begin;
var scrollCalc = parseInt(((input.ownerDocument.defaultView || window).getComputedStyle ? (input.ownerDocument.defaultView || window).getComputedStyle(input, null) : input.currentStyle).fontSize) * end;
if (input.scrollLeft = scrollCalc > input.scrollWidth ? scrollCalc : 0, mobile || opts.insertMode !== !1 || begin !== end || end++,
input.setSelectionRange) input.selectionStart = begin, input.selectionEnd = end; else if (window.getSelection) {
if (range = document.createRange(), void 0 === input.firstChild || null === input.firstChild) {
var textNode = document.createTextNode("");
input.appendChild(textNode);
}
range.setStart(input.firstChild, begin < input.inputmask._valueGet().length ? begin : input.inputmask._valueGet().length),
range.setEnd(input.firstChild, end < input.inputmask._valueGet().length ? end : input.inputmask._valueGet().length),
range.collapse(!0);
var sel = window.getSelection();
sel