Updated Drupal to 8.6. This goes with the following updates because it's possible...
[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(
8     /** @lends Drupal.contextual.AuralView# */ {
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').prop('hidden', !isOpen);
39
40         // Update the view of the trigger.
41         this.$el
42           .find('.trigger')
43           .text(
44             Drupal.t('@action @title configuration options', {
45               '@action': !isOpen
46                 ? this.options.strings.open
47                 : this.options.strings.close,
48               '@title': this.model.get('title'),
49             }),
50           )
51           .attr('aria-pressed', isOpen);
52       },
53     },
54   );
55 })(Drupal, Backbone);