From 21895ef0aa0327fcbbf277a29db983a4ef0d3245 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 16 Aug 2018 22:39:01 -0500 Subject: [PATCH] utility.js: simplify $.fn.selectEnd(). Remove createTextRange fallback; setSelectionRange is supported by all modern browsers. https://caniuse.com/#feat=input-selection --- app/javascript/src/javascripts/utility.js | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/app/javascript/src/javascripts/utility.js b/app/javascript/src/javascripts/utility.js index 8d83ce3bb..0b391fe07 100644 --- a/app/javascript/src/javascripts/utility.js +++ b/app/javascript/src/javascripts/utility.js @@ -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() {