1(function($) { 2 $(".ect-event-wrapper").each(function(){ 3 const wrapper = $(this); 4 const random = wrapper.data('random'); // Use data() method to get data attribute value 5 const postAttributes = window['ect_event_wrapper_' + random]; 6 const masonry_filter = wrapper.find('.ect-fitlers-wrapper'); 7 masonry_filter.hide(); 8 9 // Function to handle AJAX call 10 const handleAjax = function() { 11 ect_filter_bar_ajax(wrapper); 12 }; 13 14 // Function to check if any filter is applied 15 const checkFilters = function() { 16 const selectedCat = wrapper.find("#ect-fb-category").val(); 17 const selectedTag = wrapper.find("#ect-fb-tags").val(); 18 const selectedVenue = wrapper.find("#ect-fb-venue").val(); 19 const selectedOrg = wrapper.find("#ect-fb-org").val(); 20 const searchInput = wrapper.find("#ect-fb-search").val(); 21 const filtterbatStyle = postAttributes.attribute.filterbarstyle; 22 23 // Check if any filter has a value other than the default or search input is not empty 24 if( filtterbatStyle === 'both' || filtterbatStyle === 'filter'){ 25 if ( 26 (selectedCat && selectedCat !== (getFirstValue(postAttributes.attribute.category) || 'all')) || 27 (selectedTag !== (getFirstValue(postAttributes.attribute.tags) || '')) || 28 (selectedVenue && selectedVenue !== (getFirstValue(postAttributes.attribute.venues) || '')) || 29 (selectedOrg && selectedOrg !== (getFirstValue(postAttributes.attribute.organizers) || '')) || 30 (searchInput && searchInput !== '') 31 ) { 32 wrapper.find('.ect-clear-filter').css('display', 'block'); 33 } else { 34 wrapper.find('.ect-clear-filter').css('display', 'none'); 35 } 36 }else if( filtterbatStyle === 'search'){ 37 if(searchInput && searchInput !== ''){ 38 wrapper.find('.ect-clear-filter').css('display', 'block'); 39 } else { 40 wrapper.find('.ect-clear-filter').css('display', 'none'); 41 } 42 } 43 44 }; 45 46 // Bind change events for filter elements 47 wrapper.find("#ect-fb-category, #ect-fb-tags, #ect-fb-venue, #ect-fb-org").on("change", function() { 48 handleAjax(); 49 checkFilters(); 50 }); 51 52 // Bind keypress event for search input 53 wrapper.find("#ect-fb-search").on("keypress", function(event) { 54 if (event.key === "Enter") { 55 handleAjax(); 56 checkFilters(); 57 } 58 }); 59 60 // Get first value from comma-separated string 61 const getFirstValue = (str) => str.split(',')[0]; 62 63 // Bind click event for the clear filter button 64 wrapper.find(".ect-clear-filter").on("click", function() { 65 // Get default values from attributes 66 const defaultCat = (postAttributes.attribute.category) ? getFirstValue( postAttributes.attribute.category ) : 'all'; 67 const defaultTag = (postAttributes.attribute.tags) ? getFirstValue( postAttributes.attribute.tags ) : ''; 68 const defaultVenue = (postAttributes.attribute.venues) ? getFirstValue( postAttributes.attribute.venues ) : ''; 69 const defaultOrg = (postAttributes.attribute.organizers) ? getFirstValue( postAttributes.attribute.organizers ) : ''; 70 // Reset all filters to default values or "all" 71 wrapper.find("#ect-fb-category").val(defaultCat); 72 wrapper.find("#ect-fb-tags").val(defaultTag); 73 wrapper.find("#ect-fb-venue").val(defaultVenue); 74 wrapper.find("#ect-fb-org").val(defaultOrg); 75 wrapper.find("#ect-fb-search").val(''); 76 77 // Call AJAX handler and update filter visibility 78 handleAjax(); 79 checkFilters(); 80 }); 81 82 // Bind click event for show/hide filters button 83 wrapper.find(".ect-showfilter-btn").on("click", function() { 84 wrapper.find(".ect-filterbar-filters").toggleClass("active"); 85 const btnText = wrapper.find(".ect-filterbar-filters").hasClass("active") ? postAttributes.hideFiltersText : postAttributes.showFiltersText; 86 $(this).html(btnText); 87 }); 88 89 90 // AJAX call function 91 function ect_filter_bar_ajax(wrapper) { 92 const selectedCat = wrapper.find("#ect-fb-category").val(); 93 const selectedTag = wrapper.find("#ect-fb-tags").val(); 94 const selectedVenue = wrapper.find("#ect-fb-venue").val(); 95 const selectedOrg = wrapper.find("#ect-fb-org").val(); 96 const searchInput = wrapper.find("#ect-fb-search").val(); 97 const random = wrapper.data('random'); 98
99 const postAttributes = window['ect_event_wrapper_' + random]; 100 const ajaxUrl = postAttributes.url; 101 const query = postAttributes.query; 102 const nonce = postAttributes.nonce; 103 const dateFormat = postAttributes.dateFormat; 104 const hideVenue = postAttributes.hideVenue; 105 const showDescription = postAttributes.showDescription; 106 const socialShare = postAttributes.socialShare; 107 const loadmore_nonce = postAttributes.loadmore_nonce; 108 const style = postAttributes.style; 109 const template = postAttributes.template; 110 const attribute = postAttributes.attribute; 111 112 let ect_masonry_cls = `ect-masonry-view-${attribute['style']}`; 113 const data = { 114 'action': 'ect_filterbar_change', 115 'selectedCat': selectedCat, 116 'query': query, 117 'selectedTag': selectedTag, 118 'selectedVenue': selectedVenue, 119 'selectedOrg': selectedOrg, 120 'searchInput': searchInput, 121 '_ajax_nonce': nonce, 122 'style': style, 123 'template': template, 124 'socialShare': socialShare, 125 'showDescription': showDescription, 126 'hideVenue': hideVenue, 127 'dateFormat': dateFormat, 128 'attribute': attribute, 129 'loadmore_data': loadmore_nonce, 130 }; 131 132 wrapper.find("#ect-filter-loader").show(); 133 wrapper.find('.ect-list-wrapper, .tect-grid-wrapper, .ect-minimal-list-wrapper, .ect-accordion-container, .cool-event-timeline, .slick-track, .ect-masonary-cont, .ect-advance-list').css('opacity', '0.5'); 134 135 $.ajax({
136 type: 'POST', 137 url: ajaxUrl, 138 data: data, 139 dataType: 'json', 140 success: function(response) { 141 let contentdiv; 142 //const default_no_evt_found_div = $('.ect-no-events'); 143 // const default_no_evt_found_div = wrapper.siblings('.ect-no-events'); 144 // default_no_evt_found_div.remove(); 145 const default_no_evt_found_div = wrapper.next('.ect-no-events'); 146 if (default_no_evt_found_div.length) { 147 default_no_evt_found_div.remove(); 148 } 149 var oldpaginationdiv; 150 const check = ['timeline', 'classic-timeline', 'timeline-view']; 151 if (response.template === 'default') { 152 contentdiv = wrapper.find('.ect-list-wrapper'); 153 } else if (response.template === 'grid-view') { 154 contentdiv = wrapper.find('.tect-grid-wrapper').find('.row'); 155 } else if (response.template === 'minimal-list') { 156 contentdiv = wrapper.find('.ect-minimal-list-wrapper'); 157 } else if (response.template === 'accordion-view') { 158 contentdiv = wrapper.find('.ect-accordion-container'); 159 } else if (check.includes(response.template)) { 160 contentdiv = wrapper.find('.cool-event-timeline'); 161 } else if (response.template === 'slider-view' || response.template === 'carousel-view') { 162 contentdiv = wrapper.find('.slick-track'); 163 } else if (response.template === 'masonry-view') { 164 contentdiv = wrapper.find('.ect-masonary-cont'); 165 166 } else if (response.template === 'advance-list') { 167 contentdiv = wrapper.find('.ect-advance-list tbody'); 168 } else if (response.template === 'highlighted-layout') { 169 contentdiv = wrapper.find('.ect-show-events'); 170 } 171 172 if (response.content !== '') { 173 if (response.template === 'slider-view' || response.template === 'carousel-view') { 174 const slickCarousel = wrapper.find('.ect-slider-view, .ect-carousel'); 175 if (slickCarousel.length) { 176 slickCarousel.slick("slickRemove"); // Destroy existing slick instance 177 contentdiv.html(response.content); 178 slickCarousel.slick("slickAdd"); // Reinitialize slick 179 const autoplayOption1 = attribute['autoplay'] === 'true'; 180 const autoplayOption = attribute['autoplay'] === 'true'; 181 slickCarousel.slick("slickSetOption", "autoplay", autoplayOption1, autoplayOption); 182 } 183 } else if (response.template === 'masonry-view') { 184 if (contentdiv.length === 0) { 185 contentdiv = $(`<div id="ect-grid-wrapper" class="ect-masonary-cont ${ect_masonry_cls}"></div>`).appendTo(wrapper.find('.ect-masonry-template-cont')); 186 } 187 188 // Check if Masonry is already initialized before destroying it 189 if (contentdiv.data('masonry')) { 190 contentdiv.masonry('destroy'); // Destroy existing Masonry instance 191 } 192 // Clear the content 193 contentdiv.empty(); 194 195 // Append new content 196 contentdiv.html(response.content); 197 198 // Reinitialize Masonry 199 contentdiv.imagesLoaded(function() { 200 contentdiv.masonry({ 201 itemSelector: '.ect-grid-event', 202 percentPosition: true, 203 columnWidth: '.ect-grid-event' 204 }); 205 }); 206 207 } else { 208 contentdiv.html(response.content); 209 } 210 var paginationdiv = ''; 211 212 if (response['template'] === 'masonry-view') { 213 oldpaginationdiv = wrapper.find('.ect-masonay-load-more'); 214 } 215 if (response['pagination'] != '') { 216 paginationdiv = wrapper.find('.ect-load-more'); 217 if (response['template'] === 'default') { 218 contentparentDiv = wrapper.find('.ectt-list-wrapper'); 219 } else if (response['template'] === 'grid-view') { 220 contentparentDiv = wrapper.find('.tect-grid-wrapper'); 221 } else if (response['template'] === 'minimal-list') { 222 contentparentDiv = wrapper.find('.ectt-simple-list-wrapper'); 223 } else if (response['template'] === 'accordion-view') { 224 contentparentDiv = wrapper.find('#ect-accordion-wrapper'); 225 } else if (response['template'] === 'masonry-view') { 226 contentparentDiv = wrapper.find('.ect-masonry-template-cont'); 227 } 228 if(response['template'] != 'highlighted-layout'){ 229 if (paginationdiv.length) { 230 paginationdiv.hide(); 231 contentparentDiv.append(response['pagination']); 232 } else { 233 if ((response['template'] === 'masonry-view') && oldpaginationdiv) { 234 oldpaginationdiv.remove(); 235 } 236 contentparentDiv.append(response['pagination']); 237 } 238 } 239 } else { 240 if ((response['template'] === 'masonry-view') && oldpaginationdiv) { 241 oldpaginationdiv.remove(); 242 } 243 paginationdiv = wrapper.find('.ect-load-more'); 244 paginationdiv.remove(); 245 } 246 if (response.template === 'highlighted-layout') { 247 // Select and remove the div with class 'ect-right' 248 const ectRightDiv = wrapper[0].querySelector('.ect-right'); 249 if (ectRightDiv && wrapper.data('style') !== 4) { 250 ectRightDiv.classList.remove("ect-img-hide"); 251 ectRightDiv.classList.add("ect-img-show"); 252 } 253 } 254 } else { 255 if(response.noEvents !== ''){
256 contentdiv.html(response.noEvents); 257 if (response.template === 'highlighted-layout') { 258 // Select and remove the div with class 'ect-right' 259 const ectRightDiv = wrapper[0].querySelector('.ect-right'); 260 if (ectRightDiv && wrapper.data('style') !== 4) { 261 ectRightDiv.classList.remove("ect-img-show"); 262 ectRightDiv.classList.add("ect-img-hide"); 263 } 264 } 265 } 266 const slickCarousel = wrapper.find('.ect-slider-view, .ect-carousel'); 267 if (slickCarousel.length) { 268 slickCarousel.slick("slickSetOption", "autoplay", false, true); 269 } 270 const paginationDiv = wrapper.find('.ect-load-more'); 271 paginationDiv.remove(); 272 oldpaginationdiv = wrapper.find('.ect-masonay-load-more'); 273 if ((response['template'] === 'masonry-view') && oldpaginationdiv) { 274 oldpaginationdiv.remove(); 275 } 276 277 // Destroy Masonry if no content is found 278 if (response.template === 'masonry-view' && contentdiv.data('masonry')) { 279 contentdiv.masonry('destroy'); 280 } 281 } 282 283 wrapper.find("#ect-filter-loader").hide(); 284 wrapper.find('.ect-list-wrapper, .tect-grid-wrapper, .ect-minimal-list-wrapper, .ect-accordion-container, .cool-event-timeline, .slick-track, .ect-masonary-cont, .ect-advance-list').css('opacity', '1'); 285 286 }, 287 error: function(xhr, status, error) { 288 console.error("AJAX Error:", status, error); 289 wrapper.find("#ect-filter-loader").hide(); 290 wrapper.find('.ect-list-wrapper, .tect-grid-wrapper, .ect-minimal-list-wrapper, .ect-accordion-container, .cool-event-timeline, .slick-track, .ect-masonary-cont, .ect-advance-list').css('opacity', '1'); 291 } 292 }); 293 } 294 }); 295})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.