@@ -437,11 +437,13 @@ angular.module('ui.mask', [])
437437 if ( input . selectionStart !== undefined ) {
438438 return input . selectionStart ;
439439 } else if ( document . selection ) {
440- // Curse you IE
441- input . focus ( ) ;
442- var selection = document . selection . createRange ( ) ;
443- selection . moveStart ( 'character' , input . value ? - input . value . length : 0 ) ;
444- return selection . text . length ;
440+ if ( iElement . is ( ':focus' ) ) {
441+ // Curse you IE
442+ input . focus ( ) ;
443+ var selection = document . selection . createRange ( ) ;
444+ selection . moveStart ( 'character' , input . value ? - input . value . length : 0 ) ;
445+ return selection . text . length ;
446+ }
445447 }
446448 return 0 ;
447449 }
@@ -452,16 +454,18 @@ angular.module('ui.mask', [])
452454 return ; // Input's hidden
453455 }
454456 if ( input . setSelectionRange ) {
455- input . focus ( ) ;
456- input . setSelectionRange ( pos , pos ) ;
457+ if ( iElement . is ( ':focus' ) ) {
458+ input . focus ( ) ;
459+ input . setSelectionRange ( pos , pos ) ;
460+ }
457461 }
458462 else if ( input . createTextRange ) {
459- // Curse you IE
460- var range = input . createTextRange ( ) ;
461- range . collapse ( true ) ;
462- range . moveEnd ( 'character' , pos ) ;
463- range . moveStart ( 'character' , pos ) ;
464- range . select ( ) ;
463+ // Curse you IE
464+ var range = input . createTextRange ( ) ;
465+ range . collapse ( true ) ;
466+ range . moveEnd ( 'character' , pos ) ;
467+ range . moveStart ( 'character' , pos ) ;
468+ range . select ( ) ;
465469 }
466470 }
467471
0 commit comments