ソースを参照

optimize multimask handling

Robin Herbots 12 年 前
コミット
dda4d921ac

+ 1 - 1
component.json

@@ -1,6 +1,6 @@
 {
     "name": "jquery.inputmask",
-    "version": "2.3.2",
+    "version": "2.3.3",
     "main": "./dist/jquery.inputmask.bundle.js",
     "dependencies": {
         "jquery": ">=1.5"

BIN
dist/jQuery.InputMask.2.3.2.nupkg


BIN
dist/jQuery.InputMask.2.3.3.nupkg


+ 11 - 7
dist/jquery.inputmask.bundle.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2013 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 2.3.2
+* Version: 2.3.3
 */
 
 (function ($) {
@@ -465,8 +465,12 @@
                                 results.push({ "activeMasksetIndex": index, "result": { "refresh": true, c: activeMaskset['_buffer'][maskPos] } }); //new command hack only rewrite buffer
                                 activeMaskset['lastValidPosition'] = maskPos;
                                 return false;
-                            } else activeMaskset['lastValidPosition'] = isRTL ? getMaskLength() + 1 : -1; //mark mask as validated and invalid
-                            //maskPos = isRTL ? seekPrevious(pos) : seekNext(pos);
+                            } else {
+                                if (masksets[currentActiveMasksetIndex]["lastValidPosition"] >= maskPos)
+                                    activeMaskset['lastValidPosition'] = isRTL ? getMaskLength() + 1 : -1; //mark mask as validated and invalid
+                                else maskPos = isRTL ? seekPrevious(pos) : seekNext(pos);
+                            }
+
                         }
                         if ((activeMaskset['lastValidPosition'] == undefined
                                 && maskPos == (isRTL ? seekPrevious(getMaskLength()) : seekNext(-1))
@@ -1491,7 +1495,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2013 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.3.2
+Version: 2.3.3
 
 Optional extensions on the jquery.inputmask base
 */
@@ -1593,7 +1597,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2012 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.3.2
+Version: 2.3.3
 
 Optional extensions on the jquery.inputmask base
 */
@@ -2062,7 +2066,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2013 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.3.2
+Version: 2.3.3
 
 Optional extensions on the jquery.inputmask base
 */
@@ -2229,7 +2233,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2013 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.3.2
+Version: 2.3.3
 
 Regex extensions on the jquery.inputmask base
 Allows for using regular expressions as a mask

ファイルの差分が大きいため隠しています
+ 67 - 67
dist/jquery.inputmask.bundle.min.js


ファイルの差分が大きいため隠しています
+ 44 - 44
dist/min/jquery.inputmask.js


+ 1 - 1
jquery.inputmask.jquery.json

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

+ 6 - 2
js/jquery.inputmask.js

@@ -465,8 +465,12 @@
                                 results.push({ "activeMasksetIndex": index, "result": { "refresh": true, c: activeMaskset['_buffer'][maskPos] } }); //new command hack only rewrite buffer
                                 activeMaskset['lastValidPosition'] = maskPos;
                                 return false;
-                            } else activeMaskset['lastValidPosition'] = isRTL ? getMaskLength() + 1 : -1; //mark mask as validated and invalid
-                            //maskPos = isRTL ? seekPrevious(pos) : seekNext(pos);
+                            } else {
+                                if (masksets[currentActiveMasksetIndex]["lastValidPosition"] >= maskPos)
+                                    activeMaskset['lastValidPosition'] = isRTL ? getMaskLength() + 1 : -1; //mark mask as validated and invalid
+                                else maskPos = isRTL ? seekPrevious(pos) : seekNext(pos);
+                            }
+
                         }
                         if ((activeMaskset['lastValidPosition'] == undefined
                                 && maskPos == (isRTL ? seekPrevious(getMaskLength()) : seekNext(-1))

+ 22 - 0
qunit/tests.js

@@ -514,6 +514,28 @@ test("inputmask({ mask: [\"99999\", \"99999-9999\"]]}) - input 1234512", functio
     $("#testmask").remove();
 });
 
+test("inputmask({ mask: [\"99999\", \"99999-9999\"]]}) - input 1234561234", function () {
+    $('body').append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask({ mask: ["99999", "99999-9999", "999999-9999" ] });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("1234561234");
+    equal($("#testmask").val(), "123456-1234", "Result " + $("#testmask").val());
+
+    $("#testmask").remove();
+});
+test("inputmask({ mask: [\"99999\", \"99999-9999\"]]}) - input 123456", function () {
+    $('body').append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask({ mask: ["99999", "99999-9999", "999999-9999"] });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("123456");
+    equal($("#testmask").val(), "12345-6___", "Result " + $("#testmask").val());
+    //this is correct as see sequence of the masks || currently "99999-9999", "999999-9999" are valid and thus showing "99999-9999"
+
+    $("#testmask").remove();
+});
+
 module("Date.Extensions");
 test("inputmask(\"dd/mm/yyyy\") - input 2331973", function () {
     $('body').append('<input type="text" id="testmask" />');