diff --git a/core/modules/toolbar/js/toolbar.js b/core/modules/toolbar/js/toolbar.js index d26b443..501c861 100644 --- a/core/modules/toolbar/js/toolbar.js +++ b/core/modules/toolbar/js/toolbar.js @@ -21,10 +21,11 @@ var orientation = JSON.parse(localStorage.getItem('Drupal.toolbar.trayOrientatio var locked = JSON.parse(localStorage.getItem('Drupal.toolbar.trayLocked')) || false; /** - * Holds the jQuery objects of the toolbar DOM element and the trays. + * Holds the jQuery objects of the toolbar DOM element, the trays and messages. */ var $toolbar; var $trays; +var $messages; /** * Holds the mediaQueryList object. @@ -47,6 +48,9 @@ Drupal.behaviors.toolbar = { var options = $.extend(this.options, drupalSettings.toolbar); $toolbar = $(context).find('#toolbar').once('toolbar'); if ($toolbar.length) { + // Append a messages element for appending interaction updates for screen + // readers. + $messages = $(Drupal.theme('toolbarMessageBox')).appendTo($toolbar); // Store the trays in a scoped variable. $trays = $toolbar.find('.tray'); $trays @@ -99,6 +103,10 @@ Drupal.behaviors.toolbar = { * Toggle a toolbar tab and the associated tray. */ Drupal.toolbar.toggleTray = function (event) { + var strings = { + opened: Drupal.t('opened'), + closed: Drupal.t('closed') + }; var $tab = $(event.target); var name = $tab.attr('data-toolbar-tray'); // Activate the selected tab and associated tray. @@ -110,6 +118,15 @@ Drupal.toolbar.toggleTray = function (event) { // Toggle aria-pressed. var value = $tab.attr('aria-pressed'); $tab.attr('aria-pressed', (value === 'false') ? 'true' : 'false'); + // Append a message that a tray has been opened. + $messages.html( + Drupal.theme('toolbarTrayMessage', + Drupal.t('@tray tray @state.', { + '@tray': name, + '@state': (value === 'true') ? strings.closed : strings.opened + }) + ) + ); // Store the active tab name or remove the setting. if ($tab.hasClass('active')) { localStorage.setItem('Drupal.toolbar.activeTab', JSON.stringify(name)); @@ -169,12 +186,14 @@ Drupal.toolbar.setHeight = function () { * Respond to configured media query applicability changes. */ Drupal.toolbar.mediaQueryChangeHandler = function (mql) { - var orientation = (mql.matches) ? 'horizontal' : 'vertical'; - changeOrientation(orientation); - // Adjust the body to accommodate trays. - setBodyState(); - // Adjust the height of the toolbar. - Drupal.toolbar.setHeight(); + if (!locked) { + var orientation = (mql.matches) ? 'horizontal' : 'vertical'; + changeOrientation(orientation); + // Adjust the body to accommodate trays. + setBodyState(); + // Adjust the height of the toolbar. + Drupal.toolbar.setHeight(); + } }; /** @@ -257,4 +276,24 @@ Drupal.theme.toolbarOrientationToggle = function () { ''; }; +/** + * A region to post messages that a screen reading UA will announce. + * + * @return {String} + * A string representing a DOM fragment. + */ +Drupal.theme.toolbarMessageBox = function () { + return '
'; +}; + +/** + * Wrap a message string in a p tag. + * + * @return {String} + * A string representing a DOM fragment. + */ +Drupal.theme.toolbarTrayMessage = function (message) { + return '

' + message + '

'; +}; + }(jQuery, Drupal, drupalSettings));