Browse Source

Alternator mask with keepStatic option cannot switch to an alternative at the end #612

Robin Herbots 11 years ago
parent
commit
5562b90722

+ 5 - 3
bower.json

@@ -1,6 +1,6 @@
 {
   "name": "jquery.inputmask",
-  "version": "3.0.67",
+  "version": "3.0.68",
   "main": [
     "./dist/inputmask/jquery.inputmask.js",
     "./dist/inputmask/jquery.inputmask.extensions.js",
@@ -13,13 +13,15 @@
   "description": "jquery.inputmask is a jquery plugin which create an input mask.",
   "license": "http://opensource.org/licenses/mit-license.php",
   "ignore": [
+	"**/.*",
     "qunit/",
     "nuget/",
     "tools/",
     "js/",
-    "README.md",
+    "*.md",
     "build.properties",
-    "build.xml"
+    "build.xml",
+	jquery.inputmask.jquery.json
   ],
   "dependencies": {
       "jquery": ">=1.7"

+ 1 - 1
build.properties

@@ -7,7 +7,7 @@ distdir = dist
 
 build.major = 3
 build.minor = 0
-build.revision = 67
+build.revision = 68
 
 target = jquery.inputmask.bundle.js
 target.min = jquery.inputmask.bundle.min.js

File diff suppressed because it is too large
+ 0 - 21
dist/inputmask/jquery.inputmask-multi.js


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


+ 60 - 14
dist/jquery.inputmask.bundle.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2014 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.0.67
+* Version: 3.0.68
 */
 
 (function (factory) {
@@ -763,9 +763,55 @@
                 }
 
                 var maskPos = pos;
-                if (maskPos >= getMaskLength()) {
-                    console.log("try alternate match");
-                    return false;
+                if (maskPos >= getMaskLength()) { //try fuzzy alternator logic
+                    var continueMask = false;
+                    if (opts.keepStatic) {
+                        var validPs = getMaskSet()["validPositions"],
+                            firstAlt,
+                            alternation;
+                        //find first alternation
+                        for (firstAlt in validPs) {
+                            if (validPs[firstAlt].alternation != undefined) {
+                                alternation = validPs[firstAlt].alternation;
+                                break;
+                            }
+                        }
+                        //find first decision making position
+                        for (var decisionPos in validPs) {
+                            if (parseInt(decisionPos) > parseInt(firstAlt) && validPs[decisionPos].alternation === undefined) {
+                                var altPos = validPs[decisionPos],
+                                    decisionTaker = altPos.locator[alternation],
+                                    altNdxs = validPs[firstAlt].locator[alternation].split(",");
+                                if (decisionTaker == "0") {
+                                    for (var mndx = 0; mndx < altNdxs.length; mndx++) {
+                                        if (decisionTaker != altNdxs[mndx]) {
+                                            altPos = validPs[seekPrevious(decisionPos)];
+                                            altPos.locator[alternation] = altNdxs[mndx];
+                                            break;
+                                        }
+                                    }
+                                    getMaskSet()["buffer"].splice(decisionPos, 1);
+                                    var buffer = getBuffer().slice(); //work on clone
+                                    for (var i = decisionPos; i < getLastValidPosition() + 1; i++) {
+                                        delete getMaskSet()["validPositions"][i];
+                                        delete getMaskSet()["tests"][i];
+                                    }
+                                    resetMaskSet(true); //clear getbuffer
+                                    for (var i = decisionPos; i < buffer.length; i++) {
+                                        if (buffer[i] != opts.skipOptionalPartCharacter) {
+                                            isValid(getLastValidPosition() + 1, buffer[i], false, true);
+                                        }
+                                    }
+
+                                    continueMask = true;
+                                    break;
+                                }
+                                break;
+                            }
+                        }
+                    }
+                    if (!continueMask)
+                        return false;
                 }
                 var result = _isValid(maskPos, c, strict, fromSetValid);
                 if (!strict && result === false) {
@@ -1380,14 +1426,14 @@
                 e.preventDefault();
             }
             function inputFallBackEvent(e) { //fallback when keypress & compositionevents fail
-             	if (skipInputEvent === true && e.type == "input") {
+                if (skipInputEvent === true && e.type == "input") {
                     skipInputEvent = false;
                     return true;
                 }
                 var input = this;
                 var caretPos = caret(input),
                     currentValue = input._valueGet();
-                
+
                 caret(input, caretPos.begin - 1);
                 var keypress = $.Event("keypress");
                 keypress.which = currentValue.charCodeAt(caretPos.begin - 1);
@@ -1396,7 +1442,7 @@
                 keypressEvent.call(input, keypress, undefined, undefined, false);
                 var forwardPosition = getMaskSet()["p"];
                 writeBuffer(input, getBuffer(), opts.numericInput ? seekPrevious(forwardPosition) : forwardPosition);
-               
+
                 e.preventDefault();
             }
             function compositionupdateEvent(e) { //fix for special latin-charset FF/Linux
@@ -1549,9 +1595,9 @@
                     ).bind("keypress.inputmask", keypressEvent
                     ).bind("keyup.inputmask", keyupEvent
                     ).bind("compositionupdate.inputmask", compositionupdateEvent);
-                    
+
                     if (PasteEventType === "paste") {
-                     	$el.bind("input.inputmask", inputFallBackEvent);
+                        $el.bind("input.inputmask", inputFallBackEvent);
                     }
                     if (android || androidfirefox || androidchrome || kindle) {
                         if (PasteEventType == "input") {
@@ -1887,7 +1933,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.67
+Version: 3.0.68
 
 Optional extensions on the jquery.inputmask base
 */
@@ -2014,7 +2060,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.67
+Version: 3.0.68
 
 Optional extensions on the jquery.inputmask base
 */
@@ -2508,7 +2554,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.67
+Version: 3.0.68
 
 Optional extensions on the jquery.inputmask base
 */
@@ -2767,7 +2813,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.67
+Version: 3.0.68
 
 Regex extensions on the jquery.inputmask base
 Allows for using regular expressions as a mask
@@ -2960,7 +3006,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.67
+Version: 3.0.68
 
 Phone extension.
 When using this extension make sure you specify the correct url to get the masks

File diff suppressed because it is too large
+ 67 - 66
dist/jquery.inputmask.bundle.min.js


+ 1 - 1
jquery.inputmask.jquery.json

@@ -8,7 +8,7 @@
 		"inputmask",
 		"mask"
     ],
-    "version": "3.0.67",
+    "version": "3.0.68",
     "author": {
         "name": "Robin Herbots",
         "url": "http://github.com/RobinHerbots/jquery.inputmask"

+ 54 - 8
js/jquery.inputmask.js

@@ -763,9 +763,55 @@
                 }
 
                 var maskPos = pos;
-                if (maskPos >= getMaskLength()) {
-                    console.log("try alternate match");
-                    return false;
+                if (maskPos >= getMaskLength()) { //try fuzzy alternator logic
+                    var continueMask = false;
+                    if (opts.keepStatic) {
+                        var validPs = getMaskSet()["validPositions"],
+                            firstAlt,
+                            alternation;
+                        //find first alternation
+                        for (firstAlt in validPs) {
+                            if (validPs[firstAlt].alternation != undefined) {
+                                alternation = validPs[firstAlt].alternation;
+                                break;
+                            }
+                        }
+                        //find first decision making position
+                        for (var decisionPos in validPs) {
+                            if (parseInt(decisionPos) > parseInt(firstAlt) && validPs[decisionPos].alternation === undefined) {
+                                var altPos = validPs[decisionPos],
+                                    decisionTaker = altPos.locator[alternation],
+                                    altNdxs = validPs[firstAlt].locator[alternation].split(",");
+                                if (decisionTaker == "0") {
+                                    for (var mndx = 0; mndx < altNdxs.length; mndx++) {
+                                        if (decisionTaker != altNdxs[mndx]) {
+                                            altPos = validPs[seekPrevious(decisionPos)];
+                                            altPos.locator[alternation] = altNdxs[mndx];
+                                            break;
+                                        }
+                                    }
+                                    getMaskSet()["buffer"].splice(decisionPos, 1);
+                                    var buffer = getBuffer().slice(); //work on clone
+                                    for (var i = decisionPos; i < getLastValidPosition() + 1; i++) {
+                                        delete getMaskSet()["validPositions"][i];
+                                        delete getMaskSet()["tests"][i];
+                                    }
+                                    resetMaskSet(true); //clear getbuffer
+                                    for (var i = decisionPos; i < buffer.length; i++) {
+                                        if (buffer[i] != opts.skipOptionalPartCharacter) {
+                                            isValid(getLastValidPosition() + 1, buffer[i], false, true);
+                                        }
+                                    }
+
+                                    continueMask = true;
+                                    break;
+                                }
+                                break;
+                            }
+                        }
+                    }
+                    if (!continueMask)
+                        return false;
                 }
                 var result = _isValid(maskPos, c, strict, fromSetValid);
                 if (!strict && result === false) {
@@ -1380,14 +1426,14 @@
                 e.preventDefault();
             }
             function inputFallBackEvent(e) { //fallback when keypress & compositionevents fail
-             	if (skipInputEvent === true && e.type == "input") {
+                if (skipInputEvent === true && e.type == "input") {
                     skipInputEvent = false;
                     return true;
                 }
                 var input = this;
                 var caretPos = caret(input),
                     currentValue = input._valueGet();
-                
+
                 caret(input, caretPos.begin - 1);
                 var keypress = $.Event("keypress");
                 keypress.which = currentValue.charCodeAt(caretPos.begin - 1);
@@ -1396,7 +1442,7 @@
                 keypressEvent.call(input, keypress, undefined, undefined, false);
                 var forwardPosition = getMaskSet()["p"];
                 writeBuffer(input, getBuffer(), opts.numericInput ? seekPrevious(forwardPosition) : forwardPosition);
-               
+
                 e.preventDefault();
             }
             function compositionupdateEvent(e) { //fix for special latin-charset FF/Linux
@@ -1549,9 +1595,9 @@
                     ).bind("keypress.inputmask", keypressEvent
                     ).bind("keyup.inputmask", keyupEvent
                     ).bind("compositionupdate.inputmask", compositionupdateEvent);
-                    
+
                     if (PasteEventType === "paste") {
-                     	$el.bind("input.inputmask", inputFallBackEvent);
+                        $el.bind("input.inputmask", inputFallBackEvent);
                     }
                     if (android || androidfirefox || androidchrome || kindle) {
                         if (PasteEventType == "input") {

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "jquery.inputmask",
-  "version": "3.0.67",
+  "version": "3.0.68",
   "description": "jquery.inputmask is a jquery plugin which create an input mask.",
   "main": [
     "./dist/inputmask/jquery.inputmask.js",