1import { getCookie } from '../../js/helper.js'; 2 3(function($) { 4 5 //Init block 6 let initializePagelinks = function( $block ) { 7 8 //Passed variables 9 let prevButtonAria = passedPagelinks.prev_arrow; 10 let nextButtonAria = passedPagelinks.next_arrow; 11 const templateUrl = passedPagelinks.template_url; 12 const ajaxNonce = passedPagelinks.ajax_nonce; 13 const ajaxUrl = passedPagelinks.ajax_url; 14 15 //Variables 16 const links = $block.find('.pagelinks-block__pagelinks'); 17 const loader = '<div class="loader"><img src="' + templateUrl + '/images/icon-loader.svg">'; 18 const carousel = $block.find('.pagelinks-block__pagelinks.carousel'); 19 let arrows = $block.find('.pagelinks-block__arrows'); 20 21 22 //Do Ajax call if area exists 23 if (links.length) { 24 25 //Variables for Ajax 26 let data = { 27 action: 'koli_get_pagelinks', 28 nonce: ajaxNonce, 29 links: links.data('links'), 30 override: Boolean( getCookie('override_season') ), 31 user_season: getCookie('user_season'), 32 }; 33 34 //Ajax query to get results 35 $.ajax({ 36 url: ajaxUrl, 37 type: 'POST', 38 data: data, 39 beforeSend: function() { 40 links.html(loader); 41 }, 42 success: function(data, textStatus, request) { 43 44 if ( data ) { 45 //Add links and order them 46 links.html(data); 47 48 //Create carousel if not grid 49 if ( carousel.length ) { 50 createCarousel(); 51 } 52 } 53 }, 54 }); 55 } 56 57 //Create carousel 58 function createCarousel() { 59 60 //Get size 61 const size = carousel.data('size'); 62 63 //Make arrows visible 64 $block.find('.pagelinks-block__arrows').css('display', 'flex'); 65 66 //Arguments for carousel 67 let carouselArgs = {}; 68 69 if ( 'big' === size ) { 70 71 carouselArgs = { 72 dots: false, 73 infinite: true, 74 slidesToShow: 1, 75 centerMode: true, 76 slidesToScroll: 1, 77 centerPadding: '30px', 78 appendArrows: arrows, 79 arrows: ( carousel.find('.pagelinks-block__pagelinks__link').length > 1 ) ? true : false, 80 prevArrow: '<button class="button-prev" aria-label="'+prevButtonAria+'"></button>', 81 nextArrow: '<button class="button-next" aria-label="'+nextButtonAria+'"></button>', 82 }; 83 } 84 85 if ( 'medium' === size ) { 86 87 carouselArgs = { 88 dots: false, 89 infinite: true, 90 slidesToShow: 2, 91 centerMode: false, 92 slidesToScroll: 1, 93 appendArrows: arrows, 94 arrows: ( carousel.find('.pagelinks-block__pagelinks__link').length > 2 ) ? true : false, 95 prevArrow: '<button class="button-prev" aria-label="'+prevButtonAria+'"></button>', 96 nextArrow: '<button class="button-next" aria-label="'+nextButtonAria+'"></button>', 97 responsive: [ 98 { 99 breakpoint: 760, 100 settings: { 101 slidesToShow: 1, 102 centerMode: true, 103 centerPadding: '30px', 104 arrows: ( carousel.find('.pagelinks-block__pagelinks__link').length > 1 ) ? true : false, 105 } 106 }, 107 ], 108 }; 109 } 110 111 if ( 'small' === size ) { 112 113 carouselArgs = { 114 dots: false, 115 infinite: true, 116 slidesToShow: 4, 117 centerMode: false, 118 slidesToScroll: 1, 119 appendArrows: arrows, 120 arrows: ( carousel.find('.pagelinks-block__pagelinks__link').length > 4 ) ? true : false, 121 prevArrow: '<button class="button-prev" aria-label="'+prevButtonAria+'"></button>', 122 nextArrow: '<button class="button-next" aria-label="'+nextButtonAria+'"></button>', 123 responsive: [ 124 { 125 breakpoint: 1024, 126 settings: { 127 slidesToShow: 3, 128 arrows: ( carousel.find('.pagelinks-block__pagelinks__link').length > 3 ) ? true : false, 129 } 130 }, 131 { 132 breakpoint: 760, 133 settings: { 134 slidesToShow: 2, 135 arrows: ( carousel.find('.pagelinks-block__pagelinks__link').length > 2 ) ? true : false, 136 } 137 }, 138 { 139 breakpoint: 480, 140 settings: { 141 slidesToShow: 1, 142 centerMode: true, 143 centerPadding: '30px', 144 arrows: ( carousel.find('.pagelinks-block__pagelinks__link').length > 1 ) ? true : false, 145 } 146 }, 147 ], 148 }; 149 } 150 151 //Init slick slider 152 //Set total number of items 153 carousel.on('init', function(event, slick) { 154 let totalSlides = slick.slideCount; 155 let currentSlides = slick.options.slidesToShow; 156 157 //Hide counter, if not enough slides for carousel
158 if (currentSlides >= totalSlides) { 159 arrows.find('p').hide(); 160 } else { 161 arrows.find('span.total').html(totalSlides); 162 } 163 }); 164 165 carousel.slick(carouselArgs); 166 167 //Change current number 168 carousel.on('afterChange', function(slick, currentSlide) { 169 let slidenumber = currentSlide.currentSlide + 1; 170 arrows.find('span.current').html(slidenumber); 171 }); 172 173 //Show or hide counter on breakpoints 174 carousel.on('breakpoint', function(event, slick, breakpoint) { 175 let totalSlides = slick.slideCount; 176 let currentSlides = 4; 177 178 if ( 'big' === size ) { 179 currentSlides = 1; 180 181 switch(breakpoint) { 182 default: 183 currentSlides = 1; 184 } 185 } 186 187 if ( 'medium' === size ) { 188 currentSlides = 2; 189 190 switch(breakpoint) { 191 case 760: 192 currentSlides = 1; 193 break; 194 default: 195 currentSlides = 1; 196 } 197 } 198 199 if ( 'small' === size ) { 200 currentSlides = 4; 201 202 switch(breakpoint) { 203 case 1024: 204 currentSlides = 3; 205 break; 206 case 760: 207 currentSlides = 2; 208 break; 209 case 480: 210 currentSlides = 1; 211 break; 212 default: 213 currentSlides = 4; 214 } 215 } 216 217 if (totalSlides > currentSlides) { 218 arrows.find('p').show(); 219 } else { 220 arrows.find('p').hide(); 221 } 222 }); 223 } 224 } 225 226 //Init block in frontend 227 $(document).ready(function() { 228 $('.pagelinks-block').each(function(){ 229 initializePagelinks( $(this) ); 230 }); 231 }); 232 233})(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.