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@0
|
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@0
|
15 if (!pathInfo.currentPathIsAdmin && !/destination=/.test(windowLocation.search)) {
|
Chris@0
|
16 sessionStorage.setItem('escapeAdminPath', windowLocation);
|
Chris@0
|
17 }
|
Chris@0
|
18
|
Chris@0
|
19 /**
|
Chris@0
|
20 * Replaces the "Home" link with "Back to site" link.
|
Chris@0
|
21 *
|
Chris@0
|
22 * Back to site link points to the last non-administrative page the user
|
Chris@0
|
23 * visited within the same browser tab.
|
Chris@0
|
24 *
|
Chris@0
|
25 * @type {Drupal~behavior}
|
Chris@0
|
26 *
|
Chris@0
|
27 * @prop {Drupal~behaviorAttach} attach
|
Chris@0
|
28 * Attaches the replacement functionality to the toolbar-escape-admin element.
|
Chris@0
|
29 */
|
Chris@0
|
30 Drupal.behaviors.escapeAdmin = {
|
Chris@0
|
31 attach() {
|
Chris@0
|
32 const $toolbarEscape = $('[data-toolbar-escape-admin]').once('escapeAdmin');
|
Chris@0
|
33 if ($toolbarEscape.length && pathInfo.currentPathIsAdmin) {
|
Chris@0
|
34 if (escapeAdminPath !== null) {
|
Chris@0
|
35 $toolbarEscape.attr('href', escapeAdminPath);
|
Chris@0
|
36 }
|
Chris@0
|
37 else {
|
Chris@0
|
38 $toolbarEscape.text(Drupal.t('Home'));
|
Chris@0
|
39 }
|
Chris@0
|
40 }
|
Chris@0
|
41 },
|
Chris@0
|
42 };
|
Chris@0
|
43 }(jQuery, Drupal, drupalSettings));
|