annotate core/modules/toolbar/js/escapeAdmin.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 * Replaces the home link in toolbar with a back to site link.
Chris@0 4 */
Chris@0 5
Chris@17 6 (function($, Drupal, drupalSettings) {
Chris@0 7 const pathInfo = drupalSettings.path;
Chris@0 8 const escapeAdminPath = sessionStorage.getItem('escapeAdminPath');
Chris@0 9 const windowLocation = window.location;
Chris@0 10
Chris@0 11 // Saves the last non-administrative page in the browser to be able to link
Chris@0 12 // back to it when browsing administrative pages. If there is a destination
Chris@0 13 // parameter there is not need to save the current path because the page is
Chris@0 14 // loaded within an existing "workflow".
Chris@17 15 if (
Chris@17 16 !pathInfo.currentPathIsAdmin &&
Chris@17 17 !/destination=/.test(windowLocation.search)
Chris@17 18 ) {
Chris@0 19 sessionStorage.setItem('escapeAdminPath', windowLocation);
Chris@0 20 }
Chris@0 21
Chris@0 22 /**
Chris@0 23 * Replaces the "Home" link with "Back to site" link.
Chris@0 24 *
Chris@0 25 * Back to site link points to the last non-administrative page the user
Chris@0 26 * visited within the same browser tab.
Chris@0 27 *
Chris@0 28 * @type {Drupal~behavior}
Chris@0 29 *
Chris@0 30 * @prop {Drupal~behaviorAttach} attach
Chris@0 31 * Attaches the replacement functionality to the toolbar-escape-admin element.
Chris@0 32 */
Chris@0 33 Drupal.behaviors.escapeAdmin = {
Chris@0 34 attach() {
Chris@17 35 const $toolbarEscape = $('[data-toolbar-escape-admin]').once(
Chris@17 36 'escapeAdmin',
Chris@17 37 );
Chris@0 38 if ($toolbarEscape.length && pathInfo.currentPathIsAdmin) {
Chris@0 39 if (escapeAdminPath !== null) {
Chris@0 40 $toolbarEscape.attr('href', escapeAdminPath);
Chris@17 41 } else {
Chris@0 42 $toolbarEscape.text(Drupal.t('Home'));
Chris@0 43 }
Chris@0 44 }
Chris@0 45 },
Chris@0 46 };
Chris@17 47 })(jQuery, Drupal, drupalSettings);