Browse Source

better workaround, ... if this works we can apply the patch conditionally

Robin Herbots 14 years ago
parent
commit
ab519e551b
1 changed files with 16 additions and 12 deletions
  1. 16 12
      jquery.inputmask.js

+ 16 - 12
jquery.inputmask.js

@@ -423,17 +423,6 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
             }
             }
 
 
             function caret(input, begin, end) {
             function caret(input, begin, end) {
-                function _setSelectionRange(input, begin, end) {
-                    if (document.activeElement === input) {
-                        input.setSelectionRange(begin, end);
-                    } else {
-                        input.focus();
-                        setTimeout(function() {
-                            _setSelectionRange(input, begin, end);
-                        }, 1);
-                    }
-                }
-
                 if (input.length == 0) return;
                 if (input.length == 0) return;
                 if (typeof begin == 'number') {
                 if (typeof begin == 'number') {
                     end = (typeof end == 'number') ? end : begin;
                     end = (typeof end == 'number') ? end : begin;
@@ -441,7 +430,7 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                     return input.each(function() {
                     return input.each(function() {
                         if (this.setSelectionRange) {
                         if (this.setSelectionRange) {
                             this.focus();
                             this.focus();
-                            _setSelectionRange(this, begin, end);
+                            this.setSelectionRange(begin, end);
                         } else if (this.createTextRange) {
                         } else if (this.createTextRange) {
                             var range = this.createTextRange();
                             var range = this.createTextRange();
                             range.collapse(true);
                             range.collapse(true);
@@ -475,6 +464,21 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                     'definitions': opts.definitions
                     'definitions': opts.definitions
                 });
                 });
 
 
+                //android setSelectionRange bug workaround
+                if (el._setSelectionRange == undefined) {
+                    el._setSelectionRange = el.setSelectionRange;
+                    el.setSelectionRange = function(begin, end) {
+                        if (document.activeElement === this) {
+                            this._setSelectionRange(begin, end);
+                        } else {
+                            this.focus();
+                            setTimeout(function() {
+                                this.setSelectionRange(begin, end);
+                            }, 1);
+                        }
+                    } 
+                }
+
                 //init buffer
                 //init buffer
                 var buffer = _buffer.slice();
                 var buffer = _buffer.slice();
                 var undoBuffer = _val.call(input);
                 var undoBuffer = _val.call(input);