X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Ftext%2Ftext.es6.js;fp=web%2Fcore%2Fmodules%2Ftext%2Ftext.es6.js;h=04224186126d78643910f314917204a4b77a4728;hp=6c11adae1b2e1547c5f8a43aa1488d60c184b91f;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/modules/text/text.es6.js b/web/core/modules/text/text.es6.js index 6c11adae1..042241861 100644 --- a/web/core/modules/text/text.es6.js +++ b/web/core/modules/text/text.es6.js @@ -3,7 +3,7 @@ * Text behaviors. */ -(function ($, Drupal) { +(function($, Drupal) { /** * Auto-hide summary textarea if empty and show hide and unhide links. * @@ -14,44 +14,52 @@ */ Drupal.behaviors.textSummary = { attach(context, settings) { - $(context).find('.js-text-summary').once('text-summary').each(function () { - const $widget = $(this).closest('.js-text-format-wrapper'); + $(context) + .find('.js-text-summary') + .once('text-summary') + .each(function() { + const $widget = $(this).closest('.js-text-format-wrapper'); - const $summary = $widget.find('.js-text-summary-wrapper'); - const $summaryLabel = $summary.find('label').eq(0); - const $full = $widget.find('.js-text-full').closest('.js-form-item'); - let $fullLabel = $full.find('label').eq(0); + const $summary = $widget.find('.js-text-summary-wrapper'); + const $summaryLabel = $summary.find('label').eq(0); + const $full = $widget.children('.js-form-type-textarea'); + let $fullLabel = $full.find('label').eq(0); - // Create a placeholder label when the field cardinality is greater - // than 1. - if ($fullLabel.length === 0) { - $fullLabel = $('').prependTo($full); - } - - // Set up the edit/hide summary link. - const $link = $(` ()`); - const $button = $link.find('button'); - let toggleClick = true; - $link.on('click', (e) => { - if (toggleClick) { - $summary.hide(); - $button.html(Drupal.t('Edit summary')); - $link.appendTo($fullLabel); - } - else { - $summary.show(); - $button.html(Drupal.t('Hide summary')); - $link.appendTo($summaryLabel); + // Create a placeholder label when the field cardinality is greater + // than 1. + if ($fullLabel.length === 0) { + $fullLabel = $('').prependTo($full); } - e.preventDefault(); - toggleClick = !toggleClick; - }).appendTo($summaryLabel); - // If no summary is set, hide the summary field. - if ($widget.find('.js-text-summary').val() === '') { - $link.trigger('click'); - } - }); + // Set up the edit/hide summary link. + const $link = $( + ` ()`, + ); + const $button = $link.find('button'); + let toggleClick = true; + $link + .on('click', e => { + if (toggleClick) { + $summary.hide(); + $button.html(Drupal.t('Edit summary')); + $link.appendTo($fullLabel); + } else { + $summary.show(); + $button.html(Drupal.t('Hide summary')); + $link.appendTo($summaryLabel); + } + e.preventDefault(); + toggleClick = !toggleClick; + }) + .appendTo($summaryLabel); + + // If no summary is set, hide the summary field. + if ($widget.find('.js-text-summary').val() === '') { + $link.trigger('click'); + } + }); }, }; -}(jQuery, Drupal)); +})(jQuery, Drupal);