File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ function getPasteEvent() {
88var pasteEventName = getPasteEvent ( ) + ".mask" ,
99 ua = navigator . userAgent ,
1010 iPhone = / i p h o n e / i. test ( ua ) ,
11+ chrome = / c h r o m e / i. test ( ua ) ,
1112 android = / a n d r o i d / 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-
You can’t perform that action at this time.
0 commit comments