From c600906ada9bd0cba28fdf8a9b73d9b62a237b2a Mon Sep 17 00:00:00 2001 From: b2k Date: Fri, 23 Aug 2013 14:11:01 -0500 Subject: [PATCH 1/2] 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. --- src/jquery.maskedinput.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index 749da65..0869182 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -8,6 +8,7 @@ function getPasteEvent() { var pasteEventName = getPasteEvent() + ".mask", ua = navigator.userAgent, iPhone = /iphone/i.test(ua), + chrome = /chrome/i.test(ua), android=/android/i.test(ua), caretTimeoutId; @@ -195,6 +196,22 @@ $.fn.extend({ c, next; + if (k == 0) { + // unable to detect key pressed. Grab it from pos and adjust + // this is a failsafe for mobile chrome + // which can't detect keypress events + // reliably + if (pos.begin >= len) { + input.val(input.val().substr(0, len)); + e.preventDefault(); + return false; + } + if (pos.begin == pos.end) { + k = input.val().charCodeAt(pos.begin - 1); + pos.begin--; + pos.end--; + } + } if (e.ctrlKey || e.altKey || e.metaKey || k < 32) {//Ignore return; } else if (k) { @@ -322,8 +339,10 @@ $.fn.extend({ settings.completed.call(input); }, 0); }); + if (chrome) { + input.bind("keyup.mask", keypressEvent); + } checkVal(); //Perform initial check for existing values }); } }); - From 44bac38f0a0552d6e59ca01973055c37474102dc Mon Sep 17 00:00:00 2001 From: b2k Date: Fri, 23 Aug 2013 14:15:57 -0500 Subject: [PATCH 2/2] Add android to if statement --- src/jquery.maskedinput.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index 0869182..9c0d392 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -339,7 +339,7 @@ $.fn.extend({ settings.completed.call(input); }, 0); }); - if (chrome) { + if (chrome && android) { input.bind("keyup.mask", keypressEvent); } checkVal(); //Perform initial check for existing values