Browse Source

Merge branch '2.x' into 2.6

Robin Herbots 12 years ago
parent
commit
e884e33191
4 changed files with 50 additions and 35 deletions
  1. 1 1
      build.properties
  2. 1 1
      jquery.inputmask.jquery.json
  3. 36 33
      js/jquery.inputmask.js
  4. 12 0
      qunit/tests.js

+ 1 - 1
build.properties

@@ -7,7 +7,7 @@ distdir = dist
 
 build.major = 2
 build.minor = 4
-build.revision = 28
+build.revision = 29
 
 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.4.28",
+    "version": "2.4.29",
     "author": {
         "name": "Robin Herbots",
         "url": "http://github.com/RobinHerbots/jquery.inputmask"

+ 36 - 33
js/jquery.inputmask.js

@@ -298,7 +298,8 @@
             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,
-            pasteEvent = isInputEventSupported('paste') ? 'paste' : isInputEventSupported('input') ? 'input' : "propertychange";
+            androidfirefox = navigator.userAgent.match(new RegExp("android.*firefox.*", "i")) !== null,
+            PasteEventType = isInputEventSupported('paste') ? 'paste' : isInputEventSupported('input') ? 'input' : "propertychange";
 
         //if (androidchrome) {
         //    var browser = navigator.userAgent.match(new RegExp("chrome.*", "i")),
@@ -776,6 +777,7 @@
                         }
                     } else {
                         keypressEvent.call(input, undefined, true, charCode.charCodeAt(0), writeOut, strict, ndx);
+                        strict = strict || (ndx > 0 && ndx > getActiveMaskSet()["p"]);
                     }
                 });
 
@@ -1212,13 +1214,13 @@
                         var isSlctn = isSelection(pos.begin, pos.end),
                             initialIndex = activeMasksetIndex;
                         if (isSlctn) {
-                            activeMasksetIndex = initialIndex;
                             $.each(masksets, function (ndx, lmnt) { //init undobuffer for recovery when not valid
                                 if (typeof (lmnt) == "object") {
                                     activeMasksetIndex = ndx;
                                     getActiveMaskSet()["undoBuffer"] = getActiveBuffer().join('');
                                 }
                             });
+                            activeMasksetIndex = initialIndex; //restore index
                             HandleRemove(input, opts.keyCode.DELETE, pos);
                             if (!opts.insertMode) { //preserve some space
                                 $.each(masksets, function (ndx, lmnt) {
@@ -1363,21 +1365,28 @@
                 }
             }
 
-            function inputEvent(e) {
+            function pasteEvent(e) {
                 if (skipInputEvent === true) {
                     skipInputEvent = false;
                     return true;
                 }
                 var input = this, $input = $(input);
 
-                checkVal(input, false, false);
-                writeBuffer(input, getActiveBuffer());
-                if (isComplete(getActiveBuffer()) === true)
-                    $input.trigger("complete");
-                $input.click();
+                //paste event for IE8 and lower I guess ;-)
+                if (e.type == "propertychange" && input._valueGet().length <= getMaskLength()) {
+                    return true;
+                }
+                setTimeout(function () {
+                    var pasteValue = opts.onBeforePaste != undefined ? opts.onBeforePaste.call(this, input._valueGet()) : input._valueGet();
+                    checkVal(input, false, false, pasteValue.split(''), true);
+                    writeBuffer(input, getActiveBuffer());
+                    if (isComplete(getActiveBuffer()) === true)
+                        $input.trigger("complete");
+                    $input.click();
+                }, 0);
             }
 
-            function chromeInputEvent(e) {
+            function mobileInputEvent(e) {
                 if (skipInputEvent === true) {
                     skipInputEvent = false;
                     return true;
@@ -1387,6 +1396,7 @@
                 //backspace in chrome32 only fires input event - detect & treat
                 var caretPos = caret(input),
                     currentValue = input._valueGet();
+
                 if (currentValue.charAt(caretPos.begin) != getActiveBuffer()[caretPos.begin]
               	  	&& currentValue.charAt(caretPos.begin + 1) != getActiveBuffer()[caretPos.begin]
                 	&& !isMask(caretPos.begin)) {
@@ -1557,25 +1567,8 @@
                         setTimeout(function () {
                             caret(input, 0, seekNext(getActiveMaskSet()["lastValidPosition"]));
                         }, 0);
-                    }).bind(pasteEvent + ".inputmask dragdrop.inputmask drop.inputmask", function (e) {
-                        if (skipInputEvent === true) {
-                            skipInputEvent = false;
-                            return true;
-                        }
-                        var input = this, $input = $(input);
-
-                        //paste event for IE8 and lower I guess ;-)
-                        if (e.type == "propertychange" && input._valueGet().length <= getMaskLength()) {
-                            return true;
-                        }
-                        setTimeout(function () {
-                            var pasteValue = opts.onBeforePaste != undefined ? opts.onBeforePaste.call(this, input._valueGet()) : input._valueGet();
-                            checkVal(input, true, false, pasteValue.split(''), true);
-                            if (isComplete(getActiveBuffer()) === true)
-                                $input.trigger("complete");
-                            $input.click();
-                        }, 0);
-                    }).bind('setvalue.inputmask', function () {
+                    }).bind(PasteEventType + ".inputmask dragdrop.inputmask drop.inputmask", pasteEvent
+                    ).bind('setvalue.inputmask', function () {
                         var input = this;
                         checkVal(input, true);
                         valueOnFocus = getActiveBuffer().join('');
@@ -1583,18 +1576,28 @@
                             input._valueSet('');
                     }).bind('complete.inputmask', opts.oncomplete
                     ).bind('incomplete.inputmask', opts.onincomplete
-                    ).bind('cleared.inputmask', opts.oncleared
-                    ).bind("keyup.inputmask", keyupEvent);
+                    ).bind('cleared.inputmask', opts.oncleared);
 
                     $el.bind("keydown.inputmask", keydownEvent
                          ).bind("keypress.inputmask", keypressEvent
                          ).bind("keyup.inputmask", keyupEvent);
 
-                    if (androidchrome) {
-                        $el.bind("input.inputmask", chromeInputEvent);
+
+                    if (android) {
+                        if (androidchrome) {
+                            $el.bind("input.inputmask", mobileInputEvent);
+                        } else if (PasteEventType != "input") {
+                            $el.bind("input.inputmask", pasteEvent);
+                        }
+                    }
+                    if (androidfirefox) {
+                        if (PasteEventType == "input") {
+                            $el.unbind(PasteEventType + ".inputmask");
+                        }
+                        $el.bind("input.inputmask", mobileInputEvent);
                     }
                     if (msie1x)
-                        $el.bind("input.inputmask", inputEvent);
+                        $el.bind("input.inputmask", pasteEvent);
 
                     //apply mask
                     var initialValue = opts.onBeforeMask != undefined ? opts.onBeforeMask.call(this, el._valueGet()) : el._valueGet();

+ 12 - 0
qunit/tests.js

@@ -690,6 +690,18 @@ test("inputmask({ mask: ['9 AAA-AAA', 'A 999-999'] }) ", function () {
     $("#testmask").remove();
 });
 
+test("inputmask('[9-]AAA.999') ", function () {
+    $('body').append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask('[9-]AAA.999');
+
+    $("#testmask").Type("1abc123");
+    caret($("#testmask"), 4, 5);
+    $("#testmask").Type("d");
+    equal($("#testmask").val(), "1-ABD.123", "Result " + $("#testmask").val());
+
+    $("#testmask").remove();
+});
+
 module("Date.Extensions");
 test("inputmask(\"dd/mm/yyyy\") - input 2331973", function () {
     $('body').append('<input type="text" id="testmask" />');