Commit fc554815 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

Browser support fix

skip caret positioning for browsers that don't support setSelectionRange
parent f7cd47dd
......@@ -411,14 +411,19 @@
// http://stackoverflow.com/questions/499126/jquery-set-cursor-position-in-text-area
$.fn.setCursorPosition = function(pos) {
if ($(this).get(0).setSelectionRange) {
$(this).get(0).setSelectionRange(pos, pos);
} else if ($(this).get(0).createTextRange) {
var range = $(this).get(0).createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
// not all browsers support setSelectionRange
// put it in try/catch, fallback to no text selection
try {
if ($(this).get(0).setSelectionRange) {
$(this).get(0).setSelectionRange(pos, pos);
} else if ($(this).get(0).createTextRange) {
var range = $(this).get(0).createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
} catch (err) {
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment