ソースを参照

add type=tel to supported inputtypes

Robin Herbots 11 年 前
コミット
836b4e50a1

+ 7 - 5
dist/inputmask/jquery.inputmask.js

@@ -14,10 +14,12 @@
         el = null, isSupported;
     }
     function isInputTypeSupported(inputType) {
-        var el = document.createElement("input");
-        el.setAttribute("type", inputType);
-        var isSupported = "text" !== el.type;
-        return el = null, isSupported;
+        var isSupported = "text" == inputType || "tel" == inputType;
+        if (!isSupported) {
+            var el = document.createElement("input");
+            el.setAttribute("type", inputType), isSupported = "text" === el.type, el = null;
+        }
+        return isSupported;
     }
     function resolveAlias(aliasStr, options, opts) {
         var aliasDefinition = opts.aliases[aliasStr];
@@ -831,7 +833,7 @@
             }, 0), !1;
         }
         function mask(el) {
-            if ($el = $(el), $el.is(":input") && !isInputTypeSupported($el.attr("type"))) {
+            if ($el = $(el), $el.is(":input") && isInputTypeSupported($el.attr("type"))) {
                 if ($el.data("_inputmask", {
                     maskset: maskset,
                     opts: opts,

+ 5 - 2
dist/inputmask/jquery.inputmask.numeric.extensions.js

@@ -93,12 +93,15 @@
             regex: {
                 integerPart: function() {
                     return new RegExp("[-+]?\\d+");
+                },
+                integerNPart: function() {
+                    return new RegExp("\\d+");
                 }
             },
             negationhandler: function(chrs, buffer, pos, strict, opts) {
                 if (!strict && opts.allowMinus && "-" === chrs) {
                     var matchRslt = buffer.join("").match(opts.regex.integerPart(opts));
-                    if (matchRslt.length > 0) return "+" == buffer[matchRslt.index] ? {
+                    if (matchRslt && matchRslt.length > 0) return "+" == buffer[matchRslt.index] ? {
                         pos: matchRslt.index,
                         c: "-",
                         remove: matchRslt.index,
@@ -128,7 +131,7 @@
                 return !1;
             },
             leadingZeroHandler: function(chrs, maskset, pos, strict, opts) {
-                var matchRslt = maskset.buffer.join("").match(opts.regex.integerPart(opts)), radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
+                var matchRslt = maskset.buffer.join("").match(opts.regex.integerNPart(opts)), radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
                 if (matchRslt && !strict && (-1 == radixPosition || matchRslt.index < radixPosition)) if (0 == matchRslt[0].indexOf("0") && pos >= opts.prefix.length) {
                     if (-1 == radixPosition || radixPosition >= pos && void 0 == maskset.validPositions[radixPosition]) return maskset.buffer.splice(matchRslt.index, 1), 
                     pos = pos > matchRslt.index ? pos - 1 : matchRslt.index, {

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

@@ -12,10 +12,12 @@
         el = null, isSupported;
     }
     function isInputTypeSupported(inputType) {
-        var el = document.createElement("input");
-        el.setAttribute("type", inputType);
-        var isSupported = "text" !== el.type;
-        return el = null, isSupported;
+        var isSupported = "text" == inputType || "tel" == inputType;
+        if (!isSupported) {
+            var el = document.createElement("input");
+            el.setAttribute("type", inputType), isSupported = "text" === el.type, el = null;
+        }
+        return isSupported;
     }
     function resolveAlias(aliasStr, options, opts) {
         var aliasDefinition = opts.aliases[aliasStr];
@@ -829,7 +831,7 @@
             }, 0), !1;
         }
         function mask(el) {
-            if ($el = $(el), $el.is(":input") && !isInputTypeSupported($el.attr("type"))) {
+            if ($el = $(el), $el.is(":input") && isInputTypeSupported($el.attr("type"))) {
                 if ($el.data("_inputmask", {
                     maskset: maskset,
                     opts: opts,
@@ -1817,12 +1819,15 @@
             regex: {
                 integerPart: function() {
                     return new RegExp("[-+]?\\d+");
+                },
+                integerNPart: function() {
+                    return new RegExp("\\d+");
                 }
             },
             negationhandler: function(chrs, buffer, pos, strict, opts) {
                 if (!strict && opts.allowMinus && "-" === chrs) {
                     var matchRslt = buffer.join("").match(opts.regex.integerPart(opts));
-                    if (matchRslt.length > 0) return "+" == buffer[matchRslt.index] ? {
+                    if (matchRslt && matchRslt.length > 0) return "+" == buffer[matchRslt.index] ? {
                         pos: matchRslt.index,
                         c: "-",
                         remove: matchRslt.index,
@@ -1852,7 +1857,7 @@
                 return !1;
             },
             leadingZeroHandler: function(chrs, maskset, pos, strict, opts) {
-                var matchRslt = maskset.buffer.join("").match(opts.regex.integerPart(opts)), radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
+                var matchRslt = maskset.buffer.join("").match(opts.regex.integerNPart(opts)), radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
                 if (matchRslt && !strict && (-1 == radixPosition || matchRslt.index < radixPosition)) if (0 == matchRslt[0].indexOf("0") && pos >= opts.prefix.length) {
                     if (-1 == radixPosition || radixPosition >= pos && void 0 == maskset.validPositions[radixPosition]) return maskset.buffer.splice(matchRslt.index, 1), 
                     pos = pos > matchRslt.index ? pos - 1 : matchRslt.index, {

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


+ 8 - 5
js/jquery.inputmask.js

@@ -23,10 +23,13 @@
         }
 
         function isInputTypeSupported(inputType) {
-            var el = document.createElement('input');
-            el.setAttribute("type", inputType);
-            var isSupported = el.type !== "text";
-            el = null;
+            var isSupported = inputType == "text" || inputType == "tel";
+            if (!isSupported) {
+                var el = document.createElement('input');
+                el.setAttribute("type", inputType);
+                isSupported = el.type === "text"; //apply mask only if the type is not natively supported
+                el = null;
+            }
             return isSupported;
         }
 
@@ -1513,7 +1516,7 @@
             }
             function mask(el) {
                 $el = $(el);
-                if ($el.is(":input") && !isInputTypeSupported($el.attr("type"))) {
+                if ($el.is(":input") && isInputTypeSupported($el.attr("type"))) {
                     //store tests & original buffer in the input element - used to get the unmasked value
                     $el.data('_inputmask', {
                         'maskset': maskset,

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

@@ -125,13 +125,14 @@ Optional extensions on the jquery.inputmask base
                 }
             },
             regex: {
-                integerPart: function (opts) { return new RegExp('[-\+]?\\d+'); }
+                integerPart: function (opts) { return new RegExp('[-\+]?\\d+'); },
+                integerNPart: function (opts) { return new RegExp('\\d+'); }
             },
             negationhandler: function (chrs, buffer, pos, strict, opts) {
                 if (!strict && opts.allowMinus && chrs === "-") {
                     var matchRslt = buffer.join('').match(opts.regex.integerPart(opts));
 
-                    if (matchRslt.length > 0) {
+                    if (matchRslt && matchRslt.length > 0) {
                         if (buffer[matchRslt.index] == "+") {
                             return { "pos": matchRslt.index, "c": "-", "remove": matchRslt.index, "caret": pos };
                         } else if (buffer[matchRslt.index] == "-") {
@@ -156,7 +157,7 @@ Optional extensions on the jquery.inputmask base
                 return false;
             },
             leadingZeroHandler: function (chrs, maskset, pos, strict, opts) {
-                var matchRslt = maskset.buffer.join('').match(opts.regex.integerPart(opts)), radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
+                var matchRslt = maskset.buffer.join('').match(opts.regex.integerNPart(opts)), radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
                 if (matchRslt && !strict && (radixPosition == -1 || matchRslt.index < radixPosition)) {
                     if (matchRslt["0"].indexOf("0") == 0 && pos >= opts.prefix.length) {
                         if (radixPosition == -1 || (pos <= radixPosition && maskset["validPositions"][radixPosition] == undefined)) {