I found this patch on my system, couldn't find the code in HEAD, and also couldn't find an existing issue.

textarea.js does not detach. However, all behaviors that are manipulating the DOM to add elements have to detach themselves.

The patch may be outdated though. And old. And poor. Perhaps.

CommentFileSizeAuthor
drupal.textarea-detach.0.patch695 bytessun

Comments

andypost’s picture

Status: Needs review » Reviewed & tested by the community

I think this could be useful! Patch applies cleanly, tested in FF3.6.7/8 and google chrome 6.0.472.0

sun’s picture

drupal.textarea-detach.0.patch queued for re-testing.

sun’s picture

drupal.textarea-detach.0.patch queued for re-testing.

sun’s picture

Status: Reviewed & tested by the community » Closed (won't fix)
dave reid’s picture

Assigned: sun » Unassigned
Status: Closed (won't fix) » Reviewed & tested by the community

Just because someone is upset doesn't mean we have to mark something as won't fix. Someone else is more than welcome to pick up work on a ticket.

sun’s picture

Version: 7.x-dev » 8.x-dev

Sounds like D8 material to me.

andypost’s picture

Version: 8.x-dev » 7.x-dev
Issue tags: +Needs committer feedback

This is not API change just a bug fix so let's commiters decide.

sun’s picture

Issue tags: -Needs committer feedback

Thanks, but please don't abuse that tag. It should only be used for issues that require attention.

tom_o_t’s picture

drupal.textarea-detach.0.patch queued for re-testing.

webchick’s picture

Version: 7.x-dev » 8.x-dev
Status: Reviewed & tested by the community » Needs review

This smells like D8 to me too (and the original patch author seems to agree). I wasn't able to find any other core behaviours implementing this method in a quick grep. In any case, it could definitely use some more reviews before committing given the comfort level communicated by the OP, making it not really rtbc yet.

sun’s picture

Version: 8.x-dev » 7.x-dev
Issue tags: +wysiwyg

As of now, I agree. Still need to find time to test Wysiwyg module in-depth for Drupal 7.

However, in general, we do not bump bug fixes to D8 yet. This patch is a bug fix, because all Drupal behaviors are expected to detach when they ought to, as that is what Drupal's "JavaScript behavior API" exactly states.

Will try to ping TwoD about this issue.

twod’s picture

Status: Needs review » Reviewed & tested by the community

Pong...
The patch still applies nicely and works as advertised, with multi-value fields and all that too.
While detaching this particular behavior is most likely not critical (I mean, not even Overlay detaches), it could be convenient. And if documentation states that modules _should_ detach, then this really is a Core bug that needs fixing.

I tested it with some changes to Wysiwyg module to see if we could reuse the behavior easily and it worked pretty well then too, see patch below.

I could only find another detach implementation in file module, and I didn't check to see if anything was relying on those behaviors to be detached, but if this gets in I think it'd be worth considering if not to add detach code to all modules that attach something (and add/modify DOM elements), or change the docs.

--- editors/js/none.js
+++ editors/js/none.js
@@ -36,10 +36,10 @@ Drupal.wysiwyg.editor.attach.none = function(context, params, settings) {
  *   AJAX/AHAH applications.
  */
 Drupal.wysiwyg.editor.detach.none = function(context, params) {
-  if (typeof params != 'undefined') {
-    var $wrapper = $('#' + params.field).parents('.form-textarea-wrapper:first');
-    $wrapper.removeOnce('textarea').removeClass('.resizable-textarea')
-      .find('.grippie').remove();
+  var field = $('#' + params.field, context);
+  var field_context = field.parents('.form-type-textarea'); // Possible issues if no wrapper?
+  if (typeof params !== undefined && field_context.length) {
+    Drupal.behaviors.textarea.detach(field_context.get(0), {}, 'unload');
   }
 };
webchick’s picture

Status: Reviewed & tested by the community » Needs review

At this point we're < 100 hours away from Drupal 7.0. That's not the kind of time you want to go off on a jaunt adding detach stuff to every module. That sounds like decent clean-up for 8.x though. For 7.x, I'd be happy just fixing the documentation.

The OP isn't clear to me and neither is #12 (though it's a bit clearer) exactly what "bug" this patch is fixing. Is there some limitation where WYSIWYG module can't do something without this patch? If so, could you be more explicit about what this patch actually fixes?

sun’s picture

Um, no. The current API documentation is correct (but perhaps not 100% clear): we introduced detaching behaviors for D7 to explicitly demand from all Drupal behaviors that are changing the DOM document to detach (revert) their changes. This is nothing new; it was introduced around 1.5 years ago.

twod’s picture

I think I just thought of a better/simpler example for how Wysiwyg and other modules could benefit from this. I'm not at home so I can't test it or make a patch though.

Since the resize grippie (and anything else that might be in the way) has to be removed when attaching an editor, any event handlers other modules may have registered on it will be lost, see #530288: jQuery events not restored on editor toggle.
If Wysiwyg could just call Drupal.detachBehaviors(fieldContext, settings, 'unload') and Drupal.attachBehaviors(fieldContext, settings), event handlers and whatnot would be restored (or rather, reinitialized). If there are modules that know their script is compatible with - or specifically written for - WYSIWYG editors, they could be hooked into an "attached" event triggered by Wysiwyg module after it has detached all regular-textarea-behaviors, if they aren't already implemented as plugins (thinking of Image Assist and Insert modules here).

nod_’s picture

All right, grippie this does not exist in 8.x anymore.

Is this still something we want fixed in 7.x?

nod_’s picture

Status: Needs review » Needs work

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.