responsive-details.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. var $summaries = $details.find('> summary');
  15. function detailsToggle(matches) {
  16. if (matches) {
  17. $details.attr('open', true);
  18. $summaries.attr('aria-expanded', true);
  19. $summaries.on('click.details-open', false);
  20. } else {
  21. var $notPressed = $details.find('> summary[aria-pressed!=true]').attr('aria-expanded', false);
  22. $notPressed.parent('details').attr('open', false);
  23. $summaries.off('.details-open');
  24. }
  25. }
  26. function handleDetailsMQ(event) {
  27. detailsToggle(event.matches);
  28. }
  29. var mql = window.matchMedia('(min-width:48em)');
  30. mql.addListener(handleDetailsMQ);
  31. detailsToggle(mql.matches);
  32. }
  33. };
  34. })(jQuery, Drupal);