summaryrefslogtreecommitdiff
path: root/js/util.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-04-26 19:35:28 +0200
committerJules Laplace <julescarbon@gmail.com>2018-04-26 19:35:28 +0200
commit423733ab0d391f23f12ca81efe6fbab410819e40 (patch)
tree7b26be5002b313e3170bb6a9df7301ce436db2fe /js/util.js
parent1c12b9e22f0bb88edf8eed8c68690da82ec4d283 (diff)
more subtle
Diffstat (limited to 'js/util.js')
-rw-r--r--js/util.js17
1 files changed, 17 insertions, 0 deletions
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))