3 * Provides responsive behaviors to HTML details elements.
6 (function ($, Drupal) {
11 * Initializes the responsive behaviors for details elements.
13 * @type {Drupal~behavior}
15 * @prop {Drupal~behaviorAttach} attach
16 * Attaches the responsive behavior to status report specific details elements.
18 Drupal.behaviors.responsiveDetails = {
19 attach: function (context) {
20 var $details = $(context).find('details').once('responsive-details');
22 if (!$details.length) {
26 function detailsToggle(matches) {
28 $details.attr('open', true);
29 $summaries.attr('aria-expanded', true);
30 $summaries.on('click.details-open', false);
33 // If user explicitly opened one, leave it alone.
34 var $notPressed = $details
35 .find('> summary[aria-pressed!=true]')
36 .attr('aria-expanded', false);
40 // After resize, allow user to close previously opened details.
41 $summaries.off('.details-open');
45 function handleDetailsMQ(event) {
46 detailsToggle(event.matches);
49 var $summaries = $details.find('> summary');
50 var mql = window.matchMedia('(min-width:48em)');
51 mql.addListener(handleDetailsMQ);
52 detailsToggle(mql.matches);