Browse Source

jquery.inputmask 3.1.24

Robin Herbots 11 years ago
parent
commit
177a82368a

+ 1 - 1
bower.json

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

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


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


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


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


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


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


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


+ 1 - 1
jquery.inputmask.jquery.json

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

+ 39 - 22
js/jquery.inputmask.js

@@ -42,7 +42,7 @@
         }
 
         function generateMaskSet(opts, multi) {
-            var ms = [];
+            var ms = undefined;
 
             function analyseMask(mask) {
                 var tokenizer = /(?:[?*+]|\{[0-9\+\*]+(?:,[0-9\+\*]*)?\})\??|[^.?*+^${[]()|\\]+|./g,
@@ -241,6 +241,9 @@
                 if (mask == undefined || mask == "")
                     return undefined;
                 else {
+                    if (mask.length == 1 && opts.greedy == false && opts.repeat != 0) {
+                        opts.placeholder = "";
+                    } //hide placeholder with single non-greedy mask
                     if (opts.repeat > 0 || opts.repeat == "*" || opts.repeat == "+") {
                         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;
@@ -266,6 +269,7 @@
             }
             if ($.isArray(opts.mask)) {
                 if (multi) {  //remove me
+                    ms = [];
                     $.each(opts.mask, function (ndx, msk) {
                         if (msk["mask"] != undefined && !$.isFunction(msk["mask"])) {
                             ms.push(generateMask(msk["mask"].toString(), msk));
@@ -289,13 +293,12 @@
                     ms = generateMask(altMask, opts.mask);
                 }
             } else {
-                if (opts.mask.length == 1 && opts.greedy == false && opts.repeat != 0) {
-                    opts.placeholder = "";
-                } //hide placeholder with single non-greedy mask
-                if (opts.mask["mask"] != undefined && !$.isFunction(opts.mask["mask"])) {
-                    ms = generateMask(opts.mask["mask"].toString(), opts.mask);
-                } else {
-                    ms = generateMask(opts.mask.toString(), opts.mask);
+                if (opts.mask) {
+                    if (opts.mask["mask"] != undefined && !$.isFunction(opts.mask["mask"])) {
+                        ms = generateMask(opts.mask["mask"].toString(), opts.mask);
+                    } else {
+                        ms = generateMask(opts.mask.toString(), opts.mask);
+                    }
                 }
             }
             return ms;
@@ -340,7 +343,7 @@
                         var validPos = getMaskSet()['validPositions'][pos];
                         test = validPos["match"];
                         ndxIntlzr = validPos["locator"].slice();
-                        maskTemplate.push(test["fn"] == null ? test["def"] : (includeInput === true ? validPos["input"] : test["placeholder"] || opts.placeholder.charAt(pos % opts.placeholder.length)));
+                        maskTemplate.push(includeInput === true ? validPos["input"] : getPlaceholder(pos, test));
                     } else {
                         if (minimalPos > pos) {
                             var testPositions = getTests(pos, ndxIntlzr, pos - 1);
@@ -350,7 +353,7 @@
                         }
                         test = testPos["match"];
                         ndxIntlzr = testPos["locator"].slice();
-                        maskTemplate.push(test["fn"] == null ? test["def"] : (test["placeholder"] != undefined ? test["placeholder"] : opts.placeholder.charAt(pos % opts.placeholder.length)));
+                        maskTemplate.push(getPlaceholder(pos, test));
                     }
                     pos++;
                 } while ((maxLength == undefined || pos - 1 < maxLength) && test["fn"] != null || (test["fn"] == null && test["def"] != "") || minimalPos >= pos);
@@ -907,7 +910,7 @@
             }
             function getPlaceholder(pos, test) {
                 test = test || getTest(pos);
-                return test["placeholder"] || (test["fn"] == null ? test["def"] : opts.placeholder.charAt(pos % opts.placeholder.length));
+                return ($.isFunction(test["placeholder"]) ? test["placeholder"].call(this, opts) : test["placeholder"]) || (test["fn"] == null ? test["def"] : opts.placeholder.charAt(pos % opts.placeholder.length));
             }
             function checkVal(input, writeOut, strict, nptvl, intelliCheck) {
                 var inputValue = nptvl != undefined ? nptvl.slice() : truncateInput(input._valueGet()).split('');
@@ -1880,12 +1883,23 @@
         $.fn.inputmask = function (fn, options, targetScope, targetData, msk) {
             targetScope = targetScope || maskScope;
             targetData = targetData || "_inputmask";
-            function importAttributeOptions(npt, opts) {
+            function importAttributeOptions(npt, opts, importedOptionsContainer) {
                 var $npt = $(npt);
+                if ($npt.data("inputmask-alias")) {
+                    resolveAlias($npt.data("inputmask-alias"), {}, opts);
+                }
                 for (var option in opts) {
                     var optionData = $npt.data("inputmask-" + option.toLowerCase());
-                    if (optionData != undefined)
-                        opts[option] = optionData;
+                    if (optionData != undefined) {
+                        if (option == "mask" && optionData.indexOf("[") == 0) {
+                            opts[option] = optionData.replace(/[\s[\]]/g, "").split("','");
+                            opts[option][0] = opts[option][0].replace("'", "");
+                            opts[option][opts[option].length - 1] = opts[option][opts[option].length - 1].replace("'", "");
+                        } else
+                            opts[option] = typeof optionData == "boolean" ? optionData : optionData.toString();
+                        if (importedOptionsContainer)
+                            importedOptionsContainer[option] = opts[option];
+                    }
                 }
                 return opts;
             }
@@ -1895,14 +1909,13 @@
             if (typeof fn === "string") {
                 switch (fn) {
                     case "mask":
-                    	importAttributeOptions(this, opts);
                         //resolve possible aliases given by options
                         resolveAlias(opts.alias, options, opts);
                         maskset = generateMaskSet(opts, targetScope !== maskScope);
-                        if (maskset.length == 0) { return this; }
+                        if (maskset == undefined) { return this; }
 
                         return this.each(function () {
-                            targetScope({ "action": "mask", "el": this }, $.extend(true, {}, maskset), opts);
+                            targetScope({ "action": "mask", "el": this }, $.extend(true, {}, maskset), importAttributeOptions(this, opts));
                         });
                     case "unmaskedvalue":
                         var $input = $(this);
@@ -1942,7 +1955,6 @@
                         }
                         return $.isArray(opts.mask);
                     default:
-                        importAttributeOptions(this, opts);
                         resolveAlias(opts.alias, options, opts);
                         //check if the fn is an alias
                         if (!resolveAlias(fn, options, opts)) {
@@ -1953,17 +1965,16 @@
                         maskset = generateMaskSet(opts, targetScope !== maskScope);
                         if (maskset == undefined) { return this; }
                         return this.each(function () {
-                            targetScope({ "action": "mask", "el": this }, $.extend(true, {}, maskset), opts);
+                            targetScope({ "action": "mask", "el": this }, $.extend(true, {}, maskset), importAttributeOptions(this, opts));
                         });
                 }
             } else if (typeof fn == "object") {
                 opts = $.extend(true, {}, $.inputmask.defaults, fn);
-				importAttributeOptions(this, opts);
                 resolveAlias(opts.alias, fn, opts); //resolve aliases
                 maskset = generateMaskSet(opts, targetScope !== maskScope);
                 if (maskset == undefined) { return this; }
                 return this.each(function () {
-                    targetScope({ "action": "mask", "el": this }, $.extend(true, {}, maskset), opts);
+                    targetScope({ "action": "mask", "el": this }, $.extend(true, {}, maskset), importAttributeOptions(this, opts));
                 });
             } else if (fn == undefined) {
                 //look for data-inputmask atribute - the attribute should only contain optipns
@@ -1975,13 +1986,19 @@
                             var dataoptions = $.parseJSON("{" + attrOptions + "}");
                             $.extend(true, dataoptions, options);
                             opts = $.extend(true, {}, $.inputmask.defaults, dataoptions);
+                            opts = importAttributeOptions(this, opts);
                             resolveAlias(opts.alias, dataoptions, opts);
                             opts.alias = undefined;
                             $(this).inputmask("mask", opts, targetScope);
                         } catch (ex) { } //need a more relax parseJSON
                     }
                     if ($(this).attr("data-inputmask-mask") || $(this).attr("data-inputmask-alias")) {
-                        $(this).inputmask("mask", {}, targetScope);
+                        opts = $.extend(true, {}, $.inputmask.defaults, {});
+                        var dataOptions = {};
+                        opts = importAttributeOptions(this, opts, dataOptions);
+                        resolveAlias(opts.alias, dataOptions, opts);
+                        opts.alias = undefined;
+                        $(this).inputmask("mask", opts, targetScope);
                     }
                 });
             }

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

@@ -35,8 +35,7 @@ Optional extensions on the jquery.inputmask base
                 }
 
                 opts.definitions[";"] = opts.definitions["~"]; //clone integer def for decimals
-                opts.definitions[":"].placeholder = opts.radixPoint;
-
+				
                 var mask = opts.prefix;
                 mask += "[+]";
                 mask += "~{1," + opts.integerDigits + "}";
@@ -225,7 +224,7 @@ Optional extensions on the jquery.inputmask base
                     },
                     cardinality: 1,
                     prevalidator: null,
-                    placeholder: "" //radixpoint will be set in the mask function
+                    placeholder: function(opts) { return opts.radixPoint; }
                 }
             },
             insertMode: true,