annotate core/modules/locale/locale.admin.es6.js @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
rev   line source
Chris@0 1 /**
Chris@0 2 * @file
Chris@0 3 * Locale admin behavior.
Chris@0 4 */
Chris@0 5
Chris@0 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@0 19 const $form = $('#locale-translate-edit-form').once('localetranslatedirty');
Chris@0 20 if ($form.length) {
Chris@0 21 // Display a notice if any row changed.
Chris@0 22 $form.one('formUpdated.localeTranslateDirty', 'table', function () {
Chris@0 23 const $marker = $(Drupal.theme('localeTranslateChangedWarning')).hide();
Chris@0 24 $(this).addClass('changed').before($marker);
Chris@0 25 $marker.fadeIn('slow');
Chris@0 26 });
Chris@0 27 // Highlight changed row.
Chris@0 28 $form.on('formUpdated.localeTranslateDirty', 'tr', function () {
Chris@0 29 const $row = $(this);
Chris@0 30 const $rowToMark = $row.once('localemark');
Chris@0 31 const marker = Drupal.theme('localeTranslateChangedMarker');
Chris@0 32
Chris@0 33 $row.addClass('changed');
Chris@0 34 // Add an asterisk only once if row changed.
Chris@0 35 if ($rowToMark.length) {
Chris@0 36 $rowToMark.find('td:first-child .js-form-item').append(marker);
Chris@0 37 }
Chris@0 38 });
Chris@0 39 }
Chris@0 40 },
Chris@0 41 detach(context, settings, trigger) {
Chris@0 42 if (trigger === 'unload') {
Chris@0 43 const $form = $('#locale-translate-edit-form').removeOnce('localetranslatedirty');
Chris@0 44 if ($form.length) {
Chris@0 45 $form.off('formUpdated.localeTranslateDirty');
Chris@0 46 }
Chris@0 47 }
Chris@0 48 },
Chris@0 49 };
Chris@0 50
Chris@0 51 /**
Chris@0 52 * Show/hide the description details on Available translation updates page.
Chris@0 53 *
Chris@0 54 * @type {Drupal~behavior}
Chris@0 55 *
Chris@0 56 * @prop {Drupal~behaviorAttach} attach
Chris@0 57 * Attaches behavior for toggling details on the translation update page.
Chris@0 58 */
Chris@0 59 Drupal.behaviors.hideUpdateInformation = {
Chris@0 60 attach(context, settings) {
Chris@0 61 const $table = $('#locale-translation-status-form').once('expand-updates');
Chris@0 62 if ($table.length) {
Chris@0 63 const $tbodies = $table.find('tbody');
Chris@0 64
Chris@0 65 // Open/close the description details by toggling a tr class.
Chris@0 66 $tbodies.on('click keydown', '.description', function (e) {
Chris@0 67 if (e.keyCode && (e.keyCode !== 13 && e.keyCode !== 32)) {
Chris@0 68 return;
Chris@0 69 }
Chris@0 70 e.preventDefault();
Chris@0 71 const $tr = $(this).closest('tr');
Chris@0 72
Chris@0 73 $tr.toggleClass('expanded');
Chris@0 74
Chris@0 75 // Change screen reader text.
Chris@0 76 $tr.find('.locale-translation-update__prefix').text(() => {
Chris@0 77 if ($tr.hasClass('expanded')) {
Chris@0 78 return Drupal.t('Hide description');
Chris@0 79 }
Chris@0 80
Chris@0 81 return Drupal.t('Show description');
Chris@0 82 });
Chris@0 83 });
Chris@0 84 $table.find('.requirements, .links').hide();
Chris@0 85 }
Chris@0 86 },
Chris@0 87 };
Chris@0 88
Chris@0 89 $.extend(Drupal.theme, /** @lends Drupal.theme */{
Chris@0 90
Chris@0 91 /**
Chris@0 92 * Creates markup for a changed translation marker.
Chris@0 93 *
Chris@0 94 * @return {string}
Chris@0 95 * Markup for the marker.
Chris@0 96 */
Chris@0 97 localeTranslateChangedMarker() {
Chris@0 98 return `<abbr class="warning ajax-changed" title="${Drupal.t('Changed')}">*</abbr>`;
Chris@0 99 },
Chris@0 100
Chris@0 101 /**
Chris@0 102 * Creates markup for the translation changed warning.
Chris@0 103 *
Chris@0 104 * @return {string}
Chris@0 105 * Markup for the warning.
Chris@0 106 */
Chris@0 107 localeTranslateChangedWarning() {
Chris@0 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>`;
Chris@0 109 },
Chris@0 110 });
Chris@0 111 }(jQuery, Drupal));