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