3 * Provides responsive behaviors to HTML details elements.
8 * Initializes the responsive behaviors for details elements.
10 * @type {Drupal~behavior}
12 * @prop {Drupal~behaviorAttach} attach
13 * Attaches the responsive behavior to status report specific details elements.
15 Drupal.behaviors.responsiveDetails = {
17 const $details = $(context)
19 .once('responsive-details');
21 if (!$details.length) {
25 const $summaries = $details.find('> summary');
27 function detailsToggle(matches) {
29 $details.attr('open', true);
30 $summaries.attr('aria-expanded', true);
31 $summaries.on('click.details-open', false);
33 // If user explicitly opened one, leave it alone.
34 const $notPressed = $details
35 .find('> summary[aria-pressed!=true]')
36 .attr('aria-expanded', false);
37 $notPressed.parent('details').attr('open', false);
38 // After resize, allow user to close previously opened details.
39 $summaries.off('.details-open');
43 function handleDetailsMQ(event) {
44 detailsToggle(event.matches);
47 const mql = window.matchMedia('(min-width:48em)');
48 mql.addListener(handleDetailsMQ);
49 detailsToggle(mql.matches);