3 * A Backbone View that provides the aural view of the edit mode toggle.
6 (function ($, Drupal, Backbone, _) {
7 Drupal.contextualToolbar.AuralView = Backbone.View.extend(/** @lends Drupal.contextualToolbar.AuralView# */{
10 * Tracks whether the tabbing constraint announcement has been read once.
17 * Renders the aural view of the edit mode toggle (screen reader support).
21 * @augments Backbone.View
23 * @param {object} options
24 * Options for the view.
27 this.options = options;
29 this.listenTo(this.model, 'change', this.render);
30 this.listenTo(this.model, 'change:isViewing', this.manageTabbing);
32 $(document).on('keyup', _.bind(this.onKeypress, this));
38 * @return {Drupal.contextualToolbar.AuralView}
39 * The current contextual toolbar aural view.
43 this.$el.find('button').attr('aria-pressed', !this.model.get('isViewing'));
49 * Limits tabbing to the contextual links and edit mode toolbar tab.
52 let tabbingContext = this.model.get('tabbingContext');
53 // Always release an existing tabbing context.
55 // Only announce release when the context was active.
56 if (tabbingContext.active) {
57 Drupal.announce(this.options.strings.tabbingReleased);
59 tabbingContext.release();
61 // Create a new tabbing context when edit mode is enabled.
62 if (!this.model.get('isViewing')) {
63 tabbingContext = Drupal.tabbingManager.constrain($('.contextual-toolbar-tab, .contextual'));
64 this.model.set('tabbingContext', tabbingContext);
65 this.announceTabbingConstraint();
66 this.announcedOnce = true;
71 * Announces the current tabbing constraint.
73 announceTabbingConstraint() {
74 const strings = this.options.strings;
75 Drupal.announce(Drupal.formatString(strings.tabbingConstrained, {
76 '@contextualsCount': Drupal.formatPlural(Drupal.contextual.collection.length, '@count contextual link', '@count contextual links'),
78 Drupal.announce(strings.pressEsc);
82 * Responds to esc and tab key press events.
84 * @param {jQuery.Event} event
88 // The first tab key press is tracked so that an annoucement about tabbing
89 // constraints can be raised if edit mode is enabled when the page is
91 if (!this.announcedOnce && event.keyCode === 9 && !this.model.get('isViewing')) {
92 this.announceTabbingConstraint();
93 // Set announce to true so that this conditional block won't run again.
94 this.announcedOnce = true;
96 // Respond to the ESC key. Exit out of edit mode.
97 if (event.keyCode === 27) {
98 this.model.set('isViewing', true);
103 }(jQuery, Drupal, Backbone, _));