You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

51 rivejä
1.6 KiB

  1. import IHK from '../ihk';
  2. const $ = require('jquery');
  3. class Accordion {
  4. constructor(section) {
  5. this.section = section.addClass('initiated');
  6. this.section.find('.accordion-toggler').on('click', (e) => {
  7. e.preventDefault();
  8. const item = $(e.currentTarget).closest('li');
  9. item.toggleClass('open').find('.accordion-content').stop().slideToggle(400, 'easeOutQuad');
  10. if (this.section.data('single-open') !== false) {
  11. item.siblings('.open').removeClass('open').find('.accordion-content').slideUp(400, 'easeOutQuad');
  12. }
  13. });
  14. if (section.attr('data-type') === 'event') {
  15. this.initEvent();
  16. }
  17. }
  18. initEvent() {
  19. this.openEvent();
  20. this.section.find('.referee-details').hide();
  21. this.section.find('.referees > li > a').on('click', function (e) {
  22. e.preventDefault();
  23. const a = $(this);
  24. a.siblings('.referee-details').slideToggle(400, 'easeOutQuad');
  25. })
  26. };
  27. openEvent() {
  28. const t = this;
  29. const vars = IHK.getUrlVars();
  30. const $events = t.section.find('.accordion-content');
  31. const $queryParamEvent = $('#js-event-' + vars.terminId);
  32. if ($queryParamEvent.length) {
  33. // open if the url params have the terminId
  34. $queryParamEvent.show().closest('li').addClass('open');
  35. } else {
  36. // open the first item as fallback
  37. $events.first().show().closest('li').addClass('open');
  38. }
  39. }
  40. }
  41. $('body').on('ihk-init dynamic-component-loaded gfi-dynamic-init', function () {
  42. $('.accordion:not(.initiated)').each(function (i) {
  43. new Accordion($(this));
  44. });
  45. });