8 * Auto-hide summary textarea if empty and show hide and unhide links.
10 * @type {Drupal~behavior}
12 * @prop {Drupal~behaviorAttach} attach
13 * Attaches auto-hide behavior on `text-summary` events.
15 Drupal.behaviors.textSummary = {
16 attach(context, settings) {
18 .find('.js-text-summary')
21 const $widget = $(this).closest('.js-text-format-wrapper');
23 const $summary = $widget.find('.js-text-summary-wrapper');
24 const $summaryLabel = $summary.find('label').eq(0);
25 const $full = $widget.children('.js-form-type-textarea');
26 let $fullLabel = $full.find('label').eq(0);
28 // Create a placeholder label when the field cardinality is greater
30 if ($fullLabel.length === 0) {
31 $fullLabel = $('<label></label>').prependTo($full);
34 // Set up the edit/hide summary link.
36 `<span class="field-edit-link"> (<button type="button" class="link link-edit-summary">${Drupal.t(
40 const $button = $link.find('button');
41 let toggleClick = true;
46 $button.html(Drupal.t('Edit summary'));
47 $link.appendTo($fullLabel);
50 $button.html(Drupal.t('Hide summary'));
51 $link.appendTo($summaryLabel);
54 toggleClick = !toggleClick;
56 .appendTo($summaryLabel);
58 // If no summary is set, hide the summary field.
59 if ($widget.find('.js-text-summary').val() === '') {
60 $link.trigger('click');