// $Id$ /** * Manipulation of content remove buttons. * * An onClick event handler is bound to each remove button, from where * onRemove events are invoked before the field widget is hidden. * There is a default onRemove handler that is executed first in the chain, * and it is used to enable the checked attribute of the remove checkbox. * Custom onRemove handlers are executed later, and can be used to perform * additional processing, or even disable the checked attribute of the * remove checkbox. The field widget will only be hidden if the checked * attribute of the remove checkbox is still enable after all onRemove * handlers have been executed. * * - Custom onRemove handlers may be attached to remove buttons as follows: * * * $('.content-remove-button').not('.myclass-processed').each(function() { * // Make sure the element is not processed more than once. * $(this).addClass('.myclass-processed'); * // Attach custom onRemove handler. * $(this)..bind('remove', myOnRemoveHandler); * }); * * * - onRemove handlers are executed with the following arguments: * event - The onClick event object. * settings - An object with the following properties: * checkbox_id - The ID of the checkbox element. * checkbox - The DOM object of the remove checkbox element. * button - The DOM object of the remove button element. * field_name - The name of the field. * delta - The delta of the field item. * * - Custom onRemove handlers may uncheck the checkbox element as follows: * * * $('input[@id='+ settings.checkbox_id +']').attr('checked', ''); * */ Drupal.behaviors.contentRemoveButtons = function() { $('.content-remove-button').not('.content-remove-button-processed').each(function() { // Make sure the element is not processed more than once, then // attach our onClick and default onRemove handlers. $(this).addClass('.content-remove-button-processed') .bind('click', Drupal.contentRemoveButtons.onClick) .bind('remove', Drupal.contentRemoveButtons.onRemove); }); }; Drupal.contentRemoveButtons = {}; /** * onClick handler for content remove buttons. */ Drupal.contentRemoveButtons.onClick = function(event) { var settings = $(this).attr('rel').split('|'); // Trigger all onRemove events attached to the button. $(this).trigger('remove', [event, { checkbox_id: settings[0], checkbox: $('#'+ settings[0]).get(0), button: this, field_name: settings[1], delta: settings[2] }]); // Hide the table row of the widget, but only if the checkbox element is // still checked after all onRemove handlers. if ($('input[@id='+ settings[0] +']:checked').val()) { $(this).parents('tr:first').fadeOut('slow'); } return false; }; /** * onRemove handler for content remove buttons. */ Drupal.contentRemoveButtons.onRemove = function(event, settings) { $('input[@id='+ settings.checkbox_id +']').attr('checked', 'checked'); };