Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/text/text.es6.js @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
1 /** | 1 /** |
2 * @file | 2 * @file |
3 * Text behaviors. | 3 * Text behaviors. |
4 */ | 4 */ |
5 | 5 |
6 (function ($, Drupal) { | 6 (function($, Drupal) { |
7 /** | 7 /** |
8 * Auto-hide summary textarea if empty and show hide and unhide links. | 8 * Auto-hide summary textarea if empty and show hide and unhide links. |
9 * | 9 * |
10 * @type {Drupal~behavior} | 10 * @type {Drupal~behavior} |
11 * | 11 * |
12 * @prop {Drupal~behaviorAttach} attach | 12 * @prop {Drupal~behaviorAttach} attach |
13 * Attaches auto-hide behavior on `text-summary` events. | 13 * Attaches auto-hide behavior on `text-summary` events. |
14 */ | 14 */ |
15 Drupal.behaviors.textSummary = { | 15 Drupal.behaviors.textSummary = { |
16 attach(context, settings) { | 16 attach(context, settings) { |
17 $(context).find('.js-text-summary').once('text-summary').each(function () { | 17 $(context) |
18 const $widget = $(this).closest('.js-text-format-wrapper'); | 18 .find('.js-text-summary') |
19 .once('text-summary') | |
20 .each(function() { | |
21 const $widget = $(this).closest('.js-text-format-wrapper'); | |
19 | 22 |
20 const $summary = $widget.find('.js-text-summary-wrapper'); | 23 const $summary = $widget.find('.js-text-summary-wrapper'); |
21 const $summaryLabel = $summary.find('label').eq(0); | 24 const $summaryLabel = $summary.find('label').eq(0); |
22 const $full = $widget.children('.js-form-type-textarea'); | 25 const $full = $widget.children('.js-form-type-textarea'); |
23 let $fullLabel = $full.find('label').eq(0); | 26 let $fullLabel = $full.find('label').eq(0); |
24 | 27 |
25 // Create a placeholder label when the field cardinality is greater | 28 // Create a placeholder label when the field cardinality is greater |
26 // than 1. | 29 // than 1. |
27 if ($fullLabel.length === 0) { | 30 if ($fullLabel.length === 0) { |
28 $fullLabel = $('<label></label>').prependTo($full); | 31 $fullLabel = $('<label></label>').prependTo($full); |
29 } | 32 } |
30 | 33 |
31 // Set up the edit/hide summary link. | 34 // Set up the edit/hide summary link. |
32 const $link = $(`<span class="field-edit-link"> (<button type="button" class="link link-edit-summary">${Drupal.t('Hide summary')}</button>)</span>`); | 35 const $link = $( |
33 const $button = $link.find('button'); | 36 `<span class="field-edit-link"> (<button type="button" class="link link-edit-summary">${Drupal.t( |
34 let toggleClick = true; | 37 'Hide summary', |
35 $link.on('click', (e) => { | 38 )}</button>)</span>`, |
36 if (toggleClick) { | 39 ); |
37 $summary.hide(); | 40 const $button = $link.find('button'); |
38 $button.html(Drupal.t('Edit summary')); | 41 let toggleClick = true; |
39 $link.appendTo($fullLabel); | 42 $link |
43 .on('click', e => { | |
44 if (toggleClick) { | |
45 $summary.hide(); | |
46 $button.html(Drupal.t('Edit summary')); | |
47 $link.appendTo($fullLabel); | |
48 } else { | |
49 $summary.show(); | |
50 $button.html(Drupal.t('Hide summary')); | |
51 $link.appendTo($summaryLabel); | |
52 } | |
53 e.preventDefault(); | |
54 toggleClick = !toggleClick; | |
55 }) | |
56 .appendTo($summaryLabel); | |
57 | |
58 // If no summary is set, hide the summary field. | |
59 if ($widget.find('.js-text-summary').val() === '') { | |
60 $link.trigger('click'); | |
40 } | 61 } |
41 else { | 62 }); |
42 $summary.show(); | |
43 $button.html(Drupal.t('Hide summary')); | |
44 $link.appendTo($summaryLabel); | |
45 } | |
46 e.preventDefault(); | |
47 toggleClick = !toggleClick; | |
48 }).appendTo($summaryLabel); | |
49 | |
50 // If no summary is set, hide the summary field. | |
51 if ($widget.find('.js-text-summary').val() === '') { | |
52 $link.trigger('click'); | |
53 } | |
54 }); | |
55 }, | 63 }, |
56 }; | 64 }; |
57 }(jQuery, Drupal)); | 65 })(jQuery, Drupal); |