5 * Auto-hide summary textarea if empty and show hide and unhide links.
7 Drupal
.behaviors
.textSummary
= {
8 attach: function (context
, settings
) {
9 $('.text-summary', context
).once('text-summary', function () {
10 var $widget
= $(this).closest('div.field-type-text-with-summary');
11 var $summaries
= $widget
.find('div.text-summary-wrapper');
13 $summaries
.once('text-summary-wrapper').each(function(index
) {
14 var $summary
= $(this);
15 var $summaryLabel
= $summary
.find('label');
16 var $full
= $widget
.find('.text-full').eq(index
).closest('.form-item');
17 var $fullLabel
= $full
.find('label');
19 // Create a placeholder label when the field cardinality is
20 // unlimited or greater than 1.
21 if ($fullLabel
.length
== 0) {
22 $fullLabel
= $('<label></label>').prependTo($full
);
25 // Setup the edit/hide summary link.
26 var $link
= $('<span class="field-edit-link">(<a class="link-edit-summary" href="#">' + Drupal
.t('Hide summary') + '</a>)</span>').toggle(
29 $(this).find('a').html(Drupal
.t('Edit summary')).end().appendTo($fullLabel
);
34 $(this).find('a').html(Drupal
.t('Hide summary')).end().appendTo($summaryLabel
);
37 ).appendTo($summaryLabel
);
39 // If no summary is set, hide the summary field.
40 if ($(this).find('.text-summary').val() == '') {