summaryrefslogtreecommitdiff
path: root/js/util.js
diff options
context:
space:
mode:
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))