3 * Locale admin behavior.
8 * Marks changes of translations.
10 * @type {Drupal~behavior}
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.
17 Drupal.behaviors.localeTranslateDirty = {
19 const $form = $('#locale-translate-edit-form').once(
20 'localetranslatedirty',
23 // Display a notice if any row changed.
24 $form.one('formUpdated.localeTranslateDirty', 'table', function() {
26 Drupal.theme('localeTranslateChangedWarning'),
31 $marker.fadeIn('slow');
33 // Highlight changed row.
34 $form.on('formUpdated.localeTranslateDirty', 'tr', function() {
36 const $rowToMark = $row.once('localemark');
37 const marker = Drupal.theme('localeTranslateChangedMarker');
39 $row.addClass('changed');
40 // Add an asterisk only once if row changed.
41 if ($rowToMark.length) {
42 $rowToMark.find('td:first-child .js-form-item').append(marker);
47 detach(context, settings, trigger) {
48 if (trigger === 'unload') {
49 const $form = $('#locale-translate-edit-form').removeOnce(
50 'localetranslatedirty',
53 $form.off('formUpdated.localeTranslateDirty');
60 * Show/hide the description details on Available translation updates page.
62 * @type {Drupal~behavior}
64 * @prop {Drupal~behaviorAttach} attach
65 * Attaches behavior for toggling details on the translation update page.
67 Drupal.behaviors.hideUpdateInformation = {
68 attach(context, settings) {
69 const $table = $('#locale-translation-status-form').once(
73 const $tbodies = $table.find('tbody');
75 // Open/close the description details by toggling a tr class.
76 $tbodies.on('click keydown', '.description', function(e) {
77 if (e.keyCode && (e.keyCode !== 13 && e.keyCode !== 32)) {
81 const $tr = $(this).closest('tr');
83 $tr.toggleClass('expanded');
85 // Change screen reader text.
86 $tr.find('.locale-translation-update__prefix').text(() => {
87 if ($tr.hasClass('expanded')) {
88 return Drupal.t('Hide description');
91 return Drupal.t('Show description');
94 $table.find('.requirements, .links').hide();
101 /** @lends Drupal.theme */ {
103 * Creates markup for a changed translation marker.
106 * Markup for the marker.
108 localeTranslateChangedMarker() {
109 return `<abbr class="warning ajax-changed" title="${Drupal.t(
115 * Creates markup for the translation changed warning.
118 * Markup for the warning.
120 localeTranslateChangedWarning() {
121 return `<div class="clearfix messages messages--warning">${Drupal.theme(
122 'localeTranslateChangedMarker',
124 'Changes made in this table will not be saved until the form is submitted.',