Browse Source

selection and insert fixes

Robin Herbots 11 years ago
parent
commit
4bd925d838

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
 {
     "name": "jquery.inputmask",
     "name": "jquery.inputmask",
-    "version": "3.0.21",
+    "version": "3.0.22",
     "main": "./dist/jquery.inputmask.bundle.js",
     "main": "./dist/jquery.inputmask.bundle.js",
 	"keywords" : ["jQuery", "plugins", "input", "form", "inputmask", "mask"],
 	"keywords" : ["jQuery", "plugins", "input", "form", "inputmask", "mask"],
 	"description": "jquery.inputmask is a jquery plugin which create an input mask.",
 	"description": "jquery.inputmask is a jquery plugin which create an input mask.",

+ 1 - 1
build.properties

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

BIN
dist/jQuery.InputMask.3.0.21.nupkg


BIN
dist/jQuery.InputMask.3.0.22.nupkg


+ 29 - 22
dist/jquery.inputmask.bundle.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2014 Robin Herbots
 * Copyright (c) 2010 - 2014 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.0.21
+* Version: 3.0.22
 */
 */
 
 
 (function ($) {
 (function ($) {
@@ -249,6 +249,8 @@
                 maxLength;
                 maxLength;
 
 
             //maskset helperfunctions
             //maskset helperfunctions
+
+
             function getMaskTemplate(baseOnInput, minimalPos, includeInput) {
             function getMaskTemplate(baseOnInput, minimalPos, includeInput) {
                 minimalPos = minimalPos || 0;
                 minimalPos = minimalPos || 0;
                 var maskTemplate = [], ndxIntlzr, pos = 0, test, testPos;
                 var maskTemplate = [], ndxIntlzr, pos = 0, test, testPos;
@@ -312,20 +314,15 @@
                     }
                     }
                     getMaskSet()["validPositions"][pos] = validTest;
                     getMaskSet()["validPositions"][pos] = validTest;
                     var valid = true;
                     var valid = true;
-                    for (i = pos; i <= lvp ;) {
-                        var j = seekNext(i);
-                        if (i == j) valid = false;
+                    for (i = pos; i <= lvp ; i++) {
                         var t = positionsClone[i];
                         var t = positionsClone[i];
                         if (t != undefined) {
                         if (t != undefined) {
-                            var nextTest = getTest(j);
-                            if (nextTest.fn == null && nextTest.def == "")
-                                valid = false;
-                            else if (t["match"].fn == null || t["match"].def == nextTest.def) {
+                            var j = t["match"].fn == null ? i + 1 : seekNext(i);
+                            if (positionCanMatchDefinition(j, t["match"].def)) {
                                 valid = valid && isValid(j, t["input"], true, true) !== false;
                                 valid = valid && isValid(j, t["input"], true, true) !== false;
-                            }
+                            } else valid = false;
                         }
                         }
                         if (!valid) break;
                         if (!valid) break;
-                        i = j;
                     }
                     }
 
 
                     if (!valid) {
                     if (!valid) {
@@ -339,22 +336,23 @@
             }
             }
 
 
             function stripValidPositions(start, end) {
             function stripValidPositions(start, end) {
-                var i, ml, startPos = seekNext(start - 1), lvp;
+                var i, startPos = start, lvp;
                 for (i = start; i < end; i++) { //clear selection
                 for (i = start; i < end; i++) { //clear selection
                     delete getMaskSet()["validPositions"][i];
                     delete getMaskSet()["validPositions"][i];
                 }
                 }
 
 
-                for (i = seekNext(end - 1) ; i <= getLastValidPosition() ; i = seekNext(i)) {
+                for (i = end ; i <= getLastValidPosition() ;) {
                     var t = getMaskSet()["validPositions"][i];
                     var t = getMaskSet()["validPositions"][i];
                     var s = getMaskSet()["validPositions"][startPos];
                     var s = getMaskSet()["validPositions"][startPos];
                     if (t != undefined && s == undefined) {
                     if (t != undefined && s == undefined) {
-                        if (getTest(startPos).def == t.match.def && isValid(startPos, t["input"], true) !== false) {
+                        if (positionCanMatchDefinition(startPos, t.match.def) && isValid(startPos, t["input"], true) !== false) {
                             delete getMaskSet()["validPositions"][i];
                             delete getMaskSet()["validPositions"][i];
+                            i++;
                         }
                         }
-                        startPos = seekNext(startPos);
-                    }
+                        startPos++;
+                    } else i++;
                 }
                 }
-                var lvp = getLastValidPosition();
+                lvp = getLastValidPosition();
                 //catchup
                 //catchup
                 while (lvp > 0 && (getMaskSet()["validPositions"][lvp] == undefined || getMaskSet()["validPositions"][lvp].match.fn == null)) {
                 while (lvp > 0 && (getMaskSet()["validPositions"][lvp] == undefined || getMaskSet()["validPositions"][lvp].match.fn == null)) {
                     delete getMaskSet()["validPositions"][lvp];
                     delete getMaskSet()["validPositions"][lvp];
@@ -380,7 +378,16 @@
                 }
                 }
                 return getTests(pos)[0]["match"];
                 return getTests(pos)[0]["match"];
             }
             }
-
+            function positionCanMatchDefinition(pos, def) {
+                var valid = false, tests = getTests(pos);
+                for (var tndx in tests) {
+                    if (tests[tndx]["match"].def == def) {
+                        valid = true;
+                        break;
+                    }
+                }
+                return valid;
+            };
             function getTests(pos, ndxIntlzr, tstPs) {
             function getTests(pos, ndxIntlzr, tstPs) {
                 var maskTokens = getMaskSet()["maskToken"], testPos = ndxIntlzr ? tstPs : 0, ndxInitializer = ndxIntlzr || [0], matches = [], insertStop = false;
                 var maskTokens = getMaskSet()["maskToken"], testPos = ndxIntlzr ? tstPs : 0, ndxInitializer = ndxIntlzr || [0], matches = [], insertStop = false;
 
 
@@ -1845,7 +1852,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.21
+Version: 3.0.22
 
 
 Optional extensions on the jquery.inputmask base
 Optional extensions on the jquery.inputmask base
 */
 */
@@ -1955,7 +1962,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.21
+Version: 3.0.22
 
 
 Optional extensions on the jquery.inputmask base
 Optional extensions on the jquery.inputmask base
 */
 */
@@ -2418,7 +2425,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.21
+Version: 3.0.22
 
 
 Optional extensions on the jquery.inputmask base
 Optional extensions on the jquery.inputmask base
 */
 */
@@ -2572,7 +2579,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.21
+Version: 3.0.22
 
 
 Regex extensions on the jquery.inputmask base
 Regex extensions on the jquery.inputmask base
 Allows for using regular expressions as a mask
 Allows for using regular expressions as a mask
@@ -2759,7 +2766,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.21
+Version: 3.0.22
 
 
 Phone extension.
 Phone extension.
 When using this extension make sure you specify the correct url to get the masks
 When using this extension make sure you specify the correct url to get the masks

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


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


+ 1 - 1
jquery.inputmask.jquery.json

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

+ 23 - 16
js/jquery.inputmask.js

@@ -249,6 +249,8 @@
                 maxLength;
                 maxLength;
 
 
             //maskset helperfunctions
             //maskset helperfunctions
+
+
             function getMaskTemplate(baseOnInput, minimalPos, includeInput) {
             function getMaskTemplate(baseOnInput, minimalPos, includeInput) {
                 minimalPos = minimalPos || 0;
                 minimalPos = minimalPos || 0;
                 var maskTemplate = [], ndxIntlzr, pos = 0, test, testPos;
                 var maskTemplate = [], ndxIntlzr, pos = 0, test, testPos;
@@ -312,20 +314,15 @@
                     }
                     }
                     getMaskSet()["validPositions"][pos] = validTest;
                     getMaskSet()["validPositions"][pos] = validTest;
                     var valid = true;
                     var valid = true;
-                    for (i = pos; i <= lvp ;) {
-                        var j = seekNext(i);
-                        if (i == j) valid = false;
+                    for (i = pos; i <= lvp ; i++) {
                         var t = positionsClone[i];
                         var t = positionsClone[i];
                         if (t != undefined) {
                         if (t != undefined) {
-                            var nextTest = getTest(j);
-                            if (nextTest.fn == null && nextTest.def == "")
-                                valid = false;
-                            else if (t["match"].fn == null || t["match"].def == nextTest.def) {
+                            var j = t["match"].fn == null ? i + 1 : seekNext(i);
+                            if (positionCanMatchDefinition(j, t["match"].def)) {
                                 valid = valid && isValid(j, t["input"], true, true) !== false;
                                 valid = valid && isValid(j, t["input"], true, true) !== false;
-                            }
+                            } else valid = false;
                         }
                         }
                         if (!valid) break;
                         if (!valid) break;
-                        i = j;
                     }
                     }
 
 
                     if (!valid) {
                     if (!valid) {
@@ -339,22 +336,23 @@
             }
             }
 
 
             function stripValidPositions(start, end) {
             function stripValidPositions(start, end) {
-                var i, ml, startPos = seekNext(start - 1), lvp;
+                var i, startPos = start, lvp;
                 for (i = start; i < end; i++) { //clear selection
                 for (i = start; i < end; i++) { //clear selection
                     delete getMaskSet()["validPositions"][i];
                     delete getMaskSet()["validPositions"][i];
                 }
                 }
 
 
-                for (i = seekNext(end - 1) ; i <= getLastValidPosition() ; i = seekNext(i)) {
+                for (i = end ; i <= getLastValidPosition() ;) {
                     var t = getMaskSet()["validPositions"][i];
                     var t = getMaskSet()["validPositions"][i];
                     var s = getMaskSet()["validPositions"][startPos];
                     var s = getMaskSet()["validPositions"][startPos];
                     if (t != undefined && s == undefined) {
                     if (t != undefined && s == undefined) {
-                        if (getTest(startPos).def == t.match.def && isValid(startPos, t["input"], true) !== false) {
+                        if (positionCanMatchDefinition(startPos, t.match.def) && isValid(startPos, t["input"], true) !== false) {
                             delete getMaskSet()["validPositions"][i];
                             delete getMaskSet()["validPositions"][i];
+                            i++;
                         }
                         }
-                        startPos = seekNext(startPos);
-                    }
+                        startPos++;
+                    } else i++;
                 }
                 }
-                var lvp = getLastValidPosition();
+                lvp = getLastValidPosition();
                 //catchup
                 //catchup
                 while (lvp > 0 && (getMaskSet()["validPositions"][lvp] == undefined || getMaskSet()["validPositions"][lvp].match.fn == null)) {
                 while (lvp > 0 && (getMaskSet()["validPositions"][lvp] == undefined || getMaskSet()["validPositions"][lvp].match.fn == null)) {
                     delete getMaskSet()["validPositions"][lvp];
                     delete getMaskSet()["validPositions"][lvp];
@@ -380,7 +378,16 @@
                 }
                 }
                 return getTests(pos)[0]["match"];
                 return getTests(pos)[0]["match"];
             }
             }
-
+            function positionCanMatchDefinition(pos, def) {
+                var valid = false, tests = getTests(pos);
+                for (var tndx in tests) {
+                    if (tests[tndx]["match"].def == def) {
+                        valid = true;
+                        break;
+                    }
+                }
+                return valid;
+            };
             function getTests(pos, ndxIntlzr, tstPs) {
             function getTests(pos, ndxIntlzr, tstPs) {
                 var maskTokens = getMaskSet()["maskToken"], testPos = ndxIntlzr ? tstPs : 0, ndxInitializer = ndxIntlzr || [0], matches = [], insertStop = false;
                 var maskTokens = getMaskSet()["maskToken"], testPos = ndxIntlzr ? tstPs : 0, ndxInitializer = ndxIntlzr || [0], matches = [], insertStop = false;
 
 

+ 1 - 0
qunit/tests.js

@@ -1299,6 +1299,7 @@ test("inputmask(\"decimal\", { autoGroup: false, groupSeparator: \",\" }\") - in
     $("#testmask").SendKey(keyCodes.DELETE);
     $("#testmask").SendKey(keyCodes.DELETE);
     $("#testmask").SendKey(keyCodes.DELETE);
     $("#testmask").SendKey(keyCodes.DELETE);
     $("#testmask").SendKey(keyCodes.DELETE);
     $("#testmask").SendKey(keyCodes.DELETE);
+    $("#testmask").SendKey(keyCodes.DELETE);
     $("#testmask").Type(".789");
     $("#testmask").Type(".789");
 
 
     equal($("#testmask").val(), "12345.789", "Result " + $("#testmask").val());
     equal($("#testmask").val(), "12345.789", "Result " + $("#testmask").val());