Mercurial > hg > isophonics-drupal-site
comparison core/modules/toolbar/js/escapeAdmin.es6.js @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 /** | |
2 * @file | |
3 * Replaces the home link in toolbar with a back to site link. | |
4 */ | |
5 | |
6 (function ($, Drupal, drupalSettings) { | |
7 const pathInfo = drupalSettings.path; | |
8 const escapeAdminPath = sessionStorage.getItem('escapeAdminPath'); | |
9 const windowLocation = window.location; | |
10 | |
11 // Saves the last non-administrative page in the browser to be able to link | |
12 // back to it when browsing administrative pages. If there is a destination | |
13 // parameter there is not need to save the current path because the page is | |
14 // loaded within an existing "workflow". | |
15 if (!pathInfo.currentPathIsAdmin && !/destination=/.test(windowLocation.search)) { | |
16 sessionStorage.setItem('escapeAdminPath', windowLocation); | |
17 } | |
18 | |
19 /** | |
20 * Replaces the "Home" link with "Back to site" link. | |
21 * | |
22 * Back to site link points to the last non-administrative page the user | |
23 * visited within the same browser tab. | |
24 * | |
25 * @type {Drupal~behavior} | |
26 * | |
27 * @prop {Drupal~behaviorAttach} attach | |
28 * Attaches the replacement functionality to the toolbar-escape-admin element. | |
29 */ | |
30 Drupal.behaviors.escapeAdmin = { | |
31 attach() { | |
32 const $toolbarEscape = $('[data-toolbar-escape-admin]').once('escapeAdmin'); | |
33 if ($toolbarEscape.length && pathInfo.currentPathIsAdmin) { | |
34 if (escapeAdminPath !== null) { | |
35 $toolbarEscape.attr('href', escapeAdminPath); | |
36 } | |
37 else { | |
38 $toolbarEscape.text(Drupal.t('Home')); | |
39 } | |
40 } | |
41 }, | |
42 }; | |
43 }(jQuery, Drupal, drupalSettings)); |