Browse Source

first version of the numeric alias + some fixes

Robin Herbots 11 years ago
parent
commit
75438b5347

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
 {
     "name": "jquery.inputmask",
     "name": "jquery.inputmask",
-    "version": "3.0.4",
+    "version": "3.0.5",
     "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 = 4
+build.revision = 5
 
 
 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.5.nupkg


+ 39 - 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.4
+* Version: 3.0.5
 */
 */
 
 
 (function ($) {
 (function ($) {
@@ -242,7 +242,7 @@
                         ndxIntlzr = validPos["locator"].slice();
                         ndxIntlzr = validPos["locator"].slice();
                         maskTemplate.push(test["fn"] == null ? test["def"] : (includeInput === true ? validPos["input"] : opts.placeholder.charAt(pos % opts.placeholder.length)));
                         maskTemplate.push(test["fn"] == null ? test["def"] : (includeInput === true ? validPos["input"] : opts.placeholder.charAt(pos % opts.placeholder.length)));
                     } else {
                     } else {
-                        var testPos = getTests(pos, true, ndxIntlzr, pos - 1);
+                        var testPos = getTests(pos, ndxIntlzr, pos - 1);
                         testPos = testPos[opts.greedy || minimalPos > pos ? 0 : (testPos.length - 1)];
                         testPos = testPos[opts.greedy || minimalPos > pos ? 0 : (testPos.length - 1)];
                         test = testPos["match"];
                         test = testPos["match"];
                         ndxIntlzr = testPos["locator"].slice();
                         ndxIntlzr = testPos["locator"].slice();
@@ -340,7 +340,7 @@
                 return getTests(pos)[0]["match"];
                 return getTests(pos)[0]["match"];
             }
             }
 
 
-            function getTests(pos, disableCache, 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;
 
 
                 function ResolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) { //ndxInitilizer contains a set of indexes to speedup searches in the mtokens
                 function ResolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) { //ndxInitilizer contains a set of indexes to speedup searches in the mtokens
@@ -411,9 +411,9 @@
                     }
                     }
                 }
                 }
 
 
-                if (disableCache !== true && getMaskSet()['tests'][pos] && !getMaskSet()['validPositions'][pos]) {
-                    return getMaskSet()['tests'][pos];
-                }
+                //if (disableCache !== true && getMaskSet()['tests'][pos] && !getMaskSet()['validPositions'][pos]) {
+                //    return getMaskSet()['tests'][pos];
+                //}
                 if (ndxIntlzr == undefined) {
                 if (ndxIntlzr == undefined) {
                     var previousPos = pos - 1, test;
                     var previousPos = pos - 1, test;
                     while ((test = getMaskSet()['validPositions'][previousPos]) == undefined && previousPos > -1) {
                     while ((test = getMaskSet()['validPositions'][previousPos]) == undefined && previousPos > -1) {
@@ -463,11 +463,10 @@
             }
             }
 
 
             function refreshFromBuffer(start, end) {
             function refreshFromBuffer(start, end) {
-                var buffer = getBuffer();
+                var buffer = getBuffer().slice(); //work on clone
                 for (var i = start; i < end; i++) {
                 for (var i = start; i < end; i++) {
-                    if (buffer[i] != getPlaceholder(i)) {
-                        var ltst = getTests(i, false)[0];
-                        setValidPosition(i, $.extend({}, ltst, { "input": casing(buffer[i], ltst["match"]) }), true);
+                    if (buffer[i] != getPlaceholder(i) && buffer[i] != opts.skipOptionalPartCharacter) {
+                        isValid(i, buffer[i], true, true);
                     }
                     }
                 }
                 }
             }
             }
@@ -491,7 +490,7 @@
                 function _isValid(position, c, strict, fromSetValid) {
                 function _isValid(position, c, strict, fromSetValid) {
 
 
                     var rslt = false;
                     var rslt = false;
-                    $.each(getTests(position, !strict), function (ndx, tst) {
+                    $.each(getTests(position), function (ndx, tst) {
                         var test = tst["match"];
                         var test = tst["match"];
                         var loopend = c ? 1 : 0, chrs = '', buffer = getBuffer();
                         var loopend = c ? 1 : 0, chrs = '', buffer = getBuffer();
                         for (var i = test.cardinality; i > loopend; i--) {
                         for (var i = test.cardinality; i > loopend; i--) {
@@ -516,19 +515,25 @@
                             if (rslt["refreshFromBuffer"]) {
                             if (rslt["refreshFromBuffer"]) {
                                 var refresh = rslt["refreshFromBuffer"];
                                 var refresh = rslt["refreshFromBuffer"];
                                 strict = true;
                                 strict = true;
-                                validatedPos = rslt.pos != undefined ? rslt.pos : position;
-                                tst = getTests(validatedPos, !strict)[0]; //possible mismatch TODO
                                 if (refresh === true) {
                                 if (refresh === true) {
                                     getMaskSet()["validPositions"] = {};
                                     getMaskSet()["validPositions"] = {};
+                                    getMaskSet()["tests"] = {};
                                     refreshFromBuffer(0, getBuffer().length);
                                     refreshFromBuffer(0, getBuffer().length);
                                 }
                                 }
                                 else {
                                 else {
                                     refreshFromBuffer(refresh["start"], refresh["end"]);
                                     refreshFromBuffer(refresh["start"], refresh["end"]);
                                 }
                                 }
+                                if (rslt.pos == undefined) {
+                                    rslt.pos = getLastValidPosition();
+                                    return false;//breakout if refreshFromBuffer && nothing to insert
+                                } 
+                                validatedPos = rslt.pos != undefined ? rslt.pos : position;
+                                tst = getTests(validatedPos)[0]; //possible mismatch TODO
+
                             } else if (rslt !== true && rslt["pos"] != position) { //their is a position offset
                             } else if (rslt !== true && rslt["pos"] != position) { //their is a position offset
                                 validatedPos = rslt["pos"];
                                 validatedPos = rslt["pos"];
                                 refreshFromBuffer(position, validatedPos);
                                 refreshFromBuffer(position, validatedPos);
-                                tst = getTests(validatedPos, !strict)[0]; //possible mismatch TODO
+                                tst = getTests(validatedPos)[0]; //possible mismatch TODO
                             }
                             }
                             if (ndx > 0) {
                             if (ndx > 0) {
                                 resetMaskSet(true);
                                 resetMaskSet(true);
@@ -1822,7 +1827,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.4
+Version: 3.0.5
 
 
 Optional extensions on the jquery.inputmask base
 Optional extensions on the jquery.inputmask base
 */
 */
@@ -1932,7 +1937,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.4
+Version: 3.0.5
 
 
 Optional extensions on the jquery.inputmask base
 Optional extensions on the jquery.inputmask base
 */
 */
@@ -2395,7 +2400,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.4
+Version: 3.0.5
 
 
 Optional extensions on the jquery.inputmask base
 Optional extensions on the jquery.inputmask base
 */
 */
@@ -2456,13 +2461,25 @@ Optional extensions on the jquery.inputmask base
                 return reformatOnly ? pos : newPos;
                 return reformatOnly ? pos : newPos;
             },
             },
             regex: {
             regex: {
-                signed: function (opts) { }
+                integerPart: function (opts) { return new RegExp('[-\+]?\\d+'); }
             },
             },
             definitions: {
             definitions: {
                 '~': {
                 '~': {
                     validator: function (chrs, buffer, pos, strict, opts) {
                     validator: function (chrs, buffer, pos, strict, opts) {
-                        if (chrs === "-") {
-                            //negate value
+                        if (!strict && chrs === "-") {
+                            var matchRslt = buffer.join('').match(opts.regex.integerPart(opts));
+
+                            if (matchRslt.length > 0) {
+                                if (buffer[matchRslt.index] == "+") {
+                                    buffer.splice(matchRslt.index, 1);
+                                    return { "pos": matchRslt.index, "c": "-", "refreshFromBuffer": true };
+                                } else if (buffer[matchRslt.index] == "-") {
+                                    buffer.splice(matchRslt.index, 1);
+                                    return { "refreshFromBuffer": true };
+                                } else {
+                                    return { "pos": matchRslt.index, "c": "-" };
+                                }
+                            }
                         }
                         }
                         var isValid = new RegExp("[0-9]").test(chrs);
                         var isValid = new RegExp("[0-9]").test(chrs);
                         return isValid;
                         return isValid;
@@ -2646,7 +2663,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.4
+Version: 3.0.5
 
 
 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
@@ -2833,7 +2850,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.4
+Version: 3.0.5
 
 
 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
+ 89 - 89
dist/jquery.inputmask.bundle.min.js


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


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


+ 1 - 1
jquery.inputmask.jquery.json

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

+ 18 - 13
js/jquery.inputmask.js

@@ -242,7 +242,7 @@
                         ndxIntlzr = validPos["locator"].slice();
                         ndxIntlzr = validPos["locator"].slice();
                         maskTemplate.push(test["fn"] == null ? test["def"] : (includeInput === true ? validPos["input"] : opts.placeholder.charAt(pos % opts.placeholder.length)));
                         maskTemplate.push(test["fn"] == null ? test["def"] : (includeInput === true ? validPos["input"] : opts.placeholder.charAt(pos % opts.placeholder.length)));
                     } else {
                     } else {
-                        var testPos = getTests(pos, true, ndxIntlzr, pos - 1);
+                        var testPos = getTests(pos, ndxIntlzr, pos - 1);
                         testPos = testPos[opts.greedy || minimalPos > pos ? 0 : (testPos.length - 1)];
                         testPos = testPos[opts.greedy || minimalPos > pos ? 0 : (testPos.length - 1)];
                         test = testPos["match"];
                         test = testPos["match"];
                         ndxIntlzr = testPos["locator"].slice();
                         ndxIntlzr = testPos["locator"].slice();
@@ -340,7 +340,7 @@
                 return getTests(pos)[0]["match"];
                 return getTests(pos)[0]["match"];
             }
             }
 
 
-            function getTests(pos, disableCache, 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;
 
 
                 function ResolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) { //ndxInitilizer contains a set of indexes to speedup searches in the mtokens
                 function ResolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) { //ndxInitilizer contains a set of indexes to speedup searches in the mtokens
@@ -411,9 +411,9 @@
                     }
                     }
                 }
                 }
 
 
-                if (disableCache !== true && getMaskSet()['tests'][pos] && !getMaskSet()['validPositions'][pos]) {
-                    return getMaskSet()['tests'][pos];
-                }
+                //if (disableCache !== true && getMaskSet()['tests'][pos] && !getMaskSet()['validPositions'][pos]) {
+                //    return getMaskSet()['tests'][pos];
+                //}
                 if (ndxIntlzr == undefined) {
                 if (ndxIntlzr == undefined) {
                     var previousPos = pos - 1, test;
                     var previousPos = pos - 1, test;
                     while ((test = getMaskSet()['validPositions'][previousPos]) == undefined && previousPos > -1) {
                     while ((test = getMaskSet()['validPositions'][previousPos]) == undefined && previousPos > -1) {
@@ -463,11 +463,10 @@
             }
             }
 
 
             function refreshFromBuffer(start, end) {
             function refreshFromBuffer(start, end) {
-                var buffer = getBuffer();
+                var buffer = getBuffer().slice(); //work on clone
                 for (var i = start; i < end; i++) {
                 for (var i = start; i < end; i++) {
-                    if (buffer[i] != getPlaceholder(i)) {
-                        var ltst = getTests(i, false)[0];
-                        setValidPosition(i, $.extend({}, ltst, { "input": casing(buffer[i], ltst["match"]) }), true);
+                    if (buffer[i] != getPlaceholder(i) && buffer[i] != opts.skipOptionalPartCharacter) {
+                        isValid(i, buffer[i], true, true);
                     }
                     }
                 }
                 }
             }
             }
@@ -491,7 +490,7 @@
                 function _isValid(position, c, strict, fromSetValid) {
                 function _isValid(position, c, strict, fromSetValid) {
 
 
                     var rslt = false;
                     var rslt = false;
-                    $.each(getTests(position, !strict), function (ndx, tst) {
+                    $.each(getTests(position), function (ndx, tst) {
                         var test = tst["match"];
                         var test = tst["match"];
                         var loopend = c ? 1 : 0, chrs = '', buffer = getBuffer();
                         var loopend = c ? 1 : 0, chrs = '', buffer = getBuffer();
                         for (var i = test.cardinality; i > loopend; i--) {
                         for (var i = test.cardinality; i > loopend; i--) {
@@ -516,19 +515,25 @@
                             if (rslt["refreshFromBuffer"]) {
                             if (rslt["refreshFromBuffer"]) {
                                 var refresh = rslt["refreshFromBuffer"];
                                 var refresh = rslt["refreshFromBuffer"];
                                 strict = true;
                                 strict = true;
-                                validatedPos = rslt.pos != undefined ? rslt.pos : position;
-                                tst = getTests(validatedPos, !strict)[0]; //possible mismatch TODO
                                 if (refresh === true) {
                                 if (refresh === true) {
                                     getMaskSet()["validPositions"] = {};
                                     getMaskSet()["validPositions"] = {};
+                                    getMaskSet()["tests"] = {};
                                     refreshFromBuffer(0, getBuffer().length);
                                     refreshFromBuffer(0, getBuffer().length);
                                 }
                                 }
                                 else {
                                 else {
                                     refreshFromBuffer(refresh["start"], refresh["end"]);
                                     refreshFromBuffer(refresh["start"], refresh["end"]);
                                 }
                                 }
+                                if (rslt.pos == undefined) {
+                                    rslt.pos = getLastValidPosition();
+                                    return false;//breakout if refreshFromBuffer && nothing to insert
+                                } 
+                                validatedPos = rslt.pos != undefined ? rslt.pos : position;
+                                tst = getTests(validatedPos)[0]; //possible mismatch TODO
+
                             } else if (rslt !== true && rslt["pos"] != position) { //their is a position offset
                             } else if (rslt !== true && rslt["pos"] != position) { //their is a position offset
                                 validatedPos = rslt["pos"];
                                 validatedPos = rslt["pos"];
                                 refreshFromBuffer(position, validatedPos);
                                 refreshFromBuffer(position, validatedPos);
-                                tst = getTests(validatedPos, !strict)[0]; //possible mismatch TODO
+                                tst = getTests(validatedPos)[0]; //possible mismatch TODO
                             }
                             }
                             if (ndx > 0) {
                             if (ndx > 0) {
                                 resetMaskSet(true);
                                 resetMaskSet(true);

+ 15 - 3
js/jquery.inputmask.numeric.extensions.js

@@ -64,13 +64,25 @@ Optional extensions on the jquery.inputmask base
                 return reformatOnly ? pos : newPos;
                 return reformatOnly ? pos : newPos;
             },
             },
             regex: {
             regex: {
-                signed: function (opts) { }
+                integerPart: function (opts) { return new RegExp('[-\+]?\\d+'); }
             },
             },
             definitions: {
             definitions: {
                 '~': {
                 '~': {
                     validator: function (chrs, buffer, pos, strict, opts) {
                     validator: function (chrs, buffer, pos, strict, opts) {
-                        if (chrs === "-") {
-                            //negate value
+                        if (!strict && chrs === "-") {
+                            var matchRslt = buffer.join('').match(opts.regex.integerPart(opts));
+
+                            if (matchRslt.length > 0) {
+                                if (buffer[matchRslt.index] == "+") {
+                                    buffer.splice(matchRslt.index, 1);
+                                    return { "pos": matchRslt.index, "c": "-", "refreshFromBuffer": true };
+                                } else if (buffer[matchRslt.index] == "-") {
+                                    buffer.splice(matchRslt.index, 1);
+                                    return { "refreshFromBuffer": true };
+                                } else {
+                                    return { "pos": matchRslt.index, "c": "-" };
+                                }
+                            }
                         }
                         }
                         var isValid = new RegExp("[0-9]").test(chrs);
                         var isValid = new RegExp("[0-9]").test(chrs);
                         return isValid;
                         return isValid;

+ 12 - 0
qunit/tests.js

@@ -1169,6 +1169,18 @@ test("inputmask(\"dd/mm/yyyy\") - input 01011000 - Skiv22", function () {
 
 
 
 
 module("Numeric.Extensions");
 module("Numeric.Extensions");
+test("inputmask(\"numeric\", { prefix: \"€ \" }\") - input 12345.12", function () {
+    var $fixture = $("#qunit-fixture");
+    $fixture.append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask("numeric", { prefix: "€ " });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("12345.12");
+  
+    equal($("#testmask").val(), "€ 12345.12", "Result " + $("#testmask").val());
+    $("#testmask").remove();
+});
+
 test("inputmask(\"decimal\", { autoGroup: true, groupSeparator: \",\" }\") - input 12345.123", function () {
 test("inputmask(\"decimal\", { autoGroup: true, groupSeparator: \",\" }\") - input 12345.123", function () {
     var $fixture = $("#qunit-fixture");
     var $fixture = $("#qunit-fixture");
     $fixture.append('<input type="text" id="testmask" />');
     $fixture.append('<input type="text" id="testmask" />');