blob: 0996a9e4f2881d657c3a2451e6118da49e56b5a5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/**
* DO NOT EDIT THIS FILE.
* See the following change record for more information,
* https://www.drupal.org/node/2815083
* @preserve
**/
(function ($, Drupal) {
Drupal.behaviors.textSummary = {
attach(context, settings) {
once('text-summary', '.js-text-summary', context).forEach(summary => {
const $widget = $(summary).closest('.js-text-format-wrapper');
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);
if ($fullLabel.length === 0) {
$fullLabel = $('<label></label>').prependTo($full);
}
if ($fullLabel.hasClass('visually-hidden')) {
$fullLabel.html((index, oldHtml) => `<span class="visually-hidden">${oldHtml}</span>`);
$fullLabel.removeClass('visually-hidden');
}
const $link = $(`<span class="field-edit-link"> (<button type="button" class="link link-edit-summary">${Drupal.t('Hide summary')}</button>)</span>`);
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 (summary.value === '') {
$link.trigger('click');
}
});
}
};
})(jQuery, Drupal);
|