Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 1c26b05

Browse files
committed
Merge pull request #415 from asadighi/master
[Fix] #317: ui-mask sets focus on the last masked input box
2 parents 4c64d0c + 4615f8e commit 1c26b05

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

modules/mask/mask.js

+17-13
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)