X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Ftoolbar%2Fjs%2FescapeAdmin.es6.js;fp=web%2Fcore%2Fmodules%2Ftoolbar%2Fjs%2FescapeAdmin.es6.js;h=c381f021c7085151910e92c80a9f8da15360058a;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=0000000000000000000000000000000000000000;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/web/core/modules/toolbar/js/escapeAdmin.es6.js b/web/core/modules/toolbar/js/escapeAdmin.es6.js new file mode 100644 index 000000000..c381f021c --- /dev/null +++ b/web/core/modules/toolbar/js/escapeAdmin.es6.js @@ -0,0 +1,43 @@ +/** + * @file + * Replaces the home link in toolbar with a back to site link. + */ + +(function ($, Drupal, drupalSettings) { + const pathInfo = drupalSettings.path; + const escapeAdminPath = sessionStorage.getItem('escapeAdminPath'); + const windowLocation = window.location; + + // Saves the last non-administrative page in the browser to be able to link + // back to it when browsing administrative pages. If there is a destination + // parameter there is not need to save the current path because the page is + // loaded within an existing "workflow". + if (!pathInfo.currentPathIsAdmin && !/destination=/.test(windowLocation.search)) { + sessionStorage.setItem('escapeAdminPath', windowLocation); + } + + /** + * Replaces the "Home" link with "Back to site" link. + * + * Back to site link points to the last non-administrative page the user + * visited within the same browser tab. + * + * @type {Drupal~behavior} + * + * @prop {Drupal~behaviorAttach} attach + * Attaches the replacement functionality to the toolbar-escape-admin element. + */ + Drupal.behaviors.escapeAdmin = { + attach() { + const $toolbarEscape = $('[data-toolbar-escape-admin]').once('escapeAdmin'); + if ($toolbarEscape.length && pathInfo.currentPathIsAdmin) { + if (escapeAdminPath !== null) { + $toolbarEscape.attr('href', escapeAdminPath); + } + else { + $toolbarEscape.text(Drupal.t('Home')); + } + } + }, + }; +}(jQuery, Drupal, drupalSettings));