details-aria.js 689 B

1234567891011121314151617181920212223242526272829
  1. /**
  2. * @file
  3. * Add aria attribute handling for details and summary elements.
  4. */
  5. (function ($, Drupal) {
  6. 'use strict';
  7. /**
  8. * Handles `aria-expanded` and `aria-pressed` attributes on details elements.
  9. *
  10. * @type {Drupal~behavior}
  11. */
  12. Drupal.behaviors.detailsAria = {
  13. attach: function () {
  14. $('body').once('detailsAria').on('click.detailsAria', 'summary', function (event) {
  15. var $summary = $(event.currentTarget);
  16. var open = $(event.currentTarget.parentNode).attr('open') === 'open' ? 'false' : 'true';
  17. $summary.attr({
  18. 'aria-expanded': open,
  19. 'aria-pressed': open
  20. });
  21. });
  22. }
  23. };
  24. })(jQuery, Drupal);