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