responsive-details.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * DO NOT EDIT THIS FILE.
  3. * See the following change record for more information,
  4. * https://www.drupal.org/node/2815083
  5. * @preserve
  6. **/
  7. (function ($, Drupal) {
  8. Drupal.behaviors.responsiveDetails = {
  9. attach: function attach(context) {
  10. var $details = $(context).find('details').once('responsive-details');
  11. if (!$details.length) {
  12. return;
  13. }
  14. function detailsToggle(matches) {
  15. if (matches) {
  16. $details.attr('open', true);
  17. $summaries.attr('aria-expanded', true);
  18. $summaries.on('click.details-open', false);
  19. } else {
  20. var $notPressed = $details.find('> summary[aria-pressed!=true]').attr('aria-expanded', false);
  21. $notPressed.parent('details').attr('open', false);
  22. $summaries.off('.details-open');
  23. }
  24. }
  25. function handleDetailsMQ(event) {
  26. detailsToggle(event.matches);
  27. }
  28. var $summaries = $details.find('> summary');
  29. var mql = window.matchMedia('(min-width:48em)');
  30. mql.addListener(handleDetailsMQ);
  31. detailsToggle(mql.matches);
  32. }
  33. };
  34. })(jQuery, Drupal);