Fix for Fixed AHAH Wysiwyg integration

  1. // $Id$
  2.  
  3. /*
  4.  This version works when the #ahah element is a button.
  5.  Drupal passes the button name and value to .ajaxSubmit
  6.  but when we re-serialize the form that data is lost so we
  7.  need to add it manually.
  8. */
  9.  
  10. /*
  11.  * Attach AJAX/AHAH event handlers for Wysiwyg integration.
  12.  *
  13.  * This code takes care of Wysiwyg integration in D6.
  14.  * Wysiwyg module needs to be able to detach any attached editor before the
  15.  * AJAX request is made or it cannot be re-attached afterwards.
  16.  * Drupal 6 does not have detach behaviors so we need to manually call
  17.  * Drupal.wysiwygDetach(). Wysiwyg's own behavior won't be able to
  18.  * re-attach the editor either because the context doesn't include the
  19.  * format selector so we call Drupal.wysiwygAttach() manually too.
  20.  * Drupal's jquery.form.js does not trigger 'form-pre-serialize' so we must
  21.  * re-serialize the form after detaching the editor in 'ajaxSend'.
  22.  *
  23.  * @param context
  24.  *   A DOM element, supplied by Drupal.attachBehaviors().
  25.  *
  26.  * This code is based on Drupal.behaviors.attachWysiwyg from Wysiwyg module.
  27.  * @see Drupal.behaviors.attachWysiwyg in Wysiwyg module.
  28.  */
  29. Drupal.behaviors.markup_snippets = function (context) {
  30.   var params;
  31.   // Add a global AJAX listener for attaching/detaching Wysiwyg module.
  32.   $('#edit-markup-snippets-select-wrapper:not(.markup-snippets-processed)', context).each(function () {
  33.     $(this).addClass('markup-snippets-processed').bind('ajaxSend', function (event, XMLHttpRequest, ajaxOptions) {
  34.       // Detach the Wysiwyg module if this is our request.
  35.       if (ajaxOptions.url == '/markup_snippets/js') {
  36.         params = $.extend({}, Drupal.wysiwyg.instances['edit-body']);
  37.         if (params.editor == 'none') {
  38.           // No editor instance, get parameters from the selected input format.
  39.           params = Drupal.wysiwyg.getParams($(':input.wysiwyg-field-edit-body:checked, div.wysiwyg-field-edit-body', context).get(0));
  40.           // Override status to keep the editor disabled when re-attaching.
  41.           params.status = false;
  42.         }
  43.         Drupal.wysiwygDetach(context, params);
  44.         // Re-serialize the form.
  45.         $("#edit-markup-snippets-changed").attr('disabled', false);
  46.         var formValues =  $('#edit-body').parents('form').formToArray();
  47.         formValues.push({
  48.           name: 'op',
  49.           value: Drupal.settings.ahah['edit-markup-snippets-changed'].button.op
  50.         });
  51.         ajaxOptions.data = $.param(formValues);
  52.         $("#edit-markup-snippets-select, #edit-markup-snippets-changed").attr('disabled', true);
  53.       }
  54.     }).bind('ajaxComplete', function (event, XMLHttpRequest, ajaxOptions) {
  55.       // Re-attach the Wysiwyg module if this is our response.
  56.       if (ajaxOptions.url == '/markup_snippets/js') {
  57.         Drupal.wysiwygAttach(context, params);
  58.         $("#edit-markup-snippets-select").attr('disabled', false)
  59.       }
  60.     });
  61.   });
  62. }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.