/** * @file * A Backbone view for the aural feedback of the toolbar. */ (function (Backbone, Drupal) { "use strict"; /** * Backbone view for the aural feedback of the toolbar. */ Drupal.toolbar.ToolbarAuralView = Backbone.View.extend({ /** * {@inheritdoc} */ initialize: function (options) { this.strings = options.strings; this.listenTo(this.model, 'change:orientation', this.onOrientationChange); this.listenTo(this.model, 'change:activeTray', this.onActiveTrayChange); }, /** * Announces an orientation change. * * @param Drupal.Toolbar.ToolbarModel model * @param String orientation * The new value of the orientation attribute in the model. */ onOrientationChange: function (model, orientation) { Drupal.announce(Drupal.t('Tray orientation changed to @orientation.', { '@orientation': orientation })); }, /** * Announces a changed active tray. * * @param Drupal.Toolbar.ToolbarModel model * @param Element orientation * The new value of the tray attribute in the model. */ onActiveTrayChange: function (model, tray) { var relevantTray = (tray === null) ? model.previous('activeTray') : tray; var trayName = relevantTray.querySelector('.toolbar-tray-name').textContent; var text; if (tray === null) { text = Drupal.t('Tray "@tray" closed.', { '@tray': trayName }); } else { text = Drupal.t('Tray "@tray" opened.', { '@tray': trayName }); } Drupal.announce(text); } }); }(Backbone, Drupal));