// $Id$
/*
This version works when the #ahah element is a button.
Drupal passes the button name and value to .ajaxSubmit
but when we re-serialize the form that data is lost so we
need to add it manually.
*/
/*
* Attach AJAX/AHAH event handlers for Wysiwyg integration.
*
* This code takes care of Wysiwyg integration in D6.
* Wysiwyg module needs to be able to detach any attached editor before the
* AJAX request is made or it cannot be re-attached afterwards.
* Drupal 6 does not have detach behaviors so we need to manually call
* Drupal.wysiwygDetach(). Wysiwyg's own behavior won't be able to
* re-attach the editor either because the context doesn't include the
* format selector so we call Drupal.wysiwygAttach() manually too.
* Drupal's jquery.form.js does not trigger 'form-pre-serialize' so we must
* re-serialize the form after detaching the editor in 'ajaxSend'.
*
* @param context
* A DOM element, supplied by Drupal.attachBehaviors().
*
* This code is based on Drupal.behaviors.attachWysiwyg from Wysiwyg module.
* @see Drupal.behaviors.attachWysiwyg in Wysiwyg module.
*/
Drupal.behaviors.markup_snippets = function (context) {
var params;
// Add a global AJAX listener for attaching/detaching Wysiwyg module.
$('#edit-markup-snippets-select-wrapper:not(.markup-snippets-processed)', context).each(function () {
$(this).addClass('markup-snippets-processed').bind('ajaxSend', function (event, XMLHttpRequest, ajaxOptions) {
// Detach the Wysiwyg module if this is our request.
if (ajaxOptions.url == '/markup_snippets/js') {
params = $.extend({}, Drupal.wysiwyg.instances['edit-body']);
if (params.editor == 'none') {
// No editor instance, get parameters from the selected input format.
params = Drupal.wysiwyg.getParams($(':input.wysiwyg-field-edit-body:checked, div.wysiwyg-field-edit-body', context).get(0));
// Override status to keep the editor disabled when re-attaching.
params.status = false;
}
Drupal.wysiwygDetach(context, params);
// Re-serialize the form.
$("#edit-markup-snippets-changed").attr('disabled', false);
var formValues = $('#edit-body').parents('form').formToArray();
formValues.push({
name: 'op',
value: Drupal.settings.ahah['edit-markup-snippets-changed'].button.op
});
ajaxOptions.data = $.param(formValues);
$("#edit-markup-snippets-select, #edit-markup-snippets-changed").attr('disabled', true);
}
}).bind('ajaxComplete', function (event, XMLHttpRequest, ajaxOptions) {
// Re-attach the Wysiwyg module if this is our response.
if (ajaxOptions.url == '/markup_snippets/js') {
Drupal.wysiwygAttach(context, params);
$("#edit-markup-snippets-select").attr('disabled', false)
}
});
});
}