Permalink
Browse files

BUG Trigger TinyMCE onChange more frequently

Periodically check for inline changes when focused,
since TinyMCE's onChange only fires on certain actions
like inserting a new paragraph, as opposed to any user input.
This also works around an issue where the "save" button
wouldn't trigger if the click is the cause of a "blur" event
after an (undetected) inline change. This "blur" causes onChange
to trigger, which will change the button markup to show "alternative" styles,
effectively cancelling the original click event.
  • Loading branch information...
1 parent d5510f5 commit d2eef63b7da7ec795ecb82e6fded1535b38a222e @chillu chillu committed Jun 3, 2013
Showing with 18 additions and 0 deletions.
  1. +18 −0 javascript/HtmlEditorField.js
@@ -60,6 +60,24 @@ ss.editorWrappers.tinyMCE = (function() {
// Patch TinyMCE events into underlying textarea field.
ed.onInit.add(function(ed) {
jQuery(ed.getElement()).trigger('editorinit');
+
+ // Periodically check for inline changes when focused,
+ // since TinyMCE's onChange only fires on certain actions
+ // like inserting a new paragraph, as opposed to any user input.
+ // This also works around an issue where the "save" button
+ // wouldn't trigger if the click is the cause of a "blur" event
+ // after an (undetected) inline change. This "blur" causes onChange
+ // to trigger, which will change the button markup to show "alternative" styles,
+ // effectively cancelling the original click event.
+ var interval;
+ jQuery(ed.getBody()).on('focus', function() {
+ interval = setInterval(function() {
+ ed.save();
+ }, 5000);
+ });
+ jQuery(ed.getBody()).on('blur', function() {
+ clearInterval(interval);
+ });
});
ed.onChange.add(function(ed, l) {
// Update underlying textarea on every change, so external handlers

0 comments on commit d2eef63

Please sign in to comment.