utility.js: simplify $.fn.selectEnd().

Remove createTextRange fallback; setSelectionRange is supported by all modern browsers.

https://caniuse.com/#feat=input-selection
This commit is contained in:
evazion
2018-08-16 22:39:01 -05:00
parent dfffabd662
commit 21895ef0aa

View File

@@ -85,26 +85,11 @@ Utility.regexp_escape = function(string) {
return string.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
}
$.fn.selectRange = function(start, end) {
return this.each(function() {
if (this.setSelectionRange) {
this.focus();
this.setSelectionRange(start, end);
} else if (this.createTextRange) {
var range = this.createTextRange();
range.collapse(true);
range.moveEnd('character', end);
range.moveStart('character', start);
range.select();
}
});
};
$.fn.selectEnd = function() {
if (this.length) {
this.selectRange(this.val().length, this.val().length);
}
return this;
return this.each(function() {
this.focus();
this.setSelectionRange(this.value.length, this.value.length);
})
}
$(function() {