diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-04-26 19:35:28 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-04-26 19:35:28 +0200 |
| commit | 423733ab0d391f23f12ca81efe6fbab410819e40 (patch) | |
| tree | 7b26be5002b313e3170bb6a9df7301ce436db2fe /js/util.js | |
| parent | 1c12b9e22f0bb88edf8eed8c68690da82ec4d283 (diff) | |
more subtle
Diffstat (limited to 'js/util.js')
| -rw-r--r-- | js/util.js | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -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)) |
