Chris@0: /** Chris@0: * @file Chris@0: * Locale admin behavior. Chris@0: */ Chris@0: Chris@17: (function($, Drupal) { Chris@0: /** Chris@0: * Marks changes of translations. Chris@0: * Chris@0: * @type {Drupal~behavior} Chris@0: * Chris@0: * @prop {Drupal~behaviorAttach} attach Chris@0: * Attaches behavior to show the user if translations has changed. Chris@0: * @prop {Drupal~behaviorDetach} detach Chris@0: * Detach behavior to show the user if translations has changed. Chris@0: */ Chris@0: Drupal.behaviors.localeTranslateDirty = { Chris@0: attach() { Chris@17: const $form = $('#locale-translate-edit-form').once( Chris@17: 'localetranslatedirty', Chris@17: ); Chris@0: if ($form.length) { Chris@0: // Display a notice if any row changed. Chris@17: $form.one('formUpdated.localeTranslateDirty', 'table', function() { Chris@17: const $marker = $( Chris@17: Drupal.theme('localeTranslateChangedWarning'), Chris@17: ).hide(); Chris@17: $(this) Chris@17: .addClass('changed') Chris@17: .before($marker); Chris@0: $marker.fadeIn('slow'); Chris@0: }); Chris@0: // Highlight changed row. Chris@17: $form.on('formUpdated.localeTranslateDirty', 'tr', function() { Chris@0: const $row = $(this); Chris@0: const $rowToMark = $row.once('localemark'); Chris@0: const marker = Drupal.theme('localeTranslateChangedMarker'); Chris@0: Chris@0: $row.addClass('changed'); Chris@0: // Add an asterisk only once if row changed. Chris@0: if ($rowToMark.length) { Chris@0: $rowToMark.find('td:first-child .js-form-item').append(marker); Chris@0: } Chris@0: }); Chris@0: } Chris@0: }, Chris@0: detach(context, settings, trigger) { Chris@0: if (trigger === 'unload') { Chris@17: const $form = $('#locale-translate-edit-form').removeOnce( Chris@17: 'localetranslatedirty', Chris@17: ); Chris@0: if ($form.length) { Chris@0: $form.off('formUpdated.localeTranslateDirty'); Chris@0: } Chris@0: } Chris@0: }, Chris@0: }; Chris@0: Chris@0: /** Chris@0: * Show/hide the description details on Available translation updates page. Chris@0: * Chris@0: * @type {Drupal~behavior} Chris@0: * Chris@0: * @prop {Drupal~behaviorAttach} attach Chris@0: * Attaches behavior for toggling details on the translation update page. Chris@0: */ Chris@0: Drupal.behaviors.hideUpdateInformation = { Chris@0: attach(context, settings) { Chris@17: const $table = $('#locale-translation-status-form').once( Chris@17: 'expand-updates', Chris@17: ); Chris@0: if ($table.length) { Chris@0: const $tbodies = $table.find('tbody'); Chris@0: Chris@0: // Open/close the description details by toggling a tr class. Chris@17: $tbodies.on('click keydown', '.description', function(e) { Chris@0: if (e.keyCode && (e.keyCode !== 13 && e.keyCode !== 32)) { Chris@0: return; Chris@0: } Chris@0: e.preventDefault(); Chris@0: const $tr = $(this).closest('tr'); Chris@0: Chris@0: $tr.toggleClass('expanded'); Chris@0: Chris@0: // Change screen reader text. Chris@0: $tr.find('.locale-translation-update__prefix').text(() => { Chris@0: if ($tr.hasClass('expanded')) { Chris@0: return Drupal.t('Hide description'); Chris@0: } Chris@0: Chris@0: return Drupal.t('Show description'); Chris@0: }); Chris@0: }); Chris@0: $table.find('.requirements, .links').hide(); Chris@0: } Chris@0: }, Chris@0: }; Chris@0: Chris@17: $.extend( Chris@17: Drupal.theme, Chris@17: /** @lends Drupal.theme */ { Chris@17: /** Chris@17: * Creates markup for a changed translation marker. Chris@17: * Chris@17: * @return {string} Chris@17: * Markup for the marker. Chris@17: */ Chris@17: localeTranslateChangedMarker() { Chris@17: return `*`; Chris@17: }, Chris@0: Chris@17: /** Chris@17: * Creates markup for the translation changed warning. Chris@17: * Chris@17: * @return {string} Chris@17: * Markup for the warning. Chris@17: */ Chris@17: localeTranslateChangedWarning() { Chris@17: return `
`; Chris@17: }, Chris@0: }, Chris@17: ); Chris@17: })(jQuery, Drupal);