1(function ($) { 2 3 "use strict"; 4 5 $(document).ready(function () { 6 7 // Comments 8 $(".commentlist li").addClass("panel panel-default"); 9 $(".comment-reply-link").addClass("btn btn-default"); 10 11 // Forms 12 $('select, input[type=text], input[type=email], input[type=password], textarea').addClass('form-control'); 13 $('input[type=submit]').addClass('btn btn-primary'); 14 15 // You can put your own code in here 16 $(".navbar-toggle").on('click', function () { 17 $(".navbar-img").toggleClass("navbar-img-opaque"); 18 19 // if ($(".navbar-img").hasClass("navbar-img-opaque")) { 20 // setTimeout(function() { 21 // $(".navbar-brand").hide(); 22 // }, 200); 23 // } else { 24 // $(".navbar-brand").show(); 25 // } 26 27 }); 28 29 // Homepage Slick 30 $('.slick-home').on('init', function (event, slick, currentSlide, nextSlide) { 31 $('.home-wrapper .slick-paging').text("01 - 0" + $(slick.$slides).length); 32 }); 33 34 $('.slick-home').on('beforeChange', function (event, slick, currentSlide, nextSlide) { 35 // console.log('beforeChange: ' + nextSlide); 36 $('.home-wrapper .slick-paging').text("0" + (nextSlide + 1) + " - 0" + $(slick.$slides).length); 37 }); 38 39 $('.slick-home').slick({ 40 arrows: false, 41 adaptiveHeight: true, 42 autoplay: true, 43 autoplaySpeed: 8000, 44 pauseOnFocus: false 45 }); 46 47 $('.home-wrapper .arrow-right').on('click', function () { 48 $('.slick-home').slick('slickNext'); 49 }); 50 51 $('.home-wrapper .arrow-left').on('click', function () { 52 $('.slick-home').slick('slickPrev'); 53 }); 54 55 // SAMPLES PAGE 56 // $('.sample-wrapper input:checkbox').change(function() { 57 // var title = $(this).parents('.sample-wrapper').find('.id-title').text(); 58 // var sku = $(this).parents('.sample-wrapper').find('.id-sku').text(); 59 60 // console.log(title); 61 // console.log(sku); 62 63 // if (this.checked) { 64 // // Add 65 // localStorage.setItem("turano_sku_" + sku, title); 66 67 // $('#modal-order-list').append('<p id="sku_' + sku + '">' + title + '</p>'); 68 69 // } else { 70 // // Remove 71 // localStorage.removeItem("turano_sku_" + sku); 72 // $('#modal-order-list #sku_' + sku).remove(); 73 // } 74 75 // checkCartEmpty(); 76 // }); 77 78 $('#btn-remove-samples-from-cart').on('click', function () { 79 $('label.checkbox input:checkbox:checked').each(function () { 80 // var sThisVal = (this.checked ? $(this).val() : ""); 81 var sku = $(this).parents('.sample-wrapper').find('.id-sku').text(); 82 localStorage.removeItem('turano_sku_' + sku); 83 }); 84 85 // Popup modal 86 if ($('label.checkbox input:checkbox:checked').length == 0) { 87 var selectRemodal = $('#samples-need-to-select').remodal(); 88 selectRemodal.open(); 89 } else { 90 window.location.reload(); 91 } 92 93 }); 94 95 $('#btn-samples-clear-cart').on('click', function () { 96 localStorage.clear(); 97 98 // Uncheck all products 99 // $('.sample-wrapper input:checkbox').each(function() { 100 // $(this).removeAttr('checked'); 101 // }); 102 103 // Remove all listed products 104 $('#modal-order-list p').each(function () { 105 $(this).remove(); 106 }); 107 108 checkCartEmpty(); 109 110 window.location.reload(); 111 }); 112 113 // Check/Populate list from localStorage 114 var values = [], 115 keys = Object.keys(localStorage), 116 i = keys.length, 117 totalCount = 0; 118 119 while (i--) { 120 // console.log(keys[i].indexOf("turano_sku_")); 121 if (keys[i].indexOf("turano_sku_") != -1) { 122 123 try { 124 var product = $.parseJSON(localStorage.getItem(keys[i])); 125 126 // Show buttons 127 $('.sample-cart-button-wrapper').css('display', 'flex'); 128
129 $('#modal-order-list').append('<p id="' + keys[i] + '">' + product.title + '</p>'); 130 // $('#checkbox_' + keys[i]).prop('checked', true); 131 132 // Append to Main Sample page 133 $("#samples-list").append(` 134 <div class="sample-wrapper"> 135 <a href="${product.url}" class="recipe"> 136 <div class="recipe-img-hover sample"> 137 <img class="attachment-medium size-medium wp-post-image" alt="${product.title}" src="${product.img}" /> 138 </div> 139 </a> 140 <label class="container checkbox"> 141 <input id="checkbox_sku_${product.sku}" type="checkbox"> 142 <span class="title">${product.title}</span> 143 144 </label> 145 <div class="hidden id-title">${product.title}</div> 146 <div class="hidden id-sku">${product.sku}</div> 147 </div> 148 `); 149 150 totalCount += 1; 151 } catch (error) { 152 // If old sample in cache, remove it. 153 localStorage.removeItem(keys[i]); 154 // localStorage.clear(); 155 } 156 } 157 } 158 159 // Update the "There are (X) items..." 160 if (totalCount == 1) { 161 $('#samples-sort-title span').text(`is (${totalCount}) item`) 162 } else { 163 $('#samples-sort-title span').text(`are (${totalCount}) items`); 164 } 165 166 167 checkCartEmpty(); 168 169 }); 170 171 function checkCartEmpty() { 172 // Wait for other parts to load 173 setTimeout(function () { 174 if ($('#samples-list .sample-wrapper').length == 0) { 175 $('#modal-order-list #no-items').show(); 176 $('.no-sample-products-wrapper').show(); 177 } else { 178 $('#modal-order-list #no-items').hide(); 179 } 180 }, 200); 181 } 182 183 // On load 184 checkCartEmpty(); 185 186 $('#btn-samples-submit').on('click', function () { 187 var fullName = $('#full-name').val(); 188 var userEmail = $('#email').val(); 189 var company = $('#company-name').val(); 190 var phone = $('#phone').val(); 191 var address = $('#address').val(); 192 var city = $('#city').val(); 193 var zip = $('#zip').val(); 194 var state = $('#state').val(); 195 196 var productsArray = []; 197 var productLinks = []; 198 199 Object.keys(localStorage).forEach(function (key) { 200 if (key.includes('turano_sku_')) { 201 var item = JSON.parse(localStorage.getItem(key)); 202 productsArray.push(item.title + " (" + key.replace("turano_sku_", "") + ")"); 203 productLinks.push(`<a href="${item.url}" target="_blank">${item.title}</a>`); 204 } 205 }); 206 207 var hasErrors = $('#samples-form').validator('validate').has('.has-error').length; 208 if (hasErrors) return; 209 210 $('#btn-samples-submit').addClass('disabled').text('Submitting...'); 211 212 // Mailchimp Subscription (optional) 213 if ($('#addToMailchimp').is(':checked')) { 214 var subscribeData = { 215 action: 'mailchimp_subscribe', 216 email: userEmail, 217 company: company, 218 status: 'subscribed', 219 FULLNAME: fullName, 220 COMPANY: company, 221 PHONE: phone, 222 ADDRESS: address, 223 CITY: city, 224 ZIPCODE: zip, 225 STATE: state 226 }; 227 228 $.post(mailchimp_ajax_object.ajaxurl, subscribeData) 229 .done(res => console.log('Mailchimp subscribed:', res)) 230 .fail(err => console.error('Mailchimp error:', err)); 231 } 232 233 // Insert Order into WP DB 234 $.post(mailchimp_ajax_object.ajaxurl, { 235 action: 'insert_turano_order', 236 full_name: fullName, 237 email: userEmail, 238 company: company, 239 phone: phone, 240 address: address, 241 city: city, 242 zip: zip, 243 state: state, 244 order_detail: productLinks.join(', ') 245 }).done(res => console.log('Order inserted:', res)) 246 .fail(err => console.error('Insert order error:', err)); 247 248 // Send Email via samples-email PHP (POST instead of GET) 249 var emailUrl = $('#full-name').data('site-url') + "/samples-email"; 250 var formData = { 251 full_name: fullName, 252 email: userEmail, 253 company: company, 254 phone: phone, 255 address: address, 256 city: city, 257 zip: zip, 258 state: state, 259 products: productsArray.join(', '), 260 'g-recaptcha-response': grecaptcha.getResponse() 261 }; 262 263 $.ajax({ 264 url: emailUrl, 265 type: 'POST', 266 data: formData, 267 success: function (response) { 268 $('.modal-body').hide(); 269 $('#btn-samples-submit').parents('.col-md-5').hide(); 270 $('#samples-msg-confirmation').show(); 271 grecaptcha.reset(); 272 }, 273 error: function (request, error) { 274 console.error("Email send error:", request); 275 $('#btn-samples-submit').removeClass('disabled').text('Submit Order'); 276 } 277 }); 278 279 // Google Ad Conversion 280 gtag('event', 'conversion', { 'send_to': 'AW-949173472/O_lwCNi11P4BEOD5zMQD' }); 281}); 282 283 284 // PRODUCT LIST HOME SAMPLES 285 $('.add-product-sample').on('click', function () { 286 287 // Check if Product already in "cart" 288 var item_key = 'turano_sku_' + $(this).attr('data-sku').trim(); 289 // console.log(localStorage.getItem(item_key)); 290 if (localStorage.getItem(item_key) === null) { 291 // Build JSON blob 292 var sku = $(this).attr('data-sku').trim(); 293 var title = $(this).parents('.product-item-wrapper').find('.woocommerce-loop-product__title').text().trim(); 294 var imgURL = $(this).parents('.product-item-wrapper').find('img.attachment-woocommerce_thumbnail').attr('data-src'); 295 console.log(imgURL); 296 if (!imgURL.includes("http")) { 297 imgURL = "http:" + imgURL; 298 } 299 300 var prodURL = $(this).parent().find('#product-link').attr('href'); 301 var jsonBlob = '{"title": "' + title + '", "img": "' + imgURL + '", "url": "' + prodURL + '", "sku": "' + sku + '"}'; 302 303 // console.log(jsonBlob); 304 305 localStorage.setItem("turano_sku_" + sku, jsonBlob); 306 307 // Update modal 308 $('.modal-body h5').text('Product Added To Cart');
309 $('#product-sample-modal #message').text('Thank you. This product sample has been added to your cart. Please visit the Sample Cart page to submit your order or continue browsing our products.'); 310 // $('#modal-form-group').hide(); 311 // $('#btn-modal-return').show(); 312 313 // Track conversion for Sample Confirmation Page in Google AdWords 314 gtag('event', 'conversion', { 'send_to': 'AW-949173472/jxWHCI211P4BEOD5zMQD' }); 315 316 updateNavSampleCount(); 317 } else { 318 $('.modal-body h5').text('Product Already Added'); 319 $('#product-sample-modal #message').text('That sample has already been added to your cart.'); 320 } 321 }); 322 323 // SIGNLE PRODUCT PAGE SAMPLE BUTTON 324 $('#btn-product-sample-modal').on('click', function () { 325 // var savedZip = localStorage.getItem("turano_zip"); 326 327 // if (savedZip.match(/^\d{5}(?:[-\s]\d{4})?$/)) { 328 // $('#input-samples-zip').val(savedZip); 329 // } 330 331 // Check if Product already in "cart" 332 var item_key = 'turano_sku_' + $('#product-sku').text().trim(); 333 if (localStorage.getItem(item_key) === null) { 334 addProductToLocalStorage(); 335 } else { 336 $('.modal-body h5').text('Product Already Added'); 337 $('#message').text('That sample has already been added to your cart.'); 338 } 339 }); 340 341 function addProductToLocalStorage() { 342 var sku = $('#product-sku').text().trim(); 343 344 // Build JSON blob 345 var title = $('.product_title').text().trim(); 346 var imgURL = $('.woocommerce-product-gallery__image[data-slick-index="0"]').find('img').attr('src'); 347 var prodURL = window.location.href; 348 349 if (!imgURL.includes("http")) { 350 imgURL = "http:" + imgURL; 351 } 352 353 var jsonBlob = '{"title": "' + title + '", "img": "' + imgURL + '", "url": "' + prodURL + '", "sku": "' + sku + '"}'; 354 355 console.log(jsonBlob); 356 357 // localStorage.setItem("turano_sku_" + sku, title); 358 localStorage.setItem("turano_sku_" + sku, jsonBlob); 359 360 // Update modal 361 $('.modal-body h5').text('Product Added To Cart');
362 // $('#message').text('Thank you. This product sample has been added to your cart. Please visit your the Sample Cart page to submit your order or continue browsing our products.'); 363 $('#message').text('Thank you. This product sample has been added to your cart. Please visit the Sample Cart page to submit your order or continue browsing our products.'); 364 // $('#modal-form-group').hide(); 365 // $('#btn-modal-return').show(); 366 367 updateNavSampleCount(); 368 } 369 370 371 // SAMPLES MODAL: Append extra ZIP param to "Request Sample" URL 372 var savedZip = localStorage.getItem("turano_zip"); 373 if (savedZip != null && savedZip.match(/^\d{5}(?:[-\s]\d{4})?$/)) { 374 var samplesHref = $("#navbar-upper a[title='Sample Cart']").attr("href"); 375 $("#navbar-upper a[title='Sample Cart']").attr("href", samplesHref + '?zip=' + savedZip); 376 } 377 378 // CAREER UPLOAD RESUME 379 380 $('#btn-careers-submit').on('click', function () { 381 $('.modal-form').hide(); 382 $('.modal-submitted').show(); 383 }); 384 385 // $(".wpcf7").on('wpcf7:submit', function(event) { 386 // document.addEventListener( 'wpcf7submit', function( event ) { 387 document.addEventListener('wpcf7mailsent', function (event) { 388 $('.modal-form').hide(); 389 $('.modal-submitted').show(); 390 }); 391 392 // Set default values for careers submission 393 $('#hidden-location').val($('#jobs-location').attr('data-location')); 394 $('#hidden-position').val($('#jobs-position').attr('data-position')); 395 $('#hidden-title').val($('#jobs-title').attr('data-title')); 396 397 398 // NAV CART ICON 399 // Gotta wrap it in a timeout... this JS is a mess. 400 setTimeout(function () { 401 var siteURL = $('#site-url').attr('data-site-url'); 402 // console.log(siteURL); 403 404 // if ($(".nav a:contains('Sample Cart')").parent('li').hasClass('active')) { 405 // $(".nav a:contains('Sample Cart')").append(` 406 // <img class="icon-cart" src="${siteURL}/wp-content/themes/turano/img/global/icon_cart_red.svg" /> 407 // `); 408 // } else { 409 if (screen.width <= 992) { 410 $(".nav a:contains('Sample Cart')").append(` 411 <img class="icon-cart" src="${siteURL}/wp-content/themes/turano/img/global/icon_cart_dark.svg" /> 412 `); 413 } else { 414 $(".nav a:contains('Sample Cart')").append(` 415 <img class="icon-cart" src="${siteURL}/wp-content/themes/turano/img/global/icon_cart.svg" /> 416 `); 417 } 418 // } 419 420 421
422 updateNavSampleCount(); 423 }, 1); 424 425 function updateNavSampleCount() { 426 var keys = Object.keys(localStorage), 427 i = keys.length, 428 totalCount = 0; 429 430 while (i--) { 431 if (keys[i].indexOf("turano_sku_") != -1) { 432 totalCount += 1; 433 } 434 } 435 436 // console.log("updateNavSampleCount: " + totalCount); 437 438 if (totalCount > 0) { 439 $(".nav a:contains('Sample Cart')").append(` 440 <div class="sample-cound-badge">${totalCount}</div> 441 `); 442 } 443 } 444 445 // PRINT 446 setTimeout(function () { 447 $('#print-h5').text($('.product-info-categories').text()); 448 $('#print-h1').text($('.product_title').text()); 449 450 var printImgURL = $('.woocommerce-product-gallery__image[data-slick-index="0"]').find('img').attr('src') || ''; 451 452 if (!printImgURL.includes("http")) { 453 printImgURL = "http:" + printImgURL; 454 } 455 456 $('#print-img-product').attr('src', printImgURL); 457 458 // Recipe Images 459 $('.print-recipes-imgs #print-img-recipe-0').attr('src', $('.related-recipes-image[data-slick-index="0"]').find('img').attr('src')); 460 $('.print-recipes-imgs #print-img-recipe-1').attr('src', $('.related-recipes-image[data-slick-index="1"]').find('img').attr('src')); 461 $('.print-recipes-imgs #print-img-recipe-2').attr('src', $('.related-recipes-image[data-slick-index="2"]').find('img').attr('src')); 462 }, 1000); 463 464 465}(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.