Since the detach issue got in (#1155678: Implement Drupal.behaviors.attachWysiwyg.detach), the editors detach and then reattach every time a form is submitted via AJAX. That gets especially messy when you have frequent AJAX submissions. Conveniently sun and effulgentsia got an extra parameter added to Drupal.detachBehaviors() in D7 to handle this very problem. So all we need to do is handle detaching differently for AJAX submissions (trigger = 'serialize') than we do for regular detaching (trigger = 'unload' or 'move). Patch forthcoming.

Comments

ksenzee’s picture

Status: Active » Needs review
StatusFileSize
new16.6 KB

I couldn't get TinyMCE 2 to work (maybe a browser problem), but I *think* the attached patch handles all the other editors correctly. At least everything seemed to work in my testing. It's not the most elegant code I've ever written, either; I spent all day getting it working and tested, and that's all the time I had. Feel free to iterate. :)

bmcmurray’s picture

Just confirming that this works like a charm with CKEditor.

twod’s picture

StatusFileSize
new17.46 KB

Looks good to me too, except when submitting the form normally. The editors still get a full detach then, making things jump around.
I added a 'serialize' argument in the call to Drupal.wysiwygDetach() in Wysiwyg's event handler for reacting to form submissions to fix that.
Changed the comment over the detach() method in none.js to closer match the style in Drupal.detachBehaviors().
Also fixed jWysiwyg, which was still detaching at all times.

I hope there won't be any memory leaks from this, but I suppose we'll find out sooner or later.

Can you please confirm this is working as expected?

sun’s picture

+++ b/editors/js/tinymce-2.js
@@ -67,7 +67,8 @@ Drupal.wysiwyg.editor.attach.tinymce = function(context, params, settings) {
+  trigger = trigger || 'unload';

+++ b/editors/js/tinymce-3.js
@@ -79,20 +79,25 @@ Drupal.wysiwyg.editor.attach.tinymce = function(context, params, settings) {
+  trigger = trigger || 'unload';

+++ b/editors/js/whizzywig-56.js
@@ -89,7 +89,8 @@ Drupal.wysiwyg.editor.attach.whizzywig = function(context, params, settings) {
+  trigger = trigger || 'unload';

+++ b/editors/js/whizzywig-60.js
@@ -38,7 +38,8 @@ Drupal.wysiwyg.editor.attach.whizzywig = function(context, params, settings) {
+  trigger = trigger || 'unload';

+++ b/editors/js/whizzywig.js
@@ -80,7 +80,8 @@ Drupal.wysiwyg.editor.attach.whizzywig = function(context, params, settings) {
+  trigger = trigger || 'unload';

Can't we enforce a default of 'unload' in the detach or wysiwygDetach method?

twod’s picture

I don't like that part either, but it is possible to call all those methods directly from any code...
On the other hand, not having those checks there could send the signal that we don't wish those methods to be called directly.
I think I might actually like that better, as it goes along with what I had in mind for 3.x.

sun’s picture

yep, that's in line with my thinking. Other scripts and external code should never call those editor-specific methods directly. If at all, then only our own, editor-specific integration code (within the same file) may call them.

twod’s picture

StatusFileSize
new17.27 KB

Rerolled with the changes. The editor implementations now assume the trigger parameter is always present.

To speed things up, I'll commit this in a week unless something comes up.

EDIT: Just noticed I uploaded the wrong patch, it still has a some lines with trigger = trigger || 'unload' left there, will put the correct patch up later.

jantimon’s picture

I had the same issue (with tinemce) and could fix it with #7.

Juan C’s picture

Can someone update and applied the patch on #7 against the latest dev. version.
Thanks in advance.

twod’s picture

Status: Needs review » Patch (to be ported)
StatusFileSize
new2.06 KB
new17.13 KB

I've committed the below patch to D7.
The -dev snapshots will be updated within 12 hours and this change will be in the next official D7 release.

I don't think we can fully backport this to D6 and/or D5 as we don't have the trigger argument or the detach behavior there, but if anyone has ideas, I'm interested. Marking this as 'needs backport' for now.

sun’s picture

Version: 7.x-2.x-dev » 6.x-2.x-dev

Yay, thanks!

For D6, at least our own form submit handler could pass the appropriate trigger. For any other calls, we'd default to 'unload' in wysiwygDetach(), so the previous behavior is retained.

twod’s picture

That should fix things for regular submissions, but AJAXed submissions will still make the editors flicker and the page scroll uncontrollably. I think we'll still have other issues related to AJAX in D6 anyway, so maybe that's not a priority?

twod’s picture

Status: Patch (to be ported) » Fixed

I have committed a backport of this for 6.x-2.x, without the detach() method in Drupal.behaviors.attachWysiwyg since there's no equivalent to it in D6.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.