diff --git a/core/includes/common.inc b/core/includes/common.inc index 2048ab4..ab82fdb 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -2236,11 +2236,13 @@ function drupal_add_js($data = NULL, $options = NULL) { $scriptPath = $GLOBALS['script_path']; $pathPrefix = ''; url('', array('script' => &$scriptPath, 'prefix' => &$pathPrefix)); + $current_path = current_path(); $javascript['settings']['data'][] = array( 'basePath' => base_path(), 'scriptPath' => $scriptPath, 'pathPrefix' => $pathPrefix, - 'currentPath' => current_path(), + 'currentPath' => $current_path, + 'currentPathIsAdmin' => MAINTENANCE_MODE !== 'update' ? path_is_admin($current_path) : TRUE, ); } // All JavaScript settings are placed in the header of the page with diff --git a/core/modules/toolbar/css/toolbar.icons.css b/core/modules/toolbar/css/toolbar.icons.css index b10de97..dc2577d 100644 --- a/core/modules/toolbar/css/toolbar.icons.css +++ b/core/modules/toolbar/css/toolbar.icons.css @@ -319,7 +319,12 @@ 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-right.svg"); +} +.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/css/toolbar.theme.css b/core/modules/toolbar/css/toolbar.theme.css index 5e2afe7..537002d 100644 --- a/core/modules/toolbar/css/toolbar.theme.css +++ b/core/modules/toolbar/css/toolbar.theme.css @@ -173,3 +173,9 @@ cursor: pointer; display: inline-block; } +.toolbar-oriented .toolbar-bar .escape-toolbar-tab { + float:right; +} +[dir="rtl"] .toolbar-oriented .toolbar-bar .escape-toolbar-tab { + float:left; +} diff --git a/core/modules/toolbar/js/escapeAdmin.js b/core/modules/toolbar/js/escapeAdmin.js new file mode 100644 index 0000000..c989fe2 --- /dev/null +++ b/core/modules/toolbar/js/escapeAdmin.js @@ -0,0 +1,33 @@ +(function ($, Drupal, drupalSettings) { + + "use strict"; + + var escapeAdminPage = sessionStorage.getItem('escapeAdminPage'); + + if (!drupalSettings.currentPathIsAdmin) { + sessionStorage.setItem('escapeAdminPage', drupalSettings.currentPath); + } + + Drupal.behaviors.trollverlay = { + attach: function () { + var $toolbarEscape = $('[data-toolbar-escape]').once('escapeAdmin'); + if ($toolbarEscape.length) { + if (drupalSettings.currentPathIsAdmin && escapeAdminPage) { + $toolbarEscape.attr('href', Drupal.url(escapeAdminPage)); + } + else { + $toolbarEscape.remove(); + } + + // 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 b20474b..4ce54ca 100644 --- a/core/modules/toolbar/toolbar.module +++ b/core/modules/toolbar/toolbar.module @@ -476,6 +476,35 @@ function toolbar_toolbar() { '#weight' => -15, ); + + if (\Drupal::currentUser()->hasPermission('access administration pages')) { + $items['escape_admin'] = array( + '#type' => 'toolbar_item', + 'tab' => array( + '#type' => 'link', + '#title' => t('Back to site'), + '#href' => '', + '#options' => array( + 'attributes' => array( + 'title' => t('Back to site'), + 'class' => array('toolbar-icon', 'toolbar-icon-escape'), + 'data-toolbar-escape' => TRUE, + ), + ), + ), + '#wrapper_attributes' => array( + 'class' => array('escape-toolbar-tab', 'hidden'), + 'id' => 'toolbar-tab-escape', + ), + '#attached' => array( + 'library' => array( + array('toolbar', 'toolbar.escapeAdmin'), + ), + ), + '#weight' => -30, + ); + } + return $items; } @@ -609,6 +638,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; }