(function( $ ) { 'use strict'; /** * All of the code for your public-facing JavaScript source * should reside in this file. * * Note: It has been assumed you will write jQuery code here, so the * $ function reference has been prepared for usage within the scope * of this function. * * This enables you to define handlers, for when the DOM is ready: * * $(function() { * * }); * * When the window is loaded: * * $( window ).load(function() { * * }); * * ...and/or other possibilities. * * Ideally, it is not considered best practise to attach more than a * single DOM-ready or window-load handler for a particular page. * Although scripts in the WordPress core, Plugins and Themes may be * practising this, we should strive to set a better example in our own work. */ })( jQuery ); ; jQuery(document).ready(function ($) { // MAIN FILTER $(".filter-wtr-reviews-button").on('click', function () { let number_of_active_filters = 0; let ajaxUrl = $("#wtr_reviews").data('url'); let wtr_topics_filter = ''; let wtr_topics_list = []; $("#wtrReviewTopics-filter input").each(function () { if ($(this).is(":checked")) { wtr_topics_filter = $(this).data('wtr-review-topic'); wtr_topics_list.push(wtr_topics_filter); number_of_active_filters++; } }); if (number_of_active_filters > 0) { $('.wtr-reviews-filter-toggle-button').addClass('has-filters-activated'); $('.nr-of-active-filters').html(number_of_active_filters); } $('.wtr-reviews-filter-popup').hide().removeClass('wtr-reviews-filter-popup-active'); $(".wtr-reviews-filter-toggle-button").addClass('loading-wtr-reviews'); $(".filter-loading-gif").slideDown(300); $.ajax({ url: ajaxUrl, type: 'post', data: { wtr_topics_list: wtr_topics_list, action: 'wtr_reviews_topics_filter' }, error: function (response) { console.log(response); $(".filter-loading-gif").slideUp(300); $(".wtr-reviews-filter-toggle-button").removeClass('loading-wtr-reviews'); }, success: function (response) { $('.wtr-reviews-dynamic-container').html(response); $(".filter-loading-gif").slideUp(300); $(".wtr-reviews-filter-toggle-button").removeClass('loading-wtr-reviews'); } }); }); $('body').on('click', '.load-more-wtr-reviews', function () { let loadMoreButton = $('.load-more-wtr-reviews'); let wtr_review_tags = loadMoreButton.data('terms'); let ajaxUrl = loadMoreButton.data('url'); let page = document.getElementById('load-more-reviews').dataset.page; let maxpages = loadMoreButton.data('maxpages'); let newPage = parseInt(page) + 1; loadMoreButton.addClass('loading'); $.ajax({ url: ajaxUrl, type: 'post', data: { page: page, wtr_review_tags: wtr_review_tags, action: 'wtr_reviews_load_more' }, error: function (response) { console.log(response); }, success: function (response) { $('.wtr-reviews-dynamic-container').append(response); loadMoreButton.attr('data-page', newPage); loadMoreButton.removeClass('loading'); if(newPage >= maxpages){ loadMoreButton.hide(); } } }); }); // FILTER MISCELLANEOUS $(".wtr-filter-clear-all").on('click', function () { $(".wtr-reviews-filter-option input").prop('checked', false); $(".wtr-reviews-filter-toggle-button").removeClass('has-filters-activated'); }); // MAIN FILTER POPUP $(".wtr-reviews-filter-toggle-button").on('click', function () { if (!$(this).hasClass('loading-wtr-reviews')) { $('.wtr-reviews-filter-popup').fadeIn(100).addClass('wtr-reviews-filter-popup-active'); } }); $(".hide-wtr-reviews-filter-popup").on('click', function () { $('.wtr-reviews-filter-popup').hide().removeClass('wtr-reviews-filter-popup-active'); }); }); ;