From 423733ab0d391f23f12ca81efe6fbab410819e40 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 26 Apr 2018 19:35:28 +0200 Subject: more subtle --- js/util.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index f2fd129..ca97630 100644 --- a/js/util.js +++ b/js/util.js @@ -174,6 +174,23 @@ function defaults (dest, src) { return dest } +function setSelectionRange(input, selectionStart, selectionEnd) { + if (input.setSelectionRange) { + input.focus(); + input.setSelectionRange(selectionStart, selectionEnd); + } + else if (input.createTextRange) { + var range = input.createTextRange(); + range.collapse(true); + range.moveEnd('character', selectionEnd); + range.moveStart('character', selectionStart); + range.select(); + } +} +function setCaretToPos(input, pos) { + setSelectionRange(input, pos, pos); +} + // Naive useragent detection pattern var is_iphone = (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) var is_ipad = (navigator.userAgent.match(/iPad/i)) -- cgit v1.2.3-70-g09d2