I'm using this plguin to get caret position of textarea. I have a <div>
, clicking on which shows the <ul>
with smilie list to put one of them into the textarea. Clicking on <div>
fires the blur
event on textarea. I save the caret position on blur:
oRoot.blur(function() {
caret_pos = $(this).caret();
});
And after user click on smilie, I put it in the textarea where the caret was before it lost the focus:
oList
.delegate('.chat-smile', 'click', function() {
var oRoot = $(this).parent().data('oRoot');
if (is_default_value(oRoot)) oRoot.val('');
oRoot.val(oRoot.caret(caret_pos).caret().replace($(this).attr('smilie-code')));
toggle_list($(this).parent());
});
The problem is that in IE it seems that the plugin doesn't work if textarea has no focus, and in IE the blur
event handler is fired after the focus is lost.
Any ideas of workaround this? I was thinking of saving the caret position on click
, keyup
, focus
for IE..