arrow-admin
Version:
Arrow Admin Website
357 lines • 23.9 kB
JavaScript
/*!
* jquery.inputmask.numeric.extensions.js
* http://github.com/RobinHerbots/jquery.inputmask
* Copyright (c) 2010 - 2015 Robin Herbots
* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
* Version: 3.1.63
*/
!function(factory) {
"function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./jquery.inputmask")) : factory(jQuery);
}(function($) {
return $.extend($.inputmask.defaults.aliases, {
numeric: {
mask: function(opts) {
function autoEscape(txt) {
for (var escapedTxt = "", i = 0; i < txt.length; i++) escapedTxt += opts.definitions[txt[i]] ? "\\" + txt[i] : txt[i];
return escapedTxt;
}
if (0 !== opts.repeat && isNaN(opts.integerDigits) && (opts.integerDigits = opts.repeat),
opts.repeat = 0, opts.groupSeparator == opts.radixPoint && ("." == opts.radixPoint ? opts.groupSeparator = "," : "," == opts.radixPoint ? opts.groupSeparator = "." : opts.groupSeparator = ""),
" " === opts.groupSeparator && (opts.skipOptionalPartCharacter = void 0), opts.autoGroup = opts.autoGroup && "" != opts.groupSeparator,
opts.autoGroup && ("string" == typeof opts.groupSize && isFinite(opts.groupSize) && (opts.groupSize = parseInt(opts.groupSize)),
isFinite(opts.integerDigits))) {
var seps = Math.floor(opts.integerDigits / opts.groupSize), mod = opts.integerDigits % opts.groupSize;
opts.integerDigits = parseInt(opts.integerDigits) + (0 == mod ? seps - 1 : seps);
}
opts.placeholder.length > 1 && (opts.placeholder = opts.placeholder.charAt(0)),
opts.radixFocus = opts.radixFocus && "0" == opts.placeholder, opts.definitions[";"] = opts.definitions["~"];
var mask = autoEscape(opts.prefix);
return mask += "[+]", mask += "~{1," + opts.integerDigits + "}", void 0 != opts.digits && (isNaN(opts.digits) || parseInt(opts.digits) > 0) && (mask += opts.digitsOptional ? "[" + (opts.decimalProtect ? ":" : opts.radixPoint) + ";{" + opts.digits + "}]" : (opts.decimalProtect ? ":" : opts.radixPoint) + ";{" + opts.digits + "}"),
"" != opts.negationSymbol.back && (mask += "[-]"), mask += autoEscape(opts.suffix),
opts.greedy = !1, mask;
},
placeholder: "",
greedy: !1,
digits: "*",
digitsOptional: !0,
groupSeparator: "",
radixPoint: ".",
radixFocus: !0,
groupSize: 3,
autoGroup: !1,
allowPlus: !0,
allowMinus: !0,
negationSymbol: {
front: "-",
back: ""
},
integerDigits: "+",
prefix: "",
suffix: "",
rightAlign: !0,
decimalProtect: !0,
min: void 0,
max: void 0,
postFormat: function(buffer, pos, reformatOnly, opts) {
var suffixStripped = !1;
buffer.length >= opts.suffix.length && buffer.join("").indexOf(opts.suffix) == buffer.length - opts.suffix.length && (buffer.length = buffer.length - opts.suffix.length,
suffixStripped = !0), pos = pos >= buffer.length ? buffer.length - 1 : pos < opts.prefix.length ? opts.prefix.length : pos;
var needsRefresh = !1, charAtPos = buffer[pos];
if ("" == opts.groupSeparator || -1 != $.inArray(opts.radixPoint, buffer) && pos >= $.inArray(opts.radixPoint, buffer) || new RegExp("[" + $.inputmask.escapeRegex(opts.negationSymbol.front) + "+]").test(charAtPos)) {
if (suffixStripped) for (var i = 0, l = opts.suffix.length; l > i; i++) buffer.push(opts.suffix.charAt(i));
return {
pos: pos
};
}
var cbuf = buffer.slice();
charAtPos == opts.groupSeparator && (cbuf.splice(pos--, 1), charAtPos = cbuf[pos]),
reformatOnly ? cbuf[pos] = "?" : cbuf.splice(pos, 0, "?");
var bufVal = cbuf.join(""), bufValOrigin = bufVal;
if (bufVal.length > 0 && opts.autoGroup || reformatOnly && -1 != bufVal.indexOf(opts.groupSeparator)) {
var escapedGroupSeparator = $.inputmask.escapeRegex(opts.groupSeparator);
needsRefresh = 0 == bufVal.indexOf(opts.groupSeparator), bufVal = bufVal.replace(new RegExp(escapedGroupSeparator, "g"), "");
var radixSplit = bufVal.split(opts.radixPoint);
if (bufVal = "" == opts.radixPoint ? bufVal : radixSplit[0], bufVal != opts.prefix + "?0" && bufVal.length >= opts.groupSize + opts.prefix.length) for (var reg = new RegExp("([-+]?[\\d?]+)([\\d?]{" + opts.groupSize + "})"); reg.test(bufVal); ) bufVal = bufVal.replace(reg, "$1" + opts.groupSeparator + "$2"),
bufVal = bufVal.replace(opts.groupSeparator + opts.groupSeparator, opts.groupSeparator);
"" != opts.radixPoint && radixSplit.length > 1 && (bufVal += opts.radixPoint + radixSplit[1]);
}
needsRefresh = bufValOrigin != bufVal, buffer.length = bufVal.length;
for (var i = 0, l = bufVal.length; l > i; i++) buffer[i] = bufVal.charAt(i);
var newPos = $.inArray("?", buffer);
if (reformatOnly ? buffer[newPos] = charAtPos : buffer.splice(newPos, 1), !needsRefresh && suffixStripped) for (var i = 0, l = opts.suffix.length; l > i; i++) buffer.push(opts.suffix.charAt(i));
return {
pos: newPos,
refreshFromBuffer: needsRefresh,
buffer: buffer
};
},
onBeforeWrite: function(e, buffer, caretPos, opts) {
if (e && "blur" == e.type) {
var maskedValue = buffer.join(""), processValue = maskedValue.replace(opts.prefix, "");
if (processValue = processValue.replace(opts.suffix, ""), processValue = processValue.replace(new RegExp($.inputmask.escapeRegex(opts.groupSeparator), "g"), ""),
"," === opts.radixPoint && (processValue = processValue.replace($.inputmask.escapeRegex(opts.radixPoint), ".")),
isFinite(processValue) && isFinite(opts.min) && parseFloat(processValue) < parseFloat(opts.min)) return $.extend(!0, {
refreshFromBuffer: !0,
buffer: (opts.prefix + opts.min).split("")
}, opts.postFormat((opts.prefix + opts.min).split(""), 0, !0, opts));
var tmpBufSplit = "" != opts.radixPoint ? buffer.join("").split(opts.radixPoint) : [ buffer.join("") ], matchRslt = tmpBufSplit[0].match(opts.regex.integerPart(opts)), matchRsltDigits = 2 == tmpBufSplit.length ? tmpBufSplit[1].match(opts.regex.integerNPart(opts)) : void 0;
!matchRslt || matchRslt[0] != opts.negationSymbol.front + "0" && matchRslt[0] != opts.negationSymbol.front && "+" != matchRslt[0] || void 0 != matchRsltDigits && !matchRsltDigits[0].match(/^0+$/) || buffer.splice(matchRslt.index, 1);
var radixPosition = $.inArray(opts.radixPoint, buffer);
if (-1 != radixPosition && isFinite(opts.digits) && !opts.digitsOptional) {
for (var i = 1; i <= opts.digits; i++) (void 0 == buffer[radixPosition + i] || buffer[radixPosition + i] == opts.placeholder.charAt(0)) && (buffer[radixPosition + i] = "0");
return {
refreshFromBuffer: !0,
buffer: buffer
};
}
}
if (opts.autoGroup) {
var rslt = opts.postFormat(buffer, caretPos - 1, !0, opts);
return rslt.caret = caretPos <= opts.prefix.length ? rslt.pos : rslt.pos + 1, rslt;
}
},
regex: {
integerPart: function(opts) {
return new RegExp("[" + $.inputmask.escapeRegex(opts.negationSymbol.front) + "+]?\\d+");
},
integerNPart: function(opts) {
return new RegExp("[\\d" + $.inputmask.escapeRegex(opts.groupSeparator) + "]+");
}
},
signHandler: function(chrs, maskset, pos, strict, opts) {
if (!strict && opts.allowMinus && "-" === chrs || opts.allowPlus && "+" === chrs) {
var matchRslt = maskset.buffer.join("").match(opts.regex.integerPart(opts));
if (matchRslt && matchRslt[0].length > 0) return maskset.buffer[matchRslt.index] == ("-" === chrs ? "+" : opts.negationSymbol.front) ? "-" == chrs ? "" != opts.negationSymbol.back ? {
pos: matchRslt.index,
c: opts.negationSymbol.front,
remove: matchRslt.index,
caret: pos,
insert: {
pos: maskset.buffer.length - opts.suffix.length - 1,
c: opts.negationSymbol.back
}
} : {
pos: matchRslt.index,
c: opts.negationSymbol.front,
remove: matchRslt.index,
caret: pos
} : "" != opts.negationSymbol.back ? {
pos: matchRslt.index,
c: "+",
remove: [ matchRslt.index, maskset.buffer.length - opts.suffix.length - 1 ],
caret: pos
} : {
pos: matchRslt.index,
c: "+",
remove: matchRslt.index,
caret: pos
} : maskset.buffer[matchRslt.index] == ("-" === chrs ? opts.negationSymbol.front : "+") ? "-" == chrs && "" != opts.negationSymbol.back ? {
remove: [ matchRslt.index, maskset.buffer.length - opts.suffix.length - 1 ],
caret: pos - 1
} : {
remove: matchRslt.index,
caret: pos - 1
} : "-" == chrs ? "" != opts.negationSymbol.back ? {
pos: matchRslt.index,
c: opts.negationSymbol.front,
caret: pos + 1,
insert: {
pos: maskset.buffer.length - opts.suffix.length,
c: opts.negationSymbol.back
}
} : {
pos: matchRslt.index,
c: opts.negationSymbol.front,
caret: pos + 1
} : {
pos: matchRslt.index,
c: chrs,
caret: pos + 1
};
}
return !1;
},
radixHandler: function(chrs, maskset, pos, strict, opts) {
if (!strict && chrs === opts.radixPoint && opts.digits > 0) {
var radixPos = $.inArray(opts.radixPoint, maskset.buffer), integerValue = maskset.buffer.join("").match(opts.regex.integerPart(opts));
if (-1 != radixPos && maskset.validPositions[radixPos]) return maskset.validPositions[radixPos - 1] ? {
caret: radixPos + 1
} : {
pos: integerValue.index,
c: integerValue[0],
caret: radixPos + 1
};
if (!integerValue || "0" == integerValue[0] && integerValue.index + 1 != pos) return maskset.buffer[integerValue ? integerValue.index : pos] = "0",
{
pos: (integerValue ? integerValue.index : pos) + 1
};
}
return !1;
},
leadingZeroHandler: function(chrs, maskset, pos, strict, opts) {
var matchRslt = maskset.buffer.join("").match(opts.regex.integerNPart(opts)), radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
if (matchRslt && !strict && (-1 == radixPosition || radixPosition >= pos)) if (0 == matchRslt[0].indexOf("0")) {
pos < opts.prefix.length && (pos = matchRslt.index);
var _radixPosition = $.inArray(opts.radixPoint, maskset._buffer), digitsMatch = maskset._buffer && maskset.buffer.slice(radixPosition).join("") == maskset._buffer.slice(_radixPosition).join("") || 0 == parseInt(maskset.buffer.slice(radixPosition + 1).join("")), integerMatch = maskset._buffer && maskset.buffer.slice(matchRslt.index, radixPosition).join("") == maskset._buffer.slice(opts.prefix.length, _radixPosition).join("") || "0" == maskset.buffer.slice(matchRslt.index, radixPosition).join("");
if (-1 == radixPosition || digitsMatch && integerMatch) return maskset.buffer.splice(matchRslt.index, 1),
pos = pos > matchRslt.index ? pos - 1 : matchRslt.index, {
pos: pos,
remove: matchRslt.index
};
if (matchRslt.index + 1 == pos || "0" == chrs) return maskset.buffer.splice(matchRslt.index, 1),
pos = matchRslt.index, {
pos: pos,
remove: matchRslt.index
};
} else if ("0" === chrs && pos <= matchRslt.index && matchRslt[0] != opts.groupSeparator) return !1;
return !0;
},
postValidation: function(buffer, opts) {
var isValid = !0, maskedValue = buffer.join(""), processValue = maskedValue.replace(opts.prefix, "");
return processValue = processValue.replace(opts.suffix, ""), processValue = processValue.replace(new RegExp($.inputmask.escapeRegex(opts.groupSeparator), "g"), ""),
"," === opts.radixPoint && (processValue = processValue.replace($.inputmask.escapeRegex(opts.radixPoint), ".")),
processValue = processValue.replace(new RegExp("^" + $.inputmask.escapeRegex(opts.negationSymbol.front)), "-"),
processValue = processValue.replace(new RegExp($.inputmask.escapeRegex(opts.negationSymbol.back) + "$"), ""),
isFinite(processValue) && isFinite(opts.max) && (isValid = parseFloat(processValue) <= parseFloat(opts.max)),
isValid;
},
definitions: {
"~": {
validator: function(chrs, maskset, pos, strict, opts) {
var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
if (!isValid && (isValid = opts.radixHandler(chrs, maskset, pos, strict, opts),
!isValid && (isValid = strict ? new RegExp("[0-9" + $.inputmask.escapeRegex(opts.groupSeparator) + "]").test(chrs) : new RegExp("[0-9]").test(chrs),
isValid === !0 && (isValid = opts.leadingZeroHandler(chrs, maskset, pos, strict, opts),
isValid === !0)))) {
var radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
isValid = opts.digitsOptional === !1 && pos > radixPosition && !strict ? {
pos: pos,
remove: pos
} : {
pos: pos
};
}
return isValid;
},
cardinality: 1,
prevalidator: null
},
"+": {
validator: function(chrs, maskset, pos, strict, opts) {
var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
return !isValid && (strict && opts.allowMinus && chrs === opts.negationSymbol.front || opts.allowMinus && "-" == chrs || opts.allowPlus && "+" == chrs) && (isValid = "-" == chrs ? "" != opts.negationSymbol.back ? {
pos: pos,
c: "-" === chrs ? opts.negationSymbol.front : "+",
caret: pos + 1,
insert: {
pos: maskset.buffer.length,
c: opts.negationSymbol.back
}
} : {
pos: pos,
c: "-" === chrs ? opts.negationSymbol.front : "+",
caret: pos + 1
} : !0), isValid;
},
cardinality: 1,
prevalidator: null,
placeholder: ""
},
"-": {
validator: function(chrs, maskset, pos, strict, opts) {
var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
return !isValid && strict && opts.allowMinus && chrs === opts.negationSymbol.back && (isValid = !0),
isValid;
},
cardinality: 1,
prevalidator: null,
placeholder: ""
},
":": {
validator: function(chrs, maskset, pos, strict, opts) {
var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
if (!isValid) {
var radix = "[" + $.inputmask.escapeRegex(opts.radixPoint) + "]";
isValid = new RegExp(radix).test(chrs), isValid && maskset.validPositions[pos] && maskset.validPositions[pos].match.placeholder == opts.radixPoint && (isValid = {
caret: pos + 1
});
}
return isValid;
},
cardinality: 1,
prevalidator: null,
placeholder: function(opts) {
return opts.radixPoint;
}
}
},
insertMode: !0,
autoUnmask: !1,
unmaskAsNumber: !1,
onUnMask: function(maskedValue, unmaskedValue, opts) {
var processValue = maskedValue.replace(opts.prefix, "");
return processValue = processValue.replace(opts.suffix, ""), processValue = processValue.replace(new RegExp($.inputmask.escapeRegex(opts.groupSeparator), "g"), ""),
opts.unmaskAsNumber ? (processValue = processValue.replace($.inputmask.escapeRegex.call(this, opts.radixPoint), "."),
Number(processValue)) : processValue;
},
isComplete: function(buffer, opts) {
var maskedValue = buffer.join(""), bufClone = buffer.slice();
if (opts.postFormat(bufClone, 0, !0, opts), bufClone.join("") != maskedValue) return !1;
var processValue = maskedValue.replace(opts.prefix, "");
return processValue = processValue.replace(opts.suffix, ""), processValue = processValue.replace(new RegExp($.inputmask.escapeRegex(opts.groupSeparator), "g"), ""),
"," === opts.radixPoint && (processValue = processValue.replace($.inputmask.escapeRegex(opts.radixPoint), ".")),
isFinite(processValue);
},
onBeforeMask: function(initialValue, opts) {
if ("" != opts.radixPoint && isFinite(initialValue)) initialValue = initialValue.toString().replace(".", opts.radixPoint); else {
var kommaMatches = initialValue.match(/,/g), dotMatches = initialValue.match(/\./g);
dotMatches && kommaMatches ? dotMatches.length > kommaMatches.length ? (initialValue = initialValue.replace(/\./g, ""),
initialValue = initialValue.replace(",", opts.radixPoint)) : kommaMatches.length > dotMatches.length ? (initialValue = initialValue.replace(/,/g, ""),
initialValue = initialValue.replace(".", opts.radixPoint)) : initialValue = initialValue.indexOf(".") < initialValue.indexOf(",") ? initialValue.replace(/\./g, "") : initialValue = initialValue.replace(/,/g, "") : initialValue = initialValue.replace(new RegExp($.inputmask.escapeRegex(opts.groupSeparator), "g"), "");
}
return 0 == opts.digits && (-1 != initialValue.indexOf(".") ? initialValue = initialValue.substring(0, initialValue.indexOf(".")) : -1 != initialValue.indexOf(",") && (initialValue = initialValue.substring(0, initialValue.indexOf(",")))),
initialValue;
},
canClearPosition: function(maskset, position, lvp, strict, opts) {
var positionInput = maskset.validPositions[position].input, canClear = positionInput != opts.radixPoint && isFinite(positionInput) || position == lvp || positionInput == opts.groupSeparator || positionInput == opts.negationSymbol.front || positionInput == opts.negationSymbol.back;
if (canClear && isFinite(positionInput)) {
var matchRslt;
if (!strict && maskset.buffer) {
matchRslt = maskset.buffer.join("").substr(0, position).match(opts.regex.integerNPart(opts));
var pos = position + 1, isNull = null == matchRslt || 0 == parseInt(matchRslt[0].replace(new RegExp($.inputmask.escapeRegex(opts.groupSeparator), "g"), ""));
if (isNull) for (;maskset.validPositions[pos] && (maskset.validPositions[pos].input == opts.groupSeparator || "0" == maskset.validPositions[pos].input); ) delete maskset.validPositions[pos],
pos++;
}
var buffer = [];
for (var vp in maskset.validPositions) buffer.push(maskset.validPositions[vp].input);
matchRslt = buffer.join("").match(opts.regex.integerNPart(opts));
var radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
if (matchRslt && (-1 == radixPosition || radixPosition >= position)) if (0 == matchRslt[0].indexOf("0")) canClear = matchRslt.index != position || -1 == radixPosition; else {
var intPart = parseInt(matchRslt[0].replace(new RegExp($.inputmask.escapeRegex(opts.groupSeparator), "g"), ""));
-1 != radixPosition && 10 > intPart && "0" == opts.placeholder.charAt(0) && (maskset.validPositions[position].input = "0",
maskset.p = opts.prefix.length + 1, canClear = !1);
}
}
return canClear;
}
},
currency: {
prefix: "$ ",
groupSeparator: ",",
alias: "numeric",
placeholder: "0",
autoGroup: !0,
digits: 2,
digitsOptional: !1,
clearMaskOnLostFocus: !1
},
decimal: {
alias: "numeric"
},
integer: {
alias: "numeric",
digits: "0",
radixPoint: ""
}
}), $.fn.inputmask;
});