1jQuery(document).ready(function($){ 2 3 /* ========================================================================== 4 GENERAL FUNCTIONALITIES 5 ========================================================================== */ 6 /* Form functions 7 ========================================================================== */ 8 // Function to check if an input has a value 9 function checkForInput(element) { 10 const $element = jQuery(element); 11 const $form = $element.closest('form'); // Find the nearest form 12 13 if ($element.val() && $element.val().trim().length > 0) { 14 $form.addClass('input-has-value'); 15 } else { 16 $form.removeClass('input-has-value'); 17 } 18 } 19 20 // Check inputs on page load 21 jQuery('.w-search input').each(function() { 22 checkForInput(this); 23 }); 24 25 // Check on change & keyup 26 jQuery('.w-search input').on('change keyup focus', function() { 27 checkForInput(this); 28 }); 29 30 // Check on change & keyup 31 jQuery('#show-filters, .close-filters').click(function() { 32 jQuery('#filter-wrap').slideToggle(); 33 jQuery('body').toggleClass('overflow-hidden'); 34 }); 35 36 37 /* Product detail gallery 38 ========================================================================== */ 39 40 var galleryPreview = jQuery('.preview-gallery > .post_image img'); 41 var galleryList = jQuery('.preview-gallery .w-grid.type_carousel'); 42 var galleryListItem = jQuery('.preview-gallery .w-grid.type_carousel .post_image img'); 43 44 setTimeout(function() { 45 var galleryActiveItem = jQuery('.owl-carousel .owl-item.active .post_image img'); 46 47 var imageSrc = galleryActiveItem.attr('src'); 48 var imageSrcset = galleryActiveItem.attr('srcset'); 49 var imageWidth = galleryActiveItem.attr('width'); 50 var imageHeight = galleryActiveItem.attr('height'); 51 52 galleryPreview.attr("src", imageSrc); 53 galleryPreview.attr("srcset", imageSrcset); 54 galleryPreview.attr("width", imageWidth); 55 galleryPreview.attr("height", imageHeight); 56 }, 500); 57 58 galleryListItem.click(function() { 59 var imageSrc = jQuery(this).attr('src'); 60 var imageSrcset = jQuery(this).attr('srcset'); 61 var imageWidth = jQuery(this).attr('width'); 62 var imageHeight = jQuery(this).attr('height'); 63 64 65 galleryPreview.attr("src", imageSrc); 66 galleryPreview.attr("srcset", imageSrcset); 67 galleryPreview.attr("width", imageWidth); 68 galleryPreview.attr("height", imageHeight); 69 70 }); 71 72 73 jQuery(".w-grid-list.owl-carousel .post_image img").click(function() { 74 var imageSrc = jQuery(this).attr("src"); 75 var imageSrcset = jQuery(this).attr("srcset"); 76 var imageWidth = jQuery(this).attr("width"); 77 var imageHeight = jQuery(this).attr("height"); 78 79 jQuery(".wp-post-image.zoooom").attr("src", imageSrc); 80 jQuery(".wp-post-image.zoooom").attr("srcset", imageSrcset); 81 jQuery(".wp-post-image.zoooom").attr("width", imageWidth); 82 jQuery(".wp-post-image.zoooom").attr("height", imageHeight); 83 84 jQuery(".zoomWindow").css("background-image", "url("+imageSrc+")"); 85 86 }); 87 88 /* Ingredients Calculations 89 ========================================================================== */ 90 function updateIngredients() { 91 var numberOfPortionsStart = parseInt($('.recipe_number_of_portions input').parent().data('start-portions')); 92 var numberOfPortions = parseInt($('.recipe_number_of_portions input').val()); 93 94 if (numberOfPortionsStart !== numberOfPortions) { 95 96 $('.repeater.recipe_acf_ingredients li').each(function(){ 97 var currentIngredientAmount = parseFloat($('.ingredient_amount', this).data('start-amount')); 98 var newIngredientAmount = (currentIngredientAmount / numberOfPortionsStart) * numberOfPortions; 99 //console.log(currentIngredientAmount + ' ' + newIngredientAmount); 100 //console.log(currentIngredientAmount); 101 102 var decimalPercentage = ''; 103 104 newIngredientAmount = Math.abs(newIngredientAmount); 105 var decimalPartVal = newIngredientAmount - Math.floor(newIngredientAmount); 106 107 if (newIngredientAmount <= '1') { 108 console.log('show singular: '+ newIngredientAmount); 109 $('.singular', this).show(); 110 $('.plural', this).hide(); 111 } else { 112 console.log('show plural: '+ newIngredientAmount); 113 $('.singular', this).hide(); 114 $('.plural', this).show(); 115 } 116 117 118 if ((parseFloat(decimalPartVal) <= 0.05)) { 119 decimalPercentage = ''; 120 } else if ((parseFloat(decimalPartVal) > 0.05) && (parseFloat(decimalPartVal) <= 0.15)) { 121 decimalPercentage = ',10'; //'<sup>1/5</sup>'; 122 } else if ((parseFloat(decimalPartVal) > 0.15) && (parseFloat(decimalPartVal) <= 0.25)) { 123 decimalPercentage = ',20'; //'<sup>1/4</sup>'; 124 } else if ((parseFloat(decimalPartVal) > 0.25) && (parseFloat(decimalPartVal) <= 0.35)) { 125 decimalPercentage = ',30'; //'<sup>1/3</sup>'; 126 } else if ((parseFloat(decimalPartVal) > 0.35) && (parseFloat(decimalPartVal) <= 0.45)) { 127 decimalPercentage = ',40'; //'<sup>2/5</sup>'; 128 } else if ((parseFloat(decimalPartVal) > 0.45) && (parseFloat(decimalPartVal) <= 0.55)) { 129 decimalPercentage = ',50'; //'<sup>1/2</sup>'; 130 } else if ((parseFloat(decimalPartVal) > 0.55) && (parseFloat(decimalPartVal) <= 0.65)) { 131 decimalPercentage = ',60'; //'<sup>3/5</sup>'; 132 } else if ((parseFloat(decimalPartVal) > 0.65) && (parseFloat(decimalPartVal) <= 0.75)) { 133 decimalPercentage = ',70'; //'<sup>2/3</sup>'; 134 } else if ((parseFloat(decimalPartVal) > 0.75) && (parseFloat(decimalPartVal) <= 0.85)) { 135 decimalPercentage = ',80'; //'<sup>3/4</sup>'; 136 } else if ((parseFloat(decimalPartVal) > 0.85) && (parseFloat(decimalPartVal) <= 0.95)) { 137 decimalPercentage = ',90'; //'<sup>
1374/5</sup>'; 138 } else { 139 decimalPercentage = ''; 140 newIngredientAmount += 1; 141 } 142 143 if(isNaN(currentIngredientAmount)) { 144 $('.ingredient_amount', this).html(currentIngredientAmount); 145 } else { 146 if ($("body").hasClass("site-id-10") || $("body").hasClass("site-id-13")) {; 147 $('.ingredient_amount', this).html(Math.floor(newIngredientAmount) + decimalPercentage.toString().replace(',', '.')); 148 } else { 149 $('.ingredient_amount', this).html(Math.floor(newIngredientAmount) + decimalPercentage.toString()); 150 } 151 152 } 153 154 155 }); 156 } else { 157 158 $('.repeater.recipe_acf_ingredients li').each(function(){ 159 160 var currentIngredientAmount = parseInt($('.ingredient_amount', this).data('start-amount')); 161 162 if ($("body").hasClass("site-id-10") || $("body").hasClass("site-id-13")) { 163 currentIngredientAmount.toString().replace(',', '.'); 164 } else { 165 //console.log('site-id-other'); 166 } 167 $('.ingredient_amount', this).html(currentIngredientAmount); 168 169 if (currentIngredientAmount <= '1') { 170 $('.singular', this).show(); 171 $('.plural', this).hide(); 172 } else { 173 $('.singular', this).hide(); 174 $('.plural', this).show(); 175 } 176 }); 177 } 178 } 179 180 function updatePdfContent() { 181 // Update PDF content 182 jQuery('#pdf-tpl-ingredients').html(jQuery('#recipe_acf_ingredients').html()); 183 184 jQuery('#pdf-tpl-portions').html(jQuery('.recipe_number_of_portions input').val()); 185 186 var ingredientsUpdated = jQuery("#recipe_acf_ingredients .wpb_wrapper").html(); 187 jQuery("#pdf_product_ingredients").val(encodeURIComponent(ingredientsUpdated)); 188 } 189 $('.recipe_number_of_portions .input_min').click(function(){ 190 191 var currentValue = $(this).parent().find('input').val(); 192 var newValue = currentValue - 1; 193 194 if (newValue <= 1) { 195 newValue = 1; 196 } 197 198 $(this).next().val(newValue); 199 $('#pdf_product_portions').val(newValue); 200 201 updateIngredients(); 202 updatePdfContent(); 203 }); 204 205 $('.recipe_number_of_portions .input_plus').click(function(){ 206 207 var currentValue2 = $(this).parent().find('input').val(); 208 var newValue2 = parseInt(currentValue2) + 1; 209 210 if (newValue2 >= 999) { 211 newValue2 = 999; 212 } 213 214 215 $(this).parent().find('input').val(newValue2); 216 $('#pdf_product_portions').val(newValue2); 217 218 updateIngredients(); 219 updatePdfContent(); 220 }); 221 222 $('.recipe_number_of_portions input').on('change keydown paste input', function(){ 223 updateIngredients(); 224 updatePdfContent(); 225 }); 226 227 /* Recipe show stars function 228 ========================================================================== */ 229 $('.recipe_price_category .w-post-elm-value.recipe_price_category_1').clone().addClass("recipe_price_category_clone").appendTo( ".recipe_price_category" ).clone().addClass("recipe_price_category_clone").appendTo( ".recipe_price_category" ); 230 $('.recipe_price_category .w-post-elm-value.recipe_price_category_2').clone().addClass("recipe_price_category_clone").appendTo( ".recipe_price_category" ); 231 232 233 /* ========================================================================== 234 FILTERS 235 ========================================================================== */ 236 /* Fixed filter button 237 ========================================================================== */ 238 239 if ($('#sticky-btn').length) { 240 var stickyTop = $('#sticky-btn').offset().top; 241 var stickyHeight = $('#sticky-btn').height(); 242 var windowHeight = $(window).height(); 243 var windowWidth = $(window).width(); 244 245 if ( (windowWidth) > 900 ) { 246 $('#sticky-btn').css('position', 'fixed').css('border-radius','0'); 247 } 248 249 $(window).scroll(function() { 250 var windowTop = $(window).scrollTop(); 251 252 if ((windowHeight + windowTop + stickyHeight) >= stickyTop) { 253 $('#sticky-btn').css('position', 'relative').css('border-radius','500px'); 254 } else { 255 $('#sticky-btn').css('position', 'fixed').css('border-radius','0'); 256 } 257 }); 258 259 } 260 261 /* Create selected filter tags 262 ========================================================================== */ 263 const queryString = window.location.search;
264 const urlParams = new URLSearchParams(queryString); 265 266 jQuery('.filters .filter-item').each(function(){ 267 var $container = jQuery(this); 268 var param = $container.data('filter'); // e.g. "filter-brand", "filter-certificate" 269 270 if (urlParams.has(param+'[]')) { 271 272 var values = urlParams.getAll(param+'[]'); 273 274 values.forEach((val) => { 275 276 // Find checkbox by VALUE (works even if id has prefix like cert-XXX) 277 var $input = $container.find('input.checkbox[value="' + val + '"]'); 278 var name = $input.length ? $input.next('label').text() : val; 279 280 // If you ever re-enable JS tag creation, this is correct: 281 // jQuery('.filter-tags .filter-tags-wrapper') 282 // .append('<span data-filter="'+param+'" data-filtervalue="'+val+'">'+name+'</span>'); 283 284 // Add hidden params into the SEARCH FORM (append to form, not text input) 285 jQuery("#grid-search").append( 286 '<input type="hidden" class="hidden-params" name="'+param+'[]'+'" value="'+val+'" />' 287 ); 288 289 }); 290 } 291 }); 292 293 /* Remove filters on filter tag click 294 ========================================================================== */ 295 jQuery('.filter-tags .filter-tags-wrapper span').click(function(){ 296 jQuery(this).hide(); 297 const paramName = jQuery(this).data('filter'); 298 const paramValue = jQuery(this).data('filtervalue'); 299 300 if (urlParams.has(paramName+'[]') ) { 301 var paramNameList = urlParams.getAll(paramName+'[]'); 302 urlParams.delete(paramName+'[]'); 303 const index = paramNameList.indexOf(String(paramValue)); 304 305 if (index > -1) { // only splice array when item is found 306 paramNameList.splice(index, 1); // 2nd parameter means remove one item only 307 } 308 309 310 if (paramNameList.length) { 311 paramNameList.forEach(fillParams); 312 313 function fillParams(item, index, arr) { 314 urlParams.append(paramName+'[]', item); 315 } 316 } 317 318 // Check if url is not on a paginated page 319 var pathArray = window.location.pathname.split('/'); 320 var newPathname = ""; 321 for (i = 0; i < pathArray.length; i++) { 322 if ((pathArray[i] != 'page') && ( isNaN(pathArray[i])) ) { 323 newPathname += pathArray[i]; 324 newPathname += '/'; 325 } 326 } 327 328 329 // Update the URL in the address bar without reloading 330 window.history.pushState({}, '', '/'+ newPathname +'?'+urlParams+'#us_grid_1'); 331 // Now, reload the page 332 window.location.reload(); 333 } 334 335 }); 336 337 338 /* Load page after search filter click 339 ========================================================================== */ 340 jQuery('#filter-search .checkbox').on('change', function() { 341 $('form#filter-search').submit(); 342 }); 343 344 /* Show/hide grid preloader 345 ========================================================================== */ 346 jQuery('.w-grid.has-filter .w-grid-preloader').fadeOut(); 347 348 jQuery('.form-footer input[type=submit], .filter-tags .filter-tags-wrapper span, .clear-filters').click(function(){ 349 jQuery('.w-grid.has-filter .w-grid-preloader').fadeIn(); 350 351 setTimeout(function() { 352 jQuery('.w-grid.has-filter .w-grid-preloader').fadeOut(); 353 }, 2000); 354 }); 355 356 /* Sort filters 357 ========================================================================== */ 358 jQuery('.sort-options select').on('change', function(){ 359 jQuery('.w-grid.has-filter .w-grid-preloader').fadeIn(); 360 const sortOrder = jQuery(this).val(); 361 362 if (urlParams.has('sortorder')) { 363 urlParams.delete('sortorder'); 364 }
365 urlParams.append('sortorder', sortOrder); 366 367 // Check if url is not on a paginated page 368 var pathArray = window.location.pathname.split('/'); 369 var newPathname = ""; 370 for (i = 0; i < pathArray.length; i++) { 371 if ((pathArray[i] != 'page') && ( isNaN(pathArray[i])) ) { 372 newPathname += pathArray[i]; 373 newPathname += '/'; 374 } 375 } 376 window.history.pushState({}, '', '/'+ newPathname +'?'+urlParams+'#us_grid_1'); 377 window.location.reload(); 378 }); 379 380 381});
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.