Create and dispatch 'input' events for keybind tags and quote insertion.

This commit is contained in:
Nicolas Stepien 2012-06-13 16:34:32 +02:00
parent 69c21f771a
commit 5a64b7b06c
3 changed files with 23 additions and 9 deletions

View File

@ -1254,13 +1254,16 @@
return key;
},
tags: function(tag, ta) {
var range, selEnd, selStart, value;
var e, range, selEnd, selStart, value;
value = ta.value;
selStart = ta.selectionStart;
selEnd = ta.selectionEnd;
ta.value = value.slice(0, selStart) + ("[" + tag + "]") + value.slice(selStart, selEnd) + ("[/" + tag + "]") + value.slice(selEnd);
range = ("[" + tag + "]").length + selEnd;
return ta.setSelectionRange(range, range);
ta.setSelectionRange(range, range);
e = d.createEvent('Event');
e.initEvent('input', true, false);
return ta.dispatchEvent(e);
},
img: function(thread, all) {
var thumb;
@ -1560,10 +1563,13 @@
}
ta = $('textarea', QR.el);
caretPos = ta.selectionStart;
QR.selected.el.lastChild.textContent = QR.selected.com = ta.value = ta.value.slice(0, caretPos) + text + ta.value.slice(ta.selectionEnd);
ta.value = ta.value.slice(0, caretPos) + text + ta.value.slice(ta.selectionEnd);
ta.focus();
range = caretPos + text.length;
return ta.setSelectionRange(range, range);
ta.setSelectionRange(range, range);
e = d.createEvent('Event');
e.initEvent('input', true, false);
return ta.dispatchEvent(e);
},
drag: function(e) {
var i;

View File

@ -1,4 +1,6 @@
master
- Mayhem
Fix spoiler/code tag keybinds being ignored on post submission.
2.31.6
- Mayhem

View File

@ -914,6 +914,11 @@ Keybinds =
# Move the caret to the end of the selection.
ta.setSelectionRange range, range
# Fire the 'input' event
e = d.createEvent 'Event'
e.initEvent 'input', true, false
ta.dispatchEvent e
img: (thread, all) ->
if all
$.id('imageExpand').click()
@ -1143,16 +1148,17 @@ QR =
ta = $ 'textarea', QR.el
caretPos = ta.selectionStart
# Replace selection for text.
# onchange event isn't triggered, save value.
QR.selected.el.lastChild.textContent =
QR.selected.com =
ta.value =
ta.value[...caretPos] + text + ta.value[ta.selectionEnd..]
ta.value = ta.value[...caretPos] + text + ta.value[ta.selectionEnd..]
ta.focus()
# Move the caret to the end of the new quote.
range = caretPos + text.length
ta.setSelectionRange range, range
# Fire the 'input' event
e = d.createEvent 'Event'
e.initEvent 'input', true, false
ta.dispatchEvent e
drag: (e) ->
# Let it drag anything from the page.
i = if e.type is 'dragstart' then 'off' else 'on'