angular-input-types
Version:
AngularJS directives used on form inputs. Makes it easy for the users to input the correct information using autocomplete and validation.
25 lines (22 loc) • 752 B
JavaScript
angular.module('inputTypes')
.service('inputUtils', function() {
this.getCursorPos = function(htmlElement) {
return htmlElement.selectionEnd;
};
this.setCursorPos = function(htmlElement, pos) {
if (htmlElement.setSelectionRange) {
htmlElement.focus();
window.setTimeout(function() {
// Android Chrome
htmlElement.setSelectionRange(pos, pos);
});
} else if(htmlElement.createTextRange) {
// IE compatible
var range = htmlElement.createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
};
});