Skip to content

Commit

Permalink
Merge pull request #415 from asadighi/master
Browse files Browse the repository at this point in the history
[Fix] #317:  ui-mask sets focus on the last masked input box
  • Loading branch information
PowerKiKi committed Jun 30, 2015
2 parents 4c64d0c + 4615f8e commit 1c26b05
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions modules/mask/mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,13 @@ angular.module('ui.mask', [])
if (input.selectionStart !== undefined) {
return input.selectionStart;
} else if (document.selection) {
// Curse you IE
input.focus();
var selection = document.selection.createRange();
selection.moveStart('character', input.value ? -input.value.length : 0);
return selection.text.length;
if (iElement.is(':focus')) {
// Curse you IE
input.focus();
var selection = document.selection.createRange();
selection.moveStart('character', input.value ? -input.value.length : 0);
return selection.text.length;
}
}
return 0;
}
Expand All @@ -452,16 +454,18 @@ angular.module('ui.mask', [])
return; // Input's hidden
}
if (input.setSelectionRange) {
input.focus();
input.setSelectionRange(pos, pos);
if (iElement.is(':focus')) {
input.focus();
input.setSelectionRange(pos, pos);
}
}
else if (input.createTextRange) {
// Curse you IE
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
// Curse you IE
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
}

Expand Down

0 comments on commit 1c26b05

Please sign in to comment.