responsive-details.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. /*eslint-disable */
  8. (function ($, Drupal) {
  9. Drupal.behaviors.responsiveDetails = {
  10. attach: function attach(context) {
  11. var $details = $(context).find('details').once('responsive-details');
  12. if (!$details.length) {
  13. return;
  14. }
  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. }
  21. else {
  22. var $notPressed = $details.find('> summary[aria-pressed!=true]').attr('aria-expanded', false);
  23. $notPressed.parent('details').attr('open', false);
  24. $summaries.off('.details-open');
  25. }
  26. }
  27. function handleDetailsMQ(event) {
  28. detailsToggle(event.matches);
  29. }
  30. var $summaries = $details.find('> summary');
  31. var mql = window.matchMedia('(min-width: 769px)');
  32. mql.addListener(handleDetailsMQ);
  33. detailsToggle(mql.matches);
  34. }
  35. };
  36. })(jQuery, Drupal);