diff options
-rw-r--r-- | modules/field/modules/text/text.js | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/modules/field/modules/text/text.js b/modules/field/modules/text/text.js index 42f16c9e0..877132e40 100644 --- a/modules/field/modules/text/text.js +++ b/modules/field/modules/text/text.js @@ -9,30 +9,40 @@ Drupal.behaviors.textSummary = { attach: function (context, settings) { $('.text-summary', context).once('text-summary', function () { var $widget = $(this).closest('div.field-type-text-with-summary'); - var $summary = $widget.find('div.text-summary-wrapper'); - var $summaryLabel = $summary.find('label'); - var $full = $widget.find('.form-item:has(.text-full)'); - var $fullLabel = $full.find('label'); + var $summaries = $widget.find('div.text-summary-wrapper'); - // Setup the edit/hide summary link. - var $link = $('<span class="field-edit-link">(<a class="link-edit-summary" href="#">' + Drupal.t('Hide summary') + '</a>)</span>').toggle( - function () { - $summary.hide(); - $(this).find('a').html(Drupal.t('Edit summary')).end().appendTo($fullLabel); - return false; - }, - function () { - $summary.show(); - $(this).find('a').html(Drupal.t('Hide summary')).end().appendTo($summaryLabel); - return false; + $summaries.once('text-summary-wrapper').each(function(index) { + var $summary = $(this); + var $summaryLabel = $summary.find('label'); + var $full = $widget.find('.text-full').eq(index).closest('.form-item'); + var $fullLabel = $full.find('label'); + + // Create a placeholder label when the field cardinality is + // unlimited or greater than 1. + if ($fullLabel.length == 0) { + $fullLabel = $('<label></label>').prependTo($full); } - ).appendTo($summaryLabel); - // If no summary is set, hide the summary field. - if ($(this).val() == '') { - $link.click(); - } - return; + // Setup the edit/hide summary link. + var $link = $('<span class="field-edit-link">(<a class="link-edit-summary" href="#">' + Drupal.t('Hide summary') + '</a>)</span>').toggle( + function () { + $summary.hide(); + $(this).find('a').html(Drupal.t('Edit summary')).end().appendTo($fullLabel); + return false; + }, + function () { + $summary.show(); + $(this).find('a').html(Drupal.t('Hide summary')).end().appendTo($summaryLabel); + return false; + } + ).appendTo($summaryLabel); + + // If no summary is set, hide the summary field. + if ($(this).val() == '') { + $link.click(); + } + return; + }); }); } }; |