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