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