2013-11-26 22:06:57 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Replaces the home link in toolbar with a back to site link.
|
|
|
|
*/
|
2015-06-06 15:55:42 +00:00
|
|
|
|
2013-11-26 22:06:57 +00:00
|
|
|
(function ($, Drupal, drupalSettings) {
|
|
|
|
|
2015-10-13 22:37:56 +00:00
|
|
|
'use strict';
|
2013-11-26 22:06:57 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
var pathInfo = drupalSettings.path;
|
|
|
|
var escapeAdminPath = sessionStorage.getItem('escapeAdminPath');
|
2014-02-03 14:42:59 +00:00
|
|
|
var windowLocation = window.location;
|
2013-11-26 22:06:57 +00:00
|
|
|
|
2015-08-31 16:15:48 +00:00
|
|
|
// 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".
|
2014-02-03 14:42:59 +00:00
|
|
|
if (!pathInfo.currentPathIsAdmin && !/destination=/.test(windowLocation.search)) {
|
2014-03-12 19:09:45 +00:00
|
|
|
sessionStorage.setItem('escapeAdminPath', windowLocation);
|
2014-01-27 21:41:32 +00:00
|
|
|
}
|
2013-11-26 22:06:57 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
/**
|
|
|
|
* Replaces the "Home" link with "Back to site" link.
|
|
|
|
*
|
2015-08-31 16:15:48 +00:00
|
|
|
* Back to site link points to the last non-administrative page the user
|
|
|
|
* visited within the same browser tab.
|
2015-06-06 15:55:42 +00:00
|
|
|
*
|
|
|
|
* @type {Drupal~behavior}
|
2015-08-31 16:15:48 +00:00
|
|
|
*
|
|
|
|
* @prop {Drupal~behaviorAttach} attach
|
|
|
|
* Attaches the replacement functionality to the toolbar-escape-admin element.
|
2014-01-27 21:41:32 +00:00
|
|
|
*/
|
|
|
|
Drupal.behaviors.escapeAdmin = {
|
|
|
|
attach: function () {
|
|
|
|
var $toolbarEscape = $('[data-toolbar-escape-admin]').once('escapeAdmin');
|
2014-10-03 16:04:47 +00:00
|
|
|
if ($toolbarEscape.length && pathInfo.currentPathIsAdmin) {
|
|
|
|
if (escapeAdminPath !== null) {
|
2014-03-12 19:09:45 +00:00
|
|
|
$toolbarEscape.attr('href', escapeAdminPath);
|
2014-01-27 21:41:32 +00:00
|
|
|
}
|
2014-10-03 16:04:47 +00:00
|
|
|
else {
|
|
|
|
$toolbarEscape.text(Drupal.t('Home'));
|
|
|
|
}
|
|
|
|
$toolbarEscape.closest('.toolbar-tab').removeClass('hidden');
|
2013-11-26 22:06:57 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-27 21:41:32 +00:00
|
|
|
};
|
2013-11-26 22:06:57 +00:00
|
|
|
|
|
|
|
})(jQuery, Drupal, drupalSettings);
|