Skip to content

Commit e677e8d

Browse files
b2kdigitalBush
authored andcommitted
Fix for chrome browser on Android
On a Samsung Galaxy, Chrome version 28 does not throw the keypress event. Here is a fix for that.
1 parent ef9f3f3 commit e677e8d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/jquery.maskedinput.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function getPasteEvent() {
88
var pasteEventName = getPasteEvent() + ".mask",
99
ua = navigator.userAgent,
1010
iPhone = /iphone/i.test(ua),
11+
chrome = /chrome/i.test(ua),
1112
android=/android/i.test(ua),
1213
caretTimeoutId;
1314

@@ -195,6 +196,22 @@ $.fn.extend({
195196
c,
196197
next;
197198

199+
if (k == 0) {
200+
// unable to detect key pressed. Grab it from pos and adjust
201+
// this is a failsafe for mobile chrome
202+
// which can't detect keypress events
203+
// reliably
204+
if (pos.begin >= len) {
205+
input.val(input.val().substr(0, len));
206+
e.preventDefault();
207+
return false;
208+
}
209+
if (pos.begin == pos.end) {
210+
k = input.val().charCodeAt(pos.begin - 1);
211+
pos.begin--;
212+
pos.end--;
213+
}
214+
}
198215
if (e.ctrlKey || e.altKey || e.metaKey || k < 32) {//Ignore
199216
return;
200217
} else if (k) {
@@ -322,8 +339,10 @@ $.fn.extend({
322339
settings.completed.call(input);
323340
}, 0);
324341
});
342+
if (chrome) {
343+
input.bind("keyup.mask", keypressEvent);
344+
}
325345
checkVal(); //Perform initial check for existing values
326346
});
327347
}
328348
});
329-

0 commit comments

Comments
 (0)