diff --git a/core/includes/common.inc b/core/includes/common.inc index 90641b6..0fb232e 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -2214,11 +2214,17 @@ 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; + 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 diff --git a/core/modules/block/lib/Drupal/block/Controller/BlockController.php b/core/modules/block/lib/Drupal/block/Controller/BlockController.php index c735ba0..0536022 100644 --- a/core/modules/block/lib/Drupal/block/Controller/BlockController.php +++ b/core/modules/block/lib/Drupal/block/Controller/BlockController.php @@ -30,6 +30,13 @@ public function demo($theme) { return array( '#title' => String::checkPlain($themes[$theme]->info['name']), '#attached' => array( + 'js' => array( + array( + // Let JavaScript know this really is an admin page. + 'data' => array('currentPathIsAdmin' => TRUE), + 'type' => 'setting', + ) + ), 'library' => array( array('block', 'drupal.block.admin'), ), diff --git a/core/modules/toolbar/css/toolbar.icons.css b/core/modules/toolbar/css/toolbar.icons.css index b10de97..a0cfce2 100644 --- a/core/modules/toolbar/css/toolbar.icons.css +++ b/core/modules/toolbar/css/toolbar.icons.css @@ -319,7 +319,18 @@ background-image: url("../../../misc/icons/787878/twistie-up.png"); background-size: auto auto; } - +.toolbar .toolbar-icon-escape:before { + background-image: url("../../../misc/icons/bebebe/chevron-disc-left.svg"); +} +.no-svg .toolbar .toolbar-icon-escape:before { + background-image: url("../../../misc/icons/bebebe/chevron-disc-left.png"); +} +[dir="rtl"] .toolbar .toolbar-icon-escape:before { + background-image: url("../../../misc/icons/bebebe/chevron-disc-right.svg"); +} +[dir="rtl"] .no-svg .toolbar .toolbar-icon-escape:before { + background-image: url("../../../misc/icons/bebebe/chevron-disc-right.png"); +} /** * Orientation toggle. */ diff --git a/core/modules/toolbar/js/escapeAdmin.js b/core/modules/toolbar/js/escapeAdmin.js new file mode 100644 index 0000000..4343ce1 --- /dev/null +++ b/core/modules/toolbar/js/escapeAdmin.js @@ -0,0 +1,36 @@ +(function ($, Drupal, drupalSettings) { + + "use strict"; + + var escapeAdminPage = sessionStorage.getItem('escapeAdminPage'); + + if (!drupalSettings.currentPathIsAdmin) { + sessionStorage.setItem('escapeAdminPage', drupalSettings.currentPath); + } + + Drupal.behaviors.escapeAdmin = { + attach: function () { + var $toolbarEscape = $('[data-toolbar-escape]').once('escapeAdmin'); + if ($toolbarEscape.length) { + if (drupalSettings.currentPathIsAdmin && escapeAdminPage) { + $toolbarEscape + .removeClass('toolbar-icon-home') + .addClass('toolbar-icon-escape') + .attr({ + 'href': Drupal.url(escapeAdminPage), + 'title': Drupal.t('Return to site content') + }) + .text(Drupal.t('Back to site')); + + // Escape admin when hitting Esc key. + $(window).on('keydown', function (event) { + if (event.keyCode === 27) { + window.location = Drupal.url(escapeAdminPage); + } + }); + } + } + } + }; + +})(jQuery, Drupal, drupalSettings); diff --git a/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module index 85bfafa..56f0012 100644 --- a/core/modules/toolbar/toolbar.module +++ b/core/modules/toolbar/toolbar.module @@ -416,9 +416,15 @@ function toolbar_toolbar() { 'attributes' => array( 'title' => t('Home page'), 'class' => array('toolbar-icon', 'toolbar-icon-home'), + 'data-toolbar-escape' => TRUE, ), ), ), + '#attached' => array( + 'library' => array( + array('toolbar', 'toolbar.escapeAdmin'), + ), + ), '#weight' => -20, ); @@ -609,6 +615,18 @@ function toolbar_library_info() { array('system', 'jquery.once'), ), ); + $libraries['toolbar.escapeAdmin'] = array( + 'title' => 'Provides a button to escape the admin.', + 'version' => \Drupal::VERSION, + 'js' => array( + drupal_get_path('module', 'toolbar') . '/js/escapeAdmin.js', + ), + 'dependencies' => array( + array('system', 'jquery'), + array('system', 'drupal'), + array('system', 'drupalSettings'), + ), + ); return $libraries; }