0141b04ba10e88de43b6e607372b4f2a39cb18e1
[yaffs-website] / web / core / modules / contextual / js / views / AuralView.es6.js
1 /**
2  * @file
3  * A Backbone View that provides the aural view of a contextual link.
4  */
5
6 (function (Drupal, Backbone) {
7   Drupal.contextual.AuralView = Backbone.View.extend(/** @lends Drupal.contextual.AuralView# */{
8
9     /**
10      * Renders the aural view of a contextual link (i.e. screen reader support).
11      *
12      * @constructs
13      *
14      * @augments Backbone.View
15      *
16      * @param {object} options
17      *   Options for the view.
18      */
19     initialize(options) {
20       this.options = options;
21
22       this.listenTo(this.model, 'change', this.render);
23
24       // Use aria-role form so that the number of items in the list is spoken.
25       this.$el.attr('role', 'form');
26
27       // Initial render.
28       this.render();
29     },
30
31     /**
32      * @inheritdoc
33      */
34     render() {
35       const isOpen = this.model.get('isOpen');
36
37       // Set the hidden property of the links.
38       this.$el.find('.contextual-links')
39         .prop('hidden', !isOpen);
40
41       // Update the view of the trigger.
42       this.$el.find('.trigger')
43         .text(Drupal.t('@action @title configuration options', {
44           '@action': (!isOpen) ? this.options.strings.open : this.options.strings.close,
45           '@title': this.model.get('title'),
46         }))
47         .attr('aria-pressed', isOpen);
48     },
49
50   });
51 }(Drupal, Backbone));