inputmask
Advanced tools
Comparing version 5.0.8-beta.25 to 5.0.8-beta.47
@@ -1,2 +0,2 @@ | ||
import keyCode from "./keycode.json"; | ||
import {keys} from "./keycode.js"; | ||
@@ -55,31 +55,36 @@ export default { | ||
ignorables: [ | ||
keyCode.BACKSPACE, | ||
keyCode.TAB, | ||
keyCode["PAUSE/BREAK"], | ||
keyCode.ESCAPE, | ||
keyCode.PAGE_UP, | ||
keyCode.PAGE_DOWN, | ||
keyCode.END, | ||
keyCode.HOME, | ||
keyCode.LEFT, | ||
keyCode.UP, | ||
keyCode.RIGHT, | ||
keyCode.DOWN, | ||
keyCode.INSERT, | ||
keyCode.DELETE, | ||
93, | ||
112, | ||
113, | ||
114, | ||
115, | ||
116, | ||
117, | ||
118, | ||
119, | ||
120, | ||
121, | ||
122, | ||
123, | ||
0, | ||
229 | ||
keys.Backspace, | ||
keys.Tab, | ||
keys.Pause, | ||
keys.Escape, | ||
keys.PageUp, | ||
keys.PageDown, | ||
keys.End, | ||
keys.Home, | ||
keys.ArrowLeft, | ||
keys.ArrowUp, | ||
keys.ArrowRight, | ||
keys.ArrowDown, | ||
keys.Insert, | ||
keys.Delete, | ||
keys.ContextMenu, | ||
keys.F1, | ||
keys.F2, | ||
keys.F3, | ||
keys.F4, | ||
keys.F5, | ||
keys.F6, | ||
keys.F7, | ||
keys.F8, | ||
keys.F9, | ||
keys.F10, | ||
keys.F11, | ||
keys.F12, | ||
keys.KEY_229, | ||
keys.Shift, | ||
keys.Control, | ||
keys.Alt, | ||
keys.Tab, | ||
keys.AltGraph, | ||
keys.CapsLock | ||
], | ||
@@ -102,2 +107,2 @@ isComplete: null, //override for isComplete - args => buffer, opts - return true || false | ||
substitutes: {} //define character substitutes | ||
}; | ||
}; |
@@ -10,3 +10,3 @@ import { | ||
} from "./positioning"; | ||
import keyCode from "./keycode.json"; | ||
import {keyCode, keys} from "./keycode.js"; | ||
import {iemobile, iphone} from "./environment"; | ||
@@ -20,3 +20,3 @@ import {handleRemove, isComplete, isSelection, isValid} from "./validation"; | ||
var EventHandlers = { | ||
keydownEvent: function (e) { | ||
keyEvent: function (e, checkval, writeOut, strict, ndx) { | ||
const inputmask = this.inputmask, opts = inputmask.opts, $ = inputmask.dependencyLib, | ||
@@ -27,3 +27,3 @@ maskset = inputmask.maskset; | ||
$input = $(input), | ||
k = e.keyCode, | ||
c = e.key, | ||
pos = caret.call(inputmask, input); | ||
@@ -35,17 +35,17 @@ | ||
//backspace, delete, and escape get special treatment | ||
if (k === keyCode.BACKSPACE || k === keyCode.DELETE || (iphone && k === keyCode.BACKSPACE_SAFARI) || (e.ctrlKey && k === keyCode.X && !("oncut" in input))) { //backspace/delete | ||
if (c === keys.Backspace || c === keys.Delete || (iphone && c === keys.BACKSPACE_SAFARI) || (e.ctrlKey && c === keys.x && !("oncut" in input))) { //backspace/delete | ||
e.preventDefault(); //stop default action but allow propagation | ||
handleRemove.call(inputmask, input, k, pos); | ||
handleRemove.call(inputmask, input, c, pos); | ||
writeBuffer(input, getBuffer.call(inputmask, true), maskset.p, e, input.inputmask._valueGet() !== getBuffer.call(inputmask).join("")); | ||
} else if (k === keyCode.END || k === keyCode.PAGE_DOWN) { //when END or PAGE_DOWN pressed set position at lastmatch | ||
} else if (c === keys.End || c === keys.PageDown) { //when END or PAGE_DOWN pressed set position at lastmatch | ||
e.preventDefault(); | ||
var caretPos = seekNext.call(inputmask, getLastValidPosition.call(inputmask)); | ||
caret.call(inputmask, input, e.shiftKey ? pos.begin : caretPos, caretPos, true); | ||
} else if ((k === keyCode.HOME && !e.shiftKey) || k === keyCode.PAGE_UP) { //Home or page_up | ||
} else if ((c === keys.Home && !e.shiftKey) || c === keys.PageUp) { //Home or page_up | ||
e.preventDefault(); | ||
caret.call(inputmask, input, 0, e.shiftKey ? pos.begin : 0, true); | ||
} else if (((opts.undoOnEscape && k === keyCode.ESCAPE) || (false && k === keyCode.Z && e.ctrlKey)) && e.altKey !== true) { //escape && undo && #762 | ||
} else if (((opts.undoOnEscape && c === keys.Escape) || (false && c === keys.z && e.ctrlKey)) && e.altKey !== true) { //escape && undo && #762 | ||
checkVal(input, true, false, inputmask.undoValue.split("")); | ||
$input.trigger("click"); | ||
} else if (k === keyCode.INSERT && !(e.shiftKey || e.ctrlKey) && inputmask.userOptions.insertMode === undefined) { //insert | ||
} else if (c === keys.Insert && !(e.shiftKey || e.ctrlKey) && inputmask.userOptions.insertMode === undefined) { //insert | ||
if (!isSelection.call(inputmask, pos)) { | ||
@@ -55,3 +55,3 @@ opts.insertMode = !opts.insertMode; | ||
} else opts.insertMode = !opts.insertMode; | ||
} else if (opts.tabThrough === true && k === keyCode.TAB) { | ||
} else if (opts.tabThrough === true && c === keys.Tab) { | ||
if (e.shiftKey === true) { | ||
@@ -78,3 +78,3 @@ pos.end = seekPrevious.call(inputmask, pos.end, true); | ||
if (opts.insertModeVisual && opts.insertMode === false) { | ||
if (k === keyCode.RIGHT) { | ||
if (c === keys.ArrowRight) { | ||
setTimeout(function () { | ||
@@ -84,3 +84,3 @@ var caretPos = caret.call(inputmask, input); | ||
}, 0); | ||
} else if (k === keyCode.LEFT) { | ||
} else if (c === keys.ArrowLeft) { | ||
setTimeout(function () { | ||
@@ -101,3 +101,4 @@ var caretPos = { | ||
inputmask.ignorable = opts.ignorables.includes(k); | ||
inputmask.ignorable = opts.ignorables.includes(c); | ||
return EventHandlers.keypressEvent.call(this, e, checkval, writeOut, strict, ndx); | ||
}, | ||
@@ -110,6 +111,6 @@ keypressEvent: function (e, checkval, writeOut, strict, ndx) { | ||
$input = $(input), | ||
k = e.keyCode; | ||
c = e.key; | ||
if (checkval !== true && (!(e.ctrlKey && e.altKey) && (e.ctrlKey || e.metaKey || inputmask.ignorable))) { | ||
if (k === keyCode.ENTER && inputmask.undoValue !== inputmask._valueGet(true)) { | ||
if (c === keys.Enter && inputmask.undoValue !== inputmask._valueGet(true)) { | ||
inputmask.undoValue = inputmask._valueGet(true); | ||
@@ -121,7 +122,7 @@ // e.preventDefault(); | ||
} | ||
inputmask.skipInputEvent = true; //skip the input as otherwise the skipped char could be picked up for validation by the inputfallback | ||
return true; | ||
} else if (k) { | ||
//inputmask.skipInputEvent = true; //skip the input as otherwise the skipped char could be picked up for validation by the inputfallback | ||
return; | ||
} else if (c) { | ||
//special treat the decimal separator | ||
if ((k === 44 || k === 46) && e.location === 3 && opts.radixPoint !== "") k = opts.radixPoint.charCodeAt(0); | ||
// if ((k === 44 || k === 46) && e.location === 3 && opts.radixPoint !== "") k = opts.radixPoint.charCodeAt(0); | ||
var pos = checkval ? { | ||
@@ -131,3 +132,3 @@ begin: ndx, | ||
} : caret.call(inputmask, input), | ||
forwardPosition, c = String.fromCharCode(k); | ||
forwardPosition; | ||
@@ -148,3 +149,3 @@ //allow for character substitution | ||
setTimeout(function () { | ||
opts.onKeyValidation.call(input, k, valResult); | ||
opts.onKeyValidation.call(input, c, valResult); | ||
}, 0); | ||
@@ -169,13 +170,4 @@ if (maskset.writeOutBuffer && valResult !== false) { | ||
if (inputmask.isComposing) { | ||
if (e.keyCode === keyCode.KEY_229 || e.keyCode === keyCode.ENTER) | ||
if (e.keyCode === keyCode.KEY_229 || e.key === keys.Enter) | ||
inputmask.$el.trigger("input"); | ||
else { | ||
// let keypress = new $.Event("keypress"); | ||
// //reset caretpos | ||
// // let caretPos = seekPrevious.call(inputmask, caret.call(inputmask, input).begin); | ||
// // caret.call(inputmask, input, caretPos); | ||
// keypress.keyCode = e.keyCode; | ||
// inputmask.ignorable = false; //make sure ignorable is ignored ;-) | ||
// EventHandlers.keypressEvent.call(this, keypress); | ||
} | ||
} | ||
@@ -350,3 +342,3 @@ }, | ||
var keypress = new $.Event("keypress"); | ||
keypress.keyCode = entry.charCodeAt(0); | ||
keypress.key = entry; | ||
inputmask.ignorable = false; //make sure ignorable is ignored ;-) | ||
@@ -361,4 +353,4 @@ EventHandlers.keypressEvent.call(input, keypress); | ||
var keydown = new $.Event("keydown"); | ||
keydown.keyCode = keyCode.BACKSPACE; | ||
EventHandlers.keydownEvent.call(input, keydown); | ||
keydown.key = keys.Backspace; | ||
EventHandlers.keyEvent.call(input, keydown); | ||
break; | ||
@@ -426,2 +418,3 @@ default: | ||
const inputmask = this.inputmask; | ||
inputmask.clicked++; | ||
@@ -449,3 +442,3 @@ var input = this; | ||
} | ||
handleRemove.call(inputmask, input, keyCode.DELETE, pos); | ||
handleRemove.call(inputmask, input, keys.Delete, pos); | ||
writeBuffer(input, getBuffer.call(inputmask), maskset.p, e, inputmask.undoValue !== inputmask._valueGet(true)); | ||
@@ -455,2 +448,3 @@ }, | ||
const inputmask = this.inputmask, opts = inputmask.opts, $ = inputmask.dependencyLib; | ||
inputmask.clicked=0; | ||
@@ -457,0 +451,0 @@ var $input = $(this), |
import Inputmask from "./inputmask"; | ||
import keyCode from "./keycode.json"; | ||
import {keys} from "./keycode.js"; | ||
import {getBufferTemplate} from "./positioning"; | ||
@@ -9,117 +9,106 @@ import {HandleNativePlaceholder} from "./inputHandling"; | ||
var EventRuler = { | ||
on: function (input, eventName, eventHandler) { | ||
const $ = input.inputmask.dependencyLib; | ||
on: function (input, eventName, eventHandler) { | ||
const $ = input.inputmask.dependencyLib; | ||
var ev = function (e) { | ||
if (e.originalEvent) { | ||
e = e.originalEvent || e; //get original event from jquery evenbt | ||
arguments[0] = e; | ||
} | ||
// console.log(e.type); | ||
var that = this, args, inputmask = that.inputmask, opts = inputmask ? inputmask.opts : undefined; | ||
if (inputmask === undefined && this.nodeName !== "FORM") { //happens when cloning an object with jquery.clone | ||
var imOpts = $.data(that, "_inputmask_opts"); | ||
$(that).off(); //unbind all events | ||
if (imOpts) { | ||
(new Inputmask(imOpts)).mask(that); | ||
} | ||
} else if (!["submit", "reset", "setvalue"].includes(e.type) && this.nodeName !== "FORM" && (that.disabled || (that.readOnly && !(e.type === "keydown" && (e.ctrlKey && e.keyCode === 67) || (opts.tabThrough === false && e.keyCode === keyCode.TAB))))) { | ||
e.preventDefault(); | ||
} else { | ||
switch (e.type) { | ||
case "input": | ||
if (inputmask.skipInputEvent === true || (e.inputType && e.inputType === "insertCompositionText")) { | ||
inputmask.skipInputEvent = false; | ||
return e.preventDefault(); | ||
} | ||
var ev = function (e) { | ||
if (e.originalEvent) { | ||
e = e.originalEvent || e; //get original event from jquery evenbt | ||
arguments[0] = e; | ||
} | ||
// console.log(e.type); | ||
var that = this, args, inputmask = that.inputmask, opts = inputmask ? inputmask.opts : undefined; | ||
if (inputmask === undefined && this.nodeName !== "FORM") { //happens when cloning an object with jquery.clone | ||
var imOpts = $.data(that, "_inputmask_opts"); | ||
$(that).off(); //unbind all events | ||
if (imOpts) { | ||
(new Inputmask(imOpts)).mask(that); | ||
} | ||
} else if (!["submit", "reset", "setvalue"].includes(e.type) && this.nodeName !== "FORM" && (that.disabled || (that.readOnly && !(e.type === "keydown" && (e.ctrlKey && e.key === keys.c) || (opts.tabThrough === false && e.key === keys.Tab))))) { | ||
e.preventDefault(); | ||
} else { | ||
switch (e.type) { | ||
case "input": | ||
if (inputmask.skipInputEvent === true || (e.inputType && e.inputType === "insertCompositionText")) { | ||
inputmask.skipInputEvent = false; | ||
return e.preventDefault(); | ||
} | ||
// if (mobile) { //this causes problem see #2220 | ||
// args = arguments; | ||
// setTimeout(function () { //needed for caret selection when entering a char on Android 8 - #1818 | ||
// eventHandler.apply(that, args); | ||
// caret(that, that.inputmask.caretPos, undefined, true); | ||
// }, 0); | ||
// return false; | ||
// } | ||
break; | ||
case "keydown": | ||
//Safari 5.1.x - modal dialog fires keypress twice workaround | ||
inputmask.skipKeyPressEvent = false; | ||
inputmask.skipInputEvent = inputmask.isComposing = e.keyCode === keyCode.KEY_229; | ||
break; | ||
case "keyup": | ||
case "compositionend": | ||
if (inputmask.isComposing) { | ||
inputmask.skipInputEvent = false; | ||
} | ||
break; | ||
case "keypress": | ||
if (inputmask.skipKeyPressEvent === true) { | ||
return e.preventDefault(); | ||
} | ||
inputmask.skipKeyPressEvent = true; | ||
break; | ||
case "click": | ||
case "focus": | ||
if (inputmask.validationEvent) { // #841 | ||
inputmask.validationEvent = false; | ||
input.blur(); | ||
HandleNativePlaceholder(input, (inputmask.isRTL ? getBufferTemplate.call(inputmask).slice().reverse() : getBufferTemplate.call(inputmask)).join("")); | ||
setTimeout(function () { | ||
input.focus(); | ||
}, opts.validationEventTimeOut); | ||
return false; | ||
} | ||
args = arguments; | ||
setTimeout(function () { //needed for Chrome ~ initial selection clears after the clickevent | ||
if (!input.inputmask) { | ||
// `inputmask.remove()` was called before this callback | ||
return; | ||
} | ||
eventHandler.apply(that, args); | ||
}, 0); | ||
return /*false*/; //#2423 | ||
} | ||
var returnVal = eventHandler.apply(that, arguments); | ||
if (returnVal === false) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
} | ||
return returnVal; | ||
} | ||
}; | ||
if (["submit", "reset"].includes(eventName)) { | ||
ev = ev.bind(input); //bind creates a new eventhandler (wrap) | ||
if (input.form !== null) $(input.form).on(eventName, ev); | ||
} else { | ||
$(input).on(eventName, ev); | ||
} | ||
// if (mobile) { //this causes problem see #2220 | ||
// args = arguments; | ||
// setTimeout(function () { //needed for caret selection when entering a char on Android 8 - #1818 | ||
// eventHandler.apply(that, args); | ||
// caret(that, that.inputmask.caretPos, undefined, true); | ||
// }, 0); | ||
// return false; | ||
// } | ||
break; | ||
case "keyup": | ||
case "compositionend": | ||
if (inputmask.isComposing) { | ||
inputmask.skipInputEvent = false; | ||
} | ||
break; | ||
case "click": | ||
case "focus": | ||
if (inputmask.validationEvent) { // #841 | ||
inputmask.validationEvent = false; | ||
input.blur(); | ||
HandleNativePlaceholder(input, (inputmask.isRTL ? getBufferTemplate.call(inputmask).slice().reverse() : getBufferTemplate.call(inputmask)).join("")); | ||
setTimeout(function () { | ||
input.focus(); | ||
}, opts.validationEventTimeOut); | ||
return false; | ||
} | ||
args = arguments; | ||
setTimeout(function () { //needed for Chrome ~ initial selection clears after the clickevent | ||
if (!input.inputmask) { | ||
// `inputmask.remove()` was called before this callback | ||
return; | ||
} | ||
eventHandler.apply(that, args); | ||
}, 0); | ||
return /*false*/; //#2423 | ||
} | ||
var returnVal = eventHandler.apply(that, arguments); | ||
if (returnVal === false) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
} | ||
return returnVal; | ||
} | ||
}; | ||
if (["submit", "reset"].includes(eventName)) { | ||
ev = ev.bind(input); //bind creates a new eventhandler (wrap) | ||
if (input.form !== null) $(input.form).on(eventName, ev); | ||
} else { | ||
$(input).on(eventName, ev); | ||
} | ||
//keep instance of the event | ||
input.inputmask.events[eventName] = input.inputmask.events[eventName] || []; | ||
input.inputmask.events[eventName].push(ev); | ||
//keep instance of the event | ||
input.inputmask.events[eventName] = input.inputmask.events[eventName] || []; | ||
input.inputmask.events[eventName].push(ev); | ||
}, | ||
off: function (input, event) { | ||
if (input.inputmask && input.inputmask.events) { | ||
const $ = input.inputmask.dependencyLib; | ||
let events = input.inputmask.events; | ||
if (event) { | ||
events = []; | ||
events[event] = input.inputmask.events[event]; | ||
} | ||
for (let eventName in events) { | ||
let evArr = events[eventName]; | ||
while (evArr.length > 0) { | ||
let ev = evArr.pop(); | ||
if (["submit", "reset",].includes(eventName)) { | ||
if (input.form !== null) $(input.form).off(eventName, ev); | ||
} else { | ||
$(input).off(eventName, ev); | ||
} | ||
} | ||
delete input.inputmask.events[eventName]; | ||
} | ||
} | ||
} | ||
}, | ||
off: function (input, event) { | ||
if (input.inputmask && input.inputmask.events) { | ||
const $ = input.inputmask.dependencyLib; | ||
let events = input.inputmask.events; | ||
if (event) { | ||
events = []; | ||
events[event] = input.inputmask.events[event]; | ||
} | ||
for (let eventName in events) { | ||
let evArr = events[eventName]; | ||
while (evArr.length > 0) { | ||
let ev = evArr.pop(); | ||
if (["submit", "reset",].includes(eventName)) { | ||
if (input.form !== null) $(input.form).off(eventName, ev); | ||
} else { | ||
$(input).off(eventName, ev); | ||
} | ||
} | ||
delete input.inputmask.events[eventName]; | ||
} | ||
} | ||
} | ||
}; |
@@ -8,3 +8,3 @@ /* | ||
import Inputmask from "../inputmask"; | ||
import keyCode from "../keycode.json"; | ||
import {keys} from "../keycode.js"; | ||
import escapeRegex from "../escapeRegex"; | ||
@@ -17,328 +17,328 @@ import {seekNext} from "../positioning"; | ||
class DateObject { | ||
constructor(mask, format, opts) { | ||
this.mask = mask; | ||
this.format = format; | ||
this.opts = opts; | ||
this._date = new Date(1, 0, 1); | ||
this.initDateObject(mask, this.opts); | ||
} | ||
constructor(mask, format, opts) { | ||
this.mask = mask; | ||
this.format = format; | ||
this.opts = opts; | ||
this._date = new Date(1, 0, 1); | ||
this.initDateObject(mask, this.opts); | ||
} | ||
get date() { | ||
if (this._date === undefined) { | ||
this._date = new Date(1, 0, 1); | ||
this.initDateObject(undefined, this.opts); | ||
} | ||
return this._date; | ||
} | ||
get date() { | ||
if (this._date === undefined) { | ||
this._date = new Date(1, 0, 1); | ||
this.initDateObject(undefined, this.opts); | ||
} | ||
return this._date; | ||
} | ||
initDateObject(mask, opts) { | ||
let match; | ||
getTokenizer(opts).lastIndex = 0; | ||
while ((match = getTokenizer(opts).exec(this.format))) { | ||
let dynMatches = new RegExp("\\d+$").exec(match[0]), | ||
fcode = dynMatches ? (match[0][0] + "x") : match[0], | ||
value; | ||
if (mask !== undefined) { | ||
if (dynMatches) { | ||
let lastIndex = getTokenizer(opts).lastIndex, | ||
tokenMatch = getTokenMatch(match.index, opts); | ||
getTokenizer(opts).lastIndex = lastIndex; | ||
value = mask.slice(0, mask.indexOf(tokenMatch.nextMatch[0])); | ||
} else { | ||
value = mask.slice(0, (formatCode[fcode] && formatCode[fcode][4]) || fcode.length); | ||
} | ||
mask = mask.slice(value.length); | ||
} | ||
initDateObject(mask, opts) { | ||
let match; | ||
getTokenizer(opts).lastIndex = 0; | ||
while ((match = getTokenizer(opts).exec(this.format))) { | ||
let dynMatches = new RegExp("\\d+$").exec(match[0]), | ||
fcode = dynMatches ? (match[0][0] + "x") : match[0], | ||
value; | ||
if (mask !== undefined) { | ||
if (dynMatches) { | ||
let lastIndex = getTokenizer(opts).lastIndex, | ||
tokenMatch = getTokenMatch(match.index, opts); | ||
getTokenizer(opts).lastIndex = lastIndex; | ||
value = mask.slice(0, mask.indexOf(tokenMatch.nextMatch[0])); | ||
} else { | ||
value = mask.slice(0, (formatCode[fcode] && formatCode[fcode][4]) || fcode.length); | ||
} | ||
mask = mask.slice(value.length); | ||
} | ||
if (Object.prototype.hasOwnProperty.call(formatCode, fcode)) { | ||
this.setValue(this, value, fcode, formatCode[fcode][2], formatCode[fcode][1]); | ||
} | ||
} | ||
} | ||
if (Object.prototype.hasOwnProperty.call(formatCode, fcode)) { | ||
this.setValue(this, value, fcode, formatCode[fcode][2], formatCode[fcode][1]); | ||
} | ||
} | ||
} | ||
setValue(dateObj, value, fcode, targetProp, dateOperation) { | ||
if (value !== undefined) { | ||
dateObj[targetProp] = targetProp === "ampm" ? value : value.replace(/[^0-9]/g, "0"); | ||
dateObj["raw" + targetProp] = value.replace(/\s/g, "_"); | ||
} | ||
if (dateOperation !== undefined) { | ||
let datavalue = dateObj[targetProp]; | ||
if ((targetProp === "day" && parseInt(datavalue) === 29) || (targetProp === "month" && parseInt(datavalue) === 2)) { | ||
if (parseInt(dateObj.day) === 29 && parseInt(dateObj.month) === 2 && (dateObj.year === "" || dateObj.year === undefined)) { | ||
//set temporary leap year in dateObj | ||
dateObj._date.setFullYear(2012, 1, 29); | ||
} | ||
} | ||
if (targetProp === "day") { | ||
useDateObject = true; | ||
if (parseInt(datavalue) === 0) | ||
datavalue = 1; | ||
} | ||
if (targetProp === "month") | ||
useDateObject = true; | ||
if (targetProp === "year") { | ||
useDateObject = true; | ||
if (datavalue.length < 4) | ||
datavalue = pad(datavalue, 4, true); | ||
} | ||
if (datavalue !== "" && !isNaN(datavalue)) dateOperation.call(dateObj._date, datavalue); | ||
if (targetProp === "ampm") | ||
dateOperation.call(dateObj._date, datavalue); | ||
} | ||
} | ||
setValue(dateObj, value, fcode, targetProp, dateOperation) { | ||
if (value !== undefined) { | ||
dateObj[targetProp] = targetProp === "ampm" ? value : value.replace(/[^0-9]/g, "0"); | ||
dateObj["raw" + targetProp] = value.replace(/\s/g, "_"); | ||
} | ||
if (dateOperation !== undefined) { | ||
let datavalue = dateObj[targetProp]; | ||
if ((targetProp === "day" && parseInt(datavalue) === 29) || (targetProp === "month" && parseInt(datavalue) === 2)) { | ||
if (parseInt(dateObj.day) === 29 && parseInt(dateObj.month) === 2 && (dateObj.year === "" || dateObj.year === undefined)) { | ||
//set temporary leap year in dateObj | ||
dateObj._date.setFullYear(2012, 1, 29); | ||
} | ||
} | ||
if (targetProp === "day") { | ||
useDateObject = true; | ||
if (parseInt(datavalue) === 0) | ||
datavalue = 1; | ||
} | ||
if (targetProp === "month") | ||
useDateObject = true; | ||
if (targetProp === "year") { | ||
useDateObject = true; | ||
if (datavalue.length < 4) | ||
datavalue = pad(datavalue, 4, true); | ||
} | ||
if (datavalue !== "" && !isNaN(datavalue)) dateOperation.call(dateObj._date, datavalue); | ||
if (targetProp === "ampm") | ||
dateOperation.call(dateObj._date, datavalue); | ||
} | ||
} | ||
reset() { | ||
this._date = new Date(1, 0, 1); | ||
} | ||
reset() { | ||
this._date = new Date(1, 0, 1); | ||
} | ||
reInit() { | ||
this._date = undefined; | ||
this.date; | ||
} | ||
reInit() { | ||
this._date = undefined; | ||
this.date; | ||
} | ||
} | ||
let currentYear = new Date().getFullYear(), | ||
useDateObject = false, | ||
//supported codes for formatting | ||
//http://blog.stevenlevithan.com/archives/date-time-format | ||
//https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings?view=netframework-4.7 | ||
formatCode = { //regex, valueSetter, type, displayformatter, #entries (optional) | ||
d: ["[1-9]|[12][0-9]|3[01]", Date.prototype.setDate, "day", Date.prototype.getDate], //Day of the month as digits; no leading zero for single-digit days. | ||
dd: ["0[1-9]|[12][0-9]|3[01]", Date.prototype.setDate, "day", function () { | ||
return pad(Date.prototype.getDate.call(this), 2); | ||
}], //Day of the month as digits; leading zero for single-digit days. | ||
ddd: [""], //Day of the week as a three-letter abbreviation. | ||
dddd: [""], //Day of the week as its full name. | ||
m: ["[1-9]|1[012]", function (val) { | ||
let mval = val ? parseInt(val) : 0; | ||
if (mval > 0) mval--; | ||
return Date.prototype.setMonth.call(this, mval); | ||
}, "month", function () { | ||
return Date.prototype.getMonth.call(this) + 1; | ||
}], //Month as digits; no leading zero for single-digit months. | ||
mm: ["0[1-9]|1[012]", function (val) { | ||
let mval = val ? parseInt(val) : 0; | ||
if (mval > 0) mval--; | ||
return Date.prototype.setMonth.call(this, mval); | ||
}, "month", function () { | ||
return pad(Date.prototype.getMonth.call(this) + 1, 2); | ||
}], //Month as digits; leading zero for single-digit months. | ||
mmm: [""], //Month as a three-letter abbreviation. | ||
mmmm: [""], //Month as its full name. | ||
yy: ["[0-9]{2}", Date.prototype.setFullYear, "year", function () { | ||
return pad(Date.prototype.getFullYear.call(this), 2); | ||
}], //Year as last two digits; leading zero for years less than 10. | ||
yyyy: ["[0-9]{4}", Date.prototype.setFullYear, "year", function () { | ||
return pad(Date.prototype.getFullYear.call(this), 4); | ||
}], | ||
h: ["[1-9]|1[0-2]", Date.prototype.setHours, "hours", Date.prototype.getHours], //Hours; no leading zero for single-digit hours (12-hour clock). | ||
hh: ["0[1-9]|1[0-2]", Date.prototype.setHours, "hours", function () { | ||
return pad(Date.prototype.getHours.call(this), 2); | ||
}], //Hours; leading zero for single-digit hours (12-hour clock). | ||
hx: [function (x) { | ||
return `[0-9]{${x}}`; | ||
}, Date.prototype.setHours, "hours", function (x) { | ||
return Date.prototype.getHours; | ||
}], //Hours; no limit; set maximum digits | ||
H: ["1?[0-9]|2[0-3]", Date.prototype.setHours, "hours", Date.prototype.getHours], //Hours; no leading zero for single-digit hours (24-hour clock). | ||
HH: ["0[0-9]|1[0-9]|2[0-3]", Date.prototype.setHours, "hours", function () { | ||
return pad(Date.prototype.getHours.call(this), 2); | ||
}], //Hours; leading zero for single-digit hours (24-hour clock). | ||
Hx: [function (x) { | ||
return `[0-9]{${x}}`; | ||
}, Date.prototype.setHours, "hours", function (x) { | ||
return function () { | ||
return pad(Date.prototype.getHours.call(this), x); | ||
}; | ||
}], //Hours; no limit; set maximum digits | ||
M: ["[1-5]?[0-9]", Date.prototype.setMinutes, "minutes", Date.prototype.getMinutes], //Minutes; no leading zero for single-digit minutes. Uppercase M unlike CF timeFormat's m to avoid conflict with months. | ||
MM: ["0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]", Date.prototype.setMinutes, "minutes", function () { | ||
return pad(Date.prototype.getMinutes.call(this), 2); | ||
}], //Minutes; leading zero for single-digit minutes. Uppercase MM unlike CF timeFormat's mm to avoid conflict with months. | ||
s: ["[1-5]?[0-9]", Date.prototype.setSeconds, "seconds", Date.prototype.getSeconds], //Seconds; no leading zero for single-digit seconds. | ||
ss: ["0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]", Date.prototype.setSeconds, "seconds", function () { | ||
return pad(Date.prototype.getSeconds.call(this), 2); | ||
}], //Seconds; leading zero for single-digit seconds. | ||
l: ["[0-9]{3}", Date.prototype.setMilliseconds, "milliseconds", function () { | ||
return pad(Date.prototype.getMilliseconds.call(this), 3); | ||
}, 3], //Milliseconds. 3 digits. | ||
L: ["[0-9]{2}", Date.prototype.setMilliseconds, "milliseconds", function () { | ||
return pad(Date.prototype.getMilliseconds.call(this), 2); | ||
}, 2], //Milliseconds. 2 digits. | ||
t: ["[ap]", setAMPM, "ampm", getAMPM, 1], //Lowercase, single-character time marker string: a or p. | ||
tt: ["[ap]m", setAMPM, "ampm", getAMPM, 2], //two-character time marker string: am or pm. | ||
T: ["[AP]", setAMPM, "ampm", getAMPM, 1], //single-character time marker string: A or P. | ||
TT: ["[AP]M", setAMPM, "ampm", getAMPM, 2], //two-character time marker string: AM or PM. | ||
Z: [".*", undefined, "Z", getTimeZoneAbbreviated], //US timezone abbreviation, e.g. EST or MDT. With non-US timezones or in the Opera browser, the GMT/UTC offset is returned, e.g. GMT-0500 | ||
o: [""], //GMT/UTC timezone offset, e.g. -0500 or +0230. | ||
S: [""] //The date's ordinal suffix (st, nd, rd, or th). | ||
}, | ||
formatAlias = { | ||
isoDate: "yyyy-mm-dd", //2007-06-09 | ||
isoTime: "HH:MM:ss", //17:46:21 | ||
isoDateTime: "yyyy-mm-dd'T'HH:MM:ss", //2007-06-09T17:46:21 | ||
isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'" //2007-06-09T22:46:21Z | ||
}; | ||
useDateObject = false, | ||
//supported codes for formatting | ||
//http://blog.stevenlevithan.com/archives/date-time-format | ||
//https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings?view=netframework-4.7 | ||
formatCode = { //regex, valueSetter, type, displayformatter, #entries (optional) | ||
d: ["[1-9]|[12][0-9]|3[01]", Date.prototype.setDate, "day", Date.prototype.getDate], //Day of the month as digits; no leading zero for single-digit days. | ||
dd: ["0[1-9]|[12][0-9]|3[01]", Date.prototype.setDate, "day", function () { | ||
return pad(Date.prototype.getDate.call(this), 2); | ||
}], //Day of the month as digits; leading zero for single-digit days. | ||
ddd: [""], //Day of the week as a three-letter abbreviation. | ||
dddd: [""], //Day of the week as its full name. | ||
m: ["[1-9]|1[012]", function (val) { | ||
let mval = val ? parseInt(val) : 0; | ||
if (mval > 0) mval--; | ||
return Date.prototype.setMonth.call(this, mval); | ||
}, "month", function () { | ||
return Date.prototype.getMonth.call(this) + 1; | ||
}], //Month as digits; no leading zero for single-digit months. | ||
mm: ["0[1-9]|1[012]", function (val) { | ||
let mval = val ? parseInt(val) : 0; | ||
if (mval > 0) mval--; | ||
return Date.prototype.setMonth.call(this, mval); | ||
}, "month", function () { | ||
return pad(Date.prototype.getMonth.call(this) + 1, 2); | ||
}], //Month as digits; leading zero for single-digit months. | ||
mmm: [""], //Month as a three-letter abbreviation. | ||
mmmm: [""], //Month as its full name. | ||
yy: ["[0-9]{2}", Date.prototype.setFullYear, "year", function () { | ||
return pad(Date.prototype.getFullYear.call(this), 2); | ||
}], //Year as last two digits; leading zero for years less than 10. | ||
yyyy: ["[0-9]{4}", Date.prototype.setFullYear, "year", function () { | ||
return pad(Date.prototype.getFullYear.call(this), 4); | ||
}], | ||
h: ["[1-9]|1[0-2]", Date.prototype.setHours, "hours", Date.prototype.getHours], //Hours; no leading zero for single-digit hours (12-hour clock). | ||
hh: ["0[1-9]|1[0-2]", Date.prototype.setHours, "hours", function () { | ||
return pad(Date.prototype.getHours.call(this), 2); | ||
}], //Hours; leading zero for single-digit hours (12-hour clock). | ||
hx: [function (x) { | ||
return `[0-9]{${x}}`; | ||
}, Date.prototype.setHours, "hours", function (x) { | ||
return Date.prototype.getHours; | ||
}], //Hours; no limit; set maximum digits | ||
H: ["1?[0-9]|2[0-3]", Date.prototype.setHours, "hours", Date.prototype.getHours], //Hours; no leading zero for single-digit hours (24-hour clock). | ||
HH: ["0[0-9]|1[0-9]|2[0-3]", Date.prototype.setHours, "hours", function () { | ||
return pad(Date.prototype.getHours.call(this), 2); | ||
}], //Hours; leading zero for single-digit hours (24-hour clock). | ||
Hx: [function (x) { | ||
return `[0-9]{${x}}`; | ||
}, Date.prototype.setHours, "hours", function (x) { | ||
return function () { | ||
return pad(Date.prototype.getHours.call(this), x); | ||
}; | ||
}], //Hours; no limit; set maximum digits | ||
M: ["[1-5]?[0-9]", Date.prototype.setMinutes, "minutes", Date.prototype.getMinutes], //Minutes; no leading zero for single-digit minutes. Uppercase M unlike CF timeFormat's m to avoid conflict with months. | ||
MM: ["0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]", Date.prototype.setMinutes, "minutes", function () { | ||
return pad(Date.prototype.getMinutes.call(this), 2); | ||
}], //Minutes; leading zero for single-digit minutes. Uppercase MM unlike CF timeFormat's mm to avoid conflict with months. | ||
s: ["[1-5]?[0-9]", Date.prototype.setSeconds, "seconds", Date.prototype.getSeconds], //Seconds; no leading zero for single-digit seconds. | ||
ss: ["0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]", Date.prototype.setSeconds, "seconds", function () { | ||
return pad(Date.prototype.getSeconds.call(this), 2); | ||
}], //Seconds; leading zero for single-digit seconds. | ||
l: ["[0-9]{3}", Date.prototype.setMilliseconds, "milliseconds", function () { | ||
return pad(Date.prototype.getMilliseconds.call(this), 3); | ||
}, 3], //Milliseconds. 3 digits. | ||
L: ["[0-9]{2}", Date.prototype.setMilliseconds, "milliseconds", function () { | ||
return pad(Date.prototype.getMilliseconds.call(this), 2); | ||
}, 2], //Milliseconds. 2 digits. | ||
t: ["[ap]", setAMPM, "ampm", getAMPM, 1], //Lowercase, single-character time marker string: a or p. | ||
tt: ["[ap]m", setAMPM, "ampm", getAMPM, 2], //two-character time marker string: am or pm. | ||
T: ["[AP]", setAMPM, "ampm", getAMPM, 1], //single-character time marker string: A or P. | ||
TT: ["[AP]M", setAMPM, "ampm", getAMPM, 2], //two-character time marker string: AM or PM. | ||
Z: [".*", undefined, "Z", getTimeZoneAbbreviated], //US timezone abbreviation, e.g. EST or MDT. With non-US timezones or in the Opera browser, the GMT/UTC offset is returned, e.g. GMT-0500 | ||
o: [""], //GMT/UTC timezone offset, e.g. -0500 or +0230. | ||
S: [""] //The date's ordinal suffix (st, nd, rd, or th). | ||
}, | ||
formatAlias = { | ||
isoDate: "yyyy-mm-dd", //2007-06-09 | ||
isoTime: "HH:MM:ss", //17:46:21 | ||
isoDateTime: "yyyy-mm-dd'T'HH:MM:ss", //2007-06-09T17:46:21 | ||
isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'" //2007-06-09T22:46:21Z | ||
}; | ||
function setAMPM(value) { | ||
const hours = this.getHours(); | ||
if (value.toLowerCase().includes("p")) { | ||
this.setHours(hours + 12); | ||
// console.log("setAMPM + 12"); | ||
} else if (value.toLowerCase().includes("a") && hours >= 12) { | ||
this.setHours(hours - 12); | ||
} | ||
const hours = this.getHours(); | ||
if (value.toLowerCase().includes("p")) { | ||
this.setHours(hours + 12); | ||
// console.log("setAMPM + 12"); | ||
} else if (value.toLowerCase().includes("a") && hours >= 12) { | ||
this.setHours(hours - 12); | ||
} | ||
} | ||
function getAMPM() { | ||
let date = this, | ||
hours = date.getHours(); | ||
hours = hours || 12; | ||
return hours >= 12 ? "PM" : "AM"; | ||
let date = this, | ||
hours = date.getHours(); | ||
hours = hours || 12; | ||
return hours >= 12 ? "PM" : "AM"; | ||
} | ||
function getTimeZoneAbbreviated() { | ||
//not perfect, but ok for now | ||
let date = this, {1: tz} = date.toString().match(/\((.+)\)/); | ||
if (tz.includes(" ")) { | ||
tz = tz.replace("-", " ").toUpperCase(); | ||
tz = tz.split(" ").map(([first]) => first).join(""); | ||
} | ||
return tz; | ||
//not perfect, but ok for now | ||
let date = this, {1: tz} = date.toString().match(/\((.+)\)/); | ||
if (tz.includes(" ")) { | ||
tz = tz.replace("-", " ").toUpperCase(); | ||
tz = tz.split(" ").map(([first]) => first).join(""); | ||
} | ||
return tz; | ||
} | ||
function formatcode(match) { | ||
var dynMatches = new RegExp("\\d+$").exec(match[0]); | ||
if (dynMatches && dynMatches[0] !== undefined) { | ||
var fcode = formatCode[match[0][0] + "x"].slice(""); | ||
fcode[0] = fcode[0](dynMatches[0]); | ||
fcode[3] = fcode[3](dynMatches[0]); | ||
var dynMatches = new RegExp("\\d+$").exec(match[0]); | ||
if (dynMatches && dynMatches[0] !== undefined) { | ||
var fcode = formatCode[match[0][0] + "x"].slice(""); | ||
fcode[0] = fcode[0](dynMatches[0]); | ||
fcode[3] = fcode[3](dynMatches[0]); | ||
return fcode; | ||
} else if (formatCode[match[0]]) { | ||
return formatCode[match[0]]; | ||
} | ||
return fcode; | ||
} else if (formatCode[match[0]]) { | ||
return formatCode[match[0]]; | ||
} | ||
} | ||
function getTokenizer(opts) { | ||
if (!opts.tokenizer) { | ||
var tokens = [], dyntokens = []; | ||
for (var ndx in formatCode) { | ||
if (/\.*x$/.test(ndx)) { | ||
var dynToken = ndx[0] + "\\d+"; | ||
if (dyntokens.indexOf(dynToken) === -1) { | ||
dyntokens.push(dynToken); | ||
} | ||
} else if (tokens.indexOf(ndx[0]) === -1) { | ||
tokens.push(ndx[0]); | ||
} | ||
} | ||
opts.tokenizer = "(" + (dyntokens.length > 0 ? dyntokens.join("|") + "|" : "") + tokens.join("+|") + ")+?|."; | ||
opts.tokenizer = new RegExp(opts.tokenizer, "g"); | ||
} | ||
if (!opts.tokenizer) { | ||
var tokens = [], dyntokens = []; | ||
for (var ndx in formatCode) { | ||
if (/\.*x$/.test(ndx)) { | ||
var dynToken = ndx[0] + "\\d+"; | ||
if (dyntokens.indexOf(dynToken) === -1) { | ||
dyntokens.push(dynToken); | ||
} | ||
} else if (tokens.indexOf(ndx[0]) === -1) { | ||
tokens.push(ndx[0]); | ||
} | ||
} | ||
opts.tokenizer = "(" + (dyntokens.length > 0 ? dyntokens.join("|") + "|" : "") + tokens.join("+|") + ")+?|."; | ||
opts.tokenizer = new RegExp(opts.tokenizer, "g"); | ||
} | ||
return opts.tokenizer; | ||
return opts.tokenizer; | ||
} | ||
function prefillYear(dateParts, currentResult, opts) { | ||
if (dateParts.year !== dateParts.rawyear) { | ||
var crrntyear = currentYear.toString(), | ||
enteredPart = dateParts.rawyear.replace(/[^0-9]/g, ""), | ||
currentYearPart = crrntyear.slice(0, enteredPart.length), | ||
currentYearNextPart = crrntyear.slice(enteredPart.length); | ||
if (enteredPart.length === 2 && enteredPart === currentYearPart) { | ||
const entryCurrentYear = new Date(currentYear, dateParts.month - 1, dateParts.day); | ||
if (dateParts.day == entryCurrentYear.getDate() && (!opts.max || opts.max.date.getTime() >= entryCurrentYear.getTime())) { | ||
//update dateParts | ||
dateParts.date.setFullYear(currentYear); | ||
dateParts.year = crrntyear; | ||
//update result | ||
currentResult.insert = [{ | ||
pos: currentResult.pos + 1, | ||
c: currentYearNextPart[0] | ||
}, { | ||
pos: currentResult.pos + 2, | ||
c: currentYearNextPart[1] | ||
}]; | ||
} | ||
} | ||
} | ||
if (dateParts.year !== dateParts.rawyear) { | ||
var crrntyear = currentYear.toString(), | ||
enteredPart = dateParts.rawyear.replace(/[^0-9]/g, ""), | ||
currentYearPart = crrntyear.slice(0, enteredPart.length), | ||
currentYearNextPart = crrntyear.slice(enteredPart.length); | ||
if (enteredPart.length === 2 && enteredPart === currentYearPart) { | ||
const entryCurrentYear = new Date(currentYear, dateParts.month - 1, dateParts.day); | ||
if (dateParts.day == entryCurrentYear.getDate() && (!opts.max || opts.max.date.getTime() >= entryCurrentYear.getTime())) { | ||
//update dateParts | ||
dateParts.date.setFullYear(currentYear); | ||
dateParts.year = crrntyear; | ||
//update result | ||
currentResult.insert = [{ | ||
pos: currentResult.pos + 1, | ||
c: currentYearNextPart[0] | ||
}, { | ||
pos: currentResult.pos + 2, | ||
c: currentYearNextPart[1] | ||
}]; | ||
} | ||
} | ||
} | ||
return currentResult; | ||
return currentResult; | ||
} | ||
function isValidDate(dateParts, currentResult, opts) { | ||
if (!useDateObject) return true; | ||
if (dateParts.rawday === undefined | ||
|| (!isFinite(dateParts.rawday) && new Date(dateParts.date.getFullYear(), isFinite(dateParts.rawmonth) ? dateParts.month : dateParts.date.getMonth() + 1, 0).getDate() >= dateParts.day) | ||
|| (dateParts.day == "29" && (!isFinite(dateParts.rawyear) || dateParts.rawyear === undefined || dateParts.rawyear === "")) | ||
|| new Date(dateParts.date.getFullYear(), isFinite(dateParts.rawmonth) ? dateParts.month : dateParts.date.getMonth() + 1, 0).getDate() >= dateParts.day) { | ||
return currentResult; | ||
} else { //take corrective action if possible | ||
if (dateParts.day == "29") { | ||
var tokenMatch = getTokenMatch(currentResult.pos, opts); | ||
if (tokenMatch.targetMatch[0] === "yyyy" && currentResult.pos - tokenMatch.targetMatchIndex === 2) { | ||
currentResult.remove = currentResult.pos + 1; | ||
return currentResult; | ||
} | ||
} else if (dateParts.month == "02" && dateParts.day == "30" && currentResult.c !== undefined) { | ||
dateParts.day = "03"; | ||
dateParts.date.setDate(3); | ||
dateParts.date.setMonth(1); | ||
currentResult.insert = [{pos: currentResult.pos, c: "0"}, {pos: currentResult.pos + 1, c: currentResult.c}]; | ||
currentResult.caret = seekNext.call(this, currentResult.pos + 1); | ||
return currentResult; | ||
} | ||
return false; | ||
} | ||
if (!useDateObject) return true; | ||
if (dateParts.rawday === undefined | ||
|| (!isFinite(dateParts.rawday) && new Date(dateParts.date.getFullYear(), isFinite(dateParts.rawmonth) ? dateParts.month : dateParts.date.getMonth() + 1, 0).getDate() >= dateParts.day) | ||
|| (dateParts.day == "29" && (!isFinite(dateParts.rawyear) || dateParts.rawyear === undefined || dateParts.rawyear === "")) | ||
|| new Date(dateParts.date.getFullYear(), isFinite(dateParts.rawmonth) ? dateParts.month : dateParts.date.getMonth() + 1, 0).getDate() >= dateParts.day) { | ||
return currentResult; | ||
} else { //take corrective action if possible | ||
if (dateParts.day == "29") { | ||
var tokenMatch = getTokenMatch(currentResult.pos, opts); | ||
if (tokenMatch.targetMatch[0] === "yyyy" && currentResult.pos - tokenMatch.targetMatchIndex === 2) { | ||
currentResult.remove = currentResult.pos + 1; | ||
return currentResult; | ||
} | ||
} else if (dateParts.month == "02" && dateParts.day == "30" && currentResult.c !== undefined) { | ||
dateParts.day = "03"; | ||
dateParts.date.setDate(3); | ||
dateParts.date.setMonth(1); | ||
currentResult.insert = [{pos: currentResult.pos, c: "0"}, {pos: currentResult.pos + 1, c: currentResult.c}]; | ||
currentResult.caret = seekNext.call(this, currentResult.pos + 1); | ||
return currentResult; | ||
} | ||
return false; | ||
} | ||
} | ||
function isDateInRange(dateParts, result, opts, maskset, fromCheckval) { | ||
if (!result) return result; | ||
if (result && opts.min) { | ||
if (/*useDateObject && (dateParts["year"] === undefined || dateParts["yearSet"]) && */!isNaN(opts.min.date.getTime())) { | ||
let match; | ||
dateParts.reset(); | ||
getTokenizer(opts).lastIndex = 0; | ||
while ((match = getTokenizer(opts).exec(opts.inputFormat))) { | ||
var fcode; | ||
if ((fcode = formatcode(match))) { | ||
if (fcode[3]) { | ||
var setFn = fcode[1]; | ||
var current = dateParts[fcode[2]], | ||
minVal = opts.min[fcode[2]], | ||
maxVal = opts.max ? opts.max[fcode[2]] : minVal, | ||
curVal = []; | ||
if (!result) return result; | ||
if (result && opts.min) { | ||
if (/*useDateObject && (dateParts["year"] === undefined || dateParts["yearSet"]) && */!isNaN(opts.min.date.getTime())) { | ||
let match; | ||
dateParts.reset(); | ||
getTokenizer(opts).lastIndex = 0; | ||
while ((match = getTokenizer(opts).exec(opts.inputFormat))) { | ||
var fcode; | ||
if ((fcode = formatcode(match))) { | ||
if (fcode[3]) { | ||
var setFn = fcode[1]; | ||
var current = dateParts[fcode[2]], | ||
minVal = opts.min[fcode[2]], | ||
maxVal = opts.max ? opts.max[fcode[2]] : minVal, | ||
curVal = []; | ||
let forceCurrentValue = false; | ||
for (let i = 0; i < minVal.length; i++) { | ||
if (maskset.validPositions[i + match.index] === undefined && !forceCurrentValue) { | ||
curVal[i] = minVal[i]; | ||
// ADD +1 to whoile | ||
if (fcode[2] === "year" && current.length - 1 == i && minVal != maxVal) | ||
curVal = (parseInt(curVal.join("")) + 1).toString().split(""); | ||
if (fcode[2] === "ampm" && minVal != maxVal && opts.min.date.getTime() > dateParts.date.getTime()) | ||
curVal[i] = maxVal[i]; | ||
} else { | ||
curVal[i] = current[i]; | ||
forceCurrentValue = forceCurrentValue || current[i] > minVal[i]; | ||
} | ||
} | ||
let forceCurrentValue = false; | ||
for (let i = 0; i < minVal.length; i++) { | ||
if (maskset.validPositions[i + match.index] === undefined && !forceCurrentValue) { | ||
curVal[i] = minVal[i]; | ||
// ADD +1 to whoile | ||
if (fcode[2] === "year" && current.length - 1 == i && minVal != maxVal) | ||
curVal = (parseInt(curVal.join("")) + 1).toString().split(""); | ||
if (fcode[2] === "ampm" && minVal != maxVal && opts.min.date.getTime() > dateParts.date.getTime()) | ||
curVal[i] = maxVal[i]; | ||
} else { | ||
curVal[i] = current[i]; | ||
forceCurrentValue = forceCurrentValue || current[i] > minVal[i]; | ||
} | ||
} | ||
setFn.call(dateParts._date, curVal.join("")); | ||
} | ||
} | ||
} | ||
setFn.call(dateParts._date, curVal.join("")); | ||
} | ||
} | ||
} | ||
result = opts.min.date.getTime() <= dateParts.date.getTime(); | ||
dateParts.reInit(); | ||
} | ||
} | ||
result = opts.min.date.getTime() <= dateParts.date.getTime(); | ||
dateParts.reInit(); | ||
} | ||
} | ||
if (result && opts.max) { | ||
if (!isNaN(opts.max.date.getTime())) { | ||
result = opts.max.date.getTime() >= dateParts.date.getTime(); | ||
} | ||
} | ||
return result; | ||
if (result && opts.max) { | ||
if (!isNaN(opts.max.date.getTime())) { | ||
result = opts.max.date.getTime() >= dateParts.date.getTime(); | ||
} | ||
} | ||
return result; | ||
} | ||
@@ -349,37 +349,37 @@ | ||
function parse(format, dateObjValue, opts, raw) { | ||
//parse format to regex string | ||
var mask = "", match, fcode; | ||
getTokenizer(opts).lastIndex = 0; | ||
while ((match = getTokenizer(opts).exec(format))) { | ||
if (dateObjValue === undefined) { | ||
if ((fcode = formatcode(match))) { | ||
mask += "(" + fcode[0] + ")"; | ||
} else { | ||
switch (match[0]) { | ||
case "[": | ||
mask += "("; | ||
break; | ||
case "]": | ||
mask += ")?"; | ||
break; | ||
default: | ||
mask += escapeRegex(match[0]); | ||
} | ||
} | ||
} else { | ||
if ((fcode = formatcode(match))) { | ||
if (raw !== true && fcode[3]) { | ||
var getFn = fcode[3]; | ||
mask += getFn.call(dateObjValue.date); | ||
} else if (fcode[2]) { | ||
mask += dateObjValue["raw" + fcode[2]]; | ||
} else { | ||
mask += match[0]; | ||
} | ||
} else { | ||
mask += match[0]; | ||
} | ||
} | ||
} | ||
return mask; | ||
//parse format to regex string | ||
var mask = "", match, fcode; | ||
getTokenizer(opts).lastIndex = 0; | ||
while ((match = getTokenizer(opts).exec(format))) { | ||
if (dateObjValue === undefined) { | ||
if ((fcode = formatcode(match))) { | ||
mask += "(" + fcode[0] + ")"; | ||
} else { | ||
switch (match[0]) { | ||
case "[": | ||
mask += "("; | ||
break; | ||
case "]": | ||
mask += ")?"; | ||
break; | ||
default: | ||
mask += escapeRegex(match[0]); | ||
} | ||
} | ||
} else { | ||
if ((fcode = formatcode(match))) { | ||
if (raw !== true && fcode[3]) { | ||
var getFn = fcode[3]; | ||
mask += getFn.call(dateObjValue.date); | ||
} else if (fcode[2]) { | ||
mask += dateObjValue["raw" + fcode[2]]; | ||
} else { | ||
mask += match[0]; | ||
} | ||
} else { | ||
mask += match[0]; | ||
} | ||
} | ||
} | ||
return mask; | ||
} | ||
@@ -389,39 +389,39 @@ | ||
function pad(val, len, right) { | ||
val = String(val); | ||
len = len || 2; | ||
while (val.length < len) val = right ? val + "0" : "0" + val; | ||
return val; | ||
val = String(val); | ||
len = len || 2; | ||
while (val.length < len) val = right ? val + "0" : "0" + val; | ||
return val; | ||
} | ||
function analyseMask(mask, format, opts) { | ||
if (typeof mask === "string") { | ||
return new DateObject(mask, format, opts); | ||
} else if (mask && typeof mask === "object" && Object.prototype.hasOwnProperty.call(mask, "date")) { | ||
return mask; | ||
} | ||
return undefined; | ||
if (typeof mask === "string") { | ||
return new DateObject(mask, format, opts); | ||
} else if (mask && typeof mask === "object" && Object.prototype.hasOwnProperty.call(mask, "date")) { | ||
return mask; | ||
} | ||
return undefined; | ||
} | ||
function importDate(dateObj, opts) { | ||
return parse(opts.inputFormat, {date: dateObj}, opts); | ||
return parse(opts.inputFormat, {date: dateObj}, opts); | ||
} | ||
function getTokenMatch(pos, opts) { | ||
var calcPos = 0, targetMatch, match, matchLength = 0; | ||
getTokenizer(opts).lastIndex = 0; | ||
while ((match = getTokenizer(opts).exec(opts.inputFormat))) { | ||
var dynMatches = new RegExp("\\d+$").exec(match[0]); | ||
matchLength = dynMatches ? parseInt(dynMatches[0]) : match[0].length; | ||
calcPos += matchLength; | ||
if (calcPos >= pos + 1) { | ||
targetMatch = match; | ||
match = getTokenizer(opts).exec(opts.inputFormat); | ||
break; | ||
} | ||
} | ||
return { | ||
targetMatchIndex: calcPos - matchLength, | ||
nextMatch: match, | ||
targetMatch: targetMatch | ||
}; | ||
var calcPos = 0, targetMatch, match, matchLength = 0; | ||
getTokenizer(opts).lastIndex = 0; | ||
while ((match = getTokenizer(opts).exec(opts.inputFormat))) { | ||
var dynMatches = new RegExp("\\d+$").exec(match[0]); | ||
matchLength = dynMatches ? parseInt(dynMatches[0]) : match[0].length; | ||
calcPos += matchLength; | ||
if (calcPos >= pos + 1) { | ||
targetMatch = match; | ||
match = getTokenizer(opts).exec(opts.inputFormat); | ||
break; | ||
} | ||
} | ||
return { | ||
targetMatchIndex: calcPos - matchLength, | ||
nextMatch: match, | ||
targetMatch: targetMatch | ||
}; | ||
} | ||
@@ -431,163 +431,163 @@ | ||
Inputmask.extendAliases({ | ||
"datetime": { | ||
mask: function (opts) { | ||
//do not allow numeric input in datetime alias | ||
opts.numericInput = false; | ||
"datetime": { | ||
mask: function (opts) { | ||
//do not allow numeric input in datetime alias | ||
opts.numericInput = false; | ||
//localize | ||
formatCode.S = opts.i18n.ordinalSuffix.join("|"); | ||
//localize | ||
formatCode.S = opts.i18n.ordinalSuffix.join("|"); | ||
opts.inputFormat = formatAlias[opts.inputFormat] || opts.inputFormat; //resolve possible formatAlias | ||
opts.displayFormat = formatAlias[opts.displayFormat] || opts.displayFormat || opts.inputFormat; //resolve possible formatAlias | ||
opts.outputFormat = formatAlias[opts.outputFormat] || opts.outputFormat || opts.inputFormat; //resolve possible formatAlias | ||
opts.placeholder = opts.placeholder !== "" ? opts.placeholder : opts.inputFormat.replace(/[[\]]/, ""); | ||
opts.regex = parse(opts.inputFormat, undefined, opts); | ||
opts.min = analyseMask(opts.min, opts.inputFormat, opts); | ||
opts.max = analyseMask(opts.max, opts.inputFormat, opts); | ||
return null; //migrate to regex mask | ||
}, | ||
placeholder: "", //set default as none (~ auto); when a custom placeholder is passed it will be used | ||
inputFormat: "isoDateTime", //format used to input the date | ||
displayFormat: null, //visual format when the input looses focus | ||
outputFormat: null, //unmasking format | ||
min: null, //needs to be in the same format as the inputfornat | ||
max: null, //needs to be in the same format as the inputfornat, | ||
skipOptionalPartCharacter: "", | ||
// Internationalization strings | ||
i18n: { | ||
dayNames: [ | ||
"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", | ||
"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" | ||
], | ||
monthNames: [ | ||
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", | ||
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" | ||
], | ||
ordinalSuffix: ["st", "nd", "rd", "th"] | ||
}, | ||
preValidation: function (buffer, pos, c, isSelection, opts, maskset, caretPos, strict) { | ||
if (strict) return true; | ||
if (isNaN(c) && buffer[pos] !== c) { | ||
var tokenMatch = getTokenMatch(pos, opts); | ||
if (tokenMatch.nextMatch && tokenMatch.nextMatch[0] === c && tokenMatch.targetMatch[0].length > 1) { | ||
var validator = formatCode[tokenMatch.targetMatch[0]][0]; | ||
if (new RegExp(validator).test("0" + buffer[pos - 1])) { | ||
buffer[pos] = buffer[pos - 1]; | ||
buffer[pos - 1] = "0"; | ||
return { | ||
fuzzy: true, | ||
buffer: buffer, | ||
refreshFromBuffer: {start: pos - 1, end: pos + 1}, | ||
pos: pos + 1 | ||
}; | ||
} | ||
} | ||
} | ||
return true; | ||
}, | ||
postValidation: function (buffer, pos, c, currentResult, opts, maskset, strict, fromCheckval) { | ||
const inputmask = this; | ||
opts.inputFormat = formatAlias[opts.inputFormat] || opts.inputFormat; //resolve possible formatAlias | ||
opts.displayFormat = formatAlias[opts.displayFormat] || opts.displayFormat || opts.inputFormat; //resolve possible formatAlias | ||
opts.outputFormat = formatAlias[opts.outputFormat] || opts.outputFormat || opts.inputFormat; //resolve possible formatAlias | ||
opts.placeholder = opts.placeholder !== "" ? opts.placeholder : opts.inputFormat.replace(/[[\]]/, ""); | ||
opts.regex = parse(opts.inputFormat, undefined, opts); | ||
opts.min = analyseMask(opts.min, opts.inputFormat, opts); | ||
opts.max = analyseMask(opts.max, opts.inputFormat, opts); | ||
return null; //migrate to regex mask | ||
}, | ||
placeholder: "", //set default as none (~ auto); when a custom placeholder is passed it will be used | ||
inputFormat: "isoDateTime", //format used to input the date | ||
displayFormat: null, //visual format when the input looses focus | ||
outputFormat: null, //unmasking format | ||
min: null, //needs to be in the same format as the inputfornat | ||
max: null, //needs to be in the same format as the inputfornat, | ||
skipOptionalPartCharacter: "", | ||
// Internationalization strings | ||
i18n: { | ||
dayNames: [ | ||
"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", | ||
"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" | ||
], | ||
monthNames: [ | ||
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", | ||
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" | ||
], | ||
ordinalSuffix: ["st", "nd", "rd", "th"] | ||
}, | ||
preValidation: function (buffer, pos, c, isSelection, opts, maskset, caretPos, strict) { | ||
if (strict) return true; | ||
if (isNaN(c) && buffer[pos] !== c) { | ||
var tokenMatch = getTokenMatch(pos, opts); | ||
if (tokenMatch.nextMatch && tokenMatch.nextMatch[0] === c && tokenMatch.targetMatch[0].length > 1) { | ||
var validator = formatCode[tokenMatch.targetMatch[0]][0]; | ||
if (new RegExp(validator).test("0" + buffer[pos - 1])) { | ||
buffer[pos] = buffer[pos - 1]; | ||
buffer[pos - 1] = "0"; | ||
return { | ||
fuzzy: true, | ||
buffer: buffer, | ||
refreshFromBuffer: {start: pos - 1, end: pos + 1}, | ||
pos: pos + 1 | ||
}; | ||
} | ||
} | ||
} | ||
return true; | ||
}, | ||
postValidation: function (buffer, pos, c, currentResult, opts, maskset, strict, fromCheckval) { | ||
const inputmask = this; | ||
if (strict) return true; | ||
var tokenMatch, validator; | ||
if (currentResult === false) { //try some shifting | ||
tokenMatch = getTokenMatch(pos + 1, opts); | ||
if (tokenMatch.targetMatch && tokenMatch.targetMatchIndex === pos && tokenMatch.targetMatch[0].length > 1 && formatCode[tokenMatch.targetMatch[0]] !== undefined) { | ||
validator = formatCode[tokenMatch.targetMatch[0]][0]; | ||
} else { | ||
tokenMatch = getTokenMatch(pos + 2, opts); | ||
if (tokenMatch.targetMatch && tokenMatch.targetMatchIndex === pos + 1 && tokenMatch.targetMatch[0].length > 1 && formatCode[tokenMatch.targetMatch[0]] !== undefined) { | ||
validator = formatCode[tokenMatch.targetMatch[0]][0]; | ||
} | ||
} | ||
if (validator !== undefined) { | ||
if (maskset.validPositions[pos + 1] !== undefined && new RegExp(validator).test(c + "0")) { | ||
buffer[pos] = c; | ||
buffer[pos + 1] = "0"; | ||
currentResult = { | ||
//insert: [{pos: pos, c: "0"}, {pos: pos + 1, c: c}], | ||
pos: pos + 2, //this will triggeer a refreshfrombuffer | ||
caret: pos | ||
}; | ||
} else if (new RegExp(validator).test("0" + c)) { | ||
buffer[pos] = "0"; | ||
buffer[pos + 1] = c; | ||
currentResult = { | ||
//insert: [{pos: pos, c: "0"}, {pos: pos + 1, c: c}], | ||
pos: pos + 2 //this will triggeer a refreshfrombuffer | ||
}; | ||
} | ||
} | ||
if (strict) return true; | ||
var tokenMatch, validator; | ||
if (currentResult === false) { //try some shifting | ||
tokenMatch = getTokenMatch(pos + 1, opts); | ||
if (tokenMatch.targetMatch && tokenMatch.targetMatchIndex === pos && tokenMatch.targetMatch[0].length > 1 && formatCode[tokenMatch.targetMatch[0]] !== undefined) { | ||
validator = formatCode[tokenMatch.targetMatch[0]][0]; | ||
} else { | ||
tokenMatch = getTokenMatch(pos + 2, opts); | ||
if (tokenMatch.targetMatch && tokenMatch.targetMatchIndex === pos + 1 && tokenMatch.targetMatch[0].length > 1 && formatCode[tokenMatch.targetMatch[0]] !== undefined) { | ||
validator = formatCode[tokenMatch.targetMatch[0]][0]; | ||
} | ||
} | ||
if (validator !== undefined) { | ||
if (maskset.validPositions[pos + 1] !== undefined && new RegExp(validator).test(c + "0")) { | ||
buffer[pos] = c; | ||
buffer[pos + 1] = "0"; | ||
currentResult = { | ||
//insert: [{pos: pos, c: "0"}, {pos: pos + 1, c: c}], | ||
pos: pos + 2, //this will triggeer a refreshfrombuffer | ||
caret: pos | ||
}; | ||
} else if (new RegExp(validator).test("0" + c)) { | ||
buffer[pos] = "0"; | ||
buffer[pos + 1] = c; | ||
currentResult = { | ||
//insert: [{pos: pos, c: "0"}, {pos: pos + 1, c: c}], | ||
pos: pos + 2 //this will triggeer a refreshfrombuffer | ||
}; | ||
} | ||
} | ||
if (currentResult === false) return currentResult; | ||
} | ||
if (currentResult === false) return currentResult; | ||
} | ||
if (currentResult.fuzzy) { | ||
buffer = currentResult.buffer; | ||
pos = currentResult.pos; | ||
} | ||
if (currentResult.fuzzy) { | ||
buffer = currentResult.buffer; | ||
pos = currentResult.pos; | ||
} | ||
//full validate target | ||
tokenMatch = getTokenMatch(pos, opts); | ||
if (tokenMatch.targetMatch && tokenMatch.targetMatch[0] && formatCode[tokenMatch.targetMatch[0]] !== undefined) { | ||
let fcode = formatCode[tokenMatch.targetMatch[0]]; | ||
validator = fcode[0]; | ||
var part = buffer.slice(tokenMatch.targetMatchIndex, tokenMatch.targetMatchIndex + tokenMatch.targetMatch[0].length); | ||
if (new RegExp(validator).test(part.join("")) === false && tokenMatch.targetMatch[0].length === 2 && maskset.validPositions[tokenMatch.targetMatchIndex] && maskset.validPositions[tokenMatch.targetMatchIndex + 1]) { | ||
maskset.validPositions[tokenMatch.targetMatchIndex + 1].input = "0"; | ||
} | ||
if (fcode[2] == "year") { | ||
var _buffer = getMaskTemplate.call(inputmask, false, 1, undefined, true); | ||
for (let i = pos + 1; i < buffer.length; i++) { | ||
buffer[i] = _buffer[i]; | ||
delete maskset.validPositions[i]; | ||
} | ||
} | ||
} | ||
//full validate target | ||
tokenMatch = getTokenMatch(pos, opts); | ||
if (tokenMatch.targetMatch && tokenMatch.targetMatch[0] && formatCode[tokenMatch.targetMatch[0]] !== undefined) { | ||
let fcode = formatCode[tokenMatch.targetMatch[0]]; | ||
validator = fcode[0]; | ||
var part = buffer.slice(tokenMatch.targetMatchIndex, tokenMatch.targetMatchIndex + tokenMatch.targetMatch[0].length); | ||
if (new RegExp(validator).test(part.join("")) === false && tokenMatch.targetMatch[0].length === 2 && maskset.validPositions[tokenMatch.targetMatchIndex] && maskset.validPositions[tokenMatch.targetMatchIndex + 1]) { | ||
maskset.validPositions[tokenMatch.targetMatchIndex + 1].input = "0"; | ||
} | ||
if (fcode[2] == "year") { | ||
var _buffer = getMaskTemplate.call(inputmask, false, 1, undefined, true); | ||
for (let i = pos + 1; i < buffer.length; i++) { | ||
buffer[i] = _buffer[i]; | ||
delete maskset.validPositions[i]; | ||
} | ||
} | ||
} | ||
var result = currentResult, dateParts = analyseMask(buffer.join(""), opts.inputFormat, opts); | ||
if (result && !isNaN(dateParts.date.getTime())) { //check for a valid date ~ an invalid date returns NaN which isn't equal | ||
if (opts.prefillYear) result = prefillYear(dateParts, result, opts); | ||
result = isValidDate.call(inputmask, dateParts, result, opts); | ||
result = isDateInRange(dateParts, result, opts, maskset, fromCheckval); | ||
} | ||
var result = currentResult, dateParts = analyseMask(buffer.join(""), opts.inputFormat, opts); | ||
if (result && !isNaN(dateParts.date.getTime())) { //check for a valid date ~ an invalid date returns NaN which isn't equal | ||
if (opts.prefillYear) result = prefillYear(dateParts, result, opts); | ||
result = isValidDate.call(inputmask, dateParts, result, opts); | ||
result = isDateInRange(dateParts, result, opts, maskset, fromCheckval); | ||
} | ||
if (pos !== undefined && result && currentResult.pos !== pos) { | ||
return { | ||
buffer: parse(opts.inputFormat, dateParts, opts).split(""), | ||
refreshFromBuffer: {start: pos, end: currentResult.pos}, | ||
pos: currentResult.caret || currentResult.pos //correct caret position | ||
}; | ||
} | ||
if (pos !== undefined && result && currentResult.pos !== pos) { | ||
return { | ||
buffer: parse(opts.inputFormat, dateParts, opts).split(""), | ||
refreshFromBuffer: {start: pos, end: currentResult.pos}, | ||
pos: currentResult.caret || currentResult.pos //correct caret position | ||
}; | ||
} | ||
return result; | ||
}, | ||
onKeyDown: function (e, buffer, caretPos, opts) { | ||
var input = this; | ||
if (e.ctrlKey && e.keyCode === keyCode.RIGHT) { | ||
input.inputmask._valueSet(importDate(new Date(), opts)); | ||
$(input).trigger("setvalue"); | ||
} | ||
}, | ||
onUnMask: function (maskedValue, unmaskedValue, opts) { | ||
return unmaskedValue ? parse(opts.outputFormat, analyseMask(maskedValue, opts.inputFormat, opts), opts, true) : unmaskedValue; | ||
}, | ||
casing: function (elem, test, pos, validPositions) { | ||
if (test.nativeDef.indexOf("[ap]") == 0) return elem.toLowerCase(); | ||
if (test.nativeDef.indexOf("[AP]") == 0) return elem.toUpperCase(); | ||
return elem; | ||
}, | ||
onBeforeMask: function (initialValue, opts) { | ||
if (Object.prototype.toString.call(initialValue) === "[object Date]") { | ||
initialValue = importDate(initialValue, opts); | ||
} | ||
return result; | ||
}, | ||
onKeyDown: function (e, buffer, caretPos, opts) { | ||
var input = this; | ||
if (e.ctrlKey && e.key === keys.ArrowRight) { | ||
input.inputmask._valueSet(importDate(new Date(), opts)); | ||
$(input).trigger("setvalue"); | ||
} | ||
}, | ||
onUnMask: function (maskedValue, unmaskedValue, opts) { | ||
return unmaskedValue ? parse(opts.outputFormat, analyseMask(maskedValue, opts.inputFormat, opts), opts, true) : unmaskedValue; | ||
}, | ||
casing: function (elem, test, pos, validPositions) { | ||
if (test.nativeDef.indexOf("[ap]") == 0) return elem.toLowerCase(); | ||
if (test.nativeDef.indexOf("[AP]") == 0) return elem.toUpperCase(); | ||
return elem; | ||
}, | ||
onBeforeMask: function (initialValue, opts) { | ||
if (Object.prototype.toString.call(initialValue) === "[object Date]") { | ||
initialValue = importDate(initialValue, opts); | ||
} | ||
return initialValue; | ||
}, | ||
insertMode: false, | ||
shiftPositions: false, | ||
keepStatic: false, | ||
inputmode: "numeric", | ||
prefillYear: true //Allows to disable prefill for datetime year. | ||
} | ||
return initialValue; | ||
}, | ||
insertMode: false, | ||
shiftPositions: false, | ||
keepStatic: false, | ||
inputmode: "numeric", | ||
prefillYear: true //Allows to disable prefill for datetime year. | ||
} | ||
}); |
@@ -8,5 +8,5 @@ /* | ||
import Inputmask from "../inputmask"; | ||
import keyCode from "../keycode.json"; | ||
import escapeRegex from "../escapeRegex"; | ||
import {seekNext} from "../positioning"; | ||
import {keys} from "../keycode"; | ||
@@ -548,3 +548,3 @@ const $ = Inputmask.dependencyLib; | ||
if (e.location != 3) { | ||
var pattern, c = String.fromCharCode(e.keyCode).toLowerCase(); | ||
var pattern, c = e.key; | ||
if ((pattern = (opts.shortcuts && opts.shortcuts[c]))) { | ||
@@ -559,8 +559,8 @@ if (pattern.length > 1) { | ||
if (e.ctrlKey) { | ||
switch (e.keyCode) { | ||
case keyCode.UP: | ||
switch (e.key) { | ||
case keys.ArrowUp: | ||
this.inputmask.__valueSet.call(this, parseFloat(this.inputmask.unmaskedvalue()) + parseInt(opts.step)); | ||
$input.trigger("setvalue"); | ||
return false; | ||
case keyCode.DOWN: | ||
case keys.ArrowDown: | ||
this.inputmask.__valueSet.call(this, parseFloat(this.inputmask.unmaskedvalue()) - parseInt(opts.step)); | ||
@@ -571,4 +571,4 @@ $input.trigger("setvalue"); | ||
} | ||
if (!e.shiftKey && (e.keyCode === keyCode.DELETE || e.keyCode === keyCode.BACKSPACE || e.keyCode === keyCode.BACKSPACE_SAFARI) && caretPos.begin !== buffer.length) { | ||
if (buffer[e.keyCode === keyCode.DELETE ? caretPos.begin - 1 : caretPos.end] === opts.negationSymbol.front) { | ||
if (!e.shiftKey && (e.key === keys.Delete || e.key === keys.Backspace || e.key === keys.BACKSPACE_SAFARI) && caretPos.begin !== buffer.length) { | ||
if (buffer[e.key === keys.Delete ? caretPos.begin - 1 : caretPos.end] === opts.negationSymbol.front) { | ||
bffr = buffer.slice().reverse(); | ||
@@ -582,8 +582,8 @@ if (opts.negationSymbol.front !== "") bffr.shift(); | ||
if (!opts.digitsOptional) { | ||
if (radixPos !== -1 && (caretPos.begin < radixPos || caretPos.end < radixPos || (e.keyCode === keyCode.DELETE && (caretPos.begin === radixPos || caretPos.begin - 1 === radixPos)))) { | ||
if (radixPos !== -1 && (caretPos.begin < radixPos || caretPos.end < radixPos || (e.key === keys.Delete && (caretPos.begin === radixPos || caretPos.begin - 1 === radixPos)))) { | ||
var restoreCaretPos = undefined; | ||
if (caretPos.begin === caretPos.end) { //only adjust when not a selection | ||
if (e.keyCode === keyCode.BACKSPACE || e.keyCode === keyCode.BACKSPACE_SAFARI) | ||
if (e.key === keys.Backspace || e.key === keys.BACKSPACE_SAFARI) | ||
caretPos.begin++; | ||
else if (e.keyCode === keyCode.DELETE && caretPos.begin - 1 === radixPos) { | ||
else if (e.key === keys.Delete && caretPos.begin - 1 === radixPos) { | ||
restoreCaretPos = $.extend({}, caretPos); | ||
@@ -590,0 +590,0 @@ caretPos.begin--; |
@@ -1,2 +0,2 @@ | ||
import keyCode from "./keycode.json"; | ||
import {keys} from "./keycode.js"; | ||
import {getMaskTemplate, getPlaceholder, getTest} from "./validation-tests"; | ||
@@ -92,3 +92,3 @@ import { | ||
var keypress = new $.Event("_checkval"); | ||
keypress.keyCode = charCode.toString().charCodeAt(0); | ||
keypress.key = charCode; | ||
charCodes += charCode; | ||
@@ -133,3 +133,3 @@ var lvp = getLastValidPosition.call(inputmask, undefined, true); | ||
validPos.generatedInput = true; | ||
keypress.keyCode = validPos.input.charCodeAt(0); | ||
keypress.key = validPos.input; | ||
result = EventHandlers.keypressEvent.call(inputmask, keypress, true, false, strict, nextSndx); | ||
@@ -239,3 +239,3 @@ if (result && result.pos !== undefined && result.pos !== sndx && maskset.validPositions[result.pos] && maskset.validPositions[result.pos].match.static === true) { | ||
// console.log(caretPos); | ||
caret.call(inputmask, input, caretPos, undefined, undefined, (event !== undefined && event.type === "keydown" && (event.keyCode === keyCode.DELETE || event.keyCode === keyCode.BACKSPACE))); | ||
caret.call(inputmask, input, caretPos, undefined, undefined, (event !== undefined && event.type === "keydown" && (event.key === keys.Delete || event.key === keys.Backspace))); | ||
} | ||
@@ -242,0 +242,0 @@ if (triggerEvents === true) { |
@@ -58,3 +58,2 @@ /* | ||
this.$el = undefined; | ||
this.skipKeyPressEvent = false; //Safari 5.1.x - modal dialog fires keypress twice workaround | ||
this.skipInputEvent = false; //skip when triggered from within inputmask | ||
@@ -65,2 +64,3 @@ this.validationEvent = false; | ||
this.mouseEnter = false; | ||
this.clicked = 0; | ||
this.originalPlaceholder = undefined; //needed for FF | ||
@@ -67,0 +67,0 @@ this.isComposing = false; //keydowncode == 229 compositionevent fallback |
@@ -17,3 +17,3 @@ import $ from "./dependencyLibs/inputmask.dependencyLib"; | ||
if (opts.keepStatic === true) { | ||
let optionalRegex = "(?<p1>.)\\[(?<p2>[^\\]]*)\\]", | ||
let optionalRegex = "(.)\\[([^\\]]*)\\]", // "(?<p1>.)\\[(?<p2>[^\\]]*)\\]", remove named capture group @2428 | ||
maskMatches = mask.match(new RegExp(optionalRegex, "g")); | ||
@@ -137,5 +137,8 @@ maskMatches && maskMatches.forEach((m, i) => { | ||
if (regexMask) { | ||
if (element.indexOf("[") === 0 || (escaped && /\\d|\\s|\\w/i.test(element)) || element === ".") { | ||
if (element.indexOf("[") === 0 || (escaped && /\\d|\\s|\\w|\\p/i.test(element)) || element === ".") { | ||
let flag = opts.casing ? "i" : ""; | ||
if (/^\\p\{.*}$/i.test(element)) | ||
flag += "u"; | ||
mtoken.matches.splice(position++, 0, { | ||
fn: new RegExp(element, opts.casing ? "i" : ""), | ||
fn: new RegExp(element, flag), | ||
static: false, | ||
@@ -352,2 +355,6 @@ optionality: false, | ||
break; | ||
case "\\p": //Unicode Categories | ||
m += regexTokenizer.exec(mask)[0]; // { | ||
m += regexTokenizer.exec(mask)[0]; // ?} | ||
break; | ||
case "(?=": //lookahead | ||
@@ -417,16 +424,12 @@ // openenings.push(new MaskToken(true)); | ||
match = matches.pop(); | ||
if (match.isAlternator) { //handle quantifier in an alternation [0-9]{2}|[0-9]{3} | ||
matches.push(match); //push back alternator | ||
matches = match.matches; //remap target matches | ||
var groupToken = new MaskToken(true); | ||
var tmpMatch = matches.pop(); | ||
matches.push(groupToken); //push the group | ||
matches = groupToken.matches; | ||
match = tmpMatch; | ||
} | ||
// if (match.isAlternator) { //handle quantifier in an alternation [0-9]{2}|[0-9]{3} | ||
// matches.push(match); //push back alternator | ||
// matches = match.matches; //remap target matches | ||
// var groupToken = new MaskToken(true); | ||
// var tmpMatch = matches.pop(); | ||
// matches.push(groupToken); //push the group | ||
// matches = groupToken.matches; | ||
// match = tmpMatch; | ||
// } | ||
if (!match.isGroup) { | ||
// if (regexMask && match.fn === null) { //why is this needed??? | ||
// if (match.def === ".") match.fn = new RegExp(match.def, opts.casing ? "i" : ""); | ||
// } | ||
match = groupify([match]); | ||
@@ -433,0 +436,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import keyCode from "./keycode.json"; | ||
import {keys} from "./keycode.js"; | ||
import {caret, getBuffer, getBufferTemplate, getLastValidPosition, resetMaskSet, seekNext} from "./positioning"; | ||
@@ -146,3 +146,3 @@ import {applyInputValue, clearOptionalTail, writeBuffer} from "./inputHandling"; | ||
if (input.tagName.toLowerCase() !== "textarea") { | ||
opts.ignorables.push(keyCode.ENTER); | ||
opts.ignorables.push(keys.Enter); | ||
} | ||
@@ -209,4 +209,4 @@ | ||
if (opts.inputEventOnly !== true) { | ||
EventRuler.on(el, "keydown", EventHandlers.keydownEvent); | ||
EventRuler.on(el, "keypress", EventHandlers.keypressEvent); | ||
EventRuler.on(el, "keydown", EventHandlers.keyEvent); | ||
// EventRuler.on(el, "keypress", EventHandlers.keypressEvent); | ||
EventRuler.on(el, "keyup", EventHandlers.keyupEvent); | ||
@@ -213,0 +213,0 @@ } |
import { | ||
determineTestTemplate, | ||
getMaskTemplate, | ||
getPlaceholder, | ||
getTest, | ||
getTests, | ||
getTestTemplate | ||
determineTestTemplate, | ||
getMaskTemplate, | ||
getPlaceholder, | ||
getTest, | ||
getTests, | ||
getTestTemplate | ||
} from "./validation-tests"; | ||
@@ -12,13 +12,13 @@ import {checkAlternationMatch} from "./validation"; | ||
export { | ||
caret, | ||
determineLastRequiredPosition, | ||
determineNewCaretPosition, | ||
getBuffer, | ||
getBufferTemplate, | ||
getLastValidPosition, | ||
isMask, | ||
resetMaskSet, | ||
seekNext, | ||
seekPrevious, | ||
translatePosition | ||
caret, | ||
determineLastRequiredPosition, | ||
determineNewCaretPosition, | ||
getBuffer, | ||
getBufferTemplate, | ||
getLastValidPosition, | ||
isMask, | ||
resetMaskSet, | ||
seekNext, | ||
seekPrevious, | ||
translatePosition | ||
}; | ||
@@ -28,81 +28,81 @@ | ||
function caret(input, begin, end, notranslate, isDelete) { | ||
const inputmask = this, | ||
opts = this.opts; | ||
const inputmask = this, | ||
opts = this.opts; | ||
var range; | ||
if (begin !== undefined) { | ||
if (Array.isArray(begin)) { | ||
end = inputmask.isRTL ? begin[0] : begin[1]; | ||
begin = inputmask.isRTL ? begin[1] : begin[0]; | ||
} | ||
if (begin.begin !== undefined) { | ||
end = inputmask.isRTL ? begin.begin : begin.end; | ||
begin = inputmask.isRTL ? begin.end : begin.begin; | ||
} | ||
if (typeof begin === "number") { | ||
begin = notranslate ? begin : translatePosition.call(inputmask, begin); | ||
end = notranslate ? end : translatePosition.call(inputmask, end); | ||
end = (typeof end == "number") ? end : begin; | ||
// if (!$(input).is(":visible")) { | ||
// return; | ||
// } | ||
var range; | ||
if (begin !== undefined) { | ||
if (Array.isArray(begin)) { | ||
end = inputmask.isRTL ? begin[0] : begin[1]; | ||
begin = inputmask.isRTL ? begin[1] : begin[0]; | ||
} | ||
if (begin.begin !== undefined) { | ||
end = inputmask.isRTL ? begin.begin : begin.end; | ||
begin = inputmask.isRTL ? begin.end : begin.begin; | ||
} | ||
if (typeof begin === "number") { | ||
begin = notranslate ? begin : translatePosition.call(inputmask, begin); | ||
end = notranslate ? end : translatePosition.call(inputmask, end); | ||
end = (typeof end == "number") ? end : begin; | ||
// if (!$(input).is(":visible")) { | ||
// return; | ||
// } | ||
var scrollCalc = parseInt(((input.ownerDocument.defaultView || window).getComputedStyle ? (input.ownerDocument.defaultView || window).getComputedStyle(input, null) : input.currentStyle).fontSize) * end; | ||
input.scrollLeft = scrollCalc > input.scrollWidth ? scrollCalc : 0; | ||
input.inputmask.caretPos = {begin: begin, end: end}; //track caret internally | ||
if (opts.insertModeVisual && opts.insertMode === false && begin === end) { | ||
if (!isDelete) { | ||
end++; //set visualization for insert/overwrite mode | ||
} | ||
} | ||
if (input === (input.inputmask.shadowRoot || input.ownerDocument).activeElement) { | ||
if ("setSelectionRange" in input) { | ||
input.setSelectionRange(begin, end); | ||
} else if (window.getSelection) { | ||
range = document.createRange(); | ||
if (input.firstChild === undefined || input.firstChild === null) { | ||
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(true); | ||
var sel = window.getSelection(); | ||
sel.removeAllRanges(); | ||
sel.addRange(range); | ||
//input.focus(); | ||
} else if (input.createTextRange) { | ||
range = input.createTextRange(); | ||
range.collapse(true); | ||
range.moveEnd("character", end); | ||
range.moveStart("character", begin); | ||
range.select(); | ||
} | ||
} | ||
} | ||
} else { | ||
if ("selectionStart" in input && "selectionEnd" in input) { | ||
begin = input.selectionStart; | ||
end = input.selectionEnd; | ||
} else if (window.getSelection) { | ||
range = window.getSelection().getRangeAt(0); | ||
if (range.commonAncestorContainer.parentNode === input || range.commonAncestorContainer === input) { | ||
begin = range.startOffset; | ||
end = range.endOffset; | ||
} | ||
} else if (document.selection && document.selection.createRange) { | ||
range = document.selection.createRange(); | ||
begin = 0 - range.duplicate().moveStart("character", -input.inputmask._valueGet().length); | ||
end = begin + range.text.length; | ||
} | ||
var scrollCalc = parseInt(((input.ownerDocument.defaultView || window).getComputedStyle ? (input.ownerDocument.defaultView || window).getComputedStyle(input, null) : input.currentStyle).fontSize) * end; | ||
input.scrollLeft = scrollCalc > input.scrollWidth ? scrollCalc : 0; | ||
input.inputmask.caretPos = {begin: begin, end: end}; //track caret internally | ||
if (opts.insertModeVisual && opts.insertMode === false && begin === end) { | ||
if (!isDelete) { | ||
end++; //set visualization for insert/overwrite mode | ||
} | ||
} | ||
if (input === (input.inputmask.shadowRoot || input.ownerDocument).activeElement) { | ||
if ("setSelectionRange" in input) { | ||
input.setSelectionRange(begin, end); | ||
} else if (window.getSelection) { | ||
range = document.createRange(); | ||
if (input.firstChild === undefined || input.firstChild === null) { | ||
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(true); | ||
var sel = window.getSelection(); | ||
sel.removeAllRanges(); | ||
sel.addRange(range); | ||
//input.focus(); | ||
} else if (input.createTextRange) { | ||
range = input.createTextRange(); | ||
range.collapse(true); | ||
range.moveEnd("character", end); | ||
range.moveStart("character", begin); | ||
range.select(); | ||
} | ||
} | ||
} | ||
} else { | ||
if ("selectionStart" in input && "selectionEnd" in input) { | ||
begin = input.selectionStart; | ||
end = input.selectionEnd; | ||
} else if (window.getSelection) { | ||
range = window.getSelection().getRangeAt(0); | ||
if (range.commonAncestorContainer.parentNode === input || range.commonAncestorContainer === input) { | ||
begin = range.startOffset; | ||
end = range.endOffset; | ||
} | ||
} else if (document.selection && document.selection.createRange) { | ||
range = document.selection.createRange(); | ||
begin = 0 - range.duplicate().moveStart("character", -input.inputmask._valueGet().length); | ||
end = begin + range.text.length; | ||
} | ||
// if (opts.insertModeVisual && opts.insertMode === false && begin === (end - 1)) end--; //correct caret for insert/overwrite mode | ||
// if (opts.insertModeVisual && opts.insertMode === false && begin === (end - 1)) end--; //correct caret for insert/overwrite mode | ||
/*eslint-disable consistent-return */ | ||
return { | ||
"begin": notranslate ? begin : translatePosition.call(inputmask, begin), | ||
"end": notranslate ? end : translatePosition.call(inputmask, end) | ||
}; | ||
/*eslint-enable consistent-return */ | ||
} | ||
/*eslint-disable consistent-return */ | ||
return { | ||
"begin": notranslate ? begin : translatePosition.call(inputmask, begin), | ||
"end": notranslate ? end : translatePosition.call(inputmask, end) | ||
}; | ||
/*eslint-enable consistent-return */ | ||
} | ||
} | ||
@@ -112,43 +112,43 @@ | ||
function determineLastRequiredPosition(returnDefinition) { | ||
const inputmask = this, | ||
maskset = this.maskset, | ||
$ = this.dependencyLib; | ||
const inputmask = this, | ||
maskset = this.maskset, | ||
$ = this.dependencyLib; | ||
var buffer = getMaskTemplate.call(inputmask, true, getLastValidPosition.call(inputmask), true, true), | ||
bl = buffer.length, | ||
pos, lvp = getLastValidPosition.call(inputmask), | ||
positions = {}, | ||
lvTest = maskset.validPositions[lvp], | ||
ndxIntlzr = lvTest !== undefined ? lvTest.locator.slice() : undefined, | ||
testPos; | ||
for (pos = lvp + 1; pos < buffer.length; pos++) { | ||
testPos = getTestTemplate.call(inputmask, pos, ndxIntlzr, pos - 1); | ||
ndxIntlzr = testPos.locator.slice(); | ||
positions[pos] = $.extend(true, {}, testPos); | ||
} | ||
var buffer = getMaskTemplate.call(inputmask, true, getLastValidPosition.call(inputmask), true, true), | ||
bl = buffer.length, | ||
pos, lvp = getLastValidPosition.call(inputmask), | ||
positions = {}, | ||
lvTest = maskset.validPositions[lvp], | ||
ndxIntlzr = lvTest !== undefined ? lvTest.locator.slice() : undefined, | ||
testPos; | ||
for (pos = lvp + 1; pos < buffer.length; pos++) { | ||
testPos = getTestTemplate.call(inputmask, pos, ndxIntlzr, pos - 1); | ||
ndxIntlzr = testPos.locator.slice(); | ||
positions[pos] = $.extend(true, {}, testPos); | ||
} | ||
var lvTestAlt = lvTest && lvTest.alternation !== undefined ? lvTest.locator[lvTest.alternation] : undefined; | ||
for (pos = bl - 1; pos > lvp; pos--) { | ||
testPos = positions[pos]; | ||
if ((testPos.match.optionality || | ||
(testPos.match.optionalQuantifier && testPos.match.newBlockMarker) || | ||
(lvTestAlt && | ||
( | ||
(lvTestAlt !== positions[pos].locator[lvTest.alternation] && testPos.match.static != true) || | ||
(testPos.match.static === true && | ||
testPos.locator[lvTest.alternation] && | ||
checkAlternationMatch.call(inputmask, testPos.locator[lvTest.alternation].toString().split(","), lvTestAlt.toString().split(",")) && | ||
getTests.call(inputmask, pos)[0].def !== "") | ||
) | ||
)) && | ||
buffer[pos] === getPlaceholder.call(inputmask, pos, testPos.match)) { | ||
bl--; | ||
} else { | ||
break; | ||
} | ||
} | ||
return returnDefinition ? { | ||
"l": bl, | ||
"def": positions[bl] ? positions[bl].match : undefined | ||
} : bl; | ||
var lvTestAlt = lvTest && lvTest.alternation !== undefined ? lvTest.locator[lvTest.alternation] : undefined; | ||
for (pos = bl - 1; pos > lvp; pos--) { | ||
testPos = positions[pos]; | ||
if ((testPos.match.optionality || | ||
(testPos.match.optionalQuantifier && testPos.match.newBlockMarker) || | ||
(lvTestAlt && | ||
( | ||
(lvTestAlt !== positions[pos].locator[lvTest.alternation] && testPos.match.static != true) || | ||
(testPos.match.static === true && | ||
testPos.locator[lvTest.alternation] && | ||
checkAlternationMatch.call(inputmask, testPos.locator[lvTest.alternation].toString().split(","), lvTestAlt.toString().split(",")) && | ||
getTests.call(inputmask, pos)[0].def !== "") | ||
) | ||
)) && | ||
buffer[pos] === getPlaceholder.call(inputmask, pos, testPos.match)) { | ||
bl--; | ||
} else { | ||
break; | ||
} | ||
} | ||
return returnDefinition ? { | ||
"l": bl, | ||
"def": positions[bl] ? positions[bl].match : undefined | ||
} : bl; | ||
} | ||
@@ -158,73 +158,75 @@ | ||
function determineNewCaretPosition(selectedCaret, tabbed, positionCaretOnClick) { | ||
const inputmask = this, | ||
maskset = this.maskset, | ||
opts = this.opts; | ||
const inputmask = this, | ||
maskset = this.maskset, | ||
opts = this.opts; | ||
function doRadixFocus(clickPos) { | ||
if (opts.radixPoint !== "" && opts.digits !== 0) { | ||
var vps = maskset.validPositions; | ||
if (vps[clickPos] === undefined || (vps[clickPos].input === getPlaceholder.call(inputmask, clickPos))) { | ||
if (clickPos < seekNext.call(inputmask, -1)) return true; | ||
var radixPos = getBuffer.call(inputmask).indexOf(opts.radixPoint); | ||
if (radixPos !== -1) { | ||
for (let vp = 0, vpl = vps.length; vp < vpl; vp++) { | ||
if (vps[vp] && radixPos < vp && vps[vp].input !== getPlaceholder.call(inputmask, vp)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
function doRadixFocus(clickPos) { | ||
if (opts.radixPoint !== "" && opts.digits !== 0) { | ||
var vps = maskset.validPositions; | ||
if (vps[clickPos] === undefined || (vps[clickPos].input === getPlaceholder.call(inputmask, clickPos))) { | ||
if (clickPos < seekNext.call(inputmask, -1)) return true; | ||
var radixPos = getBuffer.call(inputmask).indexOf(opts.radixPoint); | ||
if (radixPos !== -1) { | ||
for (let vp = 0, vpl = vps.length; vp < vpl; vp++) { | ||
if (vps[vp] && radixPos < vp && vps[vp].input !== getPlaceholder.call(inputmask, vp)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
if (tabbed) { | ||
if (inputmask.isRTL) { | ||
selectedCaret.end = selectedCaret.begin; | ||
} else { | ||
selectedCaret.begin = selectedCaret.end; | ||
} | ||
} | ||
if (selectedCaret.begin === selectedCaret.end) { | ||
positionCaretOnClick = positionCaretOnClick || opts.positionCaretOnClick; | ||
switch (positionCaretOnClick) { | ||
case "none": | ||
break; | ||
case "select": | ||
selectedCaret = {begin: 0, end: getBuffer.call(inputmask).length}; | ||
break; | ||
case "ignore": | ||
selectedCaret.end = selectedCaret.begin = seekNext.call(inputmask, getLastValidPosition.call(inputmask)); | ||
break; | ||
case "radixFocus": | ||
if (doRadixFocus(selectedCaret.begin)) { | ||
var radixPos = getBuffer.call(inputmask).join("").indexOf(opts.radixPoint); | ||
selectedCaret.end = selectedCaret.begin = opts.numericInput ? seekNext.call(inputmask, radixPos) : radixPos; | ||
break; | ||
} //fallback to lvp | ||
// eslint-disable-next-line no-fallthrough | ||
default: //lvp: | ||
var clickPosition = selectedCaret.begin, | ||
lvclickPosition = getLastValidPosition.call(inputmask, clickPosition, true), | ||
lastPosition = seekNext.call(inputmask, (lvclickPosition === -1 && !isMask.call(inputmask, 0)) ? -1 : lvclickPosition); | ||
if (tabbed) { | ||
if (inputmask.isRTL) { | ||
selectedCaret.end = selectedCaret.begin; | ||
} else { | ||
selectedCaret.begin = selectedCaret.end; | ||
} | ||
} | ||
if (selectedCaret.begin === selectedCaret.end) { | ||
positionCaretOnClick = positionCaretOnClick || opts.positionCaretOnClick; | ||
switch (positionCaretOnClick) { | ||
case "none": | ||
break; | ||
case "select": | ||
selectedCaret = {begin: 0, end: getBuffer.call(inputmask).length}; | ||
break; | ||
case "ignore": | ||
selectedCaret.end = selectedCaret.begin = seekNext.call(inputmask, getLastValidPosition.call(inputmask)); | ||
break; | ||
case "radixFocus": | ||
if (inputmask.clicked > 1 && maskset.validPositions.length == 0) | ||
break; | ||
if (doRadixFocus(selectedCaret.begin)) { | ||
var radixPos = getBuffer.call(inputmask).join("").indexOf(opts.radixPoint); | ||
selectedCaret.end = selectedCaret.begin = opts.numericInput ? seekNext.call(inputmask, radixPos) : radixPos; | ||
break; | ||
} //fallback to lvp | ||
// eslint-disable-next-line no-fallthrough | ||
default: //lvp: | ||
var clickPosition = selectedCaret.begin, | ||
lvclickPosition = getLastValidPosition.call(inputmask, clickPosition, true), | ||
lastPosition = seekNext.call(inputmask, (lvclickPosition === -1 && !isMask.call(inputmask, 0)) ? -1 : lvclickPosition); | ||
if (clickPosition <= lastPosition) { | ||
selectedCaret.end = selectedCaret.begin = !isMask.call(inputmask, clickPosition, false, true) ? seekNext.call(inputmask, clickPosition) : clickPosition; | ||
} else { | ||
var lvp = maskset.validPositions[lvclickPosition], | ||
tt = getTestTemplate.call(inputmask, lastPosition, lvp ? lvp.match.locator : undefined, lvp), | ||
placeholder = getPlaceholder.call(inputmask, lastPosition, tt.match); | ||
if ((placeholder !== "" && getBuffer.call(inputmask)[lastPosition] !== placeholder && tt.match.optionalQuantifier !== true && tt.match.newBlockMarker !== true) || (!isMask.call(inputmask, lastPosition, opts.keepStatic, true) && tt.match.def === placeholder)) { | ||
var newPos = seekNext.call(inputmask, lastPosition); | ||
if (clickPosition >= newPos || clickPosition === lastPosition) { | ||
lastPosition = newPos; | ||
} | ||
} | ||
selectedCaret.end = selectedCaret.begin = lastPosition; | ||
} | ||
} | ||
if (clickPosition <= lastPosition) { | ||
selectedCaret.end = selectedCaret.begin = !isMask.call(inputmask, clickPosition, false, true) ? seekNext.call(inputmask, clickPosition) : clickPosition; | ||
} else { | ||
var lvp = maskset.validPositions[lvclickPosition], | ||
tt = getTestTemplate.call(inputmask, lastPosition, lvp ? lvp.match.locator : undefined, lvp), | ||
placeholder = getPlaceholder.call(inputmask, lastPosition, tt.match); | ||
if ((placeholder !== "" && getBuffer.call(inputmask)[lastPosition] !== placeholder && tt.match.optionalQuantifier !== true && tt.match.newBlockMarker !== true) || (!isMask.call(inputmask, lastPosition, opts.keepStatic, true) && tt.match.def === placeholder)) { | ||
var newPos = seekNext.call(inputmask, lastPosition); | ||
if (clickPosition >= newPos || clickPosition === lastPosition) { | ||
lastPosition = newPos; | ||
} | ||
} | ||
selectedCaret.end = selectedCaret.begin = lastPosition; | ||
} | ||
} | ||
return selectedCaret; | ||
} | ||
return selectedCaret; | ||
} | ||
} | ||
@@ -235,9 +237,9 @@ | ||
function getBuffer(noCache) { | ||
const inputmask = this, maskset = this.maskset; | ||
const inputmask = this, maskset = this.maskset; | ||
if (maskset.buffer === undefined || noCache === true) { | ||
maskset.buffer = getMaskTemplate.call(inputmask, true, getLastValidPosition.call(inputmask), true); | ||
if (maskset._buffer === undefined) maskset._buffer = maskset.buffer.slice(); | ||
} | ||
return maskset.buffer; | ||
if (maskset.buffer === undefined || noCache === true) { | ||
maskset.buffer = getMaskTemplate.call(inputmask, true, getLastValidPosition.call(inputmask), true); | ||
if (maskset._buffer === undefined) maskset._buffer = maskset.buffer.slice(); | ||
} | ||
return maskset.buffer; | ||
} | ||
@@ -247,10 +249,10 @@ | ||
function getBufferTemplate() { | ||
const inputmask = this, maskset = this.maskset; | ||
const inputmask = this, maskset = this.maskset; | ||
if (maskset._buffer === undefined) { | ||
//generate template | ||
maskset._buffer = getMaskTemplate.call(inputmask, false, 1); | ||
if (maskset.buffer === undefined) maskset.buffer = maskset._buffer.slice(); | ||
} | ||
return maskset._buffer; | ||
if (maskset._buffer === undefined) { | ||
//generate template | ||
maskset._buffer = getMaskTemplate.call(inputmask, false, 1); | ||
if (maskset.buffer === undefined) maskset.buffer = maskset._buffer.slice(); | ||
} | ||
return maskset._buffer; | ||
} | ||
@@ -260,15 +262,15 @@ | ||
function getLastValidPosition(closestTo, strict, validPositions) { | ||
const maskset = this.maskset; | ||
const maskset = this.maskset; | ||
var before = -1, | ||
after = -1, | ||
valids = validPositions || maskset.validPositions; //for use in valhook ~ context switch | ||
if (closestTo === undefined) closestTo = -1; | ||
for (var psNdx = 0, vpl = valids.length; psNdx < vpl; psNdx++) { | ||
if (valids[psNdx] && (strict || valids[psNdx].generatedInput !== true)) { | ||
if (psNdx <= closestTo) before = psNdx; | ||
if (psNdx >= closestTo) after = psNdx; | ||
} | ||
} | ||
return (before === -1 || before == closestTo) ? after : after == -1 ? before : (closestTo - before) < (after - closestTo) ? before : after; | ||
var before = -1, | ||
after = -1, | ||
valids = validPositions || maskset.validPositions; //for use in valhook ~ context switch | ||
if (closestTo === undefined) closestTo = -1; | ||
for (var psNdx = 0, vpl = valids.length; psNdx < vpl; psNdx++) { | ||
if (valids[psNdx] && (strict || valids[psNdx].generatedInput !== true)) { | ||
if (psNdx <= closestTo) before = psNdx; | ||
if (psNdx >= closestTo) after = psNdx; | ||
} | ||
} | ||
return (before === -1 || before == closestTo) ? after : after == -1 ? before : (closestTo - before) < (after - closestTo) ? before : after; | ||
} | ||
@@ -278,26 +280,26 @@ | ||
function isMask(pos, strict, fuzzy) { | ||
const inputmask = this, maskset = this.maskset; | ||
const inputmask = this, maskset = this.maskset; | ||
var test = getTestTemplate.call(inputmask, pos).match; | ||
if (test.def === "") test = getTest.call(inputmask, pos).match; | ||
var test = getTestTemplate.call(inputmask, pos).match; | ||
if (test.def === "") test = getTest.call(inputmask, pos).match; | ||
if (test.static !== true) { | ||
return test.fn; | ||
} | ||
if (fuzzy === true && (maskset.validPositions[pos] !== undefined && maskset.validPositions[pos].generatedInput !== true)) { | ||
return true; | ||
} | ||
if (test.static !== true) { | ||
return test.fn; | ||
} | ||
if (fuzzy === true && (maskset.validPositions[pos] !== undefined && maskset.validPositions[pos].generatedInput !== true)) { | ||
return true; | ||
} | ||
if (strict !== true && pos > -1) { | ||
if (fuzzy) { //check on the number of tests | ||
var tests = getTests.call(inputmask, pos); | ||
return tests.length > (1 + (tests[tests.length - 1].match.def === "" ? 1 : 0)); | ||
} | ||
//else based on the template | ||
var testTemplate = determineTestTemplate.call(inputmask, pos, getTests.call(inputmask, pos)); | ||
var testPlaceHolder = getPlaceholder.call(inputmask, pos, testTemplate.match); | ||
return testTemplate.match.def !== testPlaceHolder; | ||
if (strict !== true && pos > -1) { | ||
if (fuzzy) { //check on the number of tests | ||
var tests = getTests.call(inputmask, pos); | ||
return tests.length > (1 + (tests[tests.length - 1].match.def === "" ? 1 : 0)); | ||
} | ||
//else based on the template | ||
var testTemplate = determineTestTemplate.call(inputmask, pos, getTests.call(inputmask, pos)); | ||
var testPlaceHolder = getPlaceholder.call(inputmask, pos, testTemplate.match); | ||
return testTemplate.match.def !== testPlaceHolder; | ||
} | ||
return false; | ||
} | ||
return false; | ||
} | ||
@@ -307,9 +309,9 @@ | ||
function resetMaskSet(soft) { | ||
const maskset = this.maskset; | ||
const maskset = this.maskset; | ||
maskset.buffer = undefined; | ||
if (soft !== true) { | ||
maskset.validPositions = []; | ||
maskset.p = 0; | ||
} | ||
maskset.buffer = undefined; | ||
if (soft !== true) { | ||
maskset.validPositions = []; | ||
maskset.p = 0; | ||
} | ||
} | ||
@@ -319,12 +321,12 @@ | ||
function seekNext(pos, newBlock, fuzzy) { | ||
const inputmask = this; | ||
const inputmask = this; | ||
if (fuzzy === undefined) fuzzy = true; | ||
var position = pos + 1; | ||
while (getTest.call(inputmask, position).match.def !== "" && | ||
((newBlock === true && (getTest.call(inputmask, position).match.newBlockMarker !== true || !isMask.call(inputmask, position, undefined, true))) || | ||
(newBlock !== true && !isMask.call(inputmask, position, undefined, fuzzy)))) { | ||
position++; | ||
} | ||
return position; | ||
if (fuzzy === undefined) fuzzy = true; | ||
var position = pos + 1; | ||
while (getTest.call(inputmask, position).match.def !== "" && | ||
((newBlock === true && (getTest.call(inputmask, position).match.newBlockMarker !== true || !isMask.call(inputmask, position, undefined, true))) || | ||
(newBlock !== true && !isMask.call(inputmask, position, undefined, fuzzy)))) { | ||
position++; | ||
} | ||
return position; | ||
} | ||
@@ -334,13 +336,13 @@ | ||
function seekPrevious(pos, newBlock) { | ||
const inputmask = this; | ||
const inputmask = this; | ||
var position = pos - 1; | ||
if (pos <= 0) return 0; | ||
var position = pos - 1; | ||
if (pos <= 0) return 0; | ||
while (position > 0 && | ||
((newBlock === true && (getTest.call(inputmask, position).match.newBlockMarker !== true || !isMask.call(inputmask, position, undefined, true))) || | ||
(newBlock !== true && !isMask.call(inputmask, position, undefined, true)))) { | ||
position--; | ||
} | ||
return position; | ||
while (position > 0 && | ||
((newBlock === true && (getTest.call(inputmask, position).match.newBlockMarker !== true || !isMask.call(inputmask, position, undefined, true))) || | ||
(newBlock !== true && !isMask.call(inputmask, position, undefined, true)))) { | ||
position--; | ||
} | ||
return position; | ||
} | ||
@@ -350,11 +352,11 @@ | ||
function translatePosition(pos) { | ||
const inputmask = this, | ||
opts = this.opts, | ||
el = this.el; | ||
const inputmask = this, | ||
opts = this.opts, | ||
el = this.el; | ||
if (inputmask.isRTL && typeof pos === "number" && (!opts.greedy || opts.placeholder !== "") && el) { | ||
pos = inputmask._valueGet().length - pos; | ||
if (pos < 0) pos = 0; | ||
} | ||
return pos; | ||
if (inputmask.isRTL && typeof pos === "number" && (!opts.greedy || opts.placeholder !== "") && el) { | ||
pos = inputmask._valueGet().length - pos; | ||
if (pos < 0) pos = 0; | ||
} | ||
return pos; | ||
} |
export { | ||
determineTestTemplate, | ||
getDecisionTaker, | ||
getMaskTemplate, | ||
getPlaceholder, | ||
getTest, | ||
getTests, | ||
getTestTemplate, | ||
isSubsetOf | ||
determineTestTemplate, | ||
getDecisionTaker, | ||
getMaskTemplate, | ||
getPlaceholder, | ||
getTest, | ||
getTests, | ||
getTestTemplate, | ||
isSubsetOf | ||
}; | ||
@@ -14,13 +14,13 @@ import Inputmask from "./inputmask"; | ||
function getLocator(tst, align) { //need to align the locators to be correct | ||
var locator = (tst.alternation != undefined ? tst.mloc[getDecisionTaker(tst)] : tst.locator).join(""); | ||
if (locator !== "") while (locator.length < align) locator += "0"; | ||
return locator; | ||
var locator = (tst.alternation != undefined ? tst.mloc[getDecisionTaker(tst)] : tst.locator).join(""); | ||
if (locator !== "") while (locator.length < align) locator += "0"; | ||
return locator; | ||
} | ||
function getDecisionTaker(tst) { | ||
var decisionTaker = tst.locator[tst.alternation]; | ||
if (typeof decisionTaker == "string" && decisionTaker.length > 0) { //no decision taken ~ take first one as decider | ||
decisionTaker = decisionTaker.split(",")[0]; | ||
} | ||
return decisionTaker !== undefined ? decisionTaker.toString() : ""; | ||
var decisionTaker = tst.locator[tst.alternation]; | ||
if (typeof decisionTaker == "string" && decisionTaker.length > 0) { //no decision taken ~ take first one as decider | ||
decisionTaker = decisionTaker.split(",")[0]; | ||
} | ||
return decisionTaker !== undefined ? decisionTaker.toString() : ""; | ||
} | ||
@@ -30,33 +30,33 @@ | ||
function getPlaceholder(pos, test, returnPL) { | ||
const inputmask = this, | ||
opts = this.opts, | ||
maskset = this.maskset; | ||
const inputmask = this, | ||
opts = this.opts, | ||
maskset = this.maskset; | ||
test = test || getTest.call(inputmask, pos).match; | ||
if (test.placeholder !== undefined || returnPL === true) { | ||
return typeof test.placeholder === "function" ? test.placeholder(opts) : test.placeholder; | ||
} else if (test.static === true) { | ||
if (pos > -1 && maskset.validPositions[pos] === undefined) { | ||
var tests = getTests.call(inputmask, pos), | ||
staticAlternations = [], | ||
prevTest; | ||
if (tests.length > 1 + (tests[tests.length - 1].match.def === "" ? 1 : 0)) { | ||
for (var i = 0; i < tests.length; i++) { | ||
if (tests[i].match.def !== "" && tests[i].match.optionality !== true && tests[i].match.optionalQuantifier !== true && | ||
(tests[i].match.static === true || (prevTest === undefined || tests[i].match.fn.test(prevTest.match.def, maskset, pos, true, opts) !== false))) { | ||
staticAlternations.push(tests[i]); | ||
if (tests[i].match.static === true) prevTest = tests[i]; | ||
if (staticAlternations.length > 1) { | ||
if (/[0-9a-bA-Z]/.test(staticAlternations[0].match.def)) { | ||
return opts.placeholder.charAt(pos % opts.placeholder.length); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return test.def; | ||
} | ||
test = test || getTest.call(inputmask, pos).match; | ||
if (test.placeholder !== undefined || returnPL === true) { | ||
return typeof test.placeholder === "function" ? test.placeholder(opts) : test.placeholder; | ||
} else if (test.static === true) { | ||
if (pos > -1 && maskset.validPositions[pos] === undefined) { | ||
var tests = getTests.call(inputmask, pos), | ||
staticAlternations = [], | ||
prevTest; | ||
if (tests.length > 1 + (tests[tests.length - 1].match.def === "" ? 1 : 0)) { | ||
for (var i = 0; i < tests.length; i++) { | ||
if (tests[i].match.def !== "" && tests[i].match.optionality !== true && tests[i].match.optionalQuantifier !== true && | ||
(tests[i].match.static === true || (prevTest === undefined || tests[i].match.fn.test(prevTest.match.def, maskset, pos, true, opts) !== false))) { | ||
staticAlternations.push(tests[i]); | ||
if (tests[i].match.static === true) prevTest = tests[i]; | ||
if (staticAlternations.length > 1) { | ||
if (/[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); | ||
return opts.placeholder.charAt(pos % opts.placeholder.length); | ||
} | ||
@@ -66,55 +66,55 @@ | ||
function getMaskTemplate(baseOnInput, minimalPos, includeMode, noJit, clearOptionalTail) { | ||
//includeMode true => input, undefined => placeholder, false => mask | ||
//includeMode true => input, undefined => placeholder, false => mask | ||
var inputmask = this, | ||
opts = this.opts, | ||
maskset = this.maskset; | ||
var inputmask = this, | ||
opts = this.opts, | ||
maskset = this.maskset; | ||
var greedy = opts.greedy; | ||
if (clearOptionalTail && opts.greedy) { | ||
opts.greedy = false; | ||
inputmask.maskset.tests = {}; | ||
} | ||
minimalPos = minimalPos || 0; | ||
var maskTemplate = [], | ||
ndxIntlzr, pos = 0, | ||
test, testPos, jitRenderStatic; | ||
do { | ||
if (baseOnInput === true && maskset.validPositions[pos]) { | ||
testPos = (clearOptionalTail && maskset.validPositions[pos].match.optionality | ||
&& maskset.validPositions[pos + 1] === undefined | ||
&& (maskset.validPositions[pos].generatedInput === true || (maskset.validPositions[pos].input == opts.skipOptionalPartCharacter && pos > 0))) | ||
? determineTestTemplate.call(inputmask, pos, getTests.call(inputmask, pos, ndxIntlzr, pos - 1)) | ||
: maskset.validPositions[pos]; | ||
test = testPos.match; | ||
ndxIntlzr = testPos.locator.slice(); | ||
maskTemplate.push(includeMode === true ? testPos.input : includeMode === false ? test.nativeDef : getPlaceholder.call(inputmask, pos, test)); | ||
} else { | ||
testPos = getTestTemplate.call(inputmask, pos, ndxIntlzr, pos - 1); | ||
test = testPos.match; | ||
ndxIntlzr = testPos.locator.slice(); | ||
var jitMasking = noJit === true ? false : (opts.jitMasking !== false ? opts.jitMasking : test.jit); | ||
//check for groupSeparator is a hack for the numerics as we don't want the render of the groupSeparator beforehand | ||
jitRenderStatic = ((jitRenderStatic && test.static && test.def !== opts.groupSeparator && test.fn === null) || (maskset.validPositions[pos - 1] && test.static && test.def !== opts.groupSeparator && test.fn === null)) && maskset.tests[pos] && maskset.tests[pos].length === 1; | ||
if (jitRenderStatic || jitMasking === false || jitMasking === undefined /*|| pos < lvp*/ || (typeof jitMasking === "number" && isFinite(jitMasking) && jitMasking > pos)) { | ||
maskTemplate.push(includeMode === false ? test.nativeDef : getPlaceholder.call(inputmask, maskTemplate.length, test)); | ||
} else { | ||
jitRenderStatic = false; | ||
} | ||
} | ||
var greedy = opts.greedy; | ||
if (clearOptionalTail && opts.greedy) { | ||
opts.greedy = false; | ||
inputmask.maskset.tests = {}; | ||
} | ||
minimalPos = minimalPos || 0; | ||
var maskTemplate = [], | ||
ndxIntlzr, pos = 0, | ||
test, testPos, jitRenderStatic; | ||
do { | ||
if (baseOnInput === true && maskset.validPositions[pos]) { | ||
testPos = (clearOptionalTail && maskset.validPositions[pos].match.optionality | ||
&& maskset.validPositions[pos + 1] === undefined | ||
&& (maskset.validPositions[pos].generatedInput === true || (maskset.validPositions[pos].input == opts.skipOptionalPartCharacter && pos > 0))) | ||
? determineTestTemplate.call(inputmask, pos, getTests.call(inputmask, pos, ndxIntlzr, pos - 1)) | ||
: maskset.validPositions[pos]; | ||
test = testPos.match; | ||
ndxIntlzr = testPos.locator.slice(); | ||
maskTemplate.push(includeMode === true ? testPos.input : includeMode === false ? test.nativeDef : getPlaceholder.call(inputmask, pos, test)); | ||
} else { | ||
testPos = getTestTemplate.call(inputmask, pos, ndxIntlzr, pos - 1); | ||
test = testPos.match; | ||
ndxIntlzr = testPos.locator.slice(); | ||
var jitMasking = noJit === true ? false : (opts.jitMasking !== false ? opts.jitMasking : test.jit); | ||
//check for groupSeparator is a hack for the numerics as we don't want the render of the groupSeparator beforehand | ||
jitRenderStatic = ((jitRenderStatic && test.static && test.def !== opts.groupSeparator && test.fn === null) || (maskset.validPositions[pos - 1] && test.static && test.def !== opts.groupSeparator && test.fn === null)) && maskset.tests[pos] && maskset.tests[pos].length === 1; | ||
if (jitRenderStatic || jitMasking === false || jitMasking === undefined /*|| pos < lvp*/ || (typeof jitMasking === "number" && isFinite(jitMasking) && jitMasking > pos)) { | ||
maskTemplate.push(includeMode === false ? test.nativeDef : getPlaceholder.call(inputmask, maskTemplate.length, test)); | ||
} else { | ||
jitRenderStatic = false; | ||
} | ||
} | ||
pos++; | ||
} while ((test.static !== true || test.def !== "") || minimalPos > pos); | ||
if (maskTemplate[maskTemplate.length - 1] === "") { | ||
maskTemplate.pop(); //drop the last one which is empty | ||
} | ||
if (includeMode !== false || //do not alter the masklength when just retrieving the maskdefinition | ||
maskset.maskLength === undefined) //just make sure the maskLength gets initialized in all cases (needed for isValid) | ||
{ | ||
maskset.maskLength = pos - 1; | ||
} | ||
pos++; | ||
} while ((test.static !== true || test.def !== "") || minimalPos > pos); | ||
if (maskTemplate[maskTemplate.length - 1] === "") { | ||
maskTemplate.pop(); //drop the last one which is empty | ||
} | ||
if (includeMode !== false || //do not alter the masklength when just retrieving the maskdefinition | ||
maskset.maskLength === undefined) //just make sure the maskLength gets initialized in all cases (needed for isValid) | ||
{ | ||
maskset.maskLength = pos - 1; | ||
} | ||
opts.greedy = greedy; | ||
return maskTemplate; | ||
opts.greedy = greedy; | ||
return maskTemplate; | ||
} | ||
@@ -124,6 +124,6 @@ | ||
function getTestTemplate(pos, ndxIntlzr, tstPs) { | ||
var inputmask = this, | ||
maskset = this.maskset; | ||
var inputmask = this, | ||
maskset = this.maskset; | ||
return maskset.validPositions[pos] || determineTestTemplate.call(inputmask, pos, getTests.call(inputmask, pos, ndxIntlzr ? ndxIntlzr.slice() : ndxIntlzr, tstPs)); | ||
return maskset.validPositions[pos] || determineTestTemplate.call(inputmask, pos, getTests.call(inputmask, pos, ndxIntlzr ? ndxIntlzr.slice() : ndxIntlzr, tstPs)); | ||
} | ||
@@ -133,47 +133,48 @@ | ||
function determineTestTemplate(pos, tests) { | ||
var inputmask = this, | ||
opts = this.opts; | ||
var optionalityLevel = determineOptionalityLevel(pos, tests); | ||
pos = pos > 0 ? pos - 1 : 0; | ||
var altTest = getTest.call(inputmask, pos), targetLocator = getLocator(altTest), tstLocator, closest, bestMatch; | ||
if (opts.greedy && tests.length > 1 && tests[tests.length - 1].match.def === "") | ||
tests.pop(); | ||
// console.log(" optionality = " + optionalityLevel); | ||
// console.log(" - " + JSON.stringify(tests)); | ||
for (var ndx = 0; ndx < tests.length; ndx++) { //find best matching | ||
var tst = tests[ndx]; | ||
tstLocator = getLocator(tst, targetLocator.length); | ||
var distance = Math.abs(tstLocator - targetLocator); | ||
var inputmask = this, | ||
opts = this.opts, | ||
lenghtOffset = 0; | ||
var optionalityLevel = determineOptionalityLevel(pos, tests); | ||
pos = pos > 0 ? pos - 1 : 0; | ||
var altTest = getTest.call(inputmask, pos), targetLocator = getLocator(altTest), tstLocator, closest, bestMatch; | ||
if (opts.greedy && tests.length > 1 && tests[tests.length - 1].match.def === "") | ||
lenghtOffset = 1; | ||
// console.log(" optionality = " + optionalityLevel); | ||
// console.log(" - " + JSON.stringify(tests)); | ||
for (var ndx = 0; ndx < tests.length - lenghtOffset; ndx++) { //find best matching | ||
var tst = tests[ndx]; | ||
tstLocator = getLocator(tst, targetLocator.length); | ||
var distance = Math.abs(tstLocator - targetLocator); | ||
if (closest === undefined | ||
|| (tstLocator !== "" && distance < closest) | ||
|| (bestMatch && !opts.greedy && | ||
(bestMatch.match.optionality && bestMatch.match.optionality - optionalityLevel > 0) && | ||
bestMatch.match.newBlockMarker === "master" && | ||
((!tst.match.optionality || tst.match.optionality - optionalityLevel < 1) || !tst.match.newBlockMarker)) | ||
|| (bestMatch && !opts.greedy && bestMatch.match.optionalQuantifier && !tst.match.optionalQuantifier)) { | ||
closest = distance; | ||
bestMatch = tst; | ||
} | ||
} | ||
return bestMatch; | ||
if (closest === undefined | ||
|| (tstLocator !== "" && distance < closest) | ||
|| (bestMatch && !opts.greedy && | ||
(bestMatch.match.optionality && bestMatch.match.optionality - optionalityLevel > 0) && | ||
bestMatch.match.newBlockMarker === "master" && | ||
((!tst.match.optionality || tst.match.optionality - optionalityLevel < 1) || !tst.match.newBlockMarker)) | ||
|| (bestMatch && !opts.greedy && bestMatch.match.optionalQuantifier && !tst.match.optionalQuantifier)) { | ||
closest = distance; | ||
bestMatch = tst; | ||
} | ||
} | ||
return bestMatch; | ||
} | ||
function determineOptionalityLevel(pos, tests) { | ||
let optionalityLevel = 0, differentOptionalLevels = false; | ||
tests.forEach(test => { | ||
if (test.match.optionality) { | ||
if (optionalityLevel !== 0 && optionalityLevel !== test.match.optionality) | ||
differentOptionalLevels = true; | ||
if (optionalityLevel === 0 || optionalityLevel > test.match.optionality) { | ||
optionalityLevel = test.match.optionality; | ||
} | ||
} | ||
}); | ||
if (optionalityLevel) { | ||
if (pos == 0) optionalityLevel = 0; | ||
else if (tests.length == 1) optionalityLevel = 0; | ||
else if (!differentOptionalLevels) optionalityLevel = 0; | ||
} | ||
return optionalityLevel; | ||
let optionalityLevel = 0, differentOptionalLevels = false; | ||
tests.forEach(test => { | ||
if (test.match.optionality) { | ||
if (optionalityLevel !== 0 && optionalityLevel !== test.match.optionality) | ||
differentOptionalLevels = true; | ||
if (optionalityLevel === 0 || optionalityLevel > test.match.optionality) { | ||
optionalityLevel = test.match.optionality; | ||
} | ||
} | ||
}); | ||
if (optionalityLevel) { | ||
if (pos == 0) optionalityLevel = 0; | ||
else if (tests.length == 1) optionalityLevel = 0; | ||
else if (!differentOptionalLevels) optionalityLevel = 0; | ||
} | ||
return optionalityLevel; | ||
} | ||
@@ -183,31 +184,31 @@ | ||
function getTest(pos, tests) { | ||
var inputmask = this, | ||
maskset = this.maskset; | ||
var inputmask = this, | ||
maskset = this.maskset; | ||
if (maskset.validPositions[pos]) { | ||
return maskset.validPositions[pos]; | ||
} | ||
return (tests || getTests.call(inputmask, pos))[0]; | ||
if (maskset.validPositions[pos]) { | ||
return maskset.validPositions[pos]; | ||
} | ||
return (tests || getTests.call(inputmask, pos))[0]; | ||
} | ||
function isSubsetOf(source, target, opts) { | ||
function expand(pattern) { | ||
var expanded = [], start = -1, end; | ||
for (var i = 0, l = pattern.length; i < l; i++) { | ||
if (pattern.charAt(i) === "-") { | ||
end = pattern.charCodeAt(i + 1); | ||
while (++start < end) expanded.push(String.fromCharCode(start)); | ||
} else { | ||
start = pattern.charCodeAt(i); | ||
expanded.push(pattern.charAt(i)); | ||
} | ||
} | ||
return expanded.join(""); | ||
} | ||
function expand(pattern) { | ||
var expanded = [], start = -1, end; | ||
for (var i = 0, l = pattern.length; i < l; i++) { | ||
if (pattern.charAt(i) === "-") { | ||
end = pattern.charCodeAt(i + 1); | ||
while (++start < end) expanded.push(String.fromCharCode(start)); | ||
} else { | ||
start = pattern.charCodeAt(i); | ||
expanded.push(pattern.charAt(i)); | ||
} | ||
} | ||
return expanded.join(""); | ||
} | ||
if (source.match.def === target.match.nativeDef) return true; | ||
if ((opts.regex || (source.match.fn instanceof RegExp && target.match.fn instanceof RegExp)) && source.match.static !== true && target.match.static !== true) { //is regex a subset | ||
return expand(target.match.fn.toString().replace(/[[\]/]/g, "")).indexOf(expand(source.match.fn.toString().replace(/[[\]/]/g, ""))) !== -1; | ||
} | ||
return false; | ||
if (source.match.def === target.match.nativeDef) return true; | ||
if ((opts.regex || (source.match.fn instanceof RegExp && target.match.fn instanceof RegExp)) && source.match.static !== true && target.match.static !== true) { //is regex a subset | ||
return expand(target.match.fn.toString().replace(/[[\]/]/g, "")).indexOf(expand(source.match.fn.toString().replace(/[[\]/]/g, ""))) !== -1; | ||
} | ||
return false; | ||
} | ||
@@ -217,388 +218,409 @@ | ||
function getTests(pos, ndxIntlzr, tstPs) { | ||
var inputmask = this, | ||
$ = this.dependencyLib, | ||
maskset = this.maskset, | ||
opts = this.opts, | ||
el = this.el, | ||
maskTokens = maskset.maskToken, | ||
testPos = ndxIntlzr ? tstPs : 0, | ||
ndxInitializer = ndxIntlzr ? ndxIntlzr.slice() : [0], | ||
matches = [], | ||
insertStop = false, | ||
latestMatch, | ||
cacheDependency = ndxIntlzr ? ndxIntlzr.join("") : ""; | ||
var inputmask = this, | ||
$ = this.dependencyLib, | ||
maskset = this.maskset, | ||
opts = this.opts, | ||
el = this.el, | ||
maskTokens = maskset.maskToken, | ||
testPos = ndxIntlzr ? tstPs : 0, | ||
ndxInitializer = ndxIntlzr ? ndxIntlzr.slice() : [0], | ||
matches = [], | ||
insertStop = false, | ||
latestMatch, | ||
cacheDependency = ndxIntlzr ? ndxIntlzr.join("") : ""; | ||
function resolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) { //ndxInitializer contains a set of indexes to speedup searches in the mtokens | ||
function handleMatch(match, loopNdx, quantifierRecurse) { | ||
function isFirstMatch(latestMatch, tokenGroup) { | ||
var firstMatch = tokenGroup.matches.indexOf(latestMatch) === 0; | ||
if (!firstMatch) { | ||
tokenGroup.matches.every(function (match, ndx) { | ||
if (match.isQuantifier === true) { | ||
firstMatch = isFirstMatch(latestMatch, tokenGroup.matches[ndx - 1]); | ||
} else if (Object.prototype.hasOwnProperty.call(match, "matches")) firstMatch = isFirstMatch(latestMatch, match); | ||
if (firstMatch) return false; | ||
function resolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) { //ndxInitializer contains a set of indexes to speedup searches in the mtokens | ||
function handleMatch(match, loopNdx, quantifierRecurse) { | ||
function isFirstMatch(latestMatch, tokenGroup) { | ||
var firstMatch = tokenGroup.matches.indexOf(latestMatch) === 0; | ||
if (!firstMatch) { | ||
tokenGroup.matches.every(function (match, ndx) { | ||
if (match.isQuantifier === true) { | ||
firstMatch = isFirstMatch(latestMatch, tokenGroup.matches[ndx - 1]); | ||
} else if (Object.prototype.hasOwnProperty.call(match, "matches")) firstMatch = isFirstMatch(latestMatch, match); | ||
if (firstMatch) return false; | ||
return true; | ||
}); | ||
} | ||
return firstMatch; | ||
} | ||
return true; | ||
}); | ||
} | ||
return firstMatch; | ||
} | ||
function resolveNdxInitializer(pos, alternateNdx, targetAlternation) { | ||
var bestMatch, indexPos; | ||
function resolveNdxInitializer(pos, alternateNdx, targetAlternation) { | ||
var bestMatch, indexPos; | ||
if (maskset.tests[pos] || maskset.validPositions[pos]) { | ||
(maskset.tests[pos] || [maskset.validPositions[pos]]).every(function (lmnt, ndx) { | ||
if (lmnt.mloc[alternateNdx]) { | ||
bestMatch = lmnt; | ||
return false; //break | ||
} | ||
var alternation = targetAlternation !== undefined ? targetAlternation : lmnt.alternation, | ||
ndxPos = lmnt.locator[alternation] !== undefined ? lmnt.locator[alternation].toString().indexOf(alternateNdx) : -1; | ||
if ((indexPos === undefined || ndxPos < indexPos) && ndxPos !== -1) { | ||
bestMatch = lmnt; | ||
indexPos = ndxPos; | ||
} | ||
if (maskset.tests[pos] || maskset.validPositions[pos]) { | ||
(maskset.tests[pos] || [maskset.validPositions[pos]]).every(function (lmnt, ndx) { | ||
if (lmnt.mloc[alternateNdx]) { | ||
bestMatch = lmnt; | ||
return false; //break | ||
} | ||
var alternation = targetAlternation !== undefined ? targetAlternation : lmnt.alternation, | ||
ndxPos = lmnt.locator[alternation] !== undefined ? lmnt.locator[alternation].toString().indexOf(alternateNdx) : -1; | ||
if ((indexPos === undefined || ndxPos < indexPos) && ndxPos !== -1) { | ||
bestMatch = lmnt; | ||
indexPos = ndxPos; | ||
} | ||
return true; | ||
}); | ||
} | ||
if (bestMatch) { | ||
var bestMatchAltIndex = bestMatch.locator[bestMatch.alternation]; | ||
var locator = bestMatch.mloc[alternateNdx] || bestMatch.mloc[bestMatchAltIndex] || bestMatch.locator; | ||
return locator.slice((targetAlternation !== undefined ? targetAlternation : bestMatch.alternation) + 1); | ||
} else { | ||
return targetAlternation !== undefined ? resolveNdxInitializer(pos, alternateNdx) : undefined; | ||
} | ||
} | ||
return true; | ||
}); | ||
} | ||
if (bestMatch) { | ||
var bestMatchAltIndex = bestMatch.locator[bestMatch.alternation]; | ||
var locator = bestMatch.mloc[alternateNdx] || bestMatch.mloc[bestMatchAltIndex] || bestMatch.locator; | ||
return locator.slice((targetAlternation !== undefined ? targetAlternation : bestMatch.alternation) + 1); | ||
} else { | ||
return targetAlternation !== undefined ? resolveNdxInitializer(pos, alternateNdx) : undefined; | ||
} | ||
} | ||
function staticCanMatchDefinition(source, target) { | ||
return source.match.static === true && target.match.static !== true ? target.match.fn.test(source.match.def, maskset, pos, false, opts, false) : false; | ||
} | ||
function staticCanMatchDefinition(source, target) { | ||
return source.match.static === true && target.match.static !== true ? target.match.fn.test(source.match.def, maskset, pos, false, opts, false) : false; | ||
} | ||
//mergelocators for retrieving the correct locator match when merging | ||
function setMergeLocators(targetMatch, altMatch) { | ||
var alternationNdx = targetMatch.alternation, | ||
shouldMerge = altMatch === undefined || (alternationNdx === altMatch.alternation && | ||
targetMatch.locator[alternationNdx].toString().indexOf(altMatch.locator[alternationNdx]) === -1); | ||
if (!shouldMerge && alternationNdx > altMatch.alternation) { | ||
for (var i = altMatch.alternation; i < alternationNdx; i++) { | ||
if (targetMatch.locator[i] !== altMatch.locator[i]) { | ||
alternationNdx = i; | ||
shouldMerge = true; | ||
break; | ||
} | ||
} | ||
} | ||
//mergelocators for retrieving the correct locator match when merging | ||
function setMergeLocators(targetMatch, altMatch) { | ||
var alternationNdx = targetMatch.alternation, | ||
shouldMerge = altMatch === undefined || (alternationNdx === altMatch.alternation && | ||
targetMatch.locator[alternationNdx].toString().indexOf(altMatch.locator[alternationNdx]) === -1); | ||
if (!shouldMerge && alternationNdx > altMatch.alternation) { | ||
for (var i = altMatch.alternation; i < alternationNdx; i++) { | ||
if (targetMatch.locator[i] !== altMatch.locator[i]) { | ||
alternationNdx = i; | ||
shouldMerge = true; | ||
break; | ||
} | ||
} | ||
} | ||
if (shouldMerge) { | ||
targetMatch.mloc = targetMatch.mloc || {}; | ||
var locNdx = targetMatch.locator[alternationNdx]; | ||
if (locNdx === undefined) { | ||
targetMatch.alternation = undefined; | ||
} else { | ||
if (typeof locNdx === "string") locNdx = locNdx.split(",")[0]; | ||
if (targetMatch.mloc[locNdx] === undefined) targetMatch.mloc[locNdx] = targetMatch.locator.slice(); | ||
if (altMatch !== undefined) { | ||
for (var ndx in altMatch.mloc) { | ||
if (typeof ndx === "string") ndx = ndx.split(",")[0]; | ||
if (targetMatch.mloc[ndx] === undefined) targetMatch.mloc[ndx] = altMatch.mloc[ndx]; | ||
} | ||
targetMatch.locator[alternationNdx] = Object.keys(targetMatch.mloc).join(","); | ||
} | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
if (shouldMerge) { | ||
targetMatch.mloc = targetMatch.mloc || {}; | ||
var locNdx = targetMatch.locator[alternationNdx]; | ||
if (locNdx === undefined) { | ||
targetMatch.alternation = undefined; | ||
} else { | ||
if (typeof locNdx === "string") locNdx = locNdx.split(",")[0]; | ||
if (targetMatch.mloc[locNdx] === undefined) targetMatch.mloc[locNdx] = targetMatch.locator.slice(); | ||
if (altMatch !== undefined) { | ||
for (var ndx in altMatch.mloc) { | ||
if (typeof ndx === "string") ndx = ndx.split(",")[0]; | ||
if (targetMatch.mloc[ndx] === undefined) targetMatch.mloc[ndx] = altMatch.mloc[ndx]; | ||
} | ||
targetMatch.locator[alternationNdx] = Object.keys(targetMatch.mloc).join(","); | ||
} | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
function isSameLevel(targetMatch, altMatch) { | ||
if (targetMatch.locator.length !== altMatch.locator.length) { | ||
return false; | ||
} | ||
for (let locNdx = targetMatch.alternation + 1; locNdx < targetMatch.locator.length; locNdx++) { | ||
if (targetMatch.locator[locNdx] !== altMatch.locator[locNdx]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
function isSameLevel(targetMatch, altMatch) { | ||
if (targetMatch.locator.length !== altMatch.locator.length) { | ||
return false; | ||
} | ||
for (let locNdx = targetMatch.alternation + 1; locNdx < targetMatch.locator.length; locNdx++) { | ||
if (targetMatch.locator[locNdx] !== altMatch.locator[locNdx]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
if (testPos > (pos + opts._maxTestPos)) { | ||
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. " + maskset.mask; | ||
} | ||
if (testPos === pos && match.matches === undefined) { | ||
matches.push({ | ||
"match": match, | ||
"locator": loopNdx.reverse(), | ||
"cd": cacheDependency, | ||
"mloc": {} | ||
}); | ||
if (match.optionality && quantifierRecurse === undefined && | ||
((opts.definitions && opts.definitions[match.nativeDef] && opts.definitions[match.nativeDef].optional) || | ||
(Inputmask.prototype.definitions[match.nativeDef] && Inputmask.prototype.definitions[match.nativeDef].optional))) { //prevent loop see #698 | ||
insertStop = true; //insert a stop | ||
testPos = pos; //match the position after the group | ||
} else { | ||
return true; | ||
} | ||
} else if (match.matches !== undefined) { | ||
if (match.isGroup && quantifierRecurse !== match) { //when a group pass along to the quantifier | ||
match = handleMatch(maskToken.matches[maskToken.matches.indexOf(match) + 1], loopNdx, quantifierRecurse); | ||
if (match) return true; | ||
} else if (match.isOptional) { | ||
var optionalToken = match, mtchsNdx = matches.length; | ||
match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse); | ||
if (match) { | ||
//mark optionality in matches | ||
matches.forEach(function (mtch, ndx) { | ||
if (ndx >= mtchsNdx) { | ||
mtch.match.optionality = mtch.match.optionality ? mtch.match.optionality + 1 : 1; | ||
} | ||
}); | ||
latestMatch = matches[matches.length - 1].match; | ||
if (testPos > (pos + opts._maxTestPos)) { | ||
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. " + maskset.mask; | ||
} | ||
if (testPos === pos && match.matches === undefined) { | ||
matches.push({ | ||
"match": match, | ||
"locator": loopNdx.reverse(), | ||
"cd": cacheDependency, | ||
"mloc": {} | ||
}); | ||
if (match.optionality && quantifierRecurse === undefined && | ||
((opts.definitions && opts.definitions[match.nativeDef] && opts.definitions[match.nativeDef].optional) || | ||
(Inputmask.prototype.definitions[match.nativeDef] && Inputmask.prototype.definitions[match.nativeDef].optional))) { //prevent loop see #698 | ||
insertStop = true; //insert a stop | ||
testPos = pos; //match the position after the group | ||
} else { | ||
return true; | ||
} | ||
} else if (match.matches !== undefined) { | ||
if (match.isGroup && quantifierRecurse !== match) { //when a group pass along to the quantifier | ||
match = handleMatch(maskToken.matches[maskToken.matches.indexOf(match) + 1], loopNdx, quantifierRecurse); | ||
if (match) return true; | ||
} else if (match.isOptional) { | ||
var optionalToken = match, mtchsNdx = matches.length; | ||
match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse); | ||
if (match) { | ||
//mark optionality in matches | ||
matches.forEach(function (mtch, ndx) { | ||
if (ndx >= mtchsNdx) { | ||
mtch.match.optionality = mtch.match.optionality ? mtch.match.optionality + 1 : 1; | ||
} | ||
}); | ||
latestMatch = matches[matches.length - 1].match; | ||
if (quantifierRecurse === undefined && isFirstMatch(latestMatch, optionalToken)) { //prevent loop see #698 | ||
insertStop = true; //insert a stop | ||
testPos = pos; //match the position after the group | ||
} else { | ||
return true; | ||
} | ||
} | ||
} else if (match.isAlternator) { | ||
var alternateToken = match, | ||
malternateMatches = [], | ||
maltMatches, | ||
currentMatches = matches.slice(), | ||
loopNdxCnt = loopNdx.length, | ||
unMatchedAlternation = false; | ||
var altIndex = ndxInitializer.length > 0 ? ndxInitializer.shift() : -1; | ||
if (altIndex === -1 || typeof altIndex === "string") { | ||
var currentPos = testPos, | ||
ndxInitializerClone = ndxInitializer.slice(), | ||
altIndexArr = [], | ||
amndx; | ||
if (typeof altIndex == "string") { | ||
altIndexArr = altIndex.split(","); | ||
} else { | ||
for (amndx = 0; amndx < alternateToken.matches.length; amndx++) { | ||
altIndexArr.push(amndx.toString()); | ||
} | ||
} | ||
if (quantifierRecurse === undefined && isFirstMatch(latestMatch, optionalToken)) { //prevent loop see #698 | ||
insertStop = true; //insert a stop | ||
testPos = pos; //match the position after the group | ||
} else { | ||
return true; | ||
} | ||
} | ||
} else if (match.isAlternator) { | ||
var alternateToken = match, | ||
malternateMatches = [], | ||
maltMatches, | ||
currentMatches = matches.slice(), | ||
loopNdxCnt = loopNdx.length, | ||
unMatchedAlternation = false; | ||
var altIndex = ndxInitializer.length > 0 ? ndxInitializer.shift() : -1; | ||
if (altIndex === -1 || typeof altIndex === "string") { | ||
var currentPos = testPos, | ||
ndxInitializerClone = ndxInitializer.slice(), | ||
altIndexArr = [], | ||
amndx; | ||
if (typeof altIndex == "string") { | ||
altIndexArr = altIndex.split(","); | ||
} else { | ||
for (amndx = 0; amndx < alternateToken.matches.length; amndx++) { | ||
altIndexArr.push(amndx.toString()); | ||
} | ||
} | ||
if (maskset.excludes[pos] !== undefined) { | ||
var altIndexArrClone = altIndexArr.slice(); | ||
for (var i = 0, exl = maskset.excludes[pos].length; i < exl; i++) { | ||
var excludeSet = maskset.excludes[pos][i].toString().split(":"); | ||
if (loopNdx.length == excludeSet[1]) { | ||
altIndexArr.splice(altIndexArr.indexOf(excludeSet[0]), 1); | ||
} | ||
} | ||
if (altIndexArr.length === 0) { //fully alternated => reset | ||
delete maskset.excludes[pos]; | ||
altIndexArr = altIndexArrClone; | ||
} | ||
} | ||
if (opts.keepStatic === true || (isFinite(parseInt(opts.keepStatic)) && currentPos >= opts.keepStatic)) altIndexArr = altIndexArr.slice(0, 1); | ||
for (var ndx = 0; ndx < altIndexArr.length; ndx++) { | ||
amndx = parseInt(altIndexArr[ndx]); | ||
matches = []; | ||
//set the correct ndxInitializer | ||
ndxInitializer = typeof altIndex === "string" ? resolveNdxInitializer(testPos, amndx, loopNdxCnt) || ndxInitializerClone.slice() : ndxInitializerClone.slice(); | ||
var tokenMatch = alternateToken.matches[amndx]; | ||
if (tokenMatch && handleMatch(tokenMatch, [amndx].concat(loopNdx), quantifierRecurse)) { | ||
match = true; | ||
} else { | ||
if (ndx === 0) { | ||
unMatchedAlternation = true; | ||
} | ||
if (tokenMatch && tokenMatch.matches && tokenMatch.matches.length > alternateToken.matches[0].matches.length) { | ||
break; | ||
} | ||
} | ||
if (maskset.excludes[pos] !== undefined) { | ||
var altIndexArrClone = altIndexArr.slice(); | ||
for (var i = 0, exl = maskset.excludes[pos].length; i < exl; i++) { | ||
var excludeSet = maskset.excludes[pos][i].toString().split(":"); | ||
if (loopNdx.length == excludeSet[1]) { | ||
altIndexArr.splice(altIndexArr.indexOf(excludeSet[0]), 1); | ||
} | ||
} | ||
if (altIndexArr.length === 0) { //fully alternated => reset | ||
delete maskset.excludes[pos]; | ||
altIndexArr = altIndexArrClone; | ||
} | ||
} | ||
if (opts.keepStatic === true || (isFinite(parseInt(opts.keepStatic)) && currentPos >= opts.keepStatic)) altIndexArr = altIndexArr.slice(0, 1); | ||
for (var ndx = 0; ndx < altIndexArr.length; ndx++) { | ||
amndx = parseInt(altIndexArr[ndx]); | ||
matches = []; | ||
//set the correct ndxInitializer | ||
ndxInitializer = typeof altIndex === "string" ? resolveNdxInitializer(testPos, amndx, loopNdxCnt) || ndxInitializerClone.slice() : ndxInitializerClone.slice(); | ||
var tokenMatch = alternateToken.matches[amndx]; | ||
if (tokenMatch && handleMatch(tokenMatch, [amndx].concat(loopNdx), quantifierRecurse)) { | ||
match = true; | ||
} else { | ||
if (ndx === 0) { | ||
unMatchedAlternation = true; | ||
} | ||
if (tokenMatch && tokenMatch.matches && tokenMatch.matches.length > alternateToken.matches[0].matches.length) { | ||
break; | ||
} | ||
} | ||
maltMatches = matches.slice(); | ||
testPos = currentPos; | ||
matches = []; | ||
maltMatches = matches.slice(); | ||
testPos = currentPos; | ||
matches = []; | ||
//fuzzy merge matches | ||
for (var ndx1 = 0; ndx1 < maltMatches.length; ndx1++) { | ||
var altMatch = maltMatches[ndx1], | ||
dropMatch = false; | ||
altMatch.match.jit = altMatch.match.jit || unMatchedAlternation; //mark jit when there are unmatched alternations ex: mask: "(a|aa)" | ||
altMatch.alternation = altMatch.alternation || loopNdxCnt; | ||
setMergeLocators(altMatch); | ||
for (var ndx2 = 0; ndx2 < malternateMatches.length; ndx2++) { | ||
var altMatch2 = malternateMatches[ndx2]; | ||
if (typeof altIndex !== "string" || (altMatch.alternation !== undefined && altIndexArr.includes(altMatch.locator[altMatch.alternation].toString()))) { | ||
if (altMatch.match.nativeDef === altMatch2.match.nativeDef) { | ||
dropMatch = true; | ||
setMergeLocators(altMatch2, altMatch); | ||
break; | ||
} else if (isSubsetOf(altMatch, altMatch2, opts)) { | ||
if (setMergeLocators(altMatch, altMatch2)) { | ||
dropMatch = true; | ||
malternateMatches.splice(malternateMatches.indexOf(altMatch2), 0, altMatch); | ||
} | ||
break; | ||
} else if (isSubsetOf(altMatch2, altMatch, opts)) { | ||
setMergeLocators(altMatch2, altMatch); | ||
break; | ||
} else if (staticCanMatchDefinition(altMatch, altMatch2)) { | ||
if (!isSameLevel(altMatch, altMatch2) && el.inputmask.userOptions.keepStatic === undefined) { | ||
opts.keepStatic = true; | ||
} else if (setMergeLocators(altMatch, altMatch2)) { | ||
//insert match above general match | ||
dropMatch = true; | ||
malternateMatches.splice(malternateMatches.indexOf(altMatch2), 0, altMatch); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
if (!dropMatch) { | ||
malternateMatches.push(altMatch); | ||
} | ||
} | ||
} | ||
//fuzzy merge matches | ||
for (var ndx1 = 0; ndx1 < maltMatches.length; ndx1++) { | ||
var altMatch = maltMatches[ndx1], | ||
dropMatch = false; | ||
altMatch.match.jit = altMatch.match.jit || unMatchedAlternation; //mark jit when there are unmatched alternations ex: mask: "(a|aa)" | ||
altMatch.alternation = altMatch.alternation || loopNdxCnt; | ||
setMergeLocators(altMatch); | ||
for (var ndx2 = 0; ndx2 < malternateMatches.length; ndx2++) { | ||
var altMatch2 = malternateMatches[ndx2]; | ||
if (typeof altIndex !== "string" || (altMatch.alternation !== undefined && altIndexArr.includes(altMatch.locator[altMatch.alternation].toString()))) { | ||
if (altMatch.match.nativeDef === altMatch2.match.nativeDef) { | ||
dropMatch = true; | ||
setMergeLocators(altMatch2, altMatch); | ||
break; | ||
} else if (isSubsetOf(altMatch, altMatch2, opts)) { | ||
if (setMergeLocators(altMatch, altMatch2)) { | ||
dropMatch = true; | ||
malternateMatches.splice(malternateMatches.indexOf(altMatch2), 0, altMatch); | ||
} | ||
break; | ||
} else if (isSubsetOf(altMatch2, altMatch, opts)) { | ||
setMergeLocators(altMatch2, altMatch); | ||
break; | ||
} else if (staticCanMatchDefinition(altMatch, altMatch2)) { | ||
if (!isSameLevel(altMatch, altMatch2) && el.inputmask.userOptions.keepStatic === undefined) { | ||
opts.keepStatic = true; | ||
} else if (setMergeLocators(altMatch, altMatch2)) { | ||
//insert match above general match | ||
dropMatch = true; | ||
malternateMatches.splice(malternateMatches.indexOf(altMatch2), 0, altMatch); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
if (!dropMatch) { | ||
malternateMatches.push(altMatch); | ||
} | ||
} | ||
} | ||
matches = currentMatches.concat(malternateMatches); | ||
testPos = pos; | ||
insertStop = matches.length > 0; //insert a stopelemnt when there is an alternate - needed for non-greedy option | ||
match = malternateMatches.length > 0; //set correct match state | ||
matches = currentMatches.concat(malternateMatches); | ||
testPos = pos; | ||
insertStop = matches.length > 0; //insert a stopelemnt when there is an alternate - needed for non-greedy option | ||
match = malternateMatches.length > 0; //set correct match state | ||
//cloneback | ||
ndxInitializer = ndxInitializerClone.slice(); | ||
} else { | ||
match = handleMatch(alternateToken.matches[altIndex] || maskToken.matches[altIndex], [altIndex].concat(loopNdx), quantifierRecurse); | ||
} | ||
if (match) return true; | ||
} else if (match.isQuantifier && quantifierRecurse !== maskToken.matches[maskToken.matches.indexOf(match) - 1]) { | ||
var qt = match; | ||
for (var qndx = (ndxInitializer.length > 0) ? ndxInitializer.shift() : 0; (qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max)) && testPos <= pos; qndx++) { | ||
var tokenGroup = maskToken.matches[maskToken.matches.indexOf(qt) - 1]; | ||
match = handleMatch(tokenGroup, [qndx].concat(loopNdx), tokenGroup); //set the tokenGroup as quantifierRecurse marker | ||
if (match) { | ||
//get latest match | ||
latestMatch = matches[matches.length - 1].match; | ||
//mark optionality | ||
//TODO FIX RECURSIVE QUANTIFIERS | ||
latestMatch.optionalQuantifier = qndx >= qt.quantifier.min; | ||
// console.log(pos + " " + qt.quantifier.min + " " + latestMatch.optionalQuantifier); | ||
//qndx + 1 as the index starts from 0 | ||
latestMatch.jit = (qndx + 1) * (tokenGroup.matches.indexOf(latestMatch) + 1) > qt.quantifier.jit; | ||
if (latestMatch.optionalQuantifier && isFirstMatch(latestMatch, tokenGroup)) { | ||
insertStop = true; | ||
testPos = pos; //match the position after the group | ||
break; //stop quantifierloop && search for next possible match | ||
} | ||
if (latestMatch.jit /*&& !latestMatch.optionalQuantifier*/) { | ||
//always set jitOffset, isvalid checks when to apply | ||
maskset.jitOffset[pos] = tokenGroup.matches.length - tokenGroup.matches.indexOf(latestMatch); | ||
} | ||
return true; | ||
} | ||
} | ||
} else { | ||
match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse); | ||
if (match) return true; | ||
} | ||
} else { | ||
testPos++; | ||
} | ||
} | ||
//cloneback | ||
ndxInitializer = ndxInitializerClone.slice(); | ||
} else { | ||
match = handleMatch(alternateToken.matches[altIndex] || maskToken.matches[altIndex], [altIndex].concat(loopNdx), quantifierRecurse); | ||
} | ||
if (match) return true; | ||
} else if (match.isQuantifier && quantifierRecurse !== maskToken.matches[maskToken.matches.indexOf(match) - 1]) { | ||
var qt = match, breakloop = false; | ||
for (var qndx = (ndxInitializer.length > 0) ? ndxInitializer.shift() : 0; (qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max)) && testPos <= pos; qndx++) { | ||
var tokenGroup = maskToken.matches[maskToken.matches.indexOf(qt) - 1]; | ||
match = handleMatch(tokenGroup, [qndx].concat(loopNdx), tokenGroup); //set the tokenGroup as quantifierRecurse marker | ||
if (match) { | ||
matches.forEach(function (mtch, ndx) { | ||
if (IsMatchOf(tokenGroup, mtch.match)) | ||
latestMatch = mtch.match; | ||
else latestMatch = matches[matches.length - 1].match; | ||
//the offset is set in the quantifierloop when git masking is used | ||
for (var tndx = (ndxInitializer.length > 0 ? ndxInitializer.shift() : 0); tndx < maskToken.matches.length; tndx++) { | ||
if (maskToken.matches[tndx].isQuantifier !== true) { | ||
var match = handleMatch(maskToken.matches[tndx], [tndx].concat(loopNdx), quantifierRecurse); | ||
if (match && testPos === pos) { | ||
return match; | ||
} else if (testPos > pos) { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
//mark optionality | ||
//TODO FIX RECURSIVE QUANTIFIERS | ||
latestMatch.optionalQuantifier = qndx >= qt.quantifier.min; | ||
// console.log(pos + " " + qt.quantifier.min + " " + latestMatch.optionalQuantifier); | ||
//qndx + 1 as the index starts from 0 | ||
latestMatch.jit = (qndx + 1) * (tokenGroup.matches.indexOf(latestMatch) + 1) > qt.quantifier.jit; | ||
if (latestMatch.optionalQuantifier && isFirstMatch(latestMatch, tokenGroup)) { | ||
insertStop = true; | ||
testPos = pos; //match the position after the group | ||
if (opts.greedy && maskset.validPositions[pos - 1] == undefined && qndx > qt.quantifier.min && ["*", "+"].indexOf(qt.quantifier.max) != -1) { | ||
matches.pop(); | ||
cacheDependency = undefined; | ||
} | ||
breakloop = true; //stop quantifierloop && search for next possible match | ||
} | ||
if (!breakloop && latestMatch.jit /*&& !latestMatch.optionalQuantifier*/) { | ||
//always set jitOffset, isvalid checks when to apply | ||
maskset.jitOffset[pos] = tokenGroup.matches.length - tokenGroup.matches.indexOf(latestMatch); | ||
} | ||
}); | ||
if (breakloop) break; | ||
return true; | ||
} | ||
} | ||
} else { | ||
match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse); | ||
if (match) return true; | ||
} | ||
} else { | ||
testPos++; | ||
} | ||
} | ||
function mergeLocators(pos, tests) { | ||
let locator = [], alternation; | ||
if (!Array.isArray(tests)) tests = [tests]; | ||
//the offset is set in the quantifierloop when git masking is used | ||
for (var tndx = (ndxInitializer.length > 0 ? ndxInitializer.shift() : 0); tndx < maskToken.matches.length; tndx++) { | ||
if (maskToken.matches[tndx].isQuantifier !== true) { | ||
var match = handleMatch(maskToken.matches[tndx], [tndx].concat(loopNdx), quantifierRecurse); | ||
if (match && testPos === pos) { | ||
return match; | ||
} else if (testPos > pos) { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
if (tests.length > 0) { | ||
if (tests[0].alternation === undefined || opts.keepStatic === true) { | ||
locator = determineTestTemplate.call(inputmask, pos, tests.slice()).locator.slice(); | ||
if (locator.length === 0) locator = tests[0].locator.slice(); | ||
} else { | ||
tests.forEach(function (tst) { | ||
if (tst.def !== "") { | ||
if (locator.length === 0) { | ||
alternation = tst.alternation; | ||
locator = tst.locator.slice(); | ||
} else { | ||
if (tst.locator[alternation] && locator[alternation].toString().indexOf(tst.locator[alternation]) === -1) { | ||
locator[alternation] += "," + tst.locator[alternation]; | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
return locator; | ||
} | ||
function IsMatchOf(tokenGroup, match) { | ||
let isMatch = tokenGroup.matches.indexOf(match) != -1; | ||
if (!isMatch) { | ||
tokenGroup.matches.forEach((mtch, ndx) => { | ||
if (mtch.matches !== undefined && !isMatch) { | ||
isMatch = IsMatchOf(mtch, match); | ||
} | ||
}); | ||
} | ||
return isMatch; | ||
} | ||
if (pos > -1) { | ||
if (ndxIntlzr === undefined) { //determine index initializer | ||
var previousPos = pos - 1, | ||
test; | ||
while ((test = maskset.validPositions[previousPos] || maskset.tests[previousPos]) === undefined && previousPos > -1) { | ||
previousPos--; | ||
} | ||
if (test !== undefined && previousPos > -1) { | ||
ndxInitializer = mergeLocators(previousPos, test); | ||
cacheDependency = ndxInitializer.join(""); | ||
testPos = previousPos; | ||
} | ||
} | ||
if (maskset.tests[pos] && maskset.tests[pos][0].cd === cacheDependency) { //cacheDependency is set on all tests, just check on the first | ||
return maskset.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; | ||
} | ||
} | ||
} | ||
if (matches.length === 0 || insertStop) { | ||
matches.push({ | ||
match: { | ||
fn: null, | ||
static: true, | ||
optionality: false, | ||
casing: null, | ||
def: "", | ||
placeholder: "" | ||
}, | ||
locator: [], | ||
mloc: {}, | ||
cd: cacheDependency | ||
}); | ||
} | ||
var result; | ||
if (ndxIntlzr !== undefined && maskset.tests[pos]) { //prioritize full tests for caching | ||
result = $.extend(true, [], matches); | ||
} else { | ||
maskset.tests[pos] = $.extend(true, [], matches); //set a clone to prevent overwriting some props | ||
result = maskset.tests[pos]; | ||
} | ||
function mergeLocators(pos, tests) { | ||
let locator = [], alternation; | ||
if (!Array.isArray(tests)) tests = [tests]; | ||
// console.log(pos + " - " + JSON.stringify(matches)); | ||
//cleanup optionality marking | ||
matches.forEach(t => { | ||
t.match.optionality = t.match.defOptionality || false; | ||
}); | ||
if (tests.length > 0) { | ||
if (tests[0].alternation === undefined || opts.keepStatic === true) { | ||
locator = determineTestTemplate.call(inputmask, pos, tests.slice()).locator.slice(); | ||
if (locator.length === 0) locator = tests[0].locator.slice(); | ||
} else { | ||
tests.forEach(function (tst) { | ||
if (tst.def !== "") { | ||
if (locator.length === 0) { | ||
alternation = tst.alternation; | ||
locator = tst.locator.slice(); | ||
} else { | ||
if (tst.locator[alternation] && locator[alternation].toString().indexOf(tst.locator[alternation]) === -1) { | ||
locator[alternation] += "," + tst.locator[alternation]; | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
return locator; | ||
} | ||
return result; | ||
if (pos > -1) { | ||
if (ndxIntlzr === undefined) { //determine index initializer | ||
var previousPos = pos - 1, | ||
test; | ||
while ((test = maskset.validPositions[previousPos] || maskset.tests[previousPos]) === undefined && previousPos > -1) { | ||
previousPos--; | ||
} | ||
if (test !== undefined && previousPos > -1) { | ||
ndxInitializer = mergeLocators(previousPos, test); | ||
cacheDependency = ndxInitializer.join(""); | ||
testPos = previousPos; | ||
} | ||
} | ||
if (maskset.tests[pos] && maskset.tests[pos][0].cd === cacheDependency) { //cacheDependency is set on all tests, just check on the first | ||
return maskset.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; | ||
} | ||
} | ||
} | ||
if (matches.length === 0 || insertStop) { | ||
matches.push({ | ||
match: { | ||
fn: null, | ||
static: true, | ||
optionality: false, | ||
casing: null, | ||
def: "", | ||
placeholder: "" | ||
}, | ||
locator: [], | ||
mloc: {}, | ||
cd: cacheDependency | ||
}); | ||
} | ||
var result; | ||
if (ndxIntlzr !== undefined && maskset.tests[pos]) { //prioritize full tests for caching | ||
result = $.extend(true, [], matches); | ||
} else { | ||
maskset.tests[pos] = $.extend(true, [], matches); //set a clone to prevent overwriting some props | ||
result = maskset.tests[pos]; | ||
} | ||
// console.log(pos + " - " + JSON.stringify(matches)); | ||
//cleanup optionality marking | ||
matches.forEach(t => { | ||
t.match.optionality = t.match.defOptionality || false; | ||
}); | ||
return result; | ||
} |
import { | ||
determineTestTemplate, | ||
getDecisionTaker, | ||
getPlaceholder, | ||
getTest, | ||
getTests, | ||
getTestTemplate | ||
determineTestTemplate, | ||
getDecisionTaker, | ||
getPlaceholder, | ||
getTest, | ||
getTests, | ||
getTestTemplate | ||
} from "./validation-tests"; | ||
import keyCode from "./keycode.json"; | ||
import {keyCode, keys} from "./keycode.js"; | ||
import { | ||
determineLastRequiredPosition, determineNewCaretPosition, | ||
getBuffer, | ||
getLastValidPosition, | ||
isMask, | ||
resetMaskSet, | ||
seekNext, | ||
seekPrevious | ||
determineLastRequiredPosition, determineNewCaretPosition, | ||
getBuffer, | ||
getLastValidPosition, | ||
isMask, | ||
resetMaskSet, | ||
seekNext, | ||
seekPrevious | ||
} from "./positioning"; | ||
import { EventHandlers } from "./eventhandlers"; | ||
import {EventHandlers} from "./eventhandlers"; | ||
export { alternate, checkAlternationMatch, isComplete, isSelection, isValid, refreshFromBuffer, revalidateMask, handleRemove }; | ||
export { | ||
alternate, | ||
checkAlternationMatch, | ||
isComplete, | ||
isSelection, | ||
isValid, | ||
refreshFromBuffer, | ||
revalidateMask, | ||
handleRemove | ||
}; | ||
//tobe put on prototype? | ||
function alternate(maskPos, c, strict, fromIsValid, rAltPos, selection) { //pos == true => generalize | ||
const inputmask = this, | ||
$ = this.dependencyLib, | ||
opts = this.opts, | ||
maskset = inputmask.maskset; | ||
const inputmask = this, | ||
$ = this.dependencyLib, | ||
opts = this.opts, | ||
maskset = inputmask.maskset; | ||
var validPsClone = $.extend(true, [], maskset.validPositions), | ||
tstClone = $.extend(true, {}, maskset.tests), | ||
lastAlt, | ||
alternation, | ||
isValidRslt = false, returnRslt = false, | ||
altPos, prevAltPos, i, validPos, | ||
decisionPos, | ||
lAltPos = rAltPos !== undefined ? rAltPos : getLastValidPosition.call(inputmask), nextPos, input, begin, end; | ||
var validPsClone = $.extend(true, [], maskset.validPositions), | ||
tstClone = $.extend(true, {}, maskset.tests), | ||
lastAlt, | ||
alternation, | ||
isValidRslt = false, returnRslt = false, | ||
altPos, prevAltPos, i, validPos, | ||
decisionPos, | ||
lAltPos = rAltPos !== undefined ? rAltPos : getLastValidPosition.call(inputmask), nextPos, input, begin, end; | ||
if (selection) { | ||
begin = selection.begin; | ||
end = selection.end; | ||
if (selection.begin > selection.end) { | ||
begin = selection.end; | ||
end = selection.begin; | ||
} | ||
} | ||
if (lAltPos === -1 && rAltPos === undefined) { //do not recurse when already paste the beginning | ||
lastAlt = 0; | ||
prevAltPos = getTest.call(inputmask, lastAlt); | ||
alternation = prevAltPos.alternation; | ||
} else { | ||
//find last modified alternation | ||
for (; lAltPos >= 0; lAltPos--) { | ||
altPos = maskset.validPositions[lAltPos]; | ||
if (altPos && altPos.alternation !== undefined) { | ||
if (prevAltPos && prevAltPos.locator[altPos.alternation] !== altPos.locator[altPos.alternation]) { | ||
break; | ||
} | ||
lastAlt = lAltPos; | ||
alternation = maskset.validPositions[lastAlt].alternation; | ||
prevAltPos = altPos; | ||
} | ||
} | ||
} | ||
if (selection) { | ||
begin = selection.begin; | ||
end = selection.end; | ||
if (selection.begin > selection.end) { | ||
begin = selection.end; | ||
end = selection.begin; | ||
} | ||
} | ||
if (lAltPos === -1 && rAltPos === undefined) { //do not recurse when already paste the beginning | ||
lastAlt = 0; | ||
prevAltPos = getTest.call(inputmask, lastAlt); | ||
alternation = prevAltPos.alternation; | ||
} else { | ||
//find last modified alternation | ||
for (; lAltPos >= 0; lAltPos--) { | ||
altPos = maskset.validPositions[lAltPos]; | ||
if (altPos && altPos.alternation !== undefined) { | ||
if (prevAltPos && prevAltPos.locator[altPos.alternation] !== altPos.locator[altPos.alternation]) { | ||
break; | ||
} | ||
lastAlt = lAltPos; | ||
alternation = maskset.validPositions[lastAlt].alternation; | ||
prevAltPos = altPos; | ||
} | ||
} | ||
} | ||
if (alternation !== undefined) { | ||
decisionPos = parseInt(lastAlt); | ||
maskset.excludes[decisionPos] = maskset.excludes[decisionPos] || []; | ||
if (maskPos !== true) { //generalize | ||
maskset.excludes[decisionPos].push(getDecisionTaker(prevAltPos) + ":" + prevAltPos.alternation); | ||
} | ||
if (alternation !== undefined) { | ||
decisionPos = parseInt(lastAlt); | ||
maskset.excludes[decisionPos] = maskset.excludes[decisionPos] || []; | ||
if (maskPos !== true) { //generalize | ||
maskset.excludes[decisionPos].push(getDecisionTaker(prevAltPos) + ":" + prevAltPos.alternation); | ||
} | ||
var validInputs = [], resultPos = -1; | ||
for (i = decisionPos; i < getLastValidPosition.call(inputmask, undefined, true) + 1; i++) { | ||
if (resultPos === -1 && maskPos <= i && c !== undefined) { | ||
validInputs.push(c); | ||
resultPos = validInputs.length - 1; | ||
} | ||
validPos = maskset.validPositions[i]; | ||
if (validPos && validPos.generatedInput !== true && (selection === undefined || (i < begin || i >= end))) { | ||
validInputs.push(validPos.input); | ||
} | ||
delete maskset.validPositions[i]; | ||
} | ||
if (resultPos === -1 && c !== undefined) { | ||
validInputs.push(c); | ||
resultPos = validInputs.length - 1; | ||
} | ||
var validInputs = [], resultPos = -1; | ||
for (i = decisionPos; i < getLastValidPosition.call(inputmask, undefined, true) + 1; i++) { | ||
if (resultPos === -1 && maskPos <= i && c !== undefined) { | ||
validInputs.push(c); | ||
resultPos = validInputs.length - 1; | ||
} | ||
validPos = maskset.validPositions[i]; | ||
if (validPos && validPos.generatedInput !== true && (selection === undefined || (i < begin || i >= end))) { | ||
validInputs.push(validPos.input); | ||
} | ||
delete maskset.validPositions[i]; | ||
} | ||
if (resultPos === -1 && c !== undefined) { | ||
validInputs.push(c); | ||
resultPos = validInputs.length - 1; | ||
} | ||
while (maskset.excludes[decisionPos] !== undefined && maskset.excludes[decisionPos].length < 10) { | ||
// maskset.tests[decisionPos] = undefined; //clear decisionPos | ||
maskset.tests = {}; //clear all | ||
resetMaskSet.call(inputmask, true); //clear getbuffer | ||
isValidRslt = true; | ||
for (i = 0; i < validInputs.length; i++) { | ||
nextPos = isValidRslt.caret || (getLastValidPosition.call(inputmask, undefined, true) + 1); | ||
input = validInputs[i]; | ||
// nextPos = translatePosition.call(inputmask, nextPos); | ||
if (!(isValidRslt = isValid.call(inputmask, nextPos, input, false, fromIsValid, true))) { | ||
break; | ||
} | ||
if (i === resultPos) { | ||
returnRslt = isValidRslt; | ||
} | ||
if (maskPos == true && isValidRslt) { //return validposition on generalise | ||
returnRslt = { caretPos: i }; | ||
} | ||
} | ||
if (!isValidRslt) { | ||
resetMaskSet.call(inputmask); | ||
prevAltPos = getTest.call(inputmask, decisionPos); //get the current decisionPos to exclude ~ needs to be before restoring the initial validation | ||
//reset & revert | ||
maskset.validPositions = $.extend(true, [], validPsClone); | ||
maskset.tests = $.extend(true, {}, tstClone); //refresh tests after possible alternating | ||
if (maskset.excludes[decisionPos]) { | ||
var decisionTaker = getDecisionTaker(prevAltPos); | ||
if (maskset.excludes[decisionPos].indexOf(decisionTaker + ":" + prevAltPos.alternation) !== -1) { | ||
returnRslt = alternate.call(inputmask, maskPos, c, strict, fromIsValid, decisionPos - 1, selection); | ||
break; | ||
} | ||
maskset.excludes[decisionPos].push(decisionTaker + ":" + prevAltPos.alternation); | ||
for (i = decisionPos; i < getLastValidPosition.call(inputmask, undefined, true) + 1; i++) delete maskset.validPositions[i]; | ||
} else { //latest alternation | ||
returnRslt = alternate.call(inputmask, maskPos, c, strict, fromIsValid, decisionPos - 1, selection); | ||
break; | ||
} | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
//reset alternation excludes | ||
if (!returnRslt || opts.keepStatic !== false) { | ||
delete maskset.excludes[decisionPos]; | ||
} | ||
return returnRslt; | ||
while (maskset.excludes[decisionPos] !== undefined && maskset.excludes[decisionPos].length < 10) { | ||
// maskset.tests[decisionPos] = undefined; //clear decisionPos | ||
maskset.tests = {}; //clear all | ||
resetMaskSet.call(inputmask, true); //clear getbuffer | ||
isValidRslt = true; | ||
for (i = 0; i < validInputs.length; i++) { | ||
nextPos = isValidRslt.caret || (getLastValidPosition.call(inputmask, undefined, true) + 1); | ||
input = validInputs[i]; | ||
// nextPos = translatePosition.call(inputmask, nextPos); | ||
if (!(isValidRslt = isValid.call(inputmask, nextPos, input, false, fromIsValid, true))) { | ||
break; | ||
} | ||
if (i === resultPos) { | ||
returnRslt = isValidRslt; | ||
} | ||
if (maskPos == true && isValidRslt) { //return validposition on generalise | ||
returnRslt = {caretPos: i}; | ||
} | ||
} | ||
if (!isValidRslt) { | ||
resetMaskSet.call(inputmask); | ||
prevAltPos = getTest.call(inputmask, decisionPos); //get the current decisionPos to exclude ~ needs to be before restoring the initial validation | ||
//reset & revert | ||
maskset.validPositions = $.extend(true, [], validPsClone); | ||
maskset.tests = $.extend(true, {}, tstClone); //refresh tests after possible alternating | ||
if (maskset.excludes[decisionPos]) { | ||
var decisionTaker = getDecisionTaker(prevAltPos); | ||
if (maskset.excludes[decisionPos].indexOf(decisionTaker + ":" + prevAltPos.alternation) !== -1) { | ||
returnRslt = alternate.call(inputmask, maskPos, c, strict, fromIsValid, decisionPos - 1, selection); | ||
break; | ||
} | ||
maskset.excludes[decisionPos].push(decisionTaker + ":" + prevAltPos.alternation); | ||
for (i = decisionPos; i < getLastValidPosition.call(inputmask, undefined, true) + 1; i++) delete maskset.validPositions[i]; | ||
} else { //latest alternation | ||
returnRslt = alternate.call(inputmask, maskPos, c, strict, fromIsValid, decisionPos - 1, selection); | ||
break; | ||
} | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
//reset alternation excludes | ||
if (!returnRslt || opts.keepStatic !== false) { | ||
delete maskset.excludes[decisionPos]; | ||
} | ||
return returnRslt; | ||
} | ||
function casing(elem, test, pos) { | ||
const opts = this.opts, | ||
maskset = this.maskset; | ||
const opts = this.opts, | ||
maskset = this.maskset; | ||
switch (opts.casing || test.casing) { | ||
case "upper": | ||
elem = elem.toUpperCase(); | ||
break; | ||
case "lower": | ||
elem = elem.toLowerCase(); | ||
break; | ||
case "title": | ||
var posBefore = maskset.validPositions[pos - 1]; | ||
if (pos === 0 || posBefore && posBefore.input === String.fromCharCode(keyCode.SPACE)) { | ||
elem = elem.toUpperCase(); | ||
} else { | ||
elem = elem.toLowerCase(); | ||
} | ||
break; | ||
default: | ||
if (typeof opts.casing === "function") { | ||
var args = Array.prototype.slice.call(arguments); | ||
args.push(maskset.validPositions); | ||
elem = opts.casing.apply(this, args); | ||
} | ||
} | ||
switch (opts.casing || test.casing) { | ||
case "upper": | ||
elem = elem.toUpperCase(); | ||
break; | ||
case "lower": | ||
elem = elem.toLowerCase(); | ||
break; | ||
case "title": | ||
var posBefore = maskset.validPositions[pos - 1]; | ||
if (pos === 0 || posBefore && posBefore.input === String.fromCharCode(keyCode.Space)) { | ||
elem = elem.toUpperCase(); | ||
} else { | ||
elem = elem.toLowerCase(); | ||
} | ||
break; | ||
default: | ||
if (typeof opts.casing === "function") { | ||
var args = Array.prototype.slice.call(arguments); | ||
args.push(maskset.validPositions); | ||
elem = opts.casing.apply(this, args); | ||
} | ||
} | ||
return elem; | ||
return elem; | ||
} | ||
@@ -171,77 +180,77 @@ | ||
function checkAlternationMatch(altArr1, altArr2, na) { | ||
const opts = this.opts; | ||
const opts = this.opts; | ||
var altArrC = opts.greedy ? altArr2 : altArr2.slice(0, 1), | ||
isMatch = false, | ||
naArr = na !== undefined ? na.split(",") : [], | ||
naNdx; | ||
var altArrC = opts.greedy ? altArr2 : altArr2.slice(0, 1), | ||
isMatch = false, | ||
naArr = na !== undefined ? na.split(",") : [], | ||
naNdx; | ||
//remove no alternate indexes from alternation array | ||
for (var i = 0; i < naArr.length; i++) { | ||
if ((naNdx = altArr1.indexOf(naArr[i])) !== -1) { | ||
altArr1.splice(naNdx, 1); | ||
} | ||
} | ||
//remove no alternate indexes from alternation array | ||
for (var i = 0; i < naArr.length; i++) { | ||
if ((naNdx = altArr1.indexOf(naArr[i])) !== -1) { | ||
altArr1.splice(naNdx, 1); | ||
} | ||
} | ||
for (var alndx = 0; alndx < altArr1.length; alndx++) { | ||
if (altArrC.includes(altArr1[alndx])) { | ||
isMatch = true; | ||
break; | ||
} | ||
} | ||
return isMatch; | ||
for (var alndx = 0; alndx < altArr1.length; alndx++) { | ||
if (altArrC.includes(altArr1[alndx])) { | ||
isMatch = true; | ||
break; | ||
} | ||
} | ||
return isMatch; | ||
} | ||
//tobe put on prototype? | ||
function handleRemove(input, k, pos, strict, fromIsValid) { | ||
const inputmask = this, maskset = this.maskset, opts = this.opts; | ||
function handleRemove(input, c, pos, strict, fromIsValid) { | ||
const inputmask = this, maskset = this.maskset, opts = this.opts; | ||
if (opts.numericInput || inputmask.isRTL) { | ||
if (k === keyCode.BACKSPACE) { | ||
k = keyCode.DELETE; | ||
} else if (k === keyCode.DELETE) { | ||
k = keyCode.BACKSPACE; | ||
} | ||
if (opts.numericInput || inputmask.isRTL) { | ||
if (c === keys.Backspace) { | ||
c = keys.Delete; | ||
} else if (c === keys.Delete) { | ||
c = keys.Backspace; | ||
} | ||
if (inputmask.isRTL) { | ||
var pend = pos.end; | ||
pos.end = pos.begin; | ||
pos.begin = pend; | ||
} | ||
} | ||
if (inputmask.isRTL) { | ||
var pend = pos.end; | ||
pos.end = pos.begin; | ||
pos.begin = pend; | ||
} | ||
} | ||
var lvp = getLastValidPosition.call(inputmask, undefined, true); | ||
if (pos.end >= getBuffer.call(inputmask).length && lvp >= pos.end) { //handle numeric negate symbol offset, due to dynamic jit masking | ||
pos.end = lvp + 1; | ||
} | ||
var lvp = getLastValidPosition.call(inputmask, undefined, true); | ||
if (pos.end >= getBuffer.call(inputmask).length && lvp >= pos.end) { //handle numeric negate symbol offset, due to dynamic jit masking | ||
pos.end = lvp + 1; | ||
} | ||
if (k === keyCode.BACKSPACE) { | ||
if ((pos.end - pos.begin < 1)) { | ||
pos.begin = seekPrevious.call(inputmask, pos.begin); | ||
} | ||
} else if (k === keyCode.DELETE) { | ||
if (pos.begin === pos.end) { | ||
pos.end = isMask.call(inputmask, pos.end, true, true) ? pos.end + 1 : seekNext.call(inputmask, pos.end) + 1; | ||
} | ||
} | ||
var offset; | ||
if ((offset = revalidateMask.call(inputmask, pos)) !== false) { | ||
if (strict !== true && opts.keepStatic !== false || (opts.regex !== null && getTest.call(inputmask, pos.begin).match.def.indexOf("|") !== -1)) { //TODO NEEDS BETTER CHECK WHEN TO ALTERNATE ~ opts regex isn"t good enough | ||
var result = alternate.call(inputmask, true); | ||
if (result) { | ||
var newPos = result.caret !== undefined ? result.caret : (result.pos ? seekNext.call(inputmask, result.pos.begin ? result.pos.begin : result.pos) : getLastValidPosition.call(inputmask, -1, true)); | ||
if (k !== keyCode.DELETE || pos.begin > newPos) { | ||
pos.begin == newPos; | ||
} | ||
} | ||
} | ||
if (c === keys.Backspace) { | ||
if ((pos.end - pos.begin < 1)) { | ||
pos.begin = seekPrevious.call(inputmask, pos.begin); | ||
} | ||
} else if (c === keys.Delete) { | ||
if (pos.begin === pos.end) { | ||
pos.end = isMask.call(inputmask, pos.end, true, true) ? pos.end + 1 : seekNext.call(inputmask, pos.end) + 1; | ||
} | ||
} | ||
var offset; | ||
if ((offset = revalidateMask.call(inputmask, pos)) !== false) { | ||
if (strict !== true && opts.keepStatic !== false || (opts.regex !== null && getTest.call(inputmask, pos.begin).match.def.indexOf("|") !== -1)) { //TODO NEEDS BETTER CHECK WHEN TO ALTERNATE ~ opts regex isn"t good enough | ||
var result = alternate.call(inputmask, true); | ||
if (result) { | ||
var newPos = result.caret !== undefined ? result.caret : (result.pos ? seekNext.call(inputmask, result.pos.begin ? result.pos.begin : result.pos) : getLastValidPosition.call(inputmask, -1, true)); | ||
if (c !== keys.Delete || pos.begin > newPos) { | ||
pos.begin == newPos; | ||
} | ||
} | ||
} | ||
if (strict !== true) { | ||
maskset.p = k === keyCode.DELETE ? pos.begin + offset : pos.begin; | ||
maskset.p = determineNewCaretPosition.call(inputmask, { | ||
begin: maskset.p, | ||
end: maskset.p | ||
}, false, opts.insertMode === false && k === keyCode.BACKSPACE ? "none" : undefined).begin; | ||
} | ||
} | ||
if (strict !== true) { | ||
maskset.p = c === keys.Delete ? pos.begin + offset : pos.begin; | ||
maskset.p = determineNewCaretPosition.call(inputmask, { | ||
begin: maskset.p, | ||
end: maskset.p | ||
}, false, opts.insertMode === false && c === keys.Backspace ? "none" : undefined).begin; | ||
} | ||
} | ||
} | ||
@@ -251,27 +260,27 @@ | ||
function isComplete(buffer) { //return true / false / undefined (repeat *) | ||
const inputmask = this, opts = this.opts, maskset = this.maskset; | ||
const inputmask = this, opts = this.opts, maskset = this.maskset; | ||
if (typeof opts.isComplete === "function") return opts.isComplete(buffer, opts); | ||
if (opts.repeat === "*") return undefined; | ||
var complete = false, | ||
lrp = determineLastRequiredPosition.call(inputmask, true), | ||
aml = seekPrevious.call(inputmask, lrp.l); | ||
if (typeof opts.isComplete === "function") return opts.isComplete(buffer, opts); | ||
if (opts.repeat === "*") return undefined; | ||
var complete = false, | ||
lrp = determineLastRequiredPosition.call(inputmask, true), | ||
aml = seekPrevious.call(inputmask, lrp.l); | ||
if (lrp.def === undefined || lrp.def.newBlockMarker || lrp.def.optionality || lrp.def.optionalQuantifier) { | ||
complete = true; | ||
for (var i = 0; i <= aml; i++) { | ||
var test = getTestTemplate.call(inputmask, i).match; | ||
if ((test.static !== true && maskset.validPositions[i] === undefined && test.optionality !== true && test.optionalQuantifier !== true) || (test.static === true && buffer[i] !== getPlaceholder.call(inputmask, i, test))) { | ||
complete = false; | ||
break; | ||
} | ||
} | ||
} | ||
return complete; | ||
if (lrp.def === undefined || lrp.def.newBlockMarker || lrp.def.optionality || lrp.def.optionalQuantifier) { | ||
complete = true; | ||
for (var i = 0; i <= aml; i++) { | ||
var test = getTestTemplate.call(inputmask, i).match; | ||
if ((test.static !== true && maskset.validPositions[i] === undefined && test.optionality !== true && test.optionalQuantifier !== true) || (test.static === true && buffer[i] !== getPlaceholder.call(inputmask, i, test))) { | ||
complete = false; | ||
break; | ||
} | ||
} | ||
} | ||
return complete; | ||
} | ||
function isSelection(posObj) { | ||
const inputmask = this, | ||
opts = this.opts, insertModeOffset = opts.insertMode ? 0 : 1; | ||
return inputmask.isRTL ? (posObj.begin - posObj.end) > insertModeOffset : (posObj.end - posObj.begin) > insertModeOffset; | ||
const inputmask = this, | ||
opts = this.opts, insertModeOffset = opts.insertMode ? 0 : 1; | ||
return inputmask.isRTL ? (posObj.begin - posObj.end) > insertModeOffset : (posObj.end - posObj.begin) > insertModeOffset; | ||
} | ||
@@ -281,193 +290,193 @@ | ||
function isValid(pos, c, strict, fromIsValid, fromAlternate, validateOnly, fromCheckval) { //strict true ~ no correction or autofill | ||
const inputmask = this, | ||
$ = this.dependencyLib, | ||
opts = this.opts, | ||
maskset = inputmask.maskset; | ||
const inputmask = this, | ||
$ = this.dependencyLib, | ||
opts = this.opts, | ||
maskset = inputmask.maskset; | ||
strict = strict === true; //always set a value to strict to prevent possible strange behavior in the extensions | ||
strict = strict === true; //always set a value to strict to prevent possible strange behavior in the extensions | ||
var maskPos = pos; | ||
if (pos.begin !== undefined) { //position was a position object - used to handle a delete by typing over a selection | ||
maskPos = inputmask.isRTL ? pos.end : pos.begin; | ||
} | ||
var maskPos = pos; | ||
if (pos.begin !== undefined) { //position was a position object - used to handle a delete by typing over a selection | ||
maskPos = inputmask.isRTL ? pos.end : pos.begin; | ||
} | ||
function processCommandObject(commandObj) { | ||
if (commandObj !== undefined) { | ||
if (commandObj.remove !== undefined) { //remove position(s) | ||
if (!Array.isArray(commandObj.remove)) commandObj.remove = [commandObj.remove]; | ||
commandObj.remove.sort(function (a, b) { | ||
return inputmask.isRTL ? a.pos - b.pos : b.pos - a.pos; | ||
}).forEach(function (lmnt) { | ||
revalidateMask.call(inputmask, { begin: lmnt, end: lmnt + 1 }); | ||
}); | ||
commandObj.remove = undefined; | ||
} | ||
if (commandObj.insert !== undefined) { //insert position(s) | ||
if (!Array.isArray(commandObj.insert)) commandObj.insert = [commandObj.insert]; | ||
commandObj.insert.sort(function (a, b) { | ||
return inputmask.isRTL ? b.pos - a.pos : a.pos - b.pos; | ||
}).forEach(function (lmnt) { | ||
if (lmnt.c !== "") { | ||
isValid.call(inputmask, lmnt.pos, lmnt.c, lmnt.strict !== undefined ? lmnt.strict : true, lmnt.fromIsValid !== undefined ? lmnt.fromIsValid : fromIsValid); | ||
} | ||
}); | ||
commandObj.insert = undefined; | ||
} | ||
function processCommandObject(commandObj) { | ||
if (commandObj !== undefined) { | ||
if (commandObj.remove !== undefined) { //remove position(s) | ||
if (!Array.isArray(commandObj.remove)) commandObj.remove = [commandObj.remove]; | ||
commandObj.remove.sort(function (a, b) { | ||
return inputmask.isRTL ? a.pos - b.pos : b.pos - a.pos; | ||
}).forEach(function (lmnt) { | ||
revalidateMask.call(inputmask, {begin: lmnt, end: lmnt + 1}); | ||
}); | ||
commandObj.remove = undefined; | ||
} | ||
if (commandObj.insert !== undefined) { //insert position(s) | ||
if (!Array.isArray(commandObj.insert)) commandObj.insert = [commandObj.insert]; | ||
commandObj.insert.sort(function (a, b) { | ||
return inputmask.isRTL ? b.pos - a.pos : a.pos - b.pos; | ||
}).forEach(function (lmnt) { | ||
if (lmnt.c !== "") { | ||
isValid.call(inputmask, lmnt.pos, lmnt.c, lmnt.strict !== undefined ? lmnt.strict : true, lmnt.fromIsValid !== undefined ? lmnt.fromIsValid : fromIsValid); | ||
} | ||
}); | ||
commandObj.insert = undefined; | ||
} | ||
if (commandObj.refreshFromBuffer && commandObj.buffer) { | ||
var refresh = commandObj.refreshFromBuffer; | ||
refreshFromBuffer.call(inputmask, refresh === true ? refresh : refresh.start, refresh.end, commandObj.buffer); | ||
commandObj.refreshFromBuffer = undefined; | ||
} | ||
if (commandObj.refreshFromBuffer && commandObj.buffer) { | ||
var refresh = commandObj.refreshFromBuffer; | ||
refreshFromBuffer.call(inputmask, refresh === true ? refresh : refresh.start, refresh.end, commandObj.buffer); | ||
commandObj.refreshFromBuffer = undefined; | ||
} | ||
if (commandObj.rewritePosition !== undefined) { | ||
maskPos = commandObj.rewritePosition; | ||
// commandObj.rewritePosition = undefined; | ||
commandObj = true; | ||
} | ||
} | ||
return commandObj; | ||
} | ||
if (commandObj.rewritePosition !== undefined) { | ||
maskPos = commandObj.rewritePosition; | ||
// commandObj.rewritePosition = undefined; | ||
commandObj = true; | ||
} | ||
} | ||
return commandObj; | ||
} | ||
function _isValid(position, c, strict) { | ||
var rslt = false; | ||
getTests.call(inputmask, position).every(function (tst, ndx) { | ||
var test = tst.match; | ||
//make sure the buffer is set and correct | ||
getBuffer.call(inputmask, true); | ||
if (test.jit && maskset.validPositions[seekPrevious.call(inputmask, position)] === undefined) //ignore if jit is not desirable | ||
{ | ||
rslt = false; | ||
} else { | ||
//return is false or a json object => { pos: ??, c: ??} or true | ||
rslt = test.fn != null ? | ||
test.fn.test(c, maskset, position, strict, opts, isSelection.call(inputmask, pos)) : (c === test.def || c === opts.skipOptionalPartCharacter) && test.def !== "" ? //non mask | ||
{ | ||
c: getPlaceholder.call(inputmask, position, test, true) || test.def, | ||
pos: position | ||
} : false; | ||
} | ||
if (rslt !== false) { | ||
var elem = rslt.c !== undefined ? rslt.c : c, validatedPos = position; | ||
elem = (elem === opts.skipOptionalPartCharacter && test.static === true) ? | ||
(getPlaceholder.call(inputmask, position, test, true) || test.def) : elem; | ||
function _isValid(position, c, strict) { | ||
var rslt = false; | ||
getTests.call(inputmask, position).every(function (tst, ndx) { | ||
var test = tst.match; | ||
//make sure the buffer is set and correct | ||
getBuffer.call(inputmask, true); | ||
if (test.jit && maskset.validPositions[seekPrevious.call(inputmask, position)] === undefined) //ignore if jit is not desirable | ||
{ | ||
rslt = false; | ||
} else { | ||
//return is false or a json object => { pos: ??, c: ??} or true | ||
rslt = test.fn != null ? | ||
test.fn.test(c, maskset, position, strict, opts, isSelection.call(inputmask, pos)) : (c === test.def || c === opts.skipOptionalPartCharacter) && test.def !== "" ? //non mask | ||
{ | ||
c: getPlaceholder.call(inputmask, position, test, true) || test.def, | ||
pos: position | ||
} : false; | ||
} | ||
if (rslt !== false) { | ||
var elem = rslt.c !== undefined ? rslt.c : c, validatedPos = position; | ||
elem = (elem === opts.skipOptionalPartCharacter && test.static === true) ? | ||
(getPlaceholder.call(inputmask, position, test, true) || test.def) : elem; | ||
rslt = processCommandObject(rslt); | ||
rslt = processCommandObject(rslt); | ||
if (rslt !== true && rslt.pos !== undefined && rslt.pos !== position) { //their is a position offset | ||
validatedPos = rslt.pos; | ||
} | ||
if (rslt !== true && rslt.pos !== undefined && rslt.pos !== position) { //their is a position offset | ||
validatedPos = rslt.pos; | ||
} | ||
if (rslt !== true && rslt.pos === undefined && rslt.c === undefined) { | ||
return false; //breakout if nothing to insert | ||
} | ||
if (rslt !== true && rslt.pos === undefined && rslt.c === undefined) { | ||
return false; //breakout if nothing to insert | ||
} | ||
if (revalidateMask.call(inputmask, pos, $.extend({}, tst, { | ||
"input": casing.call(inputmask, elem, test, validatedPos) | ||
}), fromIsValid, validatedPos) === false) { | ||
rslt = false; | ||
} | ||
return false; //break from loop | ||
} | ||
if (revalidateMask.call(inputmask, pos, $.extend({}, tst, { | ||
"input": casing.call(inputmask, elem, test, validatedPos) | ||
}), fromIsValid, validatedPos) === false) { | ||
rslt = false; | ||
} | ||
return false; //break from loop | ||
} | ||
return true; | ||
}); | ||
return rslt; | ||
} | ||
return true; | ||
}); | ||
return rslt; | ||
} | ||
var result = true, | ||
positionsClone = $.extend(true, {}, maskset.validPositions); //clone the currentPositions | ||
var result = true, | ||
positionsClone = $.extend(true, {}, maskset.validPositions); //clone the currentPositions | ||
if (opts.keepStatic === false && maskset.excludes[maskPos] !== undefined && fromAlternate !== true && fromIsValid !== true) { | ||
for (var i = maskPos; i < (inputmask.isRTL ? pos.begin : pos.end); i++) { | ||
if (maskset.excludes[i] !== undefined) { | ||
maskset.excludes[i] = undefined; | ||
delete maskset.tests[i]; | ||
} | ||
} | ||
} | ||
if (opts.keepStatic === false && maskset.excludes[maskPos] !== undefined && fromAlternate !== true && fromIsValid !== true) { | ||
for (var i = maskPos; i < (inputmask.isRTL ? pos.begin : pos.end); i++) { | ||
if (maskset.excludes[i] !== undefined) { | ||
maskset.excludes[i] = undefined; | ||
delete maskset.tests[i]; | ||
} | ||
} | ||
} | ||
if (typeof opts.preValidation === "function" && fromIsValid !== true && validateOnly !== true) { | ||
result = opts.preValidation.call(inputmask, getBuffer.call(inputmask), maskPos, c, isSelection.call(inputmask, pos), opts, maskset, pos, strict || fromAlternate); | ||
result = processCommandObject(result); | ||
} | ||
if (result === true) { //preValidation result | ||
result = _isValid(maskPos, c, strict); | ||
if ((!strict || fromIsValid === true) && result === false && validateOnly !== true) { | ||
var currentPosValid = maskset.validPositions[maskPos]; | ||
if (currentPosValid && currentPosValid.match.static === true && (currentPosValid.match.def === c || c === opts.skipOptionalPartCharacter)) { | ||
result = { | ||
"caret": seekNext.call(inputmask, maskPos) | ||
}; | ||
} else { | ||
if (opts.insertMode || maskset.validPositions[seekNext.call(inputmask, maskPos)] === undefined || pos.end > maskPos) { //does the input match on a further position? | ||
var skip = false; | ||
if (maskset.jitOffset[maskPos] && maskset.validPositions[seekNext.call(inputmask, maskPos)] === undefined) { | ||
result = isValid.call(inputmask, maskPos + maskset.jitOffset[maskPos], c, true, true); | ||
if (result !== false) { | ||
if (fromAlternate !== true) result.caret = maskPos; | ||
skip = true; | ||
} | ||
} | ||
if (pos.end > maskPos) { | ||
maskset.validPositions[maskPos] = undefined; | ||
} | ||
if (!skip && !isMask.call(inputmask, maskPos, opts.keepStatic && maskPos === 0)) { | ||
for (var nPos = maskPos + 1, snPos = seekNext.call(inputmask, maskPos, false, maskPos !== 0); nPos <= snPos; nPos++) { | ||
// if (!isMask(nPos, true)) { | ||
// continue; | ||
// } | ||
result = _isValid(nPos, c, strict); | ||
if (result !== false) { | ||
result = trackbackPositions.call(inputmask, maskPos, result.pos !== undefined ? result.pos : nPos) || result; | ||
maskPos = nPos; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
if (typeof opts.preValidation === "function" && fromIsValid !== true && validateOnly !== true) { | ||
result = opts.preValidation.call(inputmask, getBuffer.call(inputmask), maskPos, c, isSelection.call(inputmask, pos), opts, maskset, pos, strict || fromAlternate); | ||
result = processCommandObject(result); | ||
} | ||
if (result === true) { //preValidation result | ||
result = _isValid(maskPos, c, strict); | ||
if ((!strict || fromIsValid === true) && result === false && validateOnly !== true) { | ||
var currentPosValid = maskset.validPositions[maskPos]; | ||
if (currentPosValid && currentPosValid.match.static === true && (currentPosValid.match.def === c || c === opts.skipOptionalPartCharacter)) { | ||
result = { | ||
"caret": seekNext.call(inputmask, maskPos) | ||
}; | ||
} else { | ||
if (opts.insertMode || maskset.validPositions[seekNext.call(inputmask, maskPos)] === undefined || pos.end > maskPos) { //does the input match on a further position? | ||
var skip = false; | ||
if (maskset.jitOffset[maskPos] && maskset.validPositions[seekNext.call(inputmask, maskPos)] === undefined) { | ||
result = isValid.call(inputmask, maskPos + maskset.jitOffset[maskPos], c, true, true); | ||
if (result !== false) { | ||
if (fromAlternate !== true) result.caret = maskPos; | ||
skip = true; | ||
} | ||
} | ||
if (pos.end > maskPos) { | ||
maskset.validPositions[maskPos] = undefined; | ||
} | ||
if (!skip && !isMask.call(inputmask, maskPos, opts.keepStatic && maskPos === 0)) { | ||
for (var nPos = maskPos + 1, snPos = seekNext.call(inputmask, maskPos, false, maskPos !== 0); nPos <= snPos; nPos++) { | ||
// if (!isMask(nPos, true)) { | ||
// continue; | ||
// } | ||
result = _isValid(nPos, c, strict); | ||
if (result !== false) { | ||
result = trackbackPositions.call(inputmask, maskPos, result.pos !== undefined ? result.pos : nPos) || result; | ||
maskPos = nPos; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
if (result === false && opts.keepStatic && (isComplete.call(inputmask, getBuffer.call(inputmask)) || maskPos === 0) && !strict && fromAlternate !== true) { //try fuzzy alternator logic | ||
result = alternate.call(inputmask, maskPos, c, strict, fromIsValid, undefined, pos); | ||
} else if (isSelection.call(inputmask, pos) && maskset.tests[maskPos] && maskset.tests[maskPos].length > 1 && opts.keepStatic && !strict && fromAlternate !== true) { //selection clears an alternated keepstatic mask ~ #2189 | ||
result = alternate.call(inputmask, true); | ||
} | ||
if (result === false && opts.keepStatic && (isComplete.call(inputmask, getBuffer.call(inputmask)) || maskPos === 0) && !strict && fromAlternate !== true) { //try fuzzy alternator logic | ||
result = alternate.call(inputmask, maskPos, c, strict, fromIsValid, undefined, pos); | ||
} else if (isSelection.call(inputmask, pos) && maskset.tests[maskPos] && maskset.tests[maskPos].length > 1 && opts.keepStatic && !strict && fromAlternate !== true) { //selection clears an alternated keepstatic mask ~ #2189 | ||
result = alternate.call(inputmask, true); | ||
} | ||
if (result === true) { | ||
result = { | ||
"pos": maskPos | ||
}; | ||
} | ||
} | ||
if (typeof opts.postValidation === "function" && fromIsValid !== true && validateOnly !== true) { | ||
var postResult = opts.postValidation.call(inputmask, getBuffer.call(inputmask, true), pos.begin !== undefined ? (inputmask.isRTL ? pos.end : pos.begin) : pos, c, result, opts, maskset, strict, fromCheckval); | ||
if (postResult !== undefined) { | ||
result = postResult === true ? result : postResult; | ||
} | ||
} | ||
if (result === true) { | ||
result = { | ||
"pos": maskPos | ||
}; | ||
} | ||
} | ||
if (typeof opts.postValidation === "function" && fromIsValid !== true && validateOnly !== true) { | ||
var postResult = opts.postValidation.call(inputmask, getBuffer.call(inputmask, true), pos.begin !== undefined ? (inputmask.isRTL ? pos.end : pos.begin) : pos, c, result, opts, maskset, strict, fromCheckval); | ||
if (postResult !== undefined) { | ||
result = postResult === true ? result : postResult; | ||
} | ||
} | ||
if (result && result.pos === undefined) { | ||
result.pos = maskPos; | ||
} | ||
if (result && result.pos === undefined) { | ||
result.pos = maskPos; | ||
} | ||
if (result === false || validateOnly === true) { | ||
resetMaskSet.call(inputmask, true); | ||
maskset.validPositions = $.extend(true, [], positionsClone); //revert validation changes | ||
} else { | ||
trackbackPositions.call(inputmask, undefined, maskPos, true); | ||
} | ||
if (result === false || validateOnly === true) { | ||
resetMaskSet.call(inputmask, true); | ||
maskset.validPositions = $.extend(true, [], positionsClone); //revert validation changes | ||
} else { | ||
trackbackPositions.call(inputmask, undefined, maskPos, true); | ||
} | ||
var endResult = processCommandObject(result); | ||
// console.log("returned result " + JSON.stringify(endResult)); | ||
if (inputmask.maxLength !== undefined) { | ||
var buffer = getBuffer.call(inputmask); | ||
if (buffer.length > inputmask.maxLength && !fromIsValid) { | ||
resetMaskSet.call(inputmask, true); | ||
maskset.validPositions = $.extend(true, [], positionsClone); //revert validation changes | ||
endResult = false; | ||
} | ||
} | ||
return endResult; | ||
var endResult = processCommandObject(result); | ||
// console.log("returned result " + JSON.stringify(endResult)); | ||
if (inputmask.maxLength !== undefined) { | ||
var buffer = getBuffer.call(inputmask); | ||
if (buffer.length > inputmask.maxLength && !fromIsValid) { | ||
resetMaskSet.call(inputmask, true); | ||
maskset.validPositions = $.extend(true, [], positionsClone); //revert validation changes | ||
endResult = false; | ||
} | ||
} | ||
return endResult; | ||
} | ||
@@ -477,24 +486,25 @@ | ||
function positionCanMatchDefinition(pos, testDefinition, opts) { | ||
const inputmask = this, | ||
maskset = this.maskset; | ||
const inputmask = this, | ||
maskset = this.maskset; | ||
var valid = false, | ||
tests = getTests.call(inputmask, pos); | ||
for (var tndx = 0; tndx < tests.length; tndx++) { | ||
if (tests[tndx].match && | ||
((tests[tndx].match["nativeDef"] === testDefinition.match[opts.shiftPositions ? "def" : "nativeDef"] && (!opts.shiftPositions || !testDefinition.match.static)) || | ||
tests[tndx].match["nativeDef"] === testDefinition.match["nativeDef"] || (opts.regex && !tests[tndx].match.static && tests[tndx].match.fn.test(testDefinition.input)))) { | ||
valid = true; | ||
break; | ||
} else if (tests[tndx].match && tests[tndx].match["def"] === testDefinition.match["nativeDef"]) { | ||
valid = undefined; | ||
break; | ||
} | ||
} | ||
if (valid === false) { | ||
if (maskset.jitOffset[pos] !== undefined) { | ||
valid = positionCanMatchDefinition.call(inputmask, pos + maskset.jitOffset[pos], testDefinition, opts); | ||
} | ||
} | ||
return valid; | ||
var valid = false, | ||
tests = getTests.call(inputmask, pos); | ||
for (var tndx = 0; tndx < tests.length; tndx++) { | ||
if (tests[tndx].match && | ||
((tests[tndx].match["nativeDef"] === testDefinition.match[opts.shiftPositions ? "def" : "nativeDef"] && (!opts.shiftPositions || !testDefinition.match.static)) || | ||
tests[tndx].match["nativeDef"] === testDefinition.match["nativeDef"] || | ||
(opts.regex && !tests[tndx].match.static && tests[tndx].match.fn.test(testDefinition.input, maskset, pos, false, opts)))) { | ||
valid = true; | ||
break; | ||
} else if (tests[tndx].match && tests[tndx].match["def"] === testDefinition.match["nativeDef"]) { | ||
valid = undefined; | ||
break; | ||
} | ||
} | ||
if (valid === false) { | ||
if (maskset.jitOffset[pos] !== undefined) { | ||
valid = positionCanMatchDefinition.call(inputmask, pos + maskset.jitOffset[pos], testDefinition, opts); | ||
} | ||
} | ||
return valid; | ||
} | ||
@@ -504,34 +514,34 @@ | ||
function refreshFromBuffer(start, end, buffer) { | ||
const inputmask = this, | ||
maskset = this.maskset, | ||
opts = this.opts, | ||
$ = this.dependencyLib; | ||
// checkVal.call(inputmask, el, false, true, isRTL ? buffer.reverse() : buffer); | ||
var i, p, skipOptionalPartCharacter = opts.skipOptionalPartCharacter, | ||
bffr = inputmask.isRTL ? buffer.slice().reverse() : buffer; | ||
opts.skipOptionalPartCharacter = ""; | ||
if (start === true) { | ||
resetMaskSet.call(inputmask); | ||
maskset.tests = {}; //refresh tests after possible alternating | ||
start = 0; | ||
end = buffer.length; | ||
p = determineNewCaretPosition.call(inputmask, { begin: 0, end: 0 }, false).begin; | ||
} else { | ||
for (i = start; i < end; i++) { | ||
delete maskset.validPositions[i]; | ||
} | ||
p = start; | ||
} | ||
const inputmask = this, | ||
maskset = this.maskset, | ||
opts = this.opts, | ||
$ = this.dependencyLib; | ||
// checkVal.call(inputmask, el, false, true, isRTL ? buffer.reverse() : buffer); | ||
var i, p, skipOptionalPartCharacter = opts.skipOptionalPartCharacter, | ||
bffr = inputmask.isRTL ? buffer.slice().reverse() : buffer; | ||
opts.skipOptionalPartCharacter = ""; | ||
if (start === true) { | ||
resetMaskSet.call(inputmask); | ||
maskset.tests = {}; //refresh tests after possible alternating | ||
start = 0; | ||
end = buffer.length; | ||
p = determineNewCaretPosition.call(inputmask, {begin: 0, end: 0}, false).begin; | ||
} else { | ||
for (i = start; i < end; i++) { | ||
delete maskset.validPositions[i]; | ||
} | ||
p = start; | ||
} | ||
var keypress = new $.Event("keypress"); | ||
for (i = start; i < end; i++) { | ||
keypress.keyCode = bffr[i].toString().charCodeAt(0); | ||
inputmask.ignorable = false; //make sure ignorable is ignored ;-) | ||
var valResult = EventHandlers.keypressEvent.call(inputmask, keypress, true, false, false, p); | ||
if (valResult !== false && valResult !== undefined) { | ||
p = valResult.forwardPosition; | ||
} | ||
} | ||
var keypress = new $.Event("keypress"); | ||
for (i = start; i < end; i++) { | ||
keypress.key = bffr[i].toString(); | ||
inputmask.ignorable = false; //make sure ignorable is ignored ;-) | ||
var valResult = EventHandlers.keypressEvent.call(inputmask, keypress, true, false, false, p); | ||
if (valResult !== false && valResult !== undefined) { | ||
p = valResult.forwardPosition; | ||
} | ||
} | ||
opts.skipOptionalPartCharacter = skipOptionalPartCharacter; | ||
opts.skipOptionalPartCharacter = skipOptionalPartCharacter; | ||
} | ||
@@ -542,37 +552,37 @@ | ||
function trackbackPositions(originalPos, newPos, fillOnly) { | ||
const inputmask = this, | ||
maskset = this.maskset, | ||
$ = this.dependencyLib; | ||
const inputmask = this, | ||
maskset = this.maskset, | ||
$ = this.dependencyLib; | ||
// console.log("trackbackPositions " + originalPos + " " + newPos); | ||
if (originalPos === undefined) { | ||
//find previous valid | ||
for (originalPos = newPos - 1; originalPos > 0; originalPos--) { | ||
if (maskset.validPositions[originalPos]) break; | ||
} | ||
} | ||
for (var ps = originalPos; ps < newPos; ps++) { | ||
if (maskset.validPositions[ps] === undefined && !isMask.call(inputmask, ps, false)) { | ||
var vp = ps == 0 ? getTest.call(inputmask, ps) : maskset.validPositions[ps - 1]; | ||
if (vp) { | ||
var tests = getTests.call(inputmask, ps).slice(); | ||
if (tests[tests.length - 1].match.def === "") tests.pop(); | ||
var bestMatch = determineTestTemplate.call(inputmask, ps, tests), np; | ||
if (bestMatch && (bestMatch.match.jit !== true || (bestMatch.match.newBlockMarker === "master" && (np = maskset.validPositions[ps + 1]) && np.match.optionalQuantifier === true))) { | ||
bestMatch = $.extend({}, bestMatch, { | ||
"input": getPlaceholder.call(inputmask, ps, bestMatch.match, true) || bestMatch.match.def | ||
}); | ||
bestMatch.generatedInput = true; | ||
revalidateMask.call(inputmask, ps, bestMatch, true); | ||
// console.log("trackbackPositions " + originalPos + " " + newPos); | ||
if (originalPos === undefined) { | ||
//find previous valid | ||
for (originalPos = newPos - 1; originalPos > 0; originalPos--) { | ||
if (maskset.validPositions[originalPos]) break; | ||
} | ||
} | ||
for (var ps = originalPos; ps < newPos; ps++) { | ||
if (maskset.validPositions[ps] === undefined && !isMask.call(inputmask, ps, false)) { | ||
var vp = ps == 0 ? getTest.call(inputmask, ps) : maskset.validPositions[ps - 1]; | ||
if (vp) { | ||
var tests = getTests.call(inputmask, ps).slice(); | ||
if (tests[tests.length - 1].match.def === "") tests.pop(); | ||
var bestMatch = determineTestTemplate.call(inputmask, ps, tests), np; | ||
if (bestMatch && (bestMatch.match.jit !== true || (bestMatch.match.newBlockMarker === "master" && (np = maskset.validPositions[ps + 1]) && np.match.optionalQuantifier === true))) { | ||
bestMatch = $.extend({}, bestMatch, { | ||
"input": getPlaceholder.call(inputmask, ps, bestMatch.match, true) || bestMatch.match.def | ||
}); | ||
bestMatch.generatedInput = true; | ||
revalidateMask.call(inputmask, ps, bestMatch, true); | ||
if (fillOnly !== true) { | ||
//revalidate the new position to update the locator value | ||
var cvpInput = maskset.validPositions[newPos].input; | ||
maskset.validPositions[newPos] = undefined; | ||
return isValid.call(inputmask, newPos, cvpInput, true, true); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
if (fillOnly !== true) { | ||
//revalidate the new position to update the locator value | ||
var cvpInput = maskset.validPositions[newPos].input; | ||
maskset.validPositions[newPos] = undefined; | ||
return isValid.call(inputmask, newPos, cvpInput, true, true); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
@@ -582,90 +592,90 @@ | ||
function revalidateMask(pos, validTest, fromIsValid, validatedPos) { | ||
const inputmask = this, | ||
maskset = this.maskset, | ||
opts = this.opts, | ||
$ = this.dependencyLib; | ||
const inputmask = this, | ||
maskset = this.maskset, | ||
opts = this.opts, | ||
$ = this.dependencyLib; | ||
function IsEnclosedStatic(pos, valids, selection) { | ||
var posMatch = valids[pos]; | ||
if (posMatch !== undefined && posMatch.match.static === true && posMatch.match.optionality !== true && (valids[0] === undefined || valids[0].alternation === undefined)) { | ||
var prevMatch = selection.begin <= pos - 1 ? valids[pos - 1] && valids[pos - 1].match.static === true && valids[pos - 1] : valids[pos - 1], | ||
nextMatch = selection.end > pos + 1 ? valids[pos + 1] && valids[pos + 1].match.static === true && valids[pos + 1] : valids[pos + 1]; | ||
return prevMatch && nextMatch; | ||
} | ||
return false; | ||
} | ||
function IsEnclosedStatic(pos, valids, selection) { | ||
var posMatch = valids[pos]; | ||
if (posMatch !== undefined && posMatch.match.static === true && posMatch.match.optionality !== true && (valids[0] === undefined || valids[0].alternation === undefined)) { | ||
var prevMatch = selection.begin <= pos - 1 ? valids[pos - 1] && valids[pos - 1].match.static === true && valids[pos - 1] : valids[pos - 1], | ||
nextMatch = selection.end > pos + 1 ? valids[pos + 1] && valids[pos + 1].match.static === true && valids[pos + 1] : valids[pos + 1]; | ||
return prevMatch && nextMatch; | ||
} | ||
return false; | ||
} | ||
var offset = 0, begin = pos.begin !== undefined ? pos.begin : pos, end = pos.end !== undefined ? pos.end : pos, | ||
valid = true; | ||
if (pos.begin > pos.end) { | ||
begin = pos.end; | ||
end = pos.begin; | ||
} | ||
var offset = 0, begin = pos.begin !== undefined ? pos.begin : pos, end = pos.end !== undefined ? pos.end : pos, | ||
valid = true; | ||
if (pos.begin > pos.end) { | ||
begin = pos.end; | ||
end = pos.begin; | ||
} | ||
validatedPos = validatedPos !== undefined ? validatedPos : begin; | ||
if (fromIsValid === undefined && (begin !== end || (opts.insertMode && maskset.validPositions[validatedPos] !== undefined) || validTest === undefined || validTest.match.optionalQuantifier || validTest.match.optionality)) { | ||
//reposition & revalidate others | ||
var positionsClone = $.extend(true, {}, maskset.validPositions), | ||
lvp = getLastValidPosition.call(inputmask, undefined, true), | ||
i; | ||
maskset.p = begin; //needed for alternated position after overtype selection | ||
validatedPos = validatedPos !== undefined ? validatedPos : begin; | ||
if (fromIsValid === undefined && (begin !== end || (opts.insertMode && maskset.validPositions[validatedPos] !== undefined) || validTest === undefined || validTest.match.optionalQuantifier || validTest.match.optionality)) { | ||
//reposition & revalidate others | ||
var positionsClone = $.extend(true, {}, maskset.validPositions), | ||
lvp = getLastValidPosition.call(inputmask, undefined, true), | ||
i; | ||
maskset.p = begin; //needed for alternated position after overtype selection | ||
for (i = lvp; i >= begin; i--) { | ||
delete maskset.validPositions[i]; | ||
if (validTest === undefined) delete maskset.tests[i + 1]; | ||
} | ||
for (i = lvp; i >= begin; i--) { | ||
delete maskset.validPositions[i]; | ||
if (validTest === undefined) delete maskset.tests[i + 1]; | ||
} | ||
var j = validatedPos, | ||
posMatch = j, t, canMatch, test; | ||
var j = validatedPos, | ||
posMatch = j, t, canMatch, test; | ||
if (validTest) { | ||
maskset.validPositions[validatedPos] = $.extend(true, {}, validTest); | ||
posMatch++; | ||
j++; | ||
} | ||
if (validTest) { | ||
maskset.validPositions[validatedPos] = $.extend(true, {}, validTest); | ||
posMatch++; | ||
j++; | ||
} | ||
for (i = validTest ? end : end - 1; i <= lvp; i++) { | ||
if ((t = positionsClone[i]) !== undefined && t.generatedInput !== true && | ||
(i >= end || (i >= begin && IsEnclosedStatic(i, positionsClone, { | ||
begin: begin, | ||
end: end | ||
})))) { | ||
while (test = getTest.call(inputmask, posMatch), test.match.def !== "") { //loop needed to match further positions | ||
if ((canMatch = positionCanMatchDefinition.call(inputmask, posMatch, t, opts)) !== false || t.match.def === "+") { //validated match //we still need some hackery for the + validator (numeric alias) | ||
if (t.match.def === "+") getBuffer.call(inputmask, true); | ||
var result = isValid.call(inputmask, posMatch, t.input, t.match.def !== "+", /*t.match.def !== "+"*/ true); | ||
valid = result !== false; | ||
j = (result.pos || posMatch) + 1; | ||
if (!valid && canMatch) break; | ||
} else { | ||
valid = false; | ||
} | ||
if (valid) { | ||
if (validTest === undefined && t.match.static && i === pos.begin) offset++; | ||
break; | ||
} | ||
if (!valid && getBuffer.call(inputmask), posMatch > maskset.maskLength) { | ||
break; | ||
} | ||
posMatch++; | ||
} | ||
if (getTest.call(inputmask, posMatch).match.def == "") { | ||
valid = false; | ||
} | ||
//restore position | ||
posMatch = j; | ||
} | ||
if (!valid) break; | ||
} | ||
if (!valid) { | ||
maskset.validPositions = $.extend(true, [], positionsClone); | ||
resetMaskSet.call(inputmask, true); | ||
return false; | ||
} | ||
} else if (validTest && getTest.call(inputmask, validatedPos).match.cd === validTest.match.cd) { | ||
maskset.validPositions[validatedPos] = $.extend(true, {}, validTest); | ||
} | ||
for (i = validTest ? end : end - 1; i <= lvp; i++) { | ||
if ((t = positionsClone[i]) !== undefined && t.generatedInput !== true && | ||
(i >= end || (i >= begin && IsEnclosedStatic(i, positionsClone, { | ||
begin: begin, | ||
end: end | ||
})))) { | ||
while (test = getTest.call(inputmask, posMatch), test.match.def !== "") { //loop needed to match further positions | ||
if ((canMatch = positionCanMatchDefinition.call(inputmask, posMatch, t, opts)) !== false || t.match.def === "+") { //validated match //we still need some hackery for the + validator (numeric alias) | ||
if (t.match.def === "+") getBuffer.call(inputmask, true); | ||
var result = isValid.call(inputmask, posMatch, t.input, t.match.def !== "+", /*t.match.def !== "+"*/ true); | ||
valid = result !== false; | ||
j = (result.pos || posMatch) + 1; | ||
if (!valid && canMatch) break; | ||
} else { | ||
valid = false; | ||
} | ||
if (valid) { | ||
if (validTest === undefined && t.match.static && i === pos.begin) offset++; | ||
break; | ||
} | ||
if (!valid && getBuffer.call(inputmask), posMatch > maskset.maskLength) { | ||
break; | ||
} | ||
posMatch++; | ||
} | ||
if (getTest.call(inputmask, posMatch).match.def == "") { | ||
valid = false; | ||
} | ||
//restore position | ||
posMatch = j; | ||
} | ||
if (!valid) break; | ||
} | ||
if (!valid) { | ||
maskset.validPositions = $.extend(true, [], positionsClone); | ||
resetMaskSet.call(inputmask, true); | ||
return false; | ||
} | ||
} else if (validTest && getTest.call(inputmask, validatedPos).match.cd === validTest.match.cd) { | ||
maskset.validPositions[validatedPos] = $.extend(true, {}, validTest); | ||
} | ||
resetMaskSet.call(inputmask, true); | ||
return offset; | ||
resetMaskSet.call(inputmask, true); | ||
return offset; | ||
} |
{ | ||
"name": "inputmask", | ||
"version": "5.0.8-beta.25", | ||
"version": "5.0.8-beta.47", | ||
"description": "Inputmask is a javascript library which creates an input mask. Inputmask can run against vanilla javascript, jQuery and jqlite.", | ||
@@ -5,0 +5,0 @@ "main": "dist/inputmask.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
888819
11505