annotate core/modules/toolbar/js/views/ToolbarAuralView.es6.js @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
rev   line source
Chris@0 1 /**
Chris@0 2 * @file
Chris@0 3 * A Backbone view for the aural feedback of the toolbar.
Chris@0 4 */
Chris@0 5
Chris@0 6 (function (Backbone, Drupal) {
Chris@0 7 Drupal.toolbar.ToolbarAuralView = Backbone.View.extend(/** @lends Drupal.toolbar.ToolbarAuralView# */{
Chris@0 8
Chris@0 9 /**
Chris@0 10 * Backbone view for the aural feedback of the toolbar.
Chris@0 11 *
Chris@0 12 * @constructs
Chris@0 13 *
Chris@0 14 * @augments Backbone.View
Chris@0 15 *
Chris@0 16 * @param {object} options
Chris@0 17 * Options for the view.
Chris@0 18 * @param {object} options.strings
Chris@0 19 * Various strings to use in the view.
Chris@0 20 */
Chris@0 21 initialize(options) {
Chris@0 22 this.strings = options.strings;
Chris@0 23
Chris@0 24 this.listenTo(this.model, 'change:orientation', this.onOrientationChange);
Chris@0 25 this.listenTo(this.model, 'change:activeTray', this.onActiveTrayChange);
Chris@0 26 },
Chris@0 27
Chris@0 28 /**
Chris@0 29 * Announces an orientation change.
Chris@0 30 *
Chris@0 31 * @param {Drupal.toolbar.ToolbarModel} model
Chris@0 32 * The toolbar model in question.
Chris@0 33 * @param {string} orientation
Chris@0 34 * The new value of the orientation attribute in the model.
Chris@0 35 */
Chris@0 36 onOrientationChange(model, orientation) {
Chris@0 37 Drupal.announce(Drupal.t('Tray orientation changed to @orientation.', {
Chris@0 38 '@orientation': orientation,
Chris@0 39 }));
Chris@0 40 },
Chris@0 41
Chris@0 42 /**
Chris@0 43 * Announces a changed active tray.
Chris@0 44 *
Chris@0 45 * @param {Drupal.toolbar.ToolbarModel} model
Chris@0 46 * The toolbar model in question.
Chris@0 47 * @param {HTMLElement} tray
Chris@0 48 * The new value of the tray attribute in the model.
Chris@0 49 */
Chris@0 50 onActiveTrayChange(model, tray) {
Chris@0 51 const relevantTray = (tray === null) ? model.previous('activeTray') : tray;
Chris@0 52 // Current activeTray and previous activeTray are empty, no state change
Chris@0 53 // to announce.
Chris@0 54 if (!relevantTray) {
Chris@0 55 return;
Chris@0 56 }
Chris@0 57 const action = (tray === null) ? Drupal.t('closed') : Drupal.t('opened');
Chris@0 58 const trayNameElement = relevantTray.querySelector('.toolbar-tray-name');
Chris@0 59 let text;
Chris@0 60 if (trayNameElement !== null) {
Chris@0 61 text = Drupal.t('Tray "@tray" @action.', {
Chris@0 62 '@tray': trayNameElement.textContent, '@action': action,
Chris@0 63 });
Chris@0 64 }
Chris@0 65 else {
Chris@0 66 text = Drupal.t('Tray @action.', { '@action': action });
Chris@0 67 }
Chris@0 68 Drupal.announce(text);
Chris@0 69 },
Chris@0 70 });
Chris@0 71 }(Backbone, Drupal));