details-aria.es6.js 728 B

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