Newer
Older
/**
Alex Pott
committed
* DO NOT EDIT THIS FILE.
* See the following change record for more information,
catch
committed
* https://www.drupal.org/node/2815083
Alex Pott
committed
* @preserve
**/
(function ($, Drupal, Backbone, _) {
Alex Pott
committed
Drupal.contextualToolbar.AuralView = Backbone.View.extend({
announcedOnce: false,
Alex Pott
committed
initialize: function initialize(options) {
this.options = options;
this.listenTo(this.model, 'change', this.render);
this.listenTo(this.model, 'change:isViewing', this.manageTabbing);
$(document).on('keyup', _.bind(this.onKeypress, this));
},
Alex Pott
committed
render: function render() {
this.$el.find('button').attr('aria-pressed', !this.model.get('isViewing'));
return this;
},
Alex Pott
committed
manageTabbing: function manageTabbing() {
var tabbingContext = this.model.get('tabbingContext');
Alex Pott
committed
if (tabbingContext) {
if (tabbingContext.active) {
Drupal.announce(this.options.strings.tabbingReleased);
}
tabbingContext.release();
}
Alex Pott
committed
if (!this.model.get('isViewing')) {
tabbingContext = Drupal.tabbingManager.constrain($('.contextual-toolbar-tab, .contextual'));
this.model.set('tabbingContext', tabbingContext);
this.announceTabbingConstraint();
this.announcedOnce = true;
}
},
Alex Pott
committed
announceTabbingConstraint: function announceTabbingConstraint() {
var strings = this.options.strings;
Drupal.announce(Drupal.formatString(strings.tabbingConstrained, {
'@contextualsCount': Drupal.formatPlural(Drupal.contextual.collection.length, '@count contextual link', '@count contextual links')
}));
Drupal.announce(strings.pressEsc);
},
Alex Pott
committed
onKeypress: function onKeypress(event) {
if (!this.announcedOnce && event.keyCode === 9 && !this.model.get('isViewing')) {
this.announceTabbingConstraint();
Alex Pott
committed
this.announcedOnce = true;
}
Alex Pott
committed
if (event.keyCode === 27) {
this.model.set('isViewing', true);
}
}
});
Alex Pott
committed
})(jQuery, Drupal, Backbone, _);