Browse Source

test androidchrome32

Robin Herbots 12 years ago
parent
commit
0010cfbf78
1 changed files with 29 additions and 11 deletions
  1. 29 11
      js/jquery.inputmask.js

+ 29 - 11
js/jquery.inputmask.js

@@ -228,15 +228,21 @@
             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";
+            pasteEvent = isInputEventSupported('paste') ? 'paste' : isInputEventSupported('input') ? 'input' : "propertychange",
+            androidchrome32 = false;
 
+        if (androidchrome) {
+            var browser = navigator.userAgent.match(new RegExp("chrome.*", "i")),
+                version = parseInt(new RegExp(/[0-9]+/).exec(browser));
+            androidchrome32 = (version == 32);
+        }
 
         //masking scope
         //actionObj definition see below
         function maskScope(masksets, activeMasksetIndex, opts, actionObj) {
             var isRTL = false,
                 valueOnFocus = getActiveBuffer().join(''),
-                $el, chromeValueOnInput,
+                $el,
                 skipKeyPressEvent = false, //Safari 5.1.x - modal dialog fires keypress twice workaround
                 skipInputEvent = false, //skip when triggered from within inputmask
                 ignorable = false;
@@ -1133,11 +1139,6 @@
             function keyupEvent(e) {
                 var $input = $(this), input = this, k = e.keyCode, buffer = getActiveBuffer();
 
-                if (androidchrome && k == opts.keyCode.BACKSPACE) {
-                    if (chromeValueOnInput == input._valueGet())
-                        keydownEvent.call(this, e);
-                }
-
                 opts.onKeyUp.call(this, e, buffer, opts); //extra stuff to execute on keyup
                 if (k == opts.keyCode.TAB && opts.showMaskOnFocus) {
                     if ($input.hasClass('focus.inputmask') && input._valueGet().length == 0) {
@@ -1163,7 +1164,6 @@
                 }
                 var input = this, $input = $(input);
 
-                chromeValueOnInput = getActiveBuffer().join('');
                 checkVal(input, false, false);
                 writeBuffer(input, getActiveBuffer());
                 if (isComplete(getActiveBuffer()) === true)
@@ -1171,6 +1171,22 @@
                 $input.click();
             }
 
+            function chromeInputEvent(e) {
+                if (skipInputEvent === true) {
+                    skipInputEvent = false;
+                    return true;
+                }
+                var input = this, $input = $(input);
+
+                //backspace in chrome32 only fires input event - detect & treat
+                var caretPos = caret(input),
+                    currentValue = input._valueGet();
+                if (currentValue.charAt(caretPos.begin) != getActiveBuffer()[caretPos.begin] && !isMask(caretPos.begin)) {
+                    e.which = opts.keyCode.BACKSPACE;
+                    $input.trigger("keydown", e);
+                }
+            }
+
             function mask(el) {
                 $el = $(el);
                 if ($el.is(":input")) {
@@ -1356,12 +1372,14 @@
                     ).bind("keyup.inputmask", keyupEvent);
 
                     if (androidchrome) {
-                        $el.bind("input.inputmask", inputEvent);
+                        //do stuff
                     } else {
                         $el.bind("keydown.inputmask", keydownEvent
-                        ).bind("keypress.inputmask", keypressEvent);
+                        ).bind("keypress.inputmask", keypressEvent
+                        ).bind("keyup.inputmask", keyupEvent);
                     }
-
+                    if (androidchrome32)
+                        $el.bind("input.inputmask", chromeInputEvent);
                     if (msie10)
                         $el.bind("input.inputmask", inputEvent);