Index: modules/field/modules/text/text.js =================================================================== RCS file: modules/field/modules/text/text.js diff -N modules/field/modules/text/text.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/field/modules/text/text.js 17 Aug 2009 17:25:14 -0000 @@ -0,0 +1,84 @@ +// $Id$ + +(function ($) { + +/** + * Auto-hide summary textarea if empty and show hide and unhide links. + */ +Drupal.behaviors.textTextareaSummary = { + attach: function (context, settings) { + $('textarea.text-textarea-summary:not(.text-textarea-summary-processed)', context).addClass('text-textarea-summary-processed').each(function () { + var $fieldset = $(this).closest('fieldset'); + var $div = $(this).closest('div.text-summary-wrapper'); + + // If no summary is set, hide the summary field. + if ($(this).val() == '') { + $div.hide(); + // If the 'edit summary' link is present, just display it. + if ($fieldset.find('div.text-full-wrapper').prev('label > span.field-edit-link').length) { + $fieldset.find('div.text-full-wrapper span.field-edit-link').show(); + } + // Otherwise append the link and configure the click event action. + else { + $fieldset.find('div.text-full-wrapper div.form-item-textarea label') + .append($('(' + Drupal.t('Edit summary') + ')')); + $fieldset.find('a.link-edit-summary').click(function () { + $fieldset + .find('div.text-summary-wrapper').show().end() + .find('label span.field-edit-link').hide(); + var $edit_link = $fieldset.find('div.text-summary-wrapper span.field-edit-link'); + if ($edit_link.length) { + $edit_link.show(); + } + else { + $fieldset.find('div.text-summary-wrapper div.form-item-textarea label') + .append($('()')); + $fieldset.find('a.link-hide-summary').click(function () { + $fieldset.find('label span.field-edit-link').show(); + $div.hide(); + return false; + }); + } + return false; + }); + } + } + // If there is a summary set, don't hide the summary field. + else { + // If the 'hide summary' link is present, just display it. + if ($div.prev('label > span.field-edit-link').length) { + $div.prev('label > span.field-edit-link').show(); + } + // Otherwise append the link and configure the click event action. + else { + $fieldset.find('div.text-summary-wrapper div.form-item-textarea label') + .append($('()')); + $fieldset.find('a.link-hide-summary').click(function () { + var $edit_link = $fieldset.find('div.text-full-wrapper span.field-edit-link'); + if ($edit_link.length) { + $edit_link.show(); + } + else { + $fieldset.find('div.text-full-wrapper div.form-item-textarea label') + .append($('(' + Drupal.t('Edit summary') + ')')); + $fieldset.find('a.link-edit-summary').click(function () { + $fieldset + .find('div.text-full-wrapper') + .find('label span.field-edit-link') + .hide().end() + .end() + .find('div.text-summary-wrapper').show();; + return false; + }); + } + $div.hide(); + return false; + }); + } + } + }); + } +}; + +})(jQuery); + Index: modules/field/modules/text/text.module =================================================================== RCS file: /cvs/drupal/drupal/modules/field/modules/text/text.module,v retrieving revision 1.17 diff -u -p -r1.17 text.module --- modules/field/modules/text/text.module 4 Aug 2009 06:38:56 -0000 1.17 +++ modules/field/modules/text/text.module 17 Aug 2009 17:19:56 -0000 @@ -664,6 +664,10 @@ function text_textarea_with_summary_proc '#description' => t('Leave blank to use trimmed value of full text as the summary.'), '#required' => $element['#required'], '#display' => $display, + '#attached_js' => array(drupal_get_path('module', 'text') . '/text.js'), + '#attributes' => array('class' => 'text-textarea-summary'), + '#prefix' => '