Fix for ticket #2942: character counter now updates on cut and paste operations made with mouse or menu

This uses the 'copy' and 'paste' DOM events to trigger a counter update. I haven't had a chance to 100% confirm that middle-button click on X11 triggers the event, but it ought to.
Cut and paste events from context menu and main edit menu known good in:
* Firefox 4.08b-pre
* IE 9 preview 7
* IE 8 current
* Chrome 8 beta current
* Safari 5.0.3

Opera is listed as not supporting these events, oh well.

Note that using a *delete* command from a menu doesn't trigger an event. Sigh, you can't win everything.
This commit is contained in:
Brion Vibber 2010-12-15 14:57:09 -08:00
parent 0330bad688
commit 2836c4e561
2 changed files with 14 additions and 1 deletions

View File

@ -85,6 +85,19 @@ var SN = { // StatusNet
SN.U.Counter(form);
});
var delayedUpdate= function(e) {
// Cut and paste events fire *before* the operation,
// so we need to trigger an update in a little bit.
// This would be so much easier if the 'change' event
// actually fired every time the value changed. :P
window.setTimeout(function() {
SN.U.Counter(form);
}, 50);
};
// Note there's still no event for mouse-triggered 'delete'.
NDT.bind('cut', delayedUpdate)
.bind('paste', delayedUpdate);
NDT.bind('keydown', function(e) {
SN.U.SubmitOnReturn(e, form);
});

2
js/util.min.js vendored

File diff suppressed because one or more lines are too long