3 * Provides responsive behaviors to HTML details elements.
6 (function ($, Drupal) {
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).find('details').once('responsive-details');
19 if (!$details.length) {
23 function detailsToggle(matches) {
25 $details.attr('open', true);
26 $summaries.attr('aria-expanded', true);
27 $summaries.on('click.details-open', false);
30 // If user explicitly opened one, leave it alone.
31 const $notPressed = $details
32 .find('> summary[aria-pressed!=true]')
33 .attr('aria-expanded', false);
37 // After resize, allow user to close previously opened details.
38 $summaries.off('.details-open');
42 function handleDetailsMQ(event) {
43 detailsToggle(event.matches);
46 var $summaries = $details.find('> summary');
47 const mql = window.matchMedia('(min-width:48em)');
48 mql.addListener(handleDetailsMQ);
49 detailsToggle(mql.matches);