@@ -460,7 +460,7 @@ angular.module('ui.mask', [])
460
460
// Angular uses html element and calls setViewValue(element.value.trim()), setting it to the trimmed mask
461
461
// when it should be empty
462
462
var currentVal = iElement . val ( ) ;
463
- var isTemporarilyEmpty = value === '' && currentVal && angular . isDefined ( iAttrs . uiMaskPlaceholderChar ) && iAttrs . uiMaskPlaceholderChar === 'space' ;
463
+ var isTemporarilyEmpty = value === '' && currentVal && angular . isDefined ( iAttrs . uiMaskPlaceholderChar ) && iAttrs . uiMaskPlaceholderChar === 'space' ;
464
464
if ( isTemporarilyEmpty ) {
465
465
iElement . val ( '' ) ;
466
466
}
@@ -476,12 +476,20 @@ angular.module('ui.mask', [])
476
476
var change ;
477
477
if ( angular . isFunction ( window . Event ) && ! element . fireEvent ) {
478
478
// modern browsers and Edge
479
- change = new Event ( 'change' , {
480
- view : window ,
481
- bubbles : true ,
482
- cancelable : false
483
- } ) ;
484
- element . dispatchEvent ( change ) ;
479
+ try {
480
+ change = new Event ( 'change' , {
481
+ view : window ,
482
+ bubbles : true ,
483
+ cancelable : false
484
+ } ) ;
485
+ } catch ( ex ) {
486
+ //this is for certain mobile browsers that have the Event object
487
+ //but don't support the Event constructor #168
488
+ change = document . createEvent ( 'HTMLEvents' ) ;
489
+ change . initEvent ( 'change' , false , true ) ;
490
+ } finally {
491
+ element . dispatchEvent ( change ) ;
492
+ }
485
493
} else if ( 'createEvent' in document ) {
486
494
// older browsers
487
495
change = document . createEvent ( 'HTMLEvents' ) ;
@@ -511,30 +519,30 @@ angular.module('ui.mask', [])
511
519
}
512
520
513
521
function keydownHandler ( e ) {
514
- /*jshint validthis: true */
515
- var isKeyBackspace = e . which === 8 ,
516
- caretPos = getCaretPosition ( this ) - 1 || 0 , //value in keydown is pre change so bump caret position back to simulate post change
517
- isCtrlZ = e . which === 90 && e . ctrlKey ; //ctrl+z pressed
518
-
519
- if ( isKeyBackspace ) {
520
- while ( caretPos >= 0 ) {
521
- if ( isValidCaretPosition ( caretPos ) ) {
522
- //re-adjust the caret position.
523
- //Increment to account for the initial decrement to simulate post change caret position
524
- setCaretPosition ( this , caretPos + 1 ) ;
525
- break ;
526
- }
527
- caretPos -- ;
528
- }
529
- preventBackspace = caretPos === - 1 ;
530
- }
531
-
532
- if ( isCtrlZ ) {
533
- // prevent IE bug - value should be returned to initial state
534
- iElement . val ( '' ) ;
535
- e . preventDefault ( ) ;
536
- }
537
- }
522
+ /*jshint validthis: true */
523
+ var isKeyBackspace = e . which === 8 ,
524
+ caretPos = getCaretPosition ( this ) - 1 || 0 , //value in keydown is pre change so bump caret position back to simulate post change
525
+ isCtrlZ = e . which === 90 && e . ctrlKey ; //ctrl+z pressed
526
+
527
+ if ( isKeyBackspace ) {
528
+ while ( caretPos >= 0 ) {
529
+ if ( isValidCaretPosition ( caretPos ) ) {
530
+ //re-adjust the caret position.
531
+ //Increment to account for the initial decrement to simulate post change caret position
532
+ setCaretPosition ( this , caretPos + 1 ) ;
533
+ break ;
534
+ }
535
+ caretPos -- ;
536
+ }
537
+ preventBackspace = caretPos === - 1 ;
538
+ }
539
+
540
+ if ( isCtrlZ ) {
541
+ // prevent IE bug - value should be returned to initial state
542
+ iElement . val ( '' ) ;
543
+ e . preventDefault ( ) ;
544
+ }
545
+ }
538
546
539
547
function eventHandler ( e ) {
540
548
/*jshint validthis: true */
0 commit comments