Browse Source

disable cache when a custom definition is passed though options. fix #831

Robin Herbots 10 years ago
parent
commit
4cd22fb988

+ 1 - 0
CHANGELOG.md

@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
 - Add Component package manager support - component.json 
 
 ### Fixed
+- Mask cache - 2 definitions for same mask #831
 - Adding parentheses as a negative format for Decimal and Integer aliases (100) #451
 - Should not allow "-" or "+" as numbers #815
 - isComplete erroneously returning false when backspacing with an optional mask #824

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
   "name": "jquery.inputmask",
-  "version": "3.1.62-4",
+  "version": "3.1.62-6",
   "main": [
     "./dist/inputmask/jquery.inputmask.js",
     "./dist/inputmask/jquery.inputmask.extensions.js",

+ 1 - 1
component.json

@@ -2,7 +2,7 @@
     "name": "jquery_inputmask",
     "repository": "robinherbots/jquery.inputmask",
     "description": "jquery.inputmask is a jquery plugin which create an input mask.",
-    "version": "3.1.62-4",
+    "version": "3.1.62-6",
     "keywords": [ "jquery", "plugins", "input", "form", "inputmask", "mask" ],
     "main": "./dist/jquery.inputmask.bundle.js",
     "scripts": [

+ 1 - 1
composer.json

@@ -1,7 +1,7 @@
 {
     "name": "robinherbots/jquery.inputmask",
     "description": "jquery.inputmask is a jquery plugin which create an input mask.",
-	"version": "3.1.62-4",
+	"version": "3.1.62-6",
     "type": "library",
     "keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
     "homepage": "http://robinherbots.github.io/jquery.inputmask",

+ 1 - 1
dist/inputmask/jquery.inputmask.date.extensions.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.62-4
+* Version: 3.1.62-6
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : factory(jQuery);

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


+ 1 - 1
dist/inputmask/jquery.inputmask.extensions.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.62-4
+* Version: 3.1.62-6
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : factory(jQuery);

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


+ 14 - 9
dist/inputmask/jquery.inputmask.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.62-4
+* Version: 3.1.62-6
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery" ], factory) : factory(jQuery);
@@ -26,7 +26,7 @@
         return aliasDefinition ? (aliasDefinition.alias && resolveAlias(aliasDefinition.alias, void 0, opts), 
         $.extend(!0, opts, aliasDefinition), $.extend(!0, opts, options), !0) : !1;
     }
-    function generateMaskSet(opts) {
+    function generateMaskSet(opts, nocache) {
         function analyseMask(mask) {
             function maskToken(isGroup, isOptional, isQuantifier, isAlternator) {
                 this.matches = [], this.isGroup = isGroup || !1, this.isOptional = isOptional || !1, 
@@ -162,7 +162,8 @@
                 var repeatStart = "*" == opts.repeat ? 0 : "+" == opts.repeat ? 1 : opts.repeat;
                 mask = opts.groupmarker.start + mask + opts.groupmarker.end + opts.quantifiermarker.start + repeatStart + "," + opts.repeat + opts.quantifiermarker.end;
             }
-            return void 0 == $.inputmask.masksCache[mask] && ($.inputmask.masksCache[mask] = {
+            var masksetDefinition;
+            return void 0 == $.inputmask.masksCache[mask] || nocache === !0 ? (masksetDefinition = {
                 mask: mask,
                 maskToken: analyseMask(mask),
                 validPositions: {},
@@ -170,7 +171,8 @@
                 buffer: void 0,
                 tests: {},
                 metadata: metadata
-            }), $.extend(!0, {}, $.inputmask.masksCache[mask]);
+            }, nocache !== !0 && ($.inputmask.masksCache[mask] = masksetDefinition)) : masksetDefinition = $.extend(!0, {}, $.inputmask.masksCache[mask]), 
+            masksetDefinition;
         }
         function preProcessMask(mask) {
             if (mask = mask.toString(), opts.numericInput) {
@@ -1179,14 +1181,14 @@
                     action: "format",
                     value: value,
                     metadata: metadata
-                }, generateMaskSet(opts), opts);
+                }, generateMaskSet(opts, options && void 0 !== options.definitions), opts);
             },
             isValid: function(value, options) {
                 var opts = $.extend(!0, {}, $.inputmask.defaults, options);
                 return resolveAlias(opts.alias, options, opts), maskScope({
                     action: "isValid",
                     value: value
-                }, generateMaskSet(opts), opts);
+                }, generateMaskSet(opts, options && void 0 !== options.definitions), opts);
             }
         }, $.fn.inputmask = function(fn, options) {
             function importAttributeOptions(npt, opts, importedOptionsContainer) {
@@ -1204,7 +1206,8 @@
             if ("string" == typeof fn) switch (fn) {
               case "mask":
                 return resolveAlias(opts.alias, options, opts), this.each(function() {
-                    return importAttributeOptions(this, opts), maskset = generateMaskSet(opts), void 0 == maskset ? this : void maskScope({
+                    return importAttributeOptions(this, opts), maskset = generateMaskSet(opts, options && void 0 !== options.definitions), 
+                    void 0 == maskset ? this : void maskScope({
                         action: "mask",
                         el: this
                     }, maskset, opts);
@@ -1251,7 +1254,8 @@
               default:
                 return resolveAlias(opts.alias, options, opts), resolveAlias(fn, options, opts) || (opts.mask = fn), 
                 this.each(function() {
-                    return importAttributeOptions(this, opts), maskset = generateMaskSet(opts), void 0 == maskset ? this : void maskScope({
+                    return importAttributeOptions(this, opts), maskset = generateMaskSet(opts, options && void 0 !== options.definitions), 
+                    void 0 == maskset ? this : void maskScope({
                         action: "mask",
                         el: this
                     }, maskset, opts);
@@ -1259,7 +1263,8 @@
             } else {
                 if ("object" == typeof fn) return opts = $.extend(!0, {}, $.inputmask.defaults, fn), 
                 resolveAlias(opts.alias, fn, opts), this.each(function() {
-                    return importAttributeOptions(this, opts), maskset = generateMaskSet(opts), void 0 == maskset ? this : void maskScope({
+                    return importAttributeOptions(this, opts), maskset = generateMaskSet(opts, fn && void 0 !== fn.definitions), 
+                    void 0 == maskset ? this : void maskScope({
                         action: "mask",
                         el: this
                     }, maskset, opts);

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


+ 1 - 1
dist/inputmask/jquery.inputmask.numeric.extensions.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.62-4
+* Version: 3.1.62-6
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : factory(jQuery);

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


+ 1 - 1
dist/inputmask/jquery.inputmask.phone.extensions.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.62-4
+* Version: 3.1.62-6
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : factory(jQuery);

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


+ 1 - 1
dist/inputmask/jquery.inputmask.regex.extensions.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.62-4
+* Version: 3.1.62-6
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : factory(jQuery);

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


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

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.62-4
+* Version: 3.1.62-6
 */
 !function($) {
     function isInputEventSupported(eventName) {
@@ -24,7 +24,7 @@
         return aliasDefinition ? (aliasDefinition.alias && resolveAlias(aliasDefinition.alias, void 0, opts), 
         $.extend(!0, opts, aliasDefinition), $.extend(!0, opts, options), !0) : !1;
     }
-    function generateMaskSet(opts) {
+    function generateMaskSet(opts, nocache) {
         function analyseMask(mask) {
             function maskToken(isGroup, isOptional, isQuantifier, isAlternator) {
                 this.matches = [], this.isGroup = isGroup || !1, this.isOptional = isOptional || !1, 
@@ -160,7 +160,8 @@
                 var repeatStart = "*" == opts.repeat ? 0 : "+" == opts.repeat ? 1 : opts.repeat;
                 mask = opts.groupmarker.start + mask + opts.groupmarker.end + opts.quantifiermarker.start + repeatStart + "," + opts.repeat + opts.quantifiermarker.end;
             }
-            return void 0 == $.inputmask.masksCache[mask] && ($.inputmask.masksCache[mask] = {
+            var masksetDefinition;
+            return void 0 == $.inputmask.masksCache[mask] || nocache === !0 ? (masksetDefinition = {
                 mask: mask,
                 maskToken: analyseMask(mask),
                 validPositions: {},
@@ -168,7 +169,8 @@
                 buffer: void 0,
                 tests: {},
                 metadata: metadata
-            }), $.extend(!0, {}, $.inputmask.masksCache[mask]);
+            }, nocache !== !0 && ($.inputmask.masksCache[mask] = masksetDefinition)) : masksetDefinition = $.extend(!0, {}, $.inputmask.masksCache[mask]), 
+            masksetDefinition;
         }
         function preProcessMask(mask) {
             if (mask = mask.toString(), opts.numericInput) {
@@ -1177,14 +1179,14 @@
                     action: "format",
                     value: value,
                     metadata: metadata
-                }, generateMaskSet(opts), opts);
+                }, generateMaskSet(opts, options && void 0 !== options.definitions), opts);
             },
             isValid: function(value, options) {
                 var opts = $.extend(!0, {}, $.inputmask.defaults, options);
                 return resolveAlias(opts.alias, options, opts), maskScope({
                     action: "isValid",
                     value: value
-                }, generateMaskSet(opts), opts);
+                }, generateMaskSet(opts, options && void 0 !== options.definitions), opts);
             }
         }, $.fn.inputmask = function(fn, options) {
             function importAttributeOptions(npt, opts, importedOptionsContainer) {
@@ -1202,7 +1204,8 @@
             if ("string" == typeof fn) switch (fn) {
               case "mask":
                 return resolveAlias(opts.alias, options, opts), this.each(function() {
-                    return importAttributeOptions(this, opts), maskset = generateMaskSet(opts), void 0 == maskset ? this : void maskScope({
+                    return importAttributeOptions(this, opts), maskset = generateMaskSet(opts, options && void 0 !== options.definitions), 
+                    void 0 == maskset ? this : void maskScope({
                         action: "mask",
                         el: this
                     }, maskset, opts);
@@ -1249,7 +1252,8 @@
               default:
                 return resolveAlias(opts.alias, options, opts), resolveAlias(fn, options, opts) || (opts.mask = fn), 
                 this.each(function() {
-                    return importAttributeOptions(this, opts), maskset = generateMaskSet(opts), void 0 == maskset ? this : void maskScope({
+                    return importAttributeOptions(this, opts), maskset = generateMaskSet(opts, options && void 0 !== options.definitions), 
+                    void 0 == maskset ? this : void maskScope({
                         action: "mask",
                         el: this
                     }, maskset, opts);
@@ -1257,7 +1261,8 @@
             } else {
                 if ("object" == typeof fn) return opts = $.extend(!0, {}, $.inputmask.defaults, fn), 
                 resolveAlias(opts.alias, fn, opts), this.each(function() {
-                    return importAttributeOptions(this, opts), maskset = generateMaskSet(opts), void 0 == maskset ? this : void maskScope({
+                    return importAttributeOptions(this, opts), maskset = generateMaskSet(opts, fn && void 0 !== fn.definitions), 
+                    void 0 == maskset ? this : void maskScope({
                         action: "mask",
                         el: this
                     }, maskset, opts);

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


+ 14 - 10
js/jquery.inputmask.js

@@ -44,7 +44,7 @@
             return false;
         }
 
-        function generateMaskSet(opts) {
+        function generateMaskSet(opts, nocache) {
             var ms = undefined;
 
             function analyseMask(mask) {
@@ -238,8 +238,10 @@
                         var repeatStart = opts.repeat == "*" ? 0 : (opts.repeat == "+" ? 1 : opts.repeat);
                         mask = opts.groupmarker.start + mask + opts.groupmarker.end + opts.quantifiermarker.start + repeatStart + "," + opts.repeat + opts.quantifiermarker.end;
                     }
-                    if ($.inputmask.masksCache[mask] == undefined) {
-                        $.inputmask.masksCache[mask] = {
+
+                    var masksetDefinition;
+                    if ($.inputmask.masksCache[mask] == undefined || nocache === true) {
+                        masksetDefinition = {
                             "mask": mask,
                             "maskToken": analyseMask(mask),
                             "validPositions": {},
@@ -248,9 +250,11 @@
                             "tests": {},
                             "metadata": metadata
                         };
-                    }
+                        if (nocache !== true)
+                            $.inputmask.masksCache[mask] = masksetDefinition;
+                    } else masksetDefinition = $.extend(true, {}, $.inputmask.masksCache[mask]);
 
-                    return $.extend(true, {}, $.inputmask.masksCache[mask]);
+                    return masksetDefinition;
                 }
             }
             function preProcessMask(mask) {
@@ -2047,12 +2051,12 @@
             format: function (value, options, metadata) {
                 var opts = $.extend(true, {}, $.inputmask.defaults, options);
                 resolveAlias(opts.alias, options, opts);
-                return maskScope({ "action": "format", "value": value, "metadata": metadata }, generateMaskSet(opts), opts);
+                return maskScope({ "action": "format", "value": value, "metadata": metadata }, generateMaskSet(opts, options && options.definitions !== undefined), opts);
             },
             isValid: function (value, options) {
                 var opts = $.extend(true, {}, $.inputmask.defaults, options);
                 resolveAlias(opts.alias, options, opts);
-                return maskScope({ "action": "isValid", "value": value }, generateMaskSet(opts), opts);
+                return maskScope({ "action": "isValid", "value": value }, generateMaskSet(opts, options && options.definitions !== undefined), opts);
             }
         };
 
@@ -2086,7 +2090,7 @@
                         resolveAlias(opts.alias, options, opts);
                         return this.each(function () {
                             importAttributeOptions(this, opts)
-                            maskset = generateMaskSet(opts);
+                            maskset = generateMaskSet(opts, options && options.definitions !== undefined);
                             if (maskset == undefined) { return this; }
                             maskScope({ "action": "mask", "el": this }, maskset, opts);
                         });
@@ -2129,7 +2133,7 @@
 
                         return this.each(function () {
                             importAttributeOptions(this, opts);
-                            maskset = generateMaskSet(opts);
+                            maskset = generateMaskSet(opts, options && options.definitions !== undefined);
                             if (maskset == undefined) { return this; }
                             maskScope({ "action": "mask", "el": this }, maskset, opts);
                         });
@@ -2139,7 +2143,7 @@
                 resolveAlias(opts.alias, fn, opts); //resolve aliases
                 return this.each(function () {
                     importAttributeOptions(this, opts);
-                    maskset = generateMaskSet(opts);
+                    maskset = generateMaskSet(opts, fn && fn.definitions !== undefined);
                     if (maskset == undefined) { return this; }
                     maskScope({ "action": "mask", "el": this }, maskset, opts);
                 });

+ 1 - 1
package.json

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

+ 30 - 0
qunit/tests_base.js

@@ -453,4 +453,34 @@ asyncTest("creditcard switch - pchelailya", function () {
 
         $("#testmask").remove();
     }, 0);
+});
+
+test("maskscache - same mask diff definitions - StonesEditeurs", function () {
+    var $fixture = $("#qunit-fixture");
+    $fixture.append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask({
+        mask: "Z{1,*}",
+        definitions: {
+            'Z': {
+                validator: function (chrs, buffer, pos, strict, opts) {
+                    return { pos: pos, c: 'A' };
+                },
+            }
+        }
+    });
+
+    $("#testmask").inputmask({
+        mask: "Z{1,*}", // <= Same mask
+        definitions: {
+            'Z': {
+                validator: function (chrs, buffer, pos, strict, opts) {
+                    return { pos: pos, c: 'B' };  // <= another definition
+                },
+            }
+        }
+    });
+
+    $("#testmask").Type("abcdef");
+    equal(document.getElementById("testmask")._valueGet(), "BBBBBB", "Result " + document.getElementById("testmask")._valueGet());
+    $("#testmask").remove();
 });