annotate core/modules/contextual/js/views/AuralView.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 that provides the aural view of a contextual link.
Chris@0 4 */
Chris@0 5
Chris@17 6 (function(Drupal, Backbone) {
Chris@17 7 Drupal.contextual.AuralView = Backbone.View.extend(
Chris@17 8 /** @lends Drupal.contextual.AuralView# */ {
Chris@17 9 /**
Chris@17 10 * Renders the aural view of a contextual link (i.e. screen reader support).
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 */
Chris@17 19 initialize(options) {
Chris@17 20 this.options = options;
Chris@0 21
Chris@17 22 this.listenTo(this.model, 'change', this.render);
Chris@0 23
Chris@17 24 // Use aria-role form so that the number of items in the list is spoken.
Chris@17 25 this.$el.attr('role', 'form');
Chris@0 26
Chris@17 27 // Initial render.
Chris@17 28 this.render();
Chris@17 29 },
Chris@0 30
Chris@17 31 /**
Chris@17 32 * @inheritdoc
Chris@17 33 */
Chris@17 34 render() {
Chris@17 35 const isOpen = this.model.get('isOpen');
Chris@17 36
Chris@17 37 // Set the hidden property of the links.
Chris@17 38 this.$el.find('.contextual-links').prop('hidden', !isOpen);
Chris@17 39
Chris@17 40 // Update the view of the trigger.
Chris@17 41 this.$el
Chris@17 42 .find('.trigger')
Chris@17 43 .text(
Chris@17 44 Drupal.t('@action @title configuration options', {
Chris@17 45 '@action': !isOpen
Chris@17 46 ? this.options.strings.open
Chris@17 47 : this.options.strings.close,
Chris@17 48 '@title': this.model.get('title'),
Chris@17 49 }),
Chris@17 50 )
Chris@17 51 .attr('aria-pressed', isOpen);
Chris@17 52 },
Chris@0 53 },
Chris@17 54 );
Chris@17 55 })(Drupal, Backbone);