Security update to Drupal 8.4.6
[yaffs-website] / web / core / modules / locale / locale.admin.es6.js
1 /**
2  * @file
3  * Locale admin behavior.
4  */
5
6 (function ($, Drupal) {
7   /**
8    * Marks changes of translations.
9    *
10    * @type {Drupal~behavior}
11    *
12    * @prop {Drupal~behaviorAttach} attach
13    *   Attaches behavior to show the user if translations has changed.
14    * @prop {Drupal~behaviorDetach} detach
15    *   Detach behavior to show the user if translations has changed.
16    */
17   Drupal.behaviors.localeTranslateDirty = {
18     attach() {
19       const $form = $('#locale-translate-edit-form').once('localetranslatedirty');
20       if ($form.length) {
21         // Display a notice if any row changed.
22         $form.one('formUpdated.localeTranslateDirty', 'table', function () {
23           const $marker = $(Drupal.theme('localeTranslateChangedWarning')).hide();
24           $(this).addClass('changed').before($marker);
25           $marker.fadeIn('slow');
26         });
27         // Highlight changed row.
28         $form.on('formUpdated.localeTranslateDirty', 'tr', function () {
29           const $row = $(this);
30           const $rowToMark = $row.once('localemark');
31           const marker = Drupal.theme('localeTranslateChangedMarker');
32
33           $row.addClass('changed');
34           // Add an asterisk only once if row changed.
35           if ($rowToMark.length) {
36             $rowToMark.find('td:first-child .js-form-item').append(marker);
37           }
38         });
39       }
40     },
41     detach(context, settings, trigger) {
42       if (trigger === 'unload') {
43         const $form = $('#locale-translate-edit-form').removeOnce('localetranslatedirty');
44         if ($form.length) {
45           $form.off('formUpdated.localeTranslateDirty');
46         }
47       }
48     },
49   };
50
51   /**
52    * Show/hide the description details on Available translation updates page.
53    *
54    * @type {Drupal~behavior}
55    *
56    * @prop {Drupal~behaviorAttach} attach
57    *   Attaches behavior for toggling details on the translation update page.
58    */
59   Drupal.behaviors.hideUpdateInformation = {
60     attach(context, settings) {
61       const $table = $('#locale-translation-status-form').once('expand-updates');
62       if ($table.length) {
63         const $tbodies = $table.find('tbody');
64
65         // Open/close the description details by toggling a tr class.
66         $tbodies.on('click keydown', '.description', function (e) {
67           if (e.keyCode && (e.keyCode !== 13 && e.keyCode !== 32)) {
68             return;
69           }
70           e.preventDefault();
71           const $tr = $(this).closest('tr');
72
73           $tr.toggleClass('expanded');
74
75           // Change screen reader text.
76           $tr.find('.locale-translation-update__prefix').text(() => {
77             if ($tr.hasClass('expanded')) {
78               return Drupal.t('Hide description');
79             }
80
81             return Drupal.t('Show description');
82           });
83         });
84         $table.find('.requirements, .links').hide();
85       }
86     },
87   };
88
89   $.extend(Drupal.theme, /** @lends Drupal.theme */{
90
91     /**
92      * Creates markup for a changed translation marker.
93      *
94      * @return {string}
95      *   Markup for the marker.
96      */
97     localeTranslateChangedMarker() {
98       return `<abbr class="warning ajax-changed" title="${Drupal.t('Changed')}">*</abbr>`;
99     },
100
101     /**
102      * Creates markup for the translation changed warning.
103      *
104      * @return {string}
105      *   Markup for the warning.
106      */
107     localeTranslateChangedWarning() {
108       return `<div class="clearfix messages messages--warning">${Drupal.theme('localeTranslateChangedMarker')} ${Drupal.t('Changes made in this table will not be saved until the form is submitted.')}</div>`;
109     },
110   });
111 }(jQuery, Drupal));