Browse Source

fix prototype extensions on array string handling

Robin Herbots 11 years ago
parent
commit
345585e335

+ 4 - 3
dist/inputmask/jquery.inputmask.js

@@ -468,9 +468,10 @@
             function trackbackAlternations(originalPos, newPos) {
                 for (var vp = getMaskSet().validPositions[newPos], targetLocator = vp.locator, tll = targetLocator.length, ps = originalPos; newPos > ps; ps++) if (!isMask(ps)) {
                     var tests = getTests(ps), bestMatch = tests[0], equality = -1;
-                    for (var tndx in tests) for (var activeTest = tests[tndx], i = 0; tll > i; i++) activeTest.locator[i] && checkAlternationMatch(activeTest.locator[i].toString().split(","), targetLocator[i].toString().split(",")) && i > equality && (equality = i, 
-                    bestMatch = activeTest);
-                    setValidPosition(ps, $.extend({}, bestMatch, {
+                    $.each(tests, function(ndx, tst) {
+                        for (var i = 0; tll > i; i++) tst.locator[i] && checkAlternationMatch(tst.locator[i].toString().split(","), targetLocator[i].toString().split(",")) && i > equality && (equality = i, 
+                        bestMatch = tst);
+                    }), setValidPosition(ps, $.extend({}, bestMatch, {
                         input: bestMatch.match.def
                     }), !0);
                 }

+ 4 - 3
dist/jquery.inputmask.bundle.js

@@ -466,9 +466,10 @@
             function trackbackAlternations(originalPos, newPos) {
                 for (var vp = getMaskSet().validPositions[newPos], targetLocator = vp.locator, tll = targetLocator.length, ps = originalPos; newPos > ps; ps++) if (!isMask(ps)) {
                     var tests = getTests(ps), bestMatch = tests[0], equality = -1;
-                    for (var tndx in tests) for (var activeTest = tests[tndx], i = 0; tll > i; i++) activeTest.locator[i] && checkAlternationMatch(activeTest.locator[i].toString().split(","), targetLocator[i].toString().split(",")) && i > equality && (equality = i, 
-                    bestMatch = activeTest);
-                    setValidPosition(ps, $.extend({}, bestMatch, {
+                    $.each(tests, function(ndx, tst) {
+                        for (var i = 0; tll > i; i++) tst.locator[i] && checkAlternationMatch(tst.locator[i].toString().split(","), targetLocator[i].toString().split(",")) && i > equality && (equality = i, 
+                        bestMatch = tst);
+                    }), setValidPosition(ps, $.extend({}, bestMatch, {
                         input: bestMatch.match.def
                     }), !0);
                 }

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


+ 4 - 5
js/jquery.inputmask.js

@@ -852,16 +852,15 @@
                         if (!isMask(ps)) {
                             var tests = getTests(ps),
                             bestMatch = tests[0], equality = -1;
-                            for (var tndx in tests) {
-                                var activeTest = tests[tndx];
+                            $.each(tests, function(ndx, tst) {
                                 for (var i = 0; i < tll; i++) {
-                                    if (activeTest.locator[i] && checkAlternationMatch(activeTest.locator[i].toString().split(','), targetLocator[i].toString().split(',')) && equality < i) { //needs fix for locators with multiple alternations
+                                    if (tst.locator[i] && checkAlternationMatch(tst.locator[i].toString().split(','), targetLocator[i].toString().split(',')) && equality < i) {
                                         equality = i;
-                                        bestMatch = activeTest;
+                                        bestMatch = tst;
                                     }
                                 }
                                 //console.log(bestMatch.locator);
-                            }
+                            });
                             setValidPosition(ps, $.extend({}, bestMatch, { "input": bestMatch["match"].def }), true)
                         }
                     }

+ 13 - 0
qunit/prototypeExtensions.js

@@ -0,0 +1,13 @@
+/*
+
+These are dummy prototype extensions to test that the inputmask code can deal with an extension
+
+*/
+
+Array.prototype.dummy = function(){
+ 	return false;
+}
+
+String.prototype.dummy = function(){
+ 	return false;
+}

+ 1 - 0
qunit/qunit.html

@@ -11,6 +11,7 @@
   <script src="http://code.jquery.com/jquery-1.11.0.js"></script>
   <script src="http://code.jquery.com/qunit/qunit-1.14.0.js"></script>
   <script src="../dist/jquery.inputmask.bundle.js"></script>
+  <script src="./prototypeExtensions.js"></script>
   <script src="./simulator.js"></script>
   <script src="./tests_base.js"></script>
   <script src="./tests_setvalue.js"></script>