Commit 1151c73c authored by Dries's avatar Dries

Issue #787896 by nod_, cha0s, jp.stacey, sun, David_Rothstein, Bojhan,...

Issue #787896 by nod_, cha0s, jp.stacey, sun, David_Rothstein, Bojhan, lisarex: Add a link so that administrators can return to their most recently visited non-admin page.
parent d7a9d44e
......@@ -2215,11 +2215,18 @@ function drupal_add_js($data = NULL, $options = NULL) {
$scriptPath = $GLOBALS['script_path'];
$pathPrefix = '';
url('', array('script' => &$scriptPath, 'prefix' => &$pathPrefix));
$current_path = current_path();
$current_path_is_admin = FALSE;
// The function path_is_admin() is not available on update.php pages.
if (!(defined('MAINTENANCE_MODE') && MAINTENANCE_MODE === 'update')) {
$current_path_is_admin = path_is_admin($current_path);
}
$javascript['settings']['data'][] = array(
'basePath' => base_path(),
'scriptPath' => $scriptPath,
'pathPrefix' => $pathPrefix,
'currentPath' => current_path(),
'currentPath' => $current_path,
'currentPathIsAdmin' => $current_path_is_admin,
);
}
// All JavaScript settings are placed in the header of the page with
......
......@@ -30,6 +30,16 @@ public function demo($theme) {
return array(
'#title' => String::checkPlain($themes[$theme]->info['name']),
'#attached' => array(
'js' => array(
array(
// The block demonstration page is not marked as an administrative
// page by path_is_admin() function in order to use the frontend
// theme. Since JavaScript relies on a proper separation of admin
// pages, it needs to know this is an actual administrative page.
'data' => array('currentPathIsAdmin' => TRUE),
'type' => 'setting',
)
),
'library' => array(
array('block', 'drupal.block.admin'),
),
......
......@@ -65,20 +65,6 @@
/**
* Top level icons.
*/
.toolbar-bar .toolbar-icon-home:before {
background-image: url("../../../misc/icons/bebebe/house.svg");
}
.no-svg .toolbar-bar .toolbar-icon-home:before {
background-image: url("../../../misc/icons/bebebe/house.png");
}
.toolbar-bar .toolbar-icon-home:active:before,
.toolbar-bar .toolbar-icon-home.active:before {
background-image: url("../../../misc/icons/ffffff/house.svg");
}
.no-svg .toolbar-bar .toolbar-icon-home:active:before,
.no-svg .toolbar-bar .toolbar-icon-home.active:before {
background-image: url("../../../misc/icons/ffffff/house.png");
}
.toolbar-bar .toolbar-icon-menu:before {
background-image: url("../../../misc/icons/bebebe/hamburger.svg");
}
......@@ -319,7 +305,18 @@
background-image: url("../../../misc/icons/787878/twistie-up.png");
background-size: auto auto;
}
.toolbar .toolbar-icon-escape-admin:before {
background-image: url("../../../misc/icons/bebebe/chevron-disc-left.svg");
}
.no-svg .toolbar .toolbar-icon-escape-admin:before {
background-image: url("../../../misc/icons/bebebe/chevron-disc-left.png");
}
[dir="rtl"] .toolbar .toolbar-icon-escape-admin:before {
background-image: url("../../../misc/icons/bebebe/chevron-disc-right.svg");
}
[dir="rtl"] .no-svg .toolbar .toolbar-icon-escape-admin:before {
background-image: url("../../../misc/icons/bebebe/chevron-disc-right.png");
}
/**
* Orientation toggle.
*/
......
......@@ -38,6 +38,9 @@
.toolbar .menu li {
display: block;
}
.toolbar .toolbar-bar .toolbar-tab.hidden {
display: none;
}
.toolbar a {
display: block;
line-height: 1;
......
/**
* @file
*
* Replaces the home link in toolbar with a back to site link.
*/
(function ($, Drupal, drupalSettings) {
"use strict";
var escapeAdminPath = sessionStorage.getItem('escapeAdminPath');
// 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 (!drupalSettings.currentPathIsAdmin && !/destination=/.test(window.location.search)) {
sessionStorage.setItem('escapeAdminPath', drupalSettings.currentPath);
}
/**
* 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.
*/
Drupal.behaviors.escapeAdmin = {
attach: function () {
var $toolbarEscape = $('[data-toolbar-escape-admin]').once('escapeAdmin');
if ($toolbarEscape.length) {
if (drupalSettings.currentPathIsAdmin && escapeAdminPath) {
$toolbarEscape.attr('href', Drupal.url(escapeAdminPath));
$toolbarEscape.closest('.toolbar-tab').removeClass('hidden');
}
}
}
};
})(jQuery, Drupal, drupalSettings);
......@@ -410,15 +410,24 @@ function toolbar_toolbar() {
'#type' => 'toolbar_item',
'tab' => array(
'#type' => 'link',
'#title' => t('Home'),
'#title' => t('Back to site'),
'#href' => '<front>',
'#options' => array(
'attributes' => array(
'title' => t('Home page'),
'class' => array('toolbar-icon', 'toolbar-icon-home'),
'title' => t('Return to site content'),
'class' => array('toolbar-icon', 'toolbar-icon-escape-admin'),
'data-toolbar-escape-admin' => TRUE,
),
),
),
'#wrapper_attributes' => array(
'class' => array('hidden'),
),
'#attached' => array(
'library' => array(
array('toolbar', 'toolbar.escapeAdmin'),
),
),
'#weight' => -20,
);
......@@ -609,6 +618,19 @@ function toolbar_library_info() {
array('system', 'jquery.once'),
),
);
$libraries['toolbar.escapeAdmin'] = array(
'title' => 'Provides a button to escape the administration area.',
'version' => \Drupal::VERSION,
'js' => array(
drupal_get_path('module', 'toolbar') . '/js/escapeAdmin.js',
),
'dependencies' => array(
array('system', 'jquery'),
array('system', 'drupal'),
array('system', 'drupalSettings'),
array('system', 'jquery.once'),
),
);
return $libraries;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment