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:
@@ -85,26 +85,11 @@ Utility.regexp_escape = function(string) {
|
|||||||
return string.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
|
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() {
|
$.fn.selectEnd = function() {
|
||||||
if (this.length) {
|
return this.each(function() {
|
||||||
this.selectRange(this.val().length, this.val().length);
|
this.focus();
|
||||||
}
|
this.setSelectionRange(this.value.length, this.value.length);
|
||||||
return this;
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user