Merge remote-tracking branch 'zawadzki/new-design'
[wolnelektury.git] / src / wolnelektury / static / 2021 / scripts / main.js
1 // JS Menu
2 (function () {
3   let button = $('.js-menu');
4   let menu = $('.l-navigation__menu');
5   let menuLinks = menu.find('a');
6
7   button.on('click', function() {
8     if(!$(this).hasClass('is-active')) {
9       $(this).addClass('is-active');
10       menu.addClass('is-open');
11       button.find('.bar').addClass('animate');
12       menuLinks.attr('tabindex', 0);
13     } else {
14       $(this).removeClass('is-active');
15       menu.removeClass('is-open');
16       button.find('.bar').removeClass('animate');
17       menuLinks.attr('tabindex', -1);
18     }
19   });
20
21   $(document).keyup(function(e) {
22     if (e.keyCode === 27) {
23       button.removeClass('is-active');
24       menu.removeClass('is-open');
25       button.find('.bar').removeClass('animate');
26       menuLinks.attr('tabindex', -1);
27     }
28   });
29 })();
30
31 // Ebook/Audiobook Btns
32 (function() {
33   let button = $('.c-media__btn button');
34   let closeButton = $('.c-media__popup__close');
35
36   button.on('click', function () {
37     let target = $(this).attr('id');
38     $('[data-popup=' + target).addClass('is-open');
39   });
40
41   closeButton.on('click', function() {
42     $(this).closest('.c-media__popup').removeClass('is-open');
43   });
44
45   $(document).keyup(function(e) {
46     if (e.keyCode === 27) {
47       $('.c-media__popup').removeClass('is-open');
48     }
49   });
50 })();
51
52 // Text overlay toggler
53 (function () {
54   let overlays = $('.l-article__overlay');
55   let button = $('.l-article__read-more');
56
57   overlays.each(function () {
58     let maxHeight = $(this).attr('data-max-height');
59     if($(this).outerHeight() > maxHeight) {
60       $(this).css({'maxHeight': maxHeight+'px'}).addClass('is-active');
61     } else {
62       $(this).next('.l-article__read-more').hide();
63     }
64   });
65
66   button.on('click', function() {
67     let dataLabel = $(this).attr('data-label');
68     let dataAction = $(this).attr('data-action');
69     $(this).parent().find('.l-article__overlay').toggleClass('is-clicked');
70     if($(this).text() === dataLabel) {
71       $(this).text(dataAction);
72     } else {
73       $(this).text(dataLabel);
74     }
75   });
76 })();
77
78 //Zmieniamy siÄ™ popup
79 (function() {
80   let $change = $('.l-change-pop');
81   function change() {
82     if(localStorage.getItem('change') === null) {
83       $change.addClass('show');
84     } else {
85       $change.remove();
86       return false;
87     }
88
89     $change.on('click', '.l-change-pop__close', function () {
90       $change.slideUp();
91       localStorage.setItem('change', 'showed');
92     });
93   }
94
95   if($change.length) { change(); }
96 })();