Browse Source

Merge branch '2.x' into 2.6

Robin Herbots 12 years ago
parent
commit
85d5c9dd99

+ 1 - 1
build.properties

@@ -7,7 +7,7 @@ distdir = dist
 
 build.major = 2
 build.minor = 5
-build.revision = 0
+build.revision = 1
 
 target = jquery.inputmask.bundle.js
 target.min = jquery.inputmask.bundle.min.js

+ 1 - 1
jquery.inputmask.jquery.json

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

+ 31 - 13
js/jquery.inputmask.js

@@ -293,10 +293,12 @@
         var msie1x = typeof ScriptEngineMajorVersion === "function"
                         ? ScriptEngineMajorVersion() //IE11 detection
                         : new Function("/*@cc_on return @_jscript_version; @*/")() >= 10, //conditional compilation from mickeysoft trick
-            iphone = navigator.userAgent.match(new RegExp("iphone", "i")) !== null,
-            android = navigator.userAgent.match(new RegExp("android.*safari.*", "i")) !== null,
-            androidchrome = navigator.userAgent.match(new RegExp("android.*chrome.*", "i")) !== null,
-            androidfirefox = navigator.userAgent.match(new RegExp("android.*firefox.*", "i")) !== null,
+                        ua = navigator.userAgent,
+            iphone = ua.match(new RegExp("iphone", "i")) !== null,
+            android = ua.match(new RegExp("android.*safari.*", "i")) !== null,
+            androidchrome = ua.match(new RegExp("android.*chrome.*", "i")) !== null,
+            androidfirefox = ua.match(new RegExp("android.*firefox.*", "i")) !== null,
+            kindle = /Kindle/i.test(ua) || /Silk/i.test(ua) || /KFTT/i.test(ua) || /KFOT/i.test(ua) || /KFJWA/i.test(ua) || /KFJWI/i.test(ua) || /KFSOWI/i.test(ua) || /KFTHWA/i.test(ua) || /KFTHWI/i.test(ua) || /KFAPWA/i.test(ua) || /KFAPWI/i.test(ua),
             PasteEventType = isInputEventSupported('paste') ? 'paste' : isInputEventSupported('input') ? 'input' : "propertychange";
 
         //if (androidchrome) {
@@ -850,7 +852,7 @@
                     if (opts.insertMode == false && begin == end) end++; //set visualization for insert/overwrite mode
                     if (npt.setSelectionRange) {
                         npt.selectionStart = begin;
-                        npt.selectionEnd = android ? begin : end;
+                        npt.selectionEnd = end;
 
                     } else if (npt.createTextRange) {
                         range = npt.createTextRange();
@@ -1336,6 +1338,8 @@
                                 } else if (isSlctn) {
                                     getActiveMaskSet()["buffer"] = getActiveMaskSet()["undoBuffer"].split('');
                                 }
+                            } else if (isSlctn) {
+                                getActiveMaskSet()["buffer"] = getActiveMaskSet()["undoBuffer"].split('');
                             }
                         }
 
@@ -1391,6 +1395,7 @@
                 }, 0);
             }
 
+            //not used - attempt to support android 
             function mobileInputEvent(e) {
                 var input = this, $input = $(input);
 
@@ -1398,13 +1403,19 @@
                 var caretPos = caret(input),
                     currentValue = input._valueGet();
 
+                currentValue = currentValue.replace(new RegExp("(" + escapeRegex(getActiveBufferTemplate().join('')) + ")*"), "");
+                //correct caretposition for chrome
+                if (caretPos.begin > currentValue.length) {
+                    caret(input, currentValue.length);
+                    caretPos = caret(input);
+                }
                 if ((getActiveBuffer().length - currentValue.length) == 1 && currentValue.charAt(caretPos.begin) != getActiveBuffer()[caretPos.begin]
                     && currentValue.charAt(caretPos.begin + 1) != getActiveBuffer()[caretPos.begin]
                     && !isMask(caretPos.begin)) {
                     e.keyCode = opts.keyCode.BACKSPACE;
                     keydownEvent.call(input, e);
                 } else { //nonnumerics don't fire keypress 
-                    checkVal(input, false, false);
+                    checkVal(input, false, false, currentValue.split(''));
                     writeBuffer(input, getActiveBuffer());
                     if (isComplete(getActiveBuffer()) === true)
                         $input.trigger("complete");
@@ -1585,14 +1596,21 @@
 
                     // as the other inputevents aren't reliable for the moment we only base on the input event
                     // needs follow-up
-                    if (android || androidfirefox || androidchrome) {
-                        $el.unbind("keydown.inputmask", keydownEvent
-                         	).unbind("keypress.inputmask", keypressEvent
-                         	).unbind("keyup.inputmask", keyupEvent);
-                        if (PasteEventType == "input") {
-                            $el.unbind(PasteEventType + ".inputmask");
+                    if (android || androidfirefox || androidchrome || kindle) {
+                        $el.attr("autocomplete", "off")
+                        .attr("autocorrect", "off")
+                        .attr("autocapitalize", "off")
+                        .attr("spellcheck", false);
+
+                        if (androidfirefox || kindle) {
+                            $el.unbind("keydown.inputmask", keydownEvent
+                                ).unbind("keypress.inputmask", keypressEvent
+                                ).unbind("keyup.inputmask", keyupEvent);
+                            if (PasteEventType == "input") {
+                                $el.unbind(PasteEventType + ".inputmask");
+                            }
+                            $el.bind("input.inputmask", mobileInputEvent);
                         }
-                        $el.bind("input.inputmask", mobileInputEvent);
                     }
 
                     if (msie1x)

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

@@ -122,6 +122,7 @@ Optional extensions on the jquery.inputmask base
                         //strip groupseparator
                         var escapedGroupSeparator = $.inputmask.escapeRegex.call(this, opts.groupSeparator);
                         bufferStr = bufferStr.replace(new RegExp(escapedGroupSeparator, "g"), '');
+                        if (!strict && bufferStr == "") return false;
 
                         var isValid = opts.regex.number(opts).test(bufferStr);
                         if (!isValid) {

+ 3 - 4
qunit/qunit.html

@@ -3,14 +3,13 @@
 <head>
   <meta charset="utf-8">
   <title>jquery.inputmask - QUnit</title>
-  <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.12.0.css">
+  <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.14.0.css">
 </head>
 <body>
   <div id="qunit"></div>
   <div id="qunit-fixture"></div>
-  <!-- <script src="http://code.jquery.com/jquery-1.6.min.js"></script> -->
-  <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
-  <script src="http://code.jquery.com/qunit/qunit-1.12.0.js"></script>
+  <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="./simulator.js"></script>
   <script src="./tests.js"></script>

+ 59 - 0
qunit/tests.js

@@ -1177,6 +1177,23 @@ test("inputmask(\"decimal\") - value=\"123.45\" Replace last integer", function
     $("#testmask").remove();
 });
 
+test("inputmask(\"decimal\", { digits: 2 }) - value=\"123\" - RomeroMsk", function () {
+    $('body').append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask("decimal", { digits: 2 });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("123");
+    caret($("#testmask"), 0, 3);
+    $("#testmask").SendKey(",,..");
+	$("#testmask").SendKey(keyCodes.RIGHT);
+	$("#testmask").SendKey(keyCodes.RIGHT); //needed in test
+	$("#testmask").SendKey(keyCodes.RIGHT); //needed in test
+	$("#testmask").Type("45");
+
+    equal($("#testmask").val(), "12345", "Result " + $("#testmask").val());
+    $("#testmask").remove();
+});
+
 test("inputmask - Multiple inputs masked, Integer mask doesn't allow typing - #402 - albatrocity", function () {
     $('body').append('<input type="text" id="testmask" />');
     $('body').append('<input type="text" id="testmask2" />');
@@ -1196,6 +1213,48 @@ test("inputmask - Multiple inputs masked, Integer mask doesn't allow typing - #4
     $("#testmask2").remove();
 });
 
+test("decimal alias with groupseparator delete - YoussefTaghlabi", function () {
+    $('body').append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask("decimal", { 
+                radixPoint: ".", 
+                groupSeparator: ",",
+                groupSize: 3,
+                digits: 2,
+                autoGroup: true,
+                allowPlus: false,
+                allowMinus: true
+            });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("1234567");
+    caret($("#testmask"), 0);   
+	$("#testmask").SendKey(keyCodes.DELETE);
+
+    equal($("#testmask").val(), "234,567", "Result " + $("#testmask").val());
+    $("#testmask").remove();
+});
+
+test("decimal alias with groupseparator backspace - YoussefTaghlabi", function () {
+    $('body').append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask("decimal", { 
+                radixPoint: ".", 
+                groupSeparator: ",",
+                groupSize: 3,
+                digits: 2,
+                autoGroup: true,
+                allowPlus: false,
+                allowMinus: true
+            });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("1234567");
+    caret($("#testmask"), 1);   
+	$("#testmask").SendKey(keyCodes.BACKSPACE);
+
+    equal($("#testmask").val(), "234,567", "Result " + $("#testmask").val());
+    $("#testmask").remove();
+});
+
 module("Direction RTL");
 test("inputmask(\"999.999.999\") - delete 2nd with backspace, continue the mask", function () {
     $('body').append('<input type="text" id="testmask" dir="rtl" />');