AuralView.es6.js 1.4 KB

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