Mercurial > hg > isophonics-drupal-site
comparison core/modules/locale/locale.admin.es6.js @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
1 /** | 1 /** |
2 * @file | 2 * @file |
3 * Locale admin behavior. | 3 * Locale admin behavior. |
4 */ | 4 */ |
5 | 5 |
6 (function ($, Drupal) { | 6 (function($, Drupal) { |
7 /** | 7 /** |
8 * Marks changes of translations. | 8 * Marks changes of translations. |
9 * | 9 * |
10 * @type {Drupal~behavior} | 10 * @type {Drupal~behavior} |
11 * | 11 * |
14 * @prop {Drupal~behaviorDetach} detach | 14 * @prop {Drupal~behaviorDetach} detach |
15 * Detach behavior to show the user if translations has changed. | 15 * Detach behavior to show the user if translations has changed. |
16 */ | 16 */ |
17 Drupal.behaviors.localeTranslateDirty = { | 17 Drupal.behaviors.localeTranslateDirty = { |
18 attach() { | 18 attach() { |
19 const $form = $('#locale-translate-edit-form').once('localetranslatedirty'); | 19 const $form = $('#locale-translate-edit-form').once( |
20 'localetranslatedirty', | |
21 ); | |
20 if ($form.length) { | 22 if ($form.length) { |
21 // Display a notice if any row changed. | 23 // Display a notice if any row changed. |
22 $form.one('formUpdated.localeTranslateDirty', 'table', function () { | 24 $form.one('formUpdated.localeTranslateDirty', 'table', function() { |
23 const $marker = $(Drupal.theme('localeTranslateChangedWarning')).hide(); | 25 const $marker = $( |
24 $(this).addClass('changed').before($marker); | 26 Drupal.theme('localeTranslateChangedWarning'), |
27 ).hide(); | |
28 $(this) | |
29 .addClass('changed') | |
30 .before($marker); | |
25 $marker.fadeIn('slow'); | 31 $marker.fadeIn('slow'); |
26 }); | 32 }); |
27 // Highlight changed row. | 33 // Highlight changed row. |
28 $form.on('formUpdated.localeTranslateDirty', 'tr', function () { | 34 $form.on('formUpdated.localeTranslateDirty', 'tr', function() { |
29 const $row = $(this); | 35 const $row = $(this); |
30 const $rowToMark = $row.once('localemark'); | 36 const $rowToMark = $row.once('localemark'); |
31 const marker = Drupal.theme('localeTranslateChangedMarker'); | 37 const marker = Drupal.theme('localeTranslateChangedMarker'); |
32 | 38 |
33 $row.addClass('changed'); | 39 $row.addClass('changed'); |
38 }); | 44 }); |
39 } | 45 } |
40 }, | 46 }, |
41 detach(context, settings, trigger) { | 47 detach(context, settings, trigger) { |
42 if (trigger === 'unload') { | 48 if (trigger === 'unload') { |
43 const $form = $('#locale-translate-edit-form').removeOnce('localetranslatedirty'); | 49 const $form = $('#locale-translate-edit-form').removeOnce( |
50 'localetranslatedirty', | |
51 ); | |
44 if ($form.length) { | 52 if ($form.length) { |
45 $form.off('formUpdated.localeTranslateDirty'); | 53 $form.off('formUpdated.localeTranslateDirty'); |
46 } | 54 } |
47 } | 55 } |
48 }, | 56 }, |
56 * @prop {Drupal~behaviorAttach} attach | 64 * @prop {Drupal~behaviorAttach} attach |
57 * Attaches behavior for toggling details on the translation update page. | 65 * Attaches behavior for toggling details on the translation update page. |
58 */ | 66 */ |
59 Drupal.behaviors.hideUpdateInformation = { | 67 Drupal.behaviors.hideUpdateInformation = { |
60 attach(context, settings) { | 68 attach(context, settings) { |
61 const $table = $('#locale-translation-status-form').once('expand-updates'); | 69 const $table = $('#locale-translation-status-form').once( |
70 'expand-updates', | |
71 ); | |
62 if ($table.length) { | 72 if ($table.length) { |
63 const $tbodies = $table.find('tbody'); | 73 const $tbodies = $table.find('tbody'); |
64 | 74 |
65 // Open/close the description details by toggling a tr class. | 75 // Open/close the description details by toggling a tr class. |
66 $tbodies.on('click keydown', '.description', function (e) { | 76 $tbodies.on('click keydown', '.description', function(e) { |
67 if (e.keyCode && (e.keyCode !== 13 && e.keyCode !== 32)) { | 77 if (e.keyCode && (e.keyCode !== 13 && e.keyCode !== 32)) { |
68 return; | 78 return; |
69 } | 79 } |
70 e.preventDefault(); | 80 e.preventDefault(); |
71 const $tr = $(this).closest('tr'); | 81 const $tr = $(this).closest('tr'); |
84 $table.find('.requirements, .links').hide(); | 94 $table.find('.requirements, .links').hide(); |
85 } | 95 } |
86 }, | 96 }, |
87 }; | 97 }; |
88 | 98 |
89 $.extend(Drupal.theme, /** @lends Drupal.theme */{ | 99 $.extend( |
100 Drupal.theme, | |
101 /** @lends Drupal.theme */ { | |
102 /** | |
103 * Creates markup for a changed translation marker. | |
104 * | |
105 * @return {string} | |
106 * Markup for the marker. | |
107 */ | |
108 localeTranslateChangedMarker() { | |
109 return `<abbr class="warning ajax-changed" title="${Drupal.t( | |
110 'Changed', | |
111 )}">*</abbr>`; | |
112 }, | |
90 | 113 |
91 /** | 114 /** |
92 * Creates markup for a changed translation marker. | 115 * Creates markup for the translation changed warning. |
93 * | 116 * |
94 * @return {string} | 117 * @return {string} |
95 * Markup for the marker. | 118 * Markup for the warning. |
96 */ | 119 */ |
97 localeTranslateChangedMarker() { | 120 localeTranslateChangedWarning() { |
98 return `<abbr class="warning ajax-changed" title="${Drupal.t('Changed')}">*</abbr>`; | 121 return `<div class="clearfix messages messages--warning">${Drupal.theme( |
122 'localeTranslateChangedMarker', | |
123 )} ${Drupal.t( | |
124 'Changes made in this table will not be saved until the form is submitted.', | |
125 )}</div>`; | |
126 }, | |
99 }, | 127 }, |
100 | 128 ); |
101 /** | 129 })(jQuery, Drupal); |
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)); |