Skip to content

Commit 04bf482

Browse files
author
SamWM
committed
Merge pull request SamWM#67 from joaquingatica/master
Catch errors in selectionStart and setSelectionRange
2 parents cf2914f + a53f820 commit 04bf482

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

numeric/jquery.numeric.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ $.fn.getSelectionStart = function(o)
263263
if (r.text == '') return o.value.length;
264264

265265
return o.value.lastIndexOf(r.text);
266-
} else { return o.selectionStart; }
266+
} else {
267+
try { return o.selectionStart; }
268+
catch(e) { return 0; }
269+
}
267270
};
268271

269272
// Based on code from http://javascript.nwbox.com/cursor_position/ (Diego Perini <[email protected]>)
@@ -292,11 +295,16 @@ $.fn.setSelection = function(o, p)
292295
r.moveEnd('character', p[1]);
293296
r.select();
294297
}
295-
else if(o.setSelectionRange)
296-
{
297-
o.focus();
298-
o.setSelectionRange(p[0], p[1]);
299-
}
298+
else {
299+
o.focus();
300+
try{
301+
if(o.setSelectionRange)
302+
{
303+
o.setSelectionRange(p[0], p[1]);
304+
}
305+
} catch(e) {
306+
}
307+
}
300308
}
301309
};
302310

0 commit comments

Comments
 (0)