annotate core/modules/toolbar/js/views/ToolbarAuralView.es6.js @ 19:fa3358dc1485 tip

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