Robin Herbots 7 years ago
parent
commit
4ecf58e2f8

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
   "name": "inputmask",
-  "version": "5.0.0-beta.99",
+  "version": "5.0.0-beta.101",
   "main": [
 	  "./index.js",
     "./css/inputmask.css"

+ 1 - 1
composer.json

@@ -1,7 +1,7 @@
 {
   "name": "robinherbots/inputmask",
   "description": "Inputmask is a javascript library which creates an input mask.  Inputmask can run against vanilla javascript, jQuery and jqlite.",
-  "version": "5.0.0-beta.99",
+  "version": "5.0.0-beta.101",
   "type": "library",
   "keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
   "homepage": "http://robinherbots.github.io/Inputmask",

+ 22 - 22
dist/bindings/inputmask.binding.js

@@ -5,28 +5,28 @@
  Licensed under the MIT license
  */
 (function (factory) {
-	if (typeof define === "function" && define.amd) {
-		define(["jquery", "../inputmask", "../global/window"], factory);
-	} else if (typeof exports === "object") {
-		module.exports = factory(require("jquery"), require("../inputmask"), require("../global/window"));
-	} else {
-		factory(jQuery, window.Inputmask, window);
-	}
+    if (typeof define === "function" && define.amd) {
+        define(["jquery", "../inputmask", "../global/window"], factory);
+    } else if (typeof exports === "object") {
+        module.exports = factory(require("jquery"), require("../inputmask"), require("../global/window"));
+    } else {
+        factory(jQuery, window.Inputmask, window);
+    }
 }
 (function ($, Inputmask, window) {
-	$(window.document).ajaxComplete(function (event, xmlHttpRequest, ajaxOptions) {
-		if ($.inArray("html", ajaxOptions.dataTypes) !== -1) {
-			$(".inputmask, [data-inputmask], [data-inputmask-mask], [data-inputmask-alias]").each(function (ndx, lmnt) {
-				if (lmnt.inputmask === undefined) {
-					Inputmask().mask(lmnt);
-				}
-			});
-		}
-	}).ready(function () {
-		$(".inputmask, [data-inputmask], [data-inputmask-mask], [data-inputmask-alias]").each(function (ndx, lmnt) {
-			if (lmnt.inputmask === undefined) {
-				Inputmask().mask(lmnt);
-			}
-		});
-	});
+    $(window.document).ajaxComplete(function (event, xmlHttpRequest, ajaxOptions) {
+        if ($.inArray("html", ajaxOptions.dataTypes) !== -1) {
+            $(".inputmask, [data-inputmask], [data-inputmask-mask], [data-inputmask-alias], [data-inputmask-regex]").each(function (ndx, lmnt) {
+                if (lmnt.inputmask === undefined) {
+                    Inputmask().mask(lmnt);
+                }
+            });
+        }
+    }).ready(function () {
+        $(".inputmask, [data-inputmask], [data-inputmask-mask], [data-inputmask-alias],[data-inputmask-regex]").each(function (ndx, lmnt) {
+            if (lmnt.inputmask === undefined) {
+                Inputmask().mask(lmnt);
+            }
+        });
+    });
 }));

File diff suppressed because it is too large
+ 5122 - 2338
dist/inputmask.js


File diff suppressed because it is too large
+ 5157 - 1
dist/inputmask.min.js


File diff suppressed because it is too large
+ 4806 - 2245
dist/jquery.inputmask.js


File diff suppressed because it is too large
+ 4870 - 2
dist/jquery.inputmask.min.js


+ 22 - 22
lib/bindings/inputmask.binding.js

@@ -5,28 +5,28 @@
  Licensed under the MIT license
  */
 (function (factory) {
-	if (typeof define === "function" && define.amd) {
-		define(["jquery", "../inputmask", "../global/window"], factory);
-	} else if (typeof exports === "object") {
-		module.exports = factory(require("jquery"), require("../inputmask"), require("../global/window"));
-	} else {
-		factory(jQuery, window.Inputmask, window);
-	}
+    if (typeof define === "function" && define.amd) {
+        define(["jquery", "../inputmask", "../global/window"], factory);
+    } else if (typeof exports === "object") {
+        module.exports = factory(require("jquery"), require("../inputmask"), require("../global/window"));
+    } else {
+        factory(jQuery, window.Inputmask, window);
+    }
 }
 (function ($, Inputmask, window) {
-	$(window.document).ajaxComplete(function (event, xmlHttpRequest, ajaxOptions) {
-		if ($.inArray("html", ajaxOptions.dataTypes) !== -1) {
-			$(".inputmask, [data-inputmask], [data-inputmask-mask], [data-inputmask-alias]").each(function (ndx, lmnt) {
-				if (lmnt.inputmask === undefined) {
-					Inputmask().mask(lmnt);
-				}
-			});
-		}
-	}).ready(function () {
-		$(".inputmask, [data-inputmask], [data-inputmask-mask], [data-inputmask-alias]").each(function (ndx, lmnt) {
-			if (lmnt.inputmask === undefined) {
-				Inputmask().mask(lmnt);
-			}
-		});
-	});
+    $(window.document).ajaxComplete(function (event, xmlHttpRequest, ajaxOptions) {
+        if ($.inArray("html", ajaxOptions.dataTypes) !== -1) {
+            $(".inputmask, [data-inputmask], [data-inputmask-mask], [data-inputmask-alias], [data-inputmask-regex]").each(function (ndx, lmnt) {
+                if (lmnt.inputmask === undefined) {
+                    Inputmask().mask(lmnt);
+                }
+            });
+        }
+    }).ready(function () {
+        $(".inputmask, [data-inputmask], [data-inputmask-mask], [data-inputmask-alias],[data-inputmask-regex]").each(function (ndx, lmnt) {
+            if (lmnt.inputmask === undefined) {
+                Inputmask().mask(lmnt);
+            }
+        });
+    });
 }));

+ 15 - 11
lib/extensions/inputmask.numeric.extensions.js

@@ -38,6 +38,13 @@ function alignDigits(buffer, opts) {
     return buffer;
 }
 
+function GetLastValidPosition(maskset) {
+    var posNdx;
+    for (posNdx in maskset.validPositions) {
+    }
+    return posNdx;
+}
+
 //number aliases
 Inputmask.extendAliases({
     "numeric": {
@@ -126,19 +133,18 @@ Inputmask.extendAliases({
             },
             "+": {
                 validator: function (chrs, maskset, pos, strict, opts) {
-                    console.log("+ " + pos);
                     return (opts.allowMinus && (chrs === "-" || chrs === opts.negationSymbol.front));
 
                 }
             },
             "-": {
                 validator: function (chrs, maskset, pos, strict, opts) {
-                    console.log("- " + pos);
                     return (opts.allowMinus && chrs === opts.negationSymbol.back);
                 }
             }
         },
         preValidation: function (buffer, pos, c, isSelection, opts, maskset) {
+            var radixPos = $.inArray(opts.radixPoint, buffer);
             if (c === "-" || c === opts.negationSymbol.front) {
                 if (opts.allowMinus !== true) return false;
                 var isNegative = false;
@@ -149,18 +155,16 @@ Inputmask.extendAliases({
                     }
                 });
                 return isNegative ? {
-                    remove: buffer.length - 1, caret: pos + 1
+                    remove: GetLastValidPosition(maskset),
+                    caret: radixPos >= pos ? pos + 1 : pos
                 } : {
-                    insert: {pos: buffer.length, c: c, fromIsValid: true}, caret: pos + 1
+                    insert: {pos: parseInt(GetLastValidPosition(maskset)) + 1, c: c, fromIsValid: true},
+                    caret: radixPos >= pos ? pos + 1 : pos
                 };
             }
-            if (isSelection === false && c === opts.radixPoint && (opts.digits !== undefined && (isNaN(opts.digits) || parseInt(opts.digits) > 0))) {
-                var radixPos = $.inArray(opts.radixPoint, buffer);
-                if (radixPos !== pos)
-                    return {
-                        "caret": opts._radixDance && pos > radixPos ? radixPos : radixPos - 1
-                    };
-            }
+            if (isSelection === false && c === opts.radixPoint && (opts.digits !== undefined && (isNaN(opts.digits) || parseInt(opts.digits) > 0)) && radixPos !== pos) return {
+                "caret": opts._radixDance && pos > radixPos ? radixPos : radixPos - 1
+            };
 
             return true;
         },

+ 59 - 53
lib/inputmask.js

@@ -1600,7 +1600,7 @@ function maskScope(actionObj, maskset, opts) {
 
             if (maxLength === undefined || maskPos < maxLength) {
                 result = _isValid(maskPos, c, strict);
-                console.log(maskPos + " " + c + " " + JSON.stringify(getMaskSet().jitOffset))
+                // console.log(maskPos + " " + c + " " + JSON.stringify(getMaskSet().jitOffset))
                 if ((!strict || fromIsValid === true) && result === false && validateOnly !== true) {
                     var currentPosValid = getMaskSet().validPositions[maskPos];
                     if (currentPosValid && currentPosValid.match.fn === null && (currentPosValid.match.def === c || c === opts.skipOptionalPartCharacter)) {
@@ -1663,7 +1663,7 @@ function maskScope(actionObj, maskset, opts) {
 
     //fill in best positions according the current input
     function trackbackPositions(originalPos, newPos, fillOnly) {
-        // console.log("trackbackPositions " + originalPos + " " + newPos);
+        console.log("trackbackPositions " + originalPos + " " + newPos);
         var result;
         if (originalPos === undefined) {
             //find previous valid
@@ -1678,16 +1678,20 @@ function maskScope(actionObj, maskset, opts) {
                     var tests = getTests(ps).slice()
                     if (tests[tests.length - 1].match.def === "") tests.pop();
                     var bestMatch = determineTestTemplate(ps, tests);
-                    bestMatch = $.extend({}, bestMatch, {
-                        "input": getPlaceholder(ps, bestMatch.match, true) || bestMatch.match.def
-                    });
-                    bestMatch.generatedInput = true;
-                    revalidateMask(ps, bestMatch, true);
-                    if (fillOnly !== true) {
-                        //revalidate the new position to update the locator value
-                        var cvpInput = getMaskSet().validPositions[newPos].input;
-                        getMaskSet().validPositions[newPos] = undefined;
-                        result = isValid(newPos, cvpInput, true, true);
+                    if (bestMatch && (bestMatch.match.jit !== true && originalPos !== undefined)) {
+                        console.log("bestmatch " + JSON.stringify(bestMatch));
+                        console.log("newpos " + JSON.stringify(getTest(newPos)));
+                        bestMatch = $.extend({}, bestMatch, {
+                            "input": getPlaceholder(ps, bestMatch.match, true) || bestMatch.match.def
+                        });
+                        bestMatch.generatedInput = true;
+                        revalidateMask(ps, bestMatch, true);
+                        if (fillOnly !== true) {
+                            //revalidate the new position to update the locator value
+                            var cvpInput = getMaskSet().validPositions[newPos].input;
+                            getMaskSet().validPositions[newPos] = undefined;
+                            result = isValid(newPos, cvpInput, true, true);
+                        }
                     }
                 }
             }
@@ -2047,6 +2051,19 @@ function maskScope(actionObj, maskset, opts) {
                 $input = $(input),
                 k = e.which || e.charCode || e.keyCode;
 
+
+            function hanndleRadixDance(pos, c) {
+                if (opts._radixDance && opts.numericInput) {
+                    var radixPos = getBuffer().indexOf(opts.radixPoint.charAt(0)) + 1;
+                    if (pos.begin <= radixPos && (radixPos > 1 || c == opts.radixPoint)) {
+                        if (c == opts.radixPoint && radixPos > 1) offset = 1;
+                        pos.begin -= 1;
+                        pos.end -= 1;
+                    }
+                }
+                return pos;
+            }
+
             if (checkval !== true && (!(e.ctrlKey && e.altKey) && (e.ctrlKey || e.metaKey || ignorable))) {
                 if (k === Inputmask.keyCode.ENTER && undoValue !== getBuffer().join("")) {
                     undoValue = getBuffer().join("");
@@ -2056,52 +2073,41 @@ function maskScope(actionObj, maskset, opts) {
                     }, 0);
                 }
                 return true;
-            } else {
-                if (k) {
-                    //special treat the decimal separator
-                    if (k === 46 && e.shiftKey === false && opts.radixPoint !== "") k = opts.radixPoint.charCodeAt(0);
-                    var pos = checkval ? {
-                            begin: ndx,
-                            end: ndx
-                        } : caret(input),
-                        forwardPosition, c = String.fromCharCode(k), offset = 0;
-
-                    if (opts._radixDance && opts.numericInput) {
-                        var radixPos = getBuffer().indexOf(opts.radixPoint.charAt(0)) + 1;
-                        if (pos.begin <= radixPos && (radixPos > 1 || c == opts.radixPoint)) {
-                            if (c == opts.radixPoint && radixPos > 1) offset = 1;
-                            pos.begin -= 1;
-                            pos.end -= 1;
-                        }
-                    }
-
-
-                    getMaskSet().writeOutBuffer = true;
-                    var valResult = isValid(pos, c, strict);
-                    if (valResult !== false) {
-                        resetMaskSet(true);
-                        forwardPosition = valResult.caret !== undefined ? valResult.caret : seekNext(valResult.pos.begin ? valResult.pos.begin : valResult.pos);
-                        getMaskSet().p = forwardPosition; //needed for checkval
-                    }
+            } else if (k) {
+                //special treat the decimal separator
+                if (k === 46 && e.shiftKey === false && opts.radixPoint !== "") k = opts.radixPoint.charCodeAt(0);
+                var pos = checkval ? {
+                        begin: ndx,
+                        end: ndx
+                    } : caret(input),
+                    forwardPosition, c = String.fromCharCode(k), offset = 0;
+                pos = hanndleRadixDance(pos, c);
+
+                getMaskSet().writeOutBuffer = true;
+                var valResult = isValid(pos, c, strict);
+                if (valResult !== false) {
+                    resetMaskSet(true);
+                    forwardPosition = valResult.caret !== undefined ? valResult.caret : seekNext(valResult.pos.begin ? valResult.pos.begin : valResult.pos);
+                    getMaskSet().p = forwardPosition; //needed for checkval
+                }
 
 
-                    forwardPosition = ((opts.numericInput && valResult.caret === undefined) ? seekPrevious(forwardPosition) : forwardPosition) + offset;
-                    if (writeOut !== false) {
-                        setTimeout(function () {
-                            opts.onKeyValidation.call(input, k, valResult, opts);
-                        }, 0);
-                        if (getMaskSet().writeOutBuffer && valResult !== false) {
-                            var buffer = getBuffer();
-                            writeBuffer(input, buffer, forwardPosition, e, checkval !== true);
-                        }
+                forwardPosition = ((opts.numericInput && valResult.caret === undefined) ? seekPrevious(forwardPosition) : forwardPosition) + offset;
+                if (writeOut !== false) {
+                    setTimeout(function () {
+                        opts.onKeyValidation.call(input, k, valResult, opts);
+                    }, 0);
+                    if (getMaskSet().writeOutBuffer && valResult !== false) {
+                        var buffer = getBuffer();
+                        writeBuffer(input, buffer, forwardPosition, e, checkval !== true);
                     }
+                }
 
-                    e.preventDefault();
+                e.preventDefault();
 
-                    if (checkval) {
-                        if (valResult !== false) valResult.forwardPosition = forwardPosition;
-                        return valResult;
-                    }
+                if (checkval) {
+                    if (valResult !== false) valResult.forwardPosition = forwardPosition;
+                    return valResult;
                 }
             }
         },

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "inputmask",
-  "version": "5.0.0-beta.99",
+  "version": "5.0.0-beta.101",
   "description": "Inputmask is a javascript library which creates an input mask.  Inputmask can run against vanilla javascript, jQuery and jqlite.",
   "main": "index.js",
   "files": [

+ 1 - 1
webpack.config.js

@@ -84,7 +84,7 @@ module.exports = {
         "qunit": "QUnit"
     },
     optimization: {
-        minimize: true,
+        minimize: false,
         minimizer: [new UglifyJsPlugin({
             include: /\.min\.js$/,
             sourceMap: false,