3 let button = $('.js-menu');
4 let menu = $('.l-navigation');
5 let menuLinks = menu.find('a');
7 button.on('click', function() {
8 if(!$(this).hasClass('is-active')) {
9 $(this).addClass('is-active');
10 menu.addClass('is-open');
11 $('body').addClass('is-open');
12 button.find('.bar').addClass('animate');
13 menuLinks.attr('tabindex', 0);
15 $(this).removeClass('is-active');
16 menu.removeClass('is-open');
17 $('body').removeClass('is-open');
18 button.find('.bar').removeClass('animate');
19 menuLinks.attr('tabindex', -1);
23 $(document).keyup(function(e) {
24 if (e.keyCode === 27) {
25 button.removeClass('is-active');
26 menu.removeClass('is-open');
27 $('body').removeClass('is-open');
28 button.find('.bar').removeClass('animate');
29 menuLinks.attr('tabindex', -1);
36 let button = $('.l-navigation__actions .user');
37 let menu = $('#user-menu');
38 let menuLinks = menu.find('a');
40 button.on('click', function() {
41 if (!menu.hasClass('is-open')) {
42 menu.addClass('is-open');
43 menuLinks.attr('tabindex', 0);
45 menu.removeClass('is-open');
46 menuLinks.attr('tabindex', -1)
51 $(document).keyup(function(e) {
52 if (e.keyCode === 27) {
53 menu.removeClass('is-open');
54 menuLinks.attr('tabindex', -1);
58 $(document).click(function() {
59 menu.removeClass('is-open');
60 menuLinks.attr('tabindex', -1);
65 // Ebook/Audiobook Btns
67 let button = $('.c-media__btn button:not(.l-button--media--full)');
68 let popupLayer = $('.c-media__popup');
69 let closeButton = $('.c-media__popup__close');
70 let playButton = $('.c-player__btn--md');
71 let chaptersButton = $('.c-player__chapters span');
72 let select = $('.c-select');
73 let selectItem = $('.c-select li');
74 let volumeButton = $('.icon-volume');
76 button.on('click', function () {
77 let target = $(this).attr('id');
78 $('[data-popup=' + target).addClass('is-open');
79 $('body').addClass('popup-open');
82 closeButton.on('click', function() {
83 $(this).closest('.c-media__popup').removeClass('is-open');
84 $('body').removeClass('popup-open');
87 popupLayer.on('click', function(e) {
89 if($(e.target).is(popupLayer)) {
90 _this.removeClass('is-open');
91 $('body').removeClass('popup-open');
95 chaptersButton.on('click', function() {
96 $(this).parent().toggleClass('is-active');
99 select.on('click', function() {
100 $(this).toggleClass('is-active');
103 selectItem.on('click', function() {
104 selectItem.removeClass('is-active');
105 $(this).addClass('is-active');
108 $(document).keyup(function(e) {
109 if (e.keyCode === 27) {
110 $('.c-media__popup').removeClass('is-open');
115 // Homepage books sliders
117 let shelfSlider = $('.l-your-books__shelf .l-books');
118 let shelfNextSlide = $('.l-your-books__shelf .js-next-slide');
119 let shelfPrevSlide = $('.l-your-books__shelf .js-prev-slide');
120 let shelfCollapse = $('.l-your-books__shelf .js-collapse');
140 shelfNextSlide.on('click', function (event) {
141 event.preventDefault();
142 shelfSlider.slick('slickNext');
145 shelfPrevSlide.on('click', function (event) {
146 event.preventDefault();
147 shelfSlider.slick('slickPrev');
150 shelfCollapse.on('click', function (event) {
151 event.preventDefault();
152 shelfSlider.slick('slickPrev');
156 $('.js-collections').each(function() {
158 let collectionsSlider = $('.l-books', this);
159 if (collectionsSlider.children().length < 2) return;
162 collectionsSlider.css('display', 'block');
164 let collectionsNextSlide = $('.js-next-slide', this);
165 let collectionsPrevSlide = $('.js-prev-slide', this);
167 collectionsSlider.slick({
168 //prevArrow, nextArrow,
182 breakpoint: 360 - .01,
188 breakpoint: 520 - .01,
194 breakpoint: 680 - .01,
200 breakpoint: 840 - .01,
206 breakpoint: 1172 - .01,
215 collectionsNextSlide.on('click', function (event) {
216 event.preventDefault();
217 collectionsSlider.slick('slickNext');
220 collectionsPrevSlide.on('click', function (event) {
221 event.preventDefault();
222 collectionsSlider.slick('slickPrev');
225 let newBooksSlider = $('.js-new-books-slider .l-books');
226 let newBooksNextSlide = $('.js-new-books-slider .js-next-slide');
227 let newBooksPrevSlide = $('.js-new-books-slider .js-prev-slide');
229 newBooksSlider.slick({
247 newBooksNextSlide.on('click', function (event) {
248 event.preventDefault();
249 newBooksSlider.slick('slickNext');
252 newBooksPrevSlide.on('click', function (event) {
253 event.preventDefault();
254 newBooksSlider.slick('slickPrev');
260 let slider = $('.l-author__quotes__slider');
273 let sliderHomepage = $('.l-quotes');
274 sliderHomepage.slick({
291 let slider = $('.p-homepage__info__box--carousel');
309 // Text overlay toggler
311 let overlays = $('.l-article__overlay');
312 let button = $('.l-article__read-more');
314 overlays.each(function () {
315 let maxHeight = $(this).attr('data-max-height');
316 if($(this).outerHeight() > maxHeight) {
317 $(this).css({'maxHeight': maxHeight+'px'}).addClass('is-active');
319 $(this).next('.l-article__read-more').hide();
323 button.on('click', function() {
324 let dataLabel = $(this).attr('data-label');
325 let dataAction = $(this).attr('data-action');
326 $(this).parent().find('.l-article__overlay').toggleClass('is-clicked');
327 if($(this).text() === dataLabel) {
328 $(this).text(dataAction);
330 $(this).text(dataLabel);
336 $('.l-checkout__payments__box button').on('click', function() {
337 let container = $(this).closest('.l-checkout__payments');
338 $('input', container).val($(this).val());
339 $('.is-active', container).removeClass('is-active');
340 $(this).closest('.l-checkout__payments__box').addClass('is-active');
350 let $copy = $('.js-copy');
352 $copy.on('click', function() {
353 let $copyText = $(this).closest('.l-checkout__info__item').find('input');
355 document.execCommand('copy');
365 $(".icon-like").each(
367 ids.add($(e).attr('data-book'));
370 ids = [...ids].join(',');
376 $(document).on('click', '.icon-like', function(e) {
378 let liked = $(this).hasClass('icon-liked');
382 url: '/ludzie/lektura/' + $(this).attr('data-book-slug') + '/nie_lubie/',
383 data: {'csrfmiddlewaretoken': $('[name=csrfmiddlewaretoken]').val()},
384 success: function() {
385 delete state.liked[$btn.attr('data-book')];
391 url: '/ludzie/lektura/' + $(this).attr('data-book-slug') + '/lubie/',
392 data: {'csrfmiddlewaretoken': $('[name=csrfmiddlewaretoken]').val()},
393 success: function() {
394 state.liked[$btn.attr('data-book')] = [];
398 if (e.status == 403) {
399 $('#login-link').click();
406 // TODO: DYNAMICALLY ADD
407 $(".add-set-tag input[name=name]").autocomplete({
408 source: '/ludzie/moje-tagi/',
409 }).on('autocompleteopen', function() {
410 $(this).closest('article').addClass('ac-hover');
411 }).on('autocompleteclose', function() {
412 $(this).closest('article').removeClass('ac-hover');
414 $(".add-set-tag").on("submit", function(e) {
418 url: $form.attr("action"),
419 data: $form.serialize(),
421 updateFromData(data);
423 $('input[name=name]', $form).val('');
428 $(document).on("click", ".sets .close", function() {
429 let bookId = $(this).closest("[data-book]").attr('data-book');
431 url: '/ludzie/usun-tag/',
433 csrfmiddlewaretoken: $("[name=csrfmiddlewaretoken]").val(),
435 slug: $(this).parent().attr('data-set'),
438 updateFromData(data);
445 function refreshAll(ids) {
446 $.ajax('/ludzie/ulubione/?ids=' + ids, {
447 success: function(result) {
448 updateFromData(result);
454 $.refreshLikes = refreshAll;
456 function updateFromData(data) {
458 if (data[pk] === null) {
459 delete state.liked[pk];
461 state.liked[pk] = data[pk];
466 function updateLikedAll() {
467 $(".icon-like").each(
474 function updateLiked(e) {
475 let bookId = $(e).attr('data-book');
476 let liked = bookId in state.liked;
477 $(e).toggleClass('icon-liked', liked);
478 let $bookContainer = $('.book-container-' + bookId);
479 $bookContainer.toggleClass('book-liked', liked);
480 let $sets = $(".sets", $bookContainer);
482 $.each(state.liked[bookId], (i,e) => {
483 let $set = $("<span>");
484 $set.attr("data-set", e.slug);
485 let $setA = $("<a>").appendTo($set);
486 $setA.attr("href", e.url);
488 let $setX = $("<a class='close'></a>").appendTo($set);
497 // Toggle a class on long press.
502 $("[data-longpress]").on("touchstart", (e) => {
503 $e = $(e.currentTarget);
504 timer = setTimeout(() => {
505 $e.toggleClass($e.attr('data-longpress'));
509 $("[data-longpress]").on("touchend", () => {
516 // Update search form filters.
518 $('.j-form-auto').each(function() {
520 $('input', $form).change(function() {$form.submit()});
521 $('select', $form).change(function() {$form.submit()});
522 $('textarea', $form).change(function() {$form.submit()});
527 $(".experiment input").on('change', function() {
528 let name = $(this).attr('name');
529 let val = $(this).val();
530 document.cookie = 'EXPERIMENT_' + name + '=' + val + '; path=/; max-age=31536000';
531 window.location.reload(true);