Chris@0: /** Chris@0: * @file Chris@0: * Replaces the home link in toolbar with a back to site link. Chris@0: */ Chris@0: Chris@17: (function($, Drupal, drupalSettings) { Chris@0: const pathInfo = drupalSettings.path; Chris@0: const escapeAdminPath = sessionStorage.getItem('escapeAdminPath'); Chris@0: const windowLocation = window.location; Chris@0: Chris@0: // Saves the last non-administrative page in the browser to be able to link Chris@0: // back to it when browsing administrative pages. If there is a destination Chris@0: // parameter there is not need to save the current path because the page is Chris@0: // loaded within an existing "workflow". Chris@17: if ( Chris@17: !pathInfo.currentPathIsAdmin && Chris@17: !/destination=/.test(windowLocation.search) Chris@17: ) { Chris@0: sessionStorage.setItem('escapeAdminPath', windowLocation); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Replaces the "Home" link with "Back to site" link. Chris@0: * Chris@0: * Back to site link points to the last non-administrative page the user Chris@0: * visited within the same browser tab. Chris@0: * Chris@0: * @type {Drupal~behavior} Chris@0: * Chris@0: * @prop {Drupal~behaviorAttach} attach Chris@0: * Attaches the replacement functionality to the toolbar-escape-admin element. Chris@0: */ Chris@0: Drupal.behaviors.escapeAdmin = { Chris@0: attach() { Chris@17: const $toolbarEscape = $('[data-toolbar-escape-admin]').once( Chris@17: 'escapeAdmin', Chris@17: ); Chris@0: if ($toolbarEscape.length && pathInfo.currentPathIsAdmin) { Chris@0: if (escapeAdminPath !== null) { Chris@0: $toolbarEscape.attr('href', escapeAdminPath); Chris@17: } else { Chris@0: $toolbarEscape.text(Drupal.t('Home')); Chris@0: } Chris@0: } Chris@0: }, Chris@0: }; Chris@17: })(jQuery, Drupal, drupalSettings);