annotate core/modules/locale/locale.admin.es6.js @ 19:fa3358dc1485 tip

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