// $Id$
/*
drupal_add_js(this_file) on the form for which this is needed.
Customize the CHANGE ME parts to deal with the relevant fields.
*/
/*
* 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 () { // CHANGE ME: Replace markup-snippets.... with any other element (prefereably one created by your module) which will not be modified by the AHAH call. This is just an anchor point for the event handler.
$(this).addClass('markup-snippets-processed').bind('ajaxSend', function (event, XMLHttpRequest, ajaxOptions) { // CHANGE ME: See above, add class to not bind twice if behaviors are run again.
// Detach the Wysiwyg module if this is our request.
if (ajaxOptions.url == '/markup_snippets/js') { // CHANGE ME: Replace with your AHAH URL to catch only the requests going there.
params = $.extend({}, Drupal.wysiwyg.instances['edit-body']); // CHANGE ME: Replace 'edit-body' with the id of the Wysiwyged:ed field.
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)); // CHANGE ME: Replace 'edit-body' with the name of the Wysiwyg:ed field.
// Override status to keep the editor disabled when re-attaching.
params.status = false;
}
Drupal.wysiwygDetach(context, params);
// Re-serialize the form. Fields must be enabled to be included in POST data.
$("#edit-markup-snippets-select).attr('disabled', false); // CHANGE ME: The id of the element triggering AHAH.
ajaxOptions.data = $('#edit-body').parents('form').formSerialize();
$("#edit-markup-snippets-select").attr('disabled', true); // CHANGE ME: The id of the element triggering AHAH.
}
}).bind('ajaxComplete', function (event, XMLHttpRequest, ajaxOptions) {
// Re-attach the Wysiwyg module if this is our response.
if (ajaxOptions.url == '/markup_snippets/js') { // CHANGE ME: See above.
Drupal.wysiwygAttach(context, params);
}
});
});
}