1// This is where it all goes :) 2 3$(document).ready(function() { 4 5 6 7 8 9 10 11 12 13 14 var homepageInterval = null; 15 16 17 function setupPopupListeners(cartState) { 18 console.log('setting up popup listeners') 19 var hasShownAddToCartExitIntentPopup = false; 20 var hasShownPurchaseConfirmedPopup = false; 21 22 23 function showAddToCartExitIntentPopup() { 24 if (typeof Snipcart == 'object') { 25 if (Snipcart.store.getState().cart.items.count > 0 && !hasShownAddToCartExitIntentPopup && (!Cookies.get('showAddToCartExitIntentPopup'))) { 26 console.log('clicking link!'); 27 $('#add-to-cart-cta-modal').addClass('is-active'); 28 hasShownAddToCartExitIntentPopup = true; 29 Cookies.set('showAddToCartExitIntentPopup', 'true', {expires: 1/96}); 30 } 31 } 32 } 33 //on desktop 34 document.addEventListener('mouseleave', function(evt) { 35 console.log('mouse leaving', evt); 36 if (!hasShownAddToCartExitIntentPopup && evt.clientY <= 0 ) { 37 showAddToCartExitIntentPopup(); 38 } 39 }) 40 41 //on mobile 42 43 var lastScrollTop = 0; 44 window.addEventListener('scroll', function() { 45 46 var st = window.pageYOffset || document.documentElement.scrollTop; 47 if (st < lastScrollTop - 200 && !hasShownAddToCartExitIntentPopup ) { 48 showAddToCartExitIntentPopup(); 49 } 50 lastScrollTop = st <= 0 ? 0 : st; 51 }) 52 } 53 //add the logic here to see if there's even a popup to show... 54 55 //don't forget to add the actual button at the bottom of the page 56 57 58 59 60 61 var ip = ""; 62 63 if ($('#productReviewComposer').length > 0) { 64 var reviewComposer = new Vue({ 65 el: "#productReviewComposer", 66 data: { 67 reviewRating: null, 68 feedback: "", 69 name: "", 70 email: "", 71 orderNumber: "", 72 status: "New", 73 errorMessage: "" 74 }, 75 methods: { 76 cancelReview: function(e) { 77 hideReviewWriter(); 78 }, 79 validateReview: function(e) { 80 console.log('validating!') 81 if (!!this.reviewRating && !!this.name && !!this.email && this.feedback) { 82 this.status = "Submitting"; 83 submitReview(); 84 } else if (!this.reviewRating) { 85 this.errorMessage = "Please rate this product."; 86 } else if (!this.name) { 87 this.errorMessage = "Please enter your name."; 88 } else if (!this.email) { 89 this.errorMessage = "Please enter your email address."; 90 } else if (!this.feedback) { 91 this.errorMessage = "Please enter your feedback about this product." 92 } 93 } 94 } 95 }) 96 } 97 98 function submitReview() { 99 var itemSku = $('#reviewedItemSku').val(); 100 var review = { 101 sku: itemSku, 102 name: reviewComposer.name, 103 email: reviewComposer.email, 104 review: reviewComposer.feedback, 105 rating: String(reviewComposer.reviewRating), 106 order_id: reviewComposer.orderNumber 107 108 } 109 var jsonData = JSON.stringify(review); 110 console.log(jsonData); 111 var settings = { 112 "async": true, 113 "crossDomain": true, 114 "url": "https://server.pappalar.do/ear-gear/reviews/new.json?siteKey=f7e9d15f-ad99-49be-96e0-4f554b4ffec6", 115 "method": "POST", 116 "headers": { 117 "content-type": "application/json", 118 "authorization": "Bearer" 119 }, 120 "processData": false, 121 "data": jsonData 122 }; 123 $.ajax(settings).always(function(data) { 124 console.log(data); 125 reviewComposer.status = "Submitted"; 126 setTimeout(function(){ 127 hideReviewWriter(); 128 }, 1000); 129 }); 130 } 131 132 133 if ($('#shopping-list-modal').length > 0) { 134 var shoppingModal = new Vue({ 135 el: '#shopping-list-modal', 136 data: { 137 productName: "", 138 modalShown: false, 139 productColor: "", 140 productImage: "", 141 productSku: "", 142 productButtonText: "Add to Cart", 143 sizingForCart: "", 144 cordless: "false", 145 productColorOptions: [ 146 { 147 "name": "", 148 "image": "", 149 "swatch": "", 150 "productId": "", 151 "sku": "", 152 "path": "" 153 }, 154 ], 155 productUrl: "", 156 model: "", 157 item: "", 158 id: "", 159 productVariantOptions: [ 160 { 161 "name": "", 162 "id": "" 163 } 164 ], 165 selectedVariant: { 166 "name": "", 167 "id": "", 168 selected: false 169 }, 170 productDescription: "", 171 learnMoreLink: "", 172 productPrice: "0.00", 173 productPriceObject: '{"usd": "0.00", "cad": "0.0"}', 174 productQuantity: 0, 175 addedToCart: false 176 }, 177 methods: { 178 changeModalColor: function(color) {
179 this.productColor = color.name; 180 this.productImage = color.image; 181 this.productSku = color.sku; 182 this.learnMoreLink = color.path; 183 this.addedToCart = false; 184 shoppingModal.productButtonText = "Add to Cart"; 185 }, 186 modalAddToCart: function() { 187 console.log('adding to cart!!'); 188 this.productButtonText = '<i class="fas fa-spinner fa-spin"></i> Adding to Cart...'; 189 var productName = this.productName + " - " + this.productColor; 190 var productSku = this.productSku; 191 console.log(productName, productSku, this.selectedVariant.name); 192 if (this.selectedVariant.name !== "") { 193 console.log('variant selected'); 194 productName = this.productName + " - " + this.selectedVariant.name + " - " + this.productColor; 195 196 productSku = this.selectedVariant.name.replace(" ", "-") + "-" + this.productSku; 197 198 console.log(productName, productSku); 199 } 200 201 var item = { 202 "id": productSku, 203 "name": productName, 204 "description": this.sizingForCart, 205 "url": "https://www.gearforears.com/items.json", 206 "image": this.productImage, 207 "price": this.productPrice, 208 "categories": ["standard"], 209 "dimensions": { 210 "weight": 1, 211 "width": 1, 212 "height": 1, 213 "length": 1 214 }, 215 "quantity": this.productQuantity 216 }; 217 218 console.log('adding item', item); 219 try { 220 Snipcart.api.cart.items.add(item); 221 shoppingModal.addedToCart = true; 222 } catch (error) { 223 console.log(error); 224 } 225 226 227 }, 228 openCart: function() { 229 230 openingSnipcart(); 231 }, 232 closeCart: function() { 233 $('#shopping-list-modal').removeClass('is-active'); 234 }, 235 keepAddingToCart: function() { 236 this.addedToCart = false; 237 this.productButtonText = "Add to Cart"; 238 }, 239 setVariant: function(id, name) { 240 this.selectedVariant.id = id; 241 this.selectedVariant.name = name; 242 this.selectedVariant.selected = true; 243 }, 244 clearVariant: function() { 245 this.selectedVariant.id = ""; 246 this.selectedVariant.name = ""; 247 this.selectedVariant.selected = true; 248 } 249 } 250 }); 251 } 252 253 var popupModel = ""; 254 255 var helpType_qv = '<p class="is-size-4"><strong>How can we help?</strong></p>'; 256 var helpType_options_qv = '<a style="margin:10px;" class="button is-large help-type-button" data-help-type="Sizing Wizard"><i class="fad fa-tape"></i> Sizing Wizard</a><br/>'; 257 helpType_options_qv += '<a style="margin:10px;" class="button is-large help-type-button" data-help-type="Fit List"><i class="fad fa-list-ul"></i> Fit List</a><br/>'; 258 helpType_options_qv += '<a style="margin:10px;" class="button is-large help-type-button" data-help-type="Live Support"><i class="fad fa-user-headset"></i> Live Support</a><br/>'; 259 helpType_options_qv += '<a style="margin:10px;" class="button is-large help-type-button" data-help-type="Installation Video"><i class="fad fa-play-circle"></i> Installation Video</a><br/>
259'; 260 261 262 var helpTypeHtml = helpType_qv + helpType_options_qv; 263 264 var liveSupport_qv = '<p class="is-size-4"><strong>How would you like to be contacted?</strong>'; 265 var liveSupport_options_qv = '<a style="margin:10px;" class="button is-large live-support-button" data-support-type="Email">Email Me</a><br/>'; 266 liveSupport_options_qv += '<a style="margin:10px;" class="button is-large live-support-button" data-support-type="Call">Call Me</a><br/>'; 267 liveSupport_options_qv += '<a style="margin:10px;" class="button is-large live-support-button" data-support-type="Live Chat">Live Chat</a><br/>'; 268 var liveSupportHtml = liveSupport_qv + liveSupport_options_qv; 269 270 var hearing_aid_type_qv = '<p class="is-size-4"><strong>What type of hearing aid do you have?</strong></p>'; 271 var hearing_aid_options_qv = '<a style="margin:10px;" class="button is-large hearing-aid-type-button" data-hearing-aid-type="Hearing Aid (Behind the Ear)"><img src="/images/bte.png" style="max-width:75px;"> Hearing Aid (BTE RIC)</a><br/>'; 272 hearing_aid_options_qv += '<a style="margin:10px;" class="button is-large hearing-aid-type-button" data-hearing-aid-type="Hearing Aid (In the Ear)"><img src="/images/ite.png" style="max-width:75px;"> Hearing Aid (ITE)</a><br/>'; 273 hearing_aid_options_qv += '<a style="margin:10px;" class="button is-large hearing-aid-type-button" data-hearing-aid-type="Cochlear"><img src="/images/cochlear.png" style="max-width:75px;"> Cochlear Implant</a><br/>'; 274 hearing_aid_options_qv += '<a style="margin:10px;" class="button is-large hearing-aid-type-button" data-hearing-aid-type="Rondo Implant"><img src="/images/rondo.png" style="max-width:75px;"> Rondo Implant</a><br/>'; 275 hearing_aid_options_qv += '<a style="margin:10px;" class="button is-large hearing-aid-type-button" data-hearing-aid-type="Baha"><img src="/images/baha.png" style="max-width:75px;"> Baha</a><br/>'; 276 277 var hearing_aid_type_html = hearing_aid_type_qv + hearing_aid_options_qv; 278 279 var installationVideoHtml = '<p class="is-size-4"><strong>Installation Video</strong></p>'; 280 installationVideoHtml += '<iframe style="width:560px !important; height:315px !important;" width="560" height="315" src="https://www.youtube.com/embed/VO9FayGUw2g" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'; 281 282 var email_support_qv = '<p class="is-size-4"><strong>Fill out this form and we\'ll email you as soon as we can.</strong></p>'; 283 var email_support_body = '<div id="email-form-container-qv"></div>'; 284 var email_support_html = email_support_qv + email_support_body; 285 286 var call_support_qv = '<p class="is-size-4"><strong>Fill out this form and we\'ll call you as soon as we can.</strong></p>'; 287 var call_support_body = '<div id="call-form-container-qv"></div>'; 288 289 var call_support_html = call_support_qv + call_support_body; 290 291 var sizing_options_qv = '<p><a href="#" class="has-text-dark qv-1-in">IN</a> / <a href="#" class="has-text-dark qv-1-cm">CM</a></p>'; 292 sizing_options_qv += '<a style="margin:10px;" class="button is-large button-for-qv-1 qv-btn-1" data-qv1="Micro">Less than 1 Inch</a><br/>'; 293 sizing_options_qv += '<a style="margin:10px;" class="button is-large button-for-qv-1 qv-btn-2" data-qv1="Mini">Less than 1.25 Inches</a><br/>'; 294 sizing_options_qv += '<a style="margin:10px;" class="button is-large button-for-qv-1 qv-btn-3" data-qv1="Original">Less than 2 Inches</a><br/>'; 295 sizing_options_qv += '<a style="margin:10px;" class="button is-large button-for-qv-1 qv-btn-4" data-qv1="FM">2 Inches or Larger</a></div>'; 296 sizing_options_qv += '<p><small><i class="fad fa-info-circle" style="--fa-primary-color: #F57A21; --fa-secondary-color: lightgrey;"></i> If your hearing aid is in between two sizes, you can go either way.'; 297 298 var corded_or_cordless_qv = '<div id="quickview-section-2" class="quickview-sections"><p><strong class="is-size-4">What is your primary reason for buying Ear Gear?</strong></p>'; 299 corded_or_cordless_qv += '<a style="margin:10px;" class="button is-large corded-selector" data-corded-or-cordless="Cordless" id="qv-btn-2-1">Sweat, Dirt, Moisture or Wind</a><br/>
299'; 300 corded_or_cordless_qv += '<a style="margin:10px;" class="button is-large corded-selector" data-corded-or-cordless="Corded" id="qv-btn-2-2">Loss</a><br/>'; 301 corded_or_cordless_qv += '<a style="margin:10px;" class="button is-large corded-selector" data-corded-or-cordless="Both" id="qv-btn-2-2">Both</a><br/>'; 302 303 var hearing_aid_size_qv = '<div id="quickview-section-1" class="quickview-sections"><p><strong class="is-size-4">What size is your hearing aid?</strong><br/>' + sizing_options_qv + '<a style="margin:10px;" class="is-text button" id="sizing-help">Help</a></div>'; 304 305 var sizing_help_qv = '<strong>Measure your hearing instrument</strong><p>Ear Gear is great, but it only works properly if you measure your hearing instrument first! You will need to measure your hearing aid to make sure that Ear Gear fits correctly.</p><ol><li>Place the base of the hearing aid at zero on the ruler.</li><li>Measure to the top of the curve as shown here</li></ol><img src="/images/meassure.jpg" class="image"><p class="is-size-5 my-3">What size is your hearing aid?</p>' + sizing_options_qv; 306 307 var implant_type_qv = '<p class="is-size-4"><strong">What type of hearing aid do you have?</strong></p><a style="margin:10px;" class="button is-large button-for-implant-type" data-implant-type="Cochlear">Cochlear</a><br/><a style="margin:10px;" class="button is-large button-for-implant-type" data-implant-type="Coil">Coil</a><br/><a style="margin:10px;" class="button is-large button-for-implant-type" data-implant-type="Rondo">Rondo</a><br/><a style="margin:10px;" class="button is-large button for-implant-type" data-implant-type="Baha">Baha</a><br/><a style="margin:10px;" class="button is-large button-for-implant-type" data-implant-type="ITE">ITE</a><br/>'; 308 309 310 // var mono_or_binaural_options = '<a style="margin:10px;" class="button is-large mono_btn" data-model-type="Mono">Mono</a><br/><a style="margin:10px;" class="button is-large mono_btn" data-model-type="Binaural" id="qv-btn-2-2">Binaural</a>'; 311 // var mono_or_binaural_qv = '<div id="quickview-section-3" class="quickview-sections"><p><strong class="is-size-4">Do you want mono or binaural Ear Gear?</strong></p>' + mono_or_binaural_options + '<br/><br/><a style="margin:10px;" class="is-text button button-for-mono-help" id="help-for-mono-binaural">What does this mean?</a></div>'; 312 313 // var mono_or_binaural_help = '<div class="quickview-sections"><p class="is-size-4"><strong>What\'s the difference between mono and binaural?</strong></p><p>The Mono models come with just one sleeve, and a cord is included. All of our other models are binaural, meaning they come with two sleeves. If you only have one hearing aid, or you\'re needing just one replacement sleeve, the mono would be ideal for you. Otherwise, choose binaural.</p><p><strong>Which one would you like?</strong></p>' + mono_or_binaural_options; 314 315 // var eyeglasses_qv = '<div id="quickview-section-4" class="quickview-sections"><p><strong class="is-size-4">Do you want your Ear Gear to attach to your glasses?</strong></p><a style="margin:10px;" class="button is-large button-for-qv-4" data-qv-2="Yes" id="qv-btn-2-1">Yes</a><br/><a style="margin:10px;" class="button is-large button-for-qv-4" data-qv-2="No" id="qv-btn-2-2">No</a><br/><br/><a style="margin:10px;" class="is-text button" id="help-for-qv-3">What does this mean?</a></div>'; 316 317 var product_suggestion_qv = '<div id="quickview-section-5" class="quickview-sections"><p><strong class="is-size-4">Here\'s the Ear Gear for you:</strong></p>'; 318 var product_options = ''; 319 320 321 322 var hearingAidType = ""; 323 var hearingAidModel = ""; 324 var hearingAidOptions = ""; 325 326 function getUrlVars() { 327 var vars = {}; 328 var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { 329 vars[key] = value; 330 }); 331 return vars; 332 } 333 334 function activateQvButtons() { 335 $('#sizing-help').click(function(e) { 336 e.preventDefault(); 337 338 if (e.target.id == "sizing-help") { 339 console.log(e.target.id); 340 startSizingQv(sizing_help_qv, 'none'); 341 } 342 }); 343 $('.hearing-aid-type-button').click(function(e) { 344 e.preventDefault(); 345 if (e.target.dataset.hearingAidType) { 346 console.log('hearing aid type selected'); 347 hearingAidType = e.target.dataset.hearingAidType; 348 if (hearingAidType == "Hearing Aid (Behind the Ear)") { 349 startSizingQv(hearing_aid_size_qv, 2); 350 } else if (hearingAidType == "Hearing Aid (In the Ear)") { 351 hearingAidModel = "ITE"; 352 evaluateModel(); 353 // startSizingQv('<p>ITE Message Goes Here</p>', 2); 354 } else if (hearingAidType == "Cochlear") { 355 console.log('hearing aid type is' + hearingAidType); 356 hearingAidModel = "Cochlear"; 357 startSizingQv(corded_or_cordless_qv, 3); 358 359 } else if (hearingAidType == "Rondo Implant") { 360 hearingAidModel = "Rondo"; 361 startSizingQv(corded_or_cordless_qv, 3); 362 } else if (hearingAidType == "Baha") { 363 hearingAidModel = "Baha"; 364 startSizingQv(corded_or_cordless_qv, 3); 365 } 366 } 367 368 }); 369 $('.quickview-product-link').click(function(e) { 370 console.log(e.isDefaultPrevented()); 371 }); 372 373 $('.button-for-mono-help').click(function(e) { 374 e.preventDefault(); 375 if (e.target.id == "help-for-mono-binaural") { 376 startSizingQv(mono_or_binaural_help, 'none'); 377 } 378 }); 379 380 $('.corded-selector').click(function(e) { 381 e.preventDefault(); 382 if (e.target.dataset.cordedOrCordless == "Cordless") { 383 hearingAidOptions = "Cordless"; 384 console.log('show cordless models'); 385 evaluateModel(); 386 } else if (e.target.dataset.cordedOrCordless == "Corded" || e.target.dataset.cordedOrCordless == "Both") { 387 hearingAidOptions = "Corded"; 388 console.log('show corded models'); 389 evaluateModel(); 390 } 391 }); 392 393 394 395 396 $('.mono_btn').click(function(e) { 397 e.preventDefault(); 398 if (e.target.dataset.modelType == "Mono") { 399 var modelHTML = evaluateModel(); 400 startSizingQv(modelHTML, 6); 401 } else if (e.target.dataset.modelType == "Binaural") { 402 403 } 404 }); 405 406 407 408 $('.button-for-qv-1').click(function(e) { 409 e.preventDefault(); 410 411 412 if (e.target.dataset.qv1) { 413 hearingAidModel = e.target.dataset.qv1; 414 console.log(hearingAidModel); 415 startSizingQv(corded_or_cordless_qv, 3); 416 } 417 }); 418 $('.button-for-implant-type').click(function(e) { 419 e.preventDefault(); 420 if (e.target.dataset.implantType) { 421 hearingAidModel = e.target.dataset.implantType; 422 console.log(hearingAidModel); 423 startSizingQv(mono_or_binaural_qv, 3); 424 } 425 }); 426 427 $('.help-type-button').click(function(e) { 428 e.preventDefault(); 429 if ($(this).data('help-type') == "Sizing Wizard") { 430 startSizingQv(hearing_aid_type_html, 1); 431 } else if ($(this).data('help-type') == "Fit List") { 432 $(this).text('Loading Fit List...'); 433 window.location = '/fitlist'; 434 } else if ($(this).data('help-type') == "Live Support") { 435 startSizingQv(liveSupportHtml, 3); 436 } else if ($(this).data('help-type') == "Installation Video") { 437 startSizingQv(installationVideoHtml, 3); 438 } 439 }); 440 441 442 function onConversationsAPIReady() {
443 console.log('HubSpot Conversations API:'); 444 console.log(window.HubSpotConversations); 445 console.log(window.HubSpotConversations); 446 window.HubSpotConversations.widget.open(); 447 } 448 449 450 $('.live-support-button').click(function(e) { 451 e.preventDefault(); 452 if ($(this).data('support-type') == "Email") { 453 startSizingQv(email_support_html, 1); 454 hbspt.forms.create( 455 { 456 portalId: "5796626", 457 formId: "d80b2201-d82b-4a4f-9c8a-d4c1a3d60ee8", 458 target: "#email-form-container-qv" 459 } 460 ); 461 } else if ($(this).data('support-type') == "Call") { 462 startSizingQv(call_support_html, 1); 463 hbspt.forms.create({ 464 portalId: "5796626", 465 formId: "87ad9a81-78c6-4942-aeca-18b665be21c8", 466 target: "#call-form-container-qv" 467 }); 468 } else if ($(this).data('support-type') == "Live Chat") { 469 $('.quickview').removeClass('is-active'); 470 471 472 /* 473 If external API methods are already available, use them. 474 */ 475 if (window.HubSpotConversations) { 476 onConversationsAPIReady(); 477 } else { 478 /* 479 Otherwise, callbacks can be added to the hsConversationsOnReady on the window object. 480 These callbacks will be called once the external API has been initialized. 481 */ 482 window.hsConversationsOnReady = [onConversationsAPIReady]; 483 } 484 } 485 }); 486 487 488 489 } 490 491 function startSizingQv(html, stage) { 492 $('#quickview-main').html(html); 493 if (stage == "none") { 494 $('#quickview-steps').hide(); 495 } else { 496 $('#quickview-steps').show(); 497 $('.qv-steps-segment').removeClass('is-active'); 498 $('#qv-step-' + String(stage)).addClass('is-active'); 499 } 500 $('#quickview-main').show('fast'); 501 activateQvButtons(); 502 } 503 504 505 506 507 508 509 function evaluateModel() { 510 product_options = '<div class="columns is-multiline" style="margin-top:45px;">'; 511 if (hearingAidType == "Hearing Aid (Behind the Ear)" || hearingAidType == "Cochlear" || hearingAidType == "Rondo Implant" || hearingAidType == "Baha") { 512 $.each(allModels, function(i, item) { 513 console.log('item is'); 514 console.log(item); 515 //hao stands for hearing aid option 516 var hAO = false; 517 //hAM stands for hearing aid model 518 var hAM = false; 519 $.each(item.category, function(c, cat) { 520 console.log('cat is'); 521 console.log(cat); 522 if (cat.name == hearingAidOptions) { 523 console.log(cat.name); 524 console.log(hearingAidOptions); 525 hAO = true; 526 } 527 if (cat.name == hearingAidModel) { 528 console.log(cat.name); 529 console.log(hearingAidModel); 530 hAM = true; 531 } 532 }); 533 console.log('model and options'); 534 console.log(hearingAidModel + ' ' + hearingAidOptions); 535 console.log(hAO); 536 console.log(hAM); 537 if (hAO === true && hAM === true ) { 538 product_options += '<div class="column is-6" style="padding:10px;"><div class="card" style="padding:5px;"><a href="/products/' + item.slug + '/' + item.items[0].slug + '" class="quickview-product-link" data-product-link="/' + item.slug + '/' + item.items[0].slug + '"><p class="h3 has-text-centered"><strong>' + item.title + '</strong></p><div class="has-text-centered"><img class="product-image-hoverable has-text-centered" style="width:50%; margin:auto;" src="' + item.items[0].image + '?w=800&h=800&fit=crop"></div><p class="h4 has-text-centered">$' + parseFloat(item.price).toFixed(2) + '</p></a></div></div>'; 539 } 540 }); 541 542 } else if (hearingAidType == "Hearing Aid (In the Ear)") { 543 console.log('ite clicked') 544 $.each(allModels, function(i, item) { 545 //hAM stands for hearing aid model 546 var hAM = false; 547 $.each(item.category, function(c, cat) { 548 console.log('cat.name', cat.name, 'hearingAidModel', hearingAidModel); 549 if (cat.name == hearingAidModel) { 550 hAM = true; 551 } 552 }); 553 console.log('model and options'); 554 console.log(hearingAidModel + ' ' + hearingAidOptions); 555 556 if (hAM) { 557 product_options += '<div class="column is-6" style="padding:10px;"><div class="card" style="padding:5px;"><a href="/products/' + item.slug + '/' + item.items[0].slug + '" class="quickview-product-link" data-product-link="/products/' + item.slug + '/' + item.items[0].slug + '"><p class="h3 has-text-centered"><strong>' + item.title + '</strong></p><div class="has-text-centered"><img class="product-image-hoverable has-text-centered" style="width:50%; margin:auto;" src="' + item.items[0].image + '?w=800&h=800&fit=crop"></div><p class="h4 has-text-centered">$' + parseFloat(item.price).toFixed(2) + '</p></a></div></div>'; 558 } 559 }); 560 561 } 562 product_options += '</div>'; 563 $('#quickview-main').html(product_suggestion_qv + product_options); 564 565 } 566 567 568 $('#fitListSizingHelp').click(function(e) { 569 e.preventDefault(); 570 $('#find_your_ear_gear_quickview').addClass('is-active'); 571 startSizingQv(hearing_aid_type_html, 1); 572 }) 573 $('.sizing-help-qv').click(function(e) { 574 e.preventDefault(); 575 $('#find_your_ear_gear_quickview').addClass('is-active'); 576 startSizingQv(helpTypeHtml, 1); 577 }); 578 $('.sizing-help-qv-sizing-wizard').click(function(e) { 579 e.preventDefault(); 580 $('#find_your_ear_gear_quickview').addClass('is-active'); 581 startSizingQv(hearing_aid_type_html, 1); 582 }); 583 584 585 $('#1-1-help').click(function(e) { 586 e.preventDefault(); 587 startSizingQv(liveSupportHtml, 3); 588 }); 589 590 function changeProductImage(target, source) { 591 console.log('changing image now'); 592 console.log(target); 593 console.log(source); 594 target.attr('src', source); 595 } 596 597 $('.dismiss-quickview').click(function(e) { 598 e.preventDefault(); 599 $('.quickview').removeClass('is-active'); 600 }); 601 602 function resetCartModal() { 603 // $('#after-add-cart-options').hide(); 604 shoppingModal.addedToCart = false;
605 $('#listing-modal-add-to-cart').show(); 606 $('#quantity-amount').val('1'); 607 } 608 609 // $('.product-image-hoverable').on('mouseover', function(e) { 610 // var newImg = $(this).data('hoverable-img'); 611 // changeProductImage($(this), newImg); 612 // }); 613 // $('.product-image-hoverable').on('mouseout', function(e) { 614 // var newImg = $(this).data('static-img'); 615 // changeProductImage($(this), newImg); 616 // }); 617 618 619 // function applyDiscount() { 620 // var cart = Snipcart.api.cart.get(); 621 // var discounts = cart["discounts"]; 622 // console.log(discounts); 623 // var alreadyApplied = false; 624 // 625 // $.each(discounts, function(i, item) { 626 // if (item["code"] == "lzV0KnFYld") { 627 // alreadyApplied = true; 628 // } 629 // }); 630 // if (alreadyApplied == false) { 631 // Snipcart.api.cart.applyDiscount("lzV0KnFYld") 632 // .then(function (appliedCode) { 633 // console.log('code applied'); 634 // console.log(discounts); 635 // 636 // }) 637 // .fail(function (error) { 638 // console.log("Something went wrong when adding the discount code, are you sure it's a valid code?", error); 639 // }); 640 // } 641 // } 642 643 644 645 $('.product-card .product-color-hover').on('click', function(e) { 646 console.log("hovering over color"); 647 648 var newImg = $(this).data('staticImgSrc'); 649 var thisEl = $('#product-img-' + $(this).data("imgTarget")); 650 thisEl.attr('src', newImg); 651 var parentEl = thisEl.parent(); 652 parentEl.attr('href', thisEl.data('hrefInfo')); 653 var newStatic = $(this).data('staticImgSrc'); 654 var newHovered = $(this).data('hoveredImgSrc'); 655 thisEl.data('staticImg', newStatic); 656 thisEl.data('hoverableImg', newHovered); 657 var colors = $(this).parent().parent().parent().siblings(); 658 // $.each(colors, function(i, item) { 659 // console.log($(this).children().children().children().children().children()); 660 // $(this).children().children().children().children().children().removeClass('active-hover'); 661 // }); 662 // $(this).parent().parent().parent().siblings().children().children().children().children().children().children().removeClass('active-hover'); 663 // $(this).children().children().addClass('active-hover'); 664 }); 665 666 667 668 var accordions = bulmaAccordion.attach(); 669 670 671 672 $('#homepageCarousel').on('init', function(event, slick, direction){ 673 console.log('slick change', direction); 674 console.log('homepagecarousel init'); 675 console.log(direction); 676 var homepageCarouselHeight = 0; 677 $.each($('.homepage-hero-section'), function(i, item) { 678 if ($(this).height() > homepageCarouselHeight) { 679 homepageCarouselHeight = $(this).height(); 680 } 681 }); 682 $('.homepage-hero-section').css('height', homepageCarouselHeight); 683 $('#homepageCarousel').css('visibility', 'visible'); 684 }); 685 686 function showReviewWriter() { 687 $('#reviewContainer').hide(); 688 $('#productReviewComposer').show(); 689 $('#writeReview').hide(); 690 } 691 692 function hideReviewWriter() { 693 $('#reviewContainer').show(); 694 $('#productReviewComposer').hide(); 695 $('#writeReview').show(); 696 } 697 698 699 700 $('#item-carousel').slick({ 701 slidesToShow: 1, 702 slidesToScroll: 1, 703 arrows: false, 704 dots: false 705 }); 706 707 $('.mobileBrowseNav').click(function(e) { 708 e.preventDefault(); 709 $('.mobileBrowseNavList').toggleClass('is-hidden'); 710 $('.mobileBrowseNavOpenCaret').toggleClass('is-hidden'); 711 $('.mobileBrowseNavClosedCaret').toggleClass('is-hidden'); 712 }); 713 714 $('#writeReview').click(function(e) { 715 e.preventDefault(); 716 showReviewWriter() 717 }); 718 // Check for click events on the navbar burger icon 719 $(".navbar-burger").click(function() { 720 721 // Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu" 722 $(".navbar-burger").toggleClass("is-active"); 723 $(".navbar-menu").toggleClass("is-active"); 724 725 }); 726 $('#homepageCarousel').slick({ 727 autoplay:true, 728 autoplaySpeed: 8500, 729 pauseOnHover: false 730 }); 731 $('#homepageCarousel').on('init', function(event, slick, direction){ 732 733 }); 734 735 $('#homepageCarousel').fadeIn('slow'); 736 737 738 739 740 741 742 743 // $('.storeItemCarousel').on('init', function(event, slick){ 744 // console.log('slider was initialized'); 745 // var itemCar = $(this); 746 // $.each($('.product-card'), function(i, item) { 747 // 748 // var minH = 0; 749 // var thisCycle = $(this).data('card-cycle'); 750 // $.each($('.data-card-cycle-' + thisCycle), function(c, cycle) { 751 // if ($(this).hasClass('slick-initialized')) { 752 // var thisHeight = $(this).height(); 753 // console.log('cycling', minH, thisHeight, $(this), c); 754 // if (thisHeight > minH) { 755 // minH = thisHeight; 756 // console.log('product card height', thisCycle, minH
756); 757 // } 758 // $('.data-card-cycle-' + thisCycle).height(minH); 759 // } 760 // }); 761 // }); 762 // $('.storeItemCarousel').css('visibility','visible').hide().fadeIn('slow'); 763 // }); 764 console.log('is there storeItemCarousel?'); 765 if ($('.storeItemCarousel').length > 0) { 766 console.log('storeItemCarousel started!'); 767 $('.storeItemCarousel').slick( 768 { 769 "slidesToShow": 2, 770 "slidesToScroll": 1, 771 "infinite": false, 772 "prevArrow": '<button type="button" class="slick-prev"><i class="fal fa-arrow-alt-left has-text-dark"></i></button>', 773 "nextArrow": '<button type="button" class="slick-next"><i class="fal fa-arrow-alt-right has-text-dark"></i></button>', 774 "responsive": [ 775 { 776 "breakpoint": 480, 777 "settings": { 778 "slidesToShow": 1, 779 "slidesToScroll": 1 780 } 781 } 782 ] 783 } 784 ); 785 $('.storeItemCarousel').css('visibility','visible').hide().fadeIn('slow'); 786 } 787 $('.storeItemCarousel-image').one("load", function(item) { 788 console.log('image loaded', item); 789 updateProductCarouselHeights(); 790 }).each(function() { 791 if(this.complete) { 792 updateProductCarouselHeights(); 793 } 794 }); 795 796 if ($('.affiliateCardText').length > 0) { 797 798 var minH = 0; 799 $.each($('.affiliateCardText'), function(i, item) { 800 var thisHeight = $(this).outerHeight(); 801 if (thisHeight > minH) { 802 minH = thisHeight; 803 } 804 }); 805 $('.affiliateCardText').css('height', minH); 806 807 var minH = 0; 808 $.each($('.affiliateContent'), function(i, item) { 809 var thisHeight = $(this).outerHeight(); 810 if (thisHeight > minH) { 811 minH = thisHeight; 812 } 813 }); 814 $('.affiliateContent').css('height', minH); 815 } 816 817 818 819 $('.product-image').one("load", function(item) { 820 console.log('image loaded', item); 821 updateProductCarouselHeights(); 822 }).each(function() { 823 if(this.complete) { 824 updateModelImageCards(); 825 } 826 }); 827 828 function updateModelImageCards() { 829 if (window.innerWidth > 768) { 830 var minH = 0; 831 $.each($('.product-card'), function(i, item) { 832 var thisHeight = $(this).outerHeight(); 833 if (thisHeight > minH) { 834 minH = thisHeight; 835 } 836 }); 837 $('.product-card').css('height', minH); 838 } 839 840 } 841 842 function updateProductCarouselHeights() { 843 $('.product-card').css('height', 'auto'); 844 $('.product-card-header').css('height', 'auto'); 845 if (window.innerWidth > 768) { 846 var minH = 0; 847 var completedCycles = []; 848 849 $.each($('.product-card-header'), function(i, item) { 850 851 var thisCycle = $(this).data('card-header-cycle'); 852 minH = 0; 853 if (completedCycles.includes(thisCycle) == false) { 854 $.each($('.data-card-header-cycle-' + String(thisCycle)), function(c, cycle) { 855 $('.data-card-header-cycle-' + thisCycle).css('height', 'auto'); 856 857 var thisHeight = $(this).outerHeight(); 858 if (thisHeight > minH) { 859 minH = thisHeight; 860 } 861 862 $('.data-card-header-cycle-' + thisCycle).css('height', minH); 863 // var thisHeight = $(this).outerHeight(); 864 // console.log('cycling', minH, thisHeight, $(this), c); 865 // if (thisHeight > minH) { 866 // minH = thisHeight; 867 // console.log('product card height', thisCycle, minH); 868 // } 869 // $('.data-card-cycle-' + thisCycle).css('height', minH); 870 }); 871 completedCycles.push(thisCycle); 872 873 } 874 875 }); 876 completedCycles = []; 877 $.each($('.data-card-cycle'), function(i, item) { 878 879 var thisCycle = $(this).data('card-cycle'); 880 minH = 0; 881 if (completedCycles.includes(thisCycle) == false) { 882 $.each($('.data-card-cycle-' + String(thisCycle)), function(c, cycle) { 883 $('.data-card-cycle-' + thisCycle).css('height', 'auto'); 884 885 var thisHeight = $(this).outerHeight(); 886 if (thisHeight > minH) { 887 minH = thisHeight; 888 } 889 890 $('.data-card-cycle-' + thisCycle).css('height', minH); 891 // var thisHeight = $(this).outerHeight(); 892 // console.log('cycling', minH, thisHeight, $(this), c); 893 // if (thisHeight > minH) { 894 // minH = thisHeight; 895 // console.log('product card height', thisCycle, minH
895); 896 // } 897 // $('.data-card-cycle-' + thisCycle).css('height', minH); 898 }); 899 completedCycles.push(thisCycle); 900 901 } 902 903 }); 904 } 905 906 } 907 908 $( window ).resize(function() { 909 if ($('.product-card').length > 0) { 910 updateProductCarouselHeights(); 911 } 912 if ($('.loadHomepageBoxHeights').length > 0) { 913 loadHomepageBoxHeights(); 914 } 915 if ($('.product-image').length > 0) { 916 updateModelImageCards() 917 } 918 }); 919 920 $('.slider-page').click(function(e) { 921 e.preventDefault(); 922 $('#item-carousel').slick('slickGoTo', $(this).data('index'), false); 923 }); 924 925 926 927 // $('.hp-image-scroll').click(function(e) { 928 // e.preventDefault(); 929 // $('#homepageCarousel').slick('slickGoTo', $(this).data('index'), false); 930 // $('#home-page-quote').text($(this).data('quote')); 931 // $('#home-page-quoter').text($(this).data('quoter')); 932 // $('#home-page-image-1').attr('src', $(this).data('image') + '?w=300&auto=compress&h=300&fit=crop&crop=entropy' ); 933 // $('#home-page-image-2').attr('src', $(this).data('image-2') + '?w=300&auto=compress&h=300&fit=crop&crop=entropy' ); 934 // $('#home-page-quote-2').text($(this).data('quote-2')); 935 // $('#home-page-quoter-2').text($(this).data('quoter-2')); 936 // 937 // $('.hp-image-scroll').removeClass('active'); 938 // $(this).addClass('active'); 939 // }); 940 941 // $('.hp-mobile-scroll').click(function(e) { 942 // e.preventDefault(); 943 // console.log($(this).children().first().data()); 944 // $('#homepageCarousel').slick('slickGoTo', $(this).children().first().data('index'), false); 945 // $('#home-page-quote').text($(this).children().first().data('quote')); 946 // $('#home-page-quoter').text($(this).children().first().data('quoter')); 947 // $('#home-page-image-1').attr('src', $(this).children().first().data('image') + '?w=300&auto=compress&h=300&fit=crop&crop=entropy' ); 948 // $('#home-page-image-2').attr('src', $(this).children().first().data('image-2') + '?w=300&auto=compress&h=300&fit=crop&crop=entropy' ); 949 // $('#home-page-quote-2').text($(this).children().first().data('quote-2')); 950 // $('#home-page-quoter-2').text($(this).children().first().data('quoter-2')); 951 // $('.hp-mobile-scroll').removeClass('active'); 952 // $(this).addClass('active'); 953 // }); 954 955 // $('.hp-image-scroll-2').click(function(e) { 956 // e.preventDefault(); 957 // $('#homepageCarousel').slick('slickGoTo', $(this).data('index'), false); 958 // $('#home-page-quote').text($(this).data('quote')); 959 // $('#home-page-quoter').text($(this).data('quoter')); 960 // $('#home-page-quote-2').text($(this).data('quote-2')); 961 // $('#home-page-quoter-2').text($(this).data('quoter-2')); 962 // $('#home-page-image-1').attr('src', $(this).data('image') + '?w=300&auto=compress&h=300&fit=crop&crop=entropy' ); 963 // $('#home-page-image-2').attr('src', $(this).data('image-2') + '?w=300&auto=compress&h=300&fit=crop&crop=entropy' ); 964 // $('.hp-image-scroll').removeClass('active'); 965 // $(this).addClass('active'); 966 // }); 967 $('.faq-cards').click(function(e) { 968 e.preventDefault(); 969 $('.dark-card').removeClass('dark-card').addClass('white-card grey-hover'); 970 $(this).removeClass('white-card grey-hover').addClass('dark-card'); 971 var accTarget = $(this).data('target'); 972 console.log(accTarget); 973 $('.faq-accordions').hide(); 974 $('#' + accTarget).show(); 975 }); 976 977 // $('#homepageCarousel').on('afterChange', function(event, slick, currentSlide, nextSlide){ 978 // console.log(currentSlide); 979 // $('.hp-image-scroll').removeClass('active'); 980 // $('.hp-mobile-scroll').removeClass('active'); 981 // $('#hp-image-scroll-' + String(currentSlide)).addClass('active'); 982 // $('#hp-mobile-scroll-' + String(currentSlide)).addClass('active'); 983 // $('#home-page-quote').text($('#hp-image-scroll-' + String(currentSlide)).data('quote')); 984 // $('#home-page-quoter').text($('#hp-image-scroll-' + String(currentSlide)).data('quoter')); 985 // $('#home-page-quote-2').text($('#hp-image-scroll-' + String(currentSlide)).data('quote-2')); 986 // $('#home-page-quoter-2').text($('#hp-image-scroll-' + String(currentSlide)).data('quoter-2')); 987 // $('#home-page-image-1').attr('src', $('#hp-image-scroll-' + String(currentSlide)).data('image') + '?w=300&auto=compress&h=300&fit=crop&crop=entropy' ); 988 // $('#home-page-image-2').attr('src', $('#hp-image-scroll-' + String(currentSlide)).data('image-2') + '?w=300&auto=compress&h=300&fit=crop&crop=entropy' ); 989 // }); 990 991 $('.storeItemCarousel').on('afterChange', function(event, slick, currentSlide, nextSlide) { 992 993 updateProductCarouselHeights(); 994 }); 995 // 996 // function handleModalAnimationEnd() { 997 // $('.modal').removeClass('animated fadeOut fadeIn'); 998 // $('.modal').off('animationend'); 999 // } 1000 // $('.close-modal').click(function(e) { 1001 // e.preventDefault(); 1002 // $('.modal').addClass('animate fadeOut'); 1003 // handleModalAnimationEnd(); 1004 // }) 1005 // $('.modal-close').click(function(e) { 1006 // 1007 // e.preventDefault(); 1008 // $('.modal').addClass('animate fadeOut'); 1009 // handleModalAnimationEnd(); 1010 // 1011 // }); 1012 1013 $('.show-checkout').click(function(e) { 1014 e.preventDefault(); 1015 $('#cart-modal').addClass('is-active'); 1016 $('body').addClass('blurred-body'); 1017 $(body).attr('overflow', 'hidden') 1018 }); 1019 function removeModals() { 1020 $('.modal').removeClass('is-active'); 1021 $('body').removeClass('blurred-body'); 1022 } 1023 $('.close-modal').click(function(e) { 1024 e.preventDefault(); 1025 removeModals(); 1026 }); 1027 $('.modal-close').click(function(e) { 1028 e.preventDefault(); 1029 removeModals(); 1030 }); 1031 $('.modal-background').click(function(e) { 1032 e.preventDefault(); 1033 removeModals(); 1034 }); 1035 $('.show-dealer-video-modal').click(function(e) { 1036 e.preventDefault(); 1037 $('#dealer-video-modal').addClass('is-active'); 1038 }); 1039 $('.show-dealer-form').click(function(e) { 1040 e.preventDefault(); 1041 $('#dealer-form-modal').addClass('is-active'); 1042 }); 1043 1044 1045 1046 $('.closeBuyOneModal').click(function(e) { 1047 $('#buyOneModal').addClass('is-hidden'); 1048 }) 1049 1050 1051 1052 function launchBuyOneModal() { 1053 $('#buyOneModal').removeClass('is-hidden'); 1054 } 1055 1056 $('.buySecondEarGear50').click(function(e) { 1057 e.preventDefault(); 1058 var c = Snipcart.store.getState(); 1059 var currentItem = c.cart.items.items[0]; 1060 var targetQuantity = parseInt($(this).data('quantity')); 1061 1062 if (!!currentItem) { 1063 // First update the original item to ensure it's quantity is 1 1064 Snipcart.api.cart.items.update({ 1065 uniqueId: currentItem.uniqueId, 1066 quantity: targetQuantity 1067 }).then(function() { 1068 1069 $('#buyOneModal').addClass('is-hidden'); 1070 $('#shopping-list-modal').removeClass('is-active'); 1071 Snipcart.api.theme.cart.open(); 1072 1073 }); 1074 } 1075 }); 1076 1077 1078 1079 1080 document.addEventListener('snipcart.ready', function() { 1081 1082 var currencyCode = getUrlVars()["setCurrency"]; 1083 if (!!currencyCode && currencyCode == 'usd') { 1084 console.log('setting currency to usd'); 1085 Snipcart.api.session.setCurrency('usd'); 1086 } else { 1087 $.getJSON("https://api.ipstack.com/check?access_key=f494d551c1b686cb66fe67aadd03f439", function(d) { 1088 console.log(d["country_name"]); 1089 ip = d.ip; 1090 console.log("ip is: ", ip); 1091 if (d["country_name"] == "Canada") { 1092 Snipcart.api.session.setCurrency('cad'); 1093 $('.country-currency-code').text('CAD'); 1094 } else { 1095 Snipcart.api.session.setCurrency('usd'); 1096 $('.country-currency-code').text('USD'); 1097 } 1098 }) 1099 } 1100 1101 1102 1103 1104 1105 var cart = Snipcart.store.getState(); 1106 console.log('initializing cart', cart); 1107 updateCartIcon(); 1108 // if (cart) { 1109 // if (cart.cart.items.items.length > 0) { 1110 // $('#cart-nav').css('position', 'fixed').css('top:', 0).css('z-index', '1000').css('width', '100%'); 1111 // $('#main-header').css('padding-top', $('#cart-nav').height()); 1112 // $('.quickview').css('margin-top', $('#cart-nav').height()); 1113 // $('.modal-content').css('margin-top', '50px'); 1114 // updateCartIcon(); 1115 // 1116 // } 1117 // } 1118 1119 if (cart) { 1120 console.log('there is a cart'); 1121 console.log(cart); 1122 1123 1124 } else { 1125 console.log('no cart'); 1126 } 1127 1128 function retrieveDCode() { 1129 if (Cookies.get('referral_code')) { 1130 console.log('applying discount'); 1131 1132 try { 1133 Snipcart.api.cart.applyDiscount(Cookies.get('referral_code').replace("%40", "@")); 1134 Cookies.remove('referral_code'); 1135 } catch (error) { 1136 console.log("Something went wrong when adding the discount code, are you sure it's a valid code?", error, ); 1137 } 1138 } else if (Cookies.get('dCode') ) { 1139 console.log('applying discount'); 1140 var dcode = Cookies.get('dCode').replace('%40', "@").split('#')[0]; 1141 console.log('dcode', dcode); 1142 if (dcode != "undefined") { 1143 try { 1144 Snipcart.api.cart.applyDiscount(dCode); 1145 1146 1147 } catch (error) { 1148 console.log("Something went wrong when adding the discount code, are you sure it's a valid code?", error, ); 1149 } 1150 } 1151 1152 } else { 1153 console.log('Not Applying Discount'); 1154 } 1155 } 1156 1157 var dCode = getUrlVars()["dCode"]; 1158 1159 if (dCode) { 1160 dCode = decodeURI(dCode); 1161 console.log('dCode is present'); 1162 Cookies.set('dCode', dCode); 1163 retrieveDCode(); 1164 } 1165 1166 1167 1168 Snipcart.events.on('snipcart.initialized', (snipcartState) => { 1169 console.log('snipcart.initialized', snipcartState); 1170 retrieveDCode(); 1171 }); 1172 1173 Snipcart.events.on('summary.checkout_clicked', () => { 1174 changeCartHeader(); 1175 $('#add-to-cart-button-containers').removeClass('is-fixed-top'); 1176 console.log('checking for dCode'); 1177 retrieveDCode(); 1178 }); 1179 1180 function showCartErrorBox(confirmError) { 1181 $('#cart-error-box').removeClass('is-hidden'); 1182 setTimeout(function(){ 1183 $('#cart-error-box').addClass('is-hidden'); 1184 }, 30000); 1185 1186 } 1187 1188 Snipcart.events.on('cart.confirm.error', (confirmError) => { 1189 console.log('confirmError', confirmError); 1190 showCartErrorBox(confirmError); 1191 1192 }); 1193 1194 Snipcart.events.on('payment.failed', (paymentError) => { 1195 console.log('paymentError', paymentError); 1196 showCartErrorBox(paymentError); 1197 }); 1198 1199 1200 1201 1202 //check for billing address cookie 1203 console.log('looking for cookies', Cookies.get('billingaddress')); 1204 var billingAddress = Cookies.get('billingaddress') || null; 1205 console.log('billingAddress:', billingAddress); 1206 Snipcart.store.subscribe(() => { 1207 var newBillingAddress = Snipcart.store.getState().cart; 1208 var oldBillingAddress = JSON.parse(billingAddress); 1209 var processLeadInfo = false;
1210 1211 1212 if (!oldBillingAddress) { 1213 processLeadInfo = true; 1214 } else if (oldBillingAddress.fullName) { 1215 console.log(oldBillingAddress.fullName); 1216 console.log('oldBillingAddress.fullname, processing: true;'); 1217 processLeadInfo = true; 1218 } 1219 if (!processLeadInfo) { 1220 1221 1222 var newAddressString = String(newBillingAddress.billingAddress.fullName) + String(newBillingAddress.billingAddress.address1) + String(newBillingAddress.billingAddress.address2) + String(newBillingAddress.billingAddress.city) + String(newBillingAddress.billingAddress.country) + String(newBillingAddress.billingAddress.province) + String(newBillingAddress.billingAddress.postalCode); 1223 var oldAddressString; 1224 var oldEmail; 1225 if (oldBillingAddress) { 1226 1227 oldAddressString = String(oldBillingAddress.billingAddress.fullName) + String(oldBillingAddress.billingAddress.address1) + String(oldBillingAddress.billingAddress.address2) + String(oldBillingAddress.billingAddress.city) + String(oldBillingAddress.billingAddress.country) + String(oldBillingAddress.billingAddress.province) + String(oldBillingAddress.billingAddress.postalCode); 1228 if (newBillingAddress.email == oldBillingAddress.email && newAddressString == oldAddressString) { 1229 console.log('info matches!'); 1230 console.log(newBillingAddress.email); 1231 console.log(oldBillingAddress.email); 1232 console.log(newAddressString); 1233 console.log(oldAddressString); 1234 processLeadInfo = false; 1235 } else { 1236 console.log('info does not match!'); 1237 console.log(newBillingAddress.email); 1238 console.log(oldBillingAddress.email); 1239 console.log(newAddressString); 1240 console.log(oldAddressString); 1241 processLeadInfo = true; 1242 } 1243 } else { 1244 console.log('no old billing address;') 1245 processLeadInfo = true; 1246 } 1247 } 1248 1249 if (!!processLeadInfo) { 1250 if (!!Snipcart.store.getState().cart.billingAddress.hasMinimalRequiredInfo) { 1251 billingAddress = JSON.stringify(Snipcart.store.getState().cart); 1252 Cookies.set('billingaddress', JSON.stringify(Snipcart.store.getState().cart)); 1253 1254 var cdat = Snipcart.store.getState().cart.billingAddress; 1255 var ccoo = Cookies.get(); 1256 var cart = Snipcart.store.getState().cart; 1257 var jsonData = JSON.stringify({ 1258 "fields": { 1259 "ccoo": ccoo, 1260 "cdat": cdat, 1261 "page": window.location.href, 1262 "cart": cart, 1263 "title": document.title, 1264 "ip": ip 1265 } 1266 }); 1267 console.log(jsonData); 1268 var settings = { 1269 "async": true, 1270 "crossDomain": true, 1271 "url": "https://server.pappalar.do/ear-gear/cdat/catch?siteKey=f7e9d15f-ad99-49be-96e0-4f554b4ffec6", 1272 "method": "POST", 1273 "headers": { 1274 "content-type": "application/json", 1275 "authorization": "Bearer" 1276 }, 1277 "processData": false, 1278 "data": jsonData 1279 }; 1280 $.ajax(settings).done(function(data) { 1281 console.log('formResponse: '); 1282 console.log(data); 1283 }); 1284 } 1285 } 1286 }); 1287 1288 $('.snipcart-add-item').click(function(e) { 1289 console.log('clicked snipcart button'); 1290 console.log(e); 1291 Snipcart.api.modal.show(); 1292 }); 1293 console.log('snipcart ready!'); 1294 1295 $('#cart-badge-count').show('fast'); 1296 $('#cart-details').show('fast'); 1297 1298 Snipcart.events.on('item.added', function (item) { 1299 if (cart) { 1300 console.log('already a cart'); 1301 } else { 1302 cart = Snipcart.api.cart.get(); 1303 } 1304 console.log('item added', item); 1305 1306 if (Cookies.get('dCode')) { 1307 console.log('applying discount'); 1308 var dcode = Cookies.get('dCode').replace('%40', "@").split('#')[0]; 1309 console.log('dcode', dcode); 1310 try { 1311 Snipcart.api.cart.applyDiscount(dCode); 1312 1313 1314 } catch (error) { 1315 console.log("Something went wrong when adding the discount code, are you sure it's a valid code?", error, ); 1316 } 1317 } else { 1318 console.log('Not Applying dCode'); 1319 var c = Snipcart.store.getState(); 1320 if (c.cart.discounts.items.length == 0 && c.cart.items.count == 1) { 1321 var i = c.cart.items.items[0]; 1322 if (i.categories.includes('standard')) { 1323 launchBuyOneModal(); 1324 } 1325 1326 } else { 1327 console.log('not applying discount'); 1328 } 1329 1330 } 1331 1332 }); 1333 1334 Snipcart.events.on('cart.confirmed', function (item) { 1335 Cookies.remove('billingaddress'); 1336 dataLayer.push({'event':'websitePurchase','purchaseAmount': item.total, purchaseID: item.invoiceNumber }); 1337 1338 1339 $('#post-purchase-cta-modal').addClass('is-active'); 1340 var e = item.email; 1341 var f = item.billingAddress.firstName 1342 1343 var l = item.billingAddress.lastName; 1344 if (l) { 1345 l = l.split('')[0].toUpperCase() + "."; 1346 } 1347 console.log(e, f, l, ip); 1348 console.log(e); 1349 if (typeof gtag == 'function') { 1350 gtag('event', 'conversion', { 1351 'send_to': 'AW-1014371352/SIN5CJOgmtYBEJio2OMD', 1352 'value': item.total, 1353 'currency': item.currency.toUpperCase(), 1354 'transaction_id': '' 1355 }); 1356 } 1357 1358 Cookies.remove('dCode'); 1359 if (typeof fbq == 'function') { 1360 fbq('track', 'Purchase', {currency: item.currency.toUpperCase(), value: item.total}); 1361 } 1362 1363 1364 window.uetq = window.uetq || []; window.uetq.push({ 'ec': 'Conversion', 'ea': 'Purchase', 'el': 'Purchase', 'ev': item.total, 'gv': item.total, 'gc': item.currency.toUpperCase() }); 1365 1366
1367 console.log('order completed'); 1368 console.log(item); 1369 console.log('email is' + item.email); 1370 console.log('purchase is is'); 1371 console.log(item.total) 1372 console.log('shipping is'); 1373 console.log(item.shippingDetails.cost); 1374 console.log(item.shippingDetails.cost); 1375 console.log('commission amount is'); 1376 console.log(item.total - item.shippingDetails.cost); 1377 console.log('token is' + item.token); 1378 console.log('order id is' + item.invoiceNumber); 1379 $('#snipcart-title').text('Order #: ' + item.invoiceNumber); 1380 1381 if (Cookies.get('ref_id')) { 1382 console.log('referral cookie', Cookies.get('ref_id')); 1383 var refCode = Cookies.get('ref_id'); 1384 var jsonData = JSON.stringify({ 1385 "referral_code": refCode, 1386 "purchaser_email": item.email 1387 }); 1388 1389 1390 console.log(jsonData); 1391 var settings = { 1392 "async": true, 1393 "crossDomain": true, 1394 "url": "https://server.pappalar.do/ear-gear/referral/catch?siteKey=f7e9d15f-ad99-49be-96e0-4f554b4ffec6", 1395 "method": "POST", 1396 "headers": { 1397 "content-type": "application/json", 1398 "authorization": "Bearer" 1399 }, 1400 "processData": false, 1401 "data": jsonData 1402 }; 1403 $.ajax(settings).done(function(data) { 1404 console.log(data); 1405 console.log('Done'); 1406 1407 }); 1408 } else { 1409 console.log('no referral cookie', Cookies.get()); 1410 } 1411 if (item.discounts.length > 0) { 1412 1413 1414 1415 } else { 1416 1417 } 1418 1419 if (Cookies.get('affiliatly_v3')) { 1420 //setting ac as the affiliatly cookie 1421 var ac = Cookies.get('affiliatly_v3'); 1422 //it stores the values needed as key/value pairs so we can store them in a param object 1423 var p = new URLSearchParams(ac); 1424 1425 const settings = { 1426 "async": true, 1427 "crossDomain": true, 1428 "url": "https://www.affiliatly.com/api_request.php", 1429 "method": "POST", 1430 "headers": { 1431 "Content-Type": "application/x-www-form-urlencoded" 1432 }, 1433 "data": { 1434 "mode": "mark_php", 1435 "id_affiliatly": "AF-1063789", 1436 "id_user": p.get("id_user"), 1437 "id_hash": p.get("id_token"), 1438 "aff_uid": p.get("aff_uid"), 1439 "order": item.invoiceNumber, 1440 "price": String(item.total), 1441 "hash": "5c01031500fe6bdfcd1eb121745110bc" 1442 } 1443 }; 1444 1445 $.ajax(settings).done(function (response) { 1446 console.log('affiliatly response', response); 1447 }); 1448 1449 1450 } 1451 1452 1453 if (typeof _mfq == 'function') { 1454 _mfq.push(['activateFeedback', 'K48LSBB0RkywubVQdlhaow']); 1455 } 1456 1457 1458 }); 1459 1460 Snipcart.events.on('cart.confirm.error', (confirmError) => { 1461 console.log(confirmError); 1462 Sentry.captureException(new Error("Snipcart Checkout Error"), {}); 1463 }); 1464 1465 }); 1466 1467 function clearShoppingModal() { 1468 1469 shoppingModal.productName = ""; 1470 shoppingModal.productColor = ""; 1471 shoppingModal.productImage = ""; 1472 shoppingModal.productSku = ""; 1473 shoppingModal.productColorOptions = []; 1474 shoppingModal.productUrl = ""; 1475 shoppingModal.model = ""; 1476 shoppingModal.item = ""; 1477 shoppingModal.id = ""; 1478 shoppingModal.productVariantOptions = []; 1479 shoppingModal.productButtonText = "Add to Cart"; 1480 shoppingModal.productDescription = ""; 1481 shoppingModal.learnMoreLink = ""; 1482 shoppingModal.productPrice = '{"usd": "0.00", "cad": "0.00"}'; 1483 shoppingModal.productQuantity = 1; 1484 shoppingModal.addedToCart = false; 1485 shoppingModal.selectedVariant = {"name": "", "id": "", selected: false}; 1486 shoppingModal.sizingForCart = ""; 1487 $('.variant-radio').prop('checked', false); 1488 } 1489 1490 $('.product-card .product-image-hover').click(function(e) { 1491 e.preventDefault(); 1492 clearShoppingModal(); 1493 1494 // $(this).parent().parent().parent().siblings().children().children().children().removeClass('active-hover'); 1495 // console.log($(this).parent().parent().parent().siblings().children().children().children()); 1496 // $(this).addClass('active-hover'); 1497 1498 shoppingModal.productImage = $(this).data('static-img-src');
1499 shoppingModal.productColor = $(this).data('item-color'); 1500 shoppingModal.productName = $(this).data('item-name'); 1501 shoppingModal.learnMoreLink = $(this).data('link-path'); 1502 shoppingModal.productPrice = $(this).data('price'); 1503 shoppingModal.productPriceObject = '{"usd": "' + $(this).data('price') + '", "cad": "' + $(this).data('price') + '"}'; 1504 shoppingModal.productSku = $(this).data('item-sku'); 1505 shoppingModal.model = $(this).data('model-id'); 1506 shoppingModal.productDescription = $(this).data('item-summary'); 1507 shoppingModal.sizingForCart = $(this).data('sizing-for-cart'); 1508 shoppingModal.cordless = $(this).data('cordless'); 1509 if (typeof gtag == 'function') { 1510 gtag('event', 'view_item', { 1511 'event_category' : 'viewed_in_modal', 1512 'event_label' : shoppingModal.productName + " - " + shoppingModal.productColor 1513 }); 1514 } 1515 try { 1516 fbq('trackCustom', 'viewItem', {item: shoppingModal.productName + " - " + shoppingModal.productColor}); 1517 1518 } catch (error) { 1519 console.log('issue tracking fbq', error); 1520 } 1521 1522 1523 var variantString = String($(this).data('variants')); 1524 if (variantString.includes(",")) { 1525 1526 var variants = $(this).data('variants').split(','); 1527 var variantNames = $(this).data('variant-names').split(','); 1528 $.each(variants, function(i, item) { 1529 var variantObject = {"name": variantNames[i], "id": item}; 1530 shoppingModal.productVariantOptions.push(variantObject); 1531 }); 1532 } else if (variantString) { 1533 var variantObject = {"name": $(this).data('variant-names'), "id": $(this).data('variants') }; 1534 shoppingModal.productVariantOptions.push(variantObject); 1535 } 1536 1537 $('#shopping-list-modal').addClass('is-active'); 1538 1539 $.each(allModels, function(m, model) { 1540 console.log('model.id', model.id); 1541 console.log('shoppingModal.model', shoppingModal.model); 1542 if (model.id == shoppingModal.model) { 1543 $.each(model.items, function(i, item) { 1544 var colorObject = {"name": item.color, "image": item.image, "swatch": item.swatch, "productId": model.product, "sku": item.sku, "path": "/products/" + model.slug + "/" + item.sku}; 1545 shoppingModal.productColorOptions.push(colorObject); 1546 }) 1547 } 1548 }); 1549 1550 // $('#listing-modal-colors').on('click', '.color-changers', function(e) { 1551 // console.log('clicking in popup!'); 1552 // color = $(this).data('color'); 1553 // console.log(color); 1554 // $.each(allModels, function(m, model){ 1555 // if (model.id == popupModel) { 1556 // console.log('model'); 1557 // console.log(model); 1558 // $('#listing-modal-color').text(color); 1559 // $.each(model.items, function(i, item) { 1560 // 1561 // console.log(color); 1562 // console.log(item.color); 1563 // 1564 // if (color == item.color) { 1565 // console.log(item); 1566 // 1567 // 1568 // var bgImage = item.image + "?w=600&auto=compress&h=600&fit=crop"; 1569 // 1570 // //update image link 1571 // $('.modal-product-img-link').attr('href', '/products/' + model.slug + '/' + item.slug + '.html'); 1572 // 1573 // //update title link 1574 // $('#listing-modal-title').html('<a href="/products/' + model.slug + '/' + item.slug + '.html">' + model.title + '</a>'); 1575 // 1576 // var sku = item.sku; 1577 // 1578 // var theEl = $('#listing-modal-img').children().first().children().first().children().first(); 1579 // console.log(theEl); 1580 // // if (theEl.hasClass('active-hover')) { 1581 // // console.log("found active hover"); 1582 // // console.log(theEl); 1583 // // console.log($('#main-img-product-' + productId)); 1584 // // $('#main-img-product-' + productId).attr('src', bgImage).data('static-img', bgImage).data('hoverable-img', bgImage); 1585 // // } 1586 // theEl.attr('src', bgImage); 1587 // 1588 // $('#listing-modal-add-to-cart').data('item-id', item.sku); 1589 // $('#listing-modal-add-to-cart').data('item-name', model.title + ' - ' + color); 1590 // 1591 // $('#listing-modal-add-to-cart').data('item-description', model.product_description); 1592 // $('#listing-modal-add-to-cart').data('item-image', item.image); 1593 // $('#listing-modal-add-to-cart').data('item-price', '{"usd": ' + model.price + ', "cad": ' + model.price + '}'); 1594 // $('#listing-modal-add-to-cart').data('item-url', '/products/' + model.slug + '/' + item.slug); 1595 // 1596 // 1597 // theEl.data('link-path', model["slug"] + item["slug"]); 1598 // theEl.data('item-color', color); 1599 // theEl.data('static-img-src', bgImage); 1600 // theEl.data('item-sku', sku); 1601 // //theEl.data('hovered-imaage-src', item[]["url"]); 1602 // 1603 // 1604 // 1605 // if (selectedVariant == "0") { 1606 // // $('#listing-modal-add-to-cart').data('item-id', itemSku); 1607 // // $('#listing-modal-add-to-cart').data('item-name', itemName + ' - ' + itemColor); 1608 // } else { 1609 // 1610 // console.log(allModels); 1611 // 1612 // $.each(allModels, function(a, allModel) { 1613 // 1614 // $.each(allModel.category, function(c, cat) { 1615 // $.each(cat.variant, function(v, vari) { 1616 // if (vari.id == selectedVariant) { 1617 // varSlug = vari.slug; 1618 // varName = vari.name; 1619 // console.log(varSlug); 1620 // console.log(varName); 1621 // } 1622 // }); 1623 // }); 1624 // }); 1625 // $('#listing-modal-add-to-cart').data('item-id', varSlug.toUpperCase() + '-' + item.sku); 1626 // $('#listing-modal-add-to-cart').data('item-name', varName + ' - ' + model.title + ' - ' + item.color); 1627 // console.log($('#listing-modal-add-to-cart').data()); 1628 // } 1629 // 1630 // } 1631 // }); 1632 // } 1633 // 1634 // }); 1635 // 1636 // 1637 // 1638 // }); 1639 1640 }); 1641 1642 $('.homepageCardAddItem').click(function(e) { 1643 $(this).html('<i class="fas fa-spinner fa-spin"></i> Adding to Cart'); 1644 console.log($(this).data()); 1645 var itemId = $(this) 1646 var itemId = $(this).data('item-id'); 1647 var itemName = $(this).data('item-name'); 1648 var itemDescription = $(this).data('item-description'); 1649 var itemImage = $(this).data('item-image'); 1650 var itemPrice = $(this).data('item-price'); 1651 var itemUrl = $(this).data('item-url'); 1652 Snipcart.api.cart.items.add({ 1653 "id": itemId, 1654 "name": itemName, 1655 // "description": itemDescription, 1656 "url": itemUrl, 1657 "image": itemImage, 1658 "price": itemPrice, 1659 "dimensions": { 1660 "weight": 1, 1661 "width": 1, 1662 "height": 1, 1663 "length": 1 1664 }, 1665 1666 }) 1667 .then (function (cartItem) { 1668 console.log(cartItem); 1669 Snipcart.api.modal.show(); 1670 $('.homepageCardAddItem').text("ADD TO CART") 1671 1672 }); 1673 }); 1674 1675 $('#listing-modal-add-to-cart').click(function(e) { 1676 $(this).html('<i class="fas fa-spinner fa-spin"></i> Adding To Cart'); 1677 console.log($(this).data()); 1678 var itemId = $(this).data('item-id'); 1679 var itemName = $(this).data('item-name'); 1680 var itemDescription = $(this).data('item-description'); 1681 var itemImage = $(this).data('item-image'); 1682 var itemPrice = $(this).data('item-price'); 1683 var itemUrl = $(this).data('item-url'); 1684 var quantity = $('#quantity-amount').val(); 1685 1686 Snipcart.api.cart.items.add({ 1687 "id": itemId, 1688 "name": itemName, 1689 // "description": itemDescription, 1690 "url": itemUrl, 1691 "image": itemImage, 1692 1693 "dimensions": { 1694 "weight": 1, 1695 "width": 1, 1696 "height": 1, 1697 "length": 1 1698 }, 1699 "price": itemPrice, 1700 "quantity": quantity 1701 }) 1702 .then (function (cartItem) { 1703 console.log(cartItem); 1704 var itemMessage = cartItem["name"] + ' was added to your cart!'; 1705 $('#cart-add-message').html('<span class="has-text-success">' + itemMessage + '</span>'); 1706 $('#listing-modal-add-to-cart').text('Add to Cart').hide(); 1707 $('#after-add-cart-options').show(); 1708 }); 1709 1710 }); 1711 1712 var descriptionShow = true; 1713 1714 $('.show-item-description').click(function(e) { 1715 e.preventDefault(); 1716 if ( descriptionShow == false ) { 1717 console.log('hiding'); 1718 console.log('var is ' + String(descriptionShow)); 1719 $('.product-descriptions').show('slow'); 1720 descriptionShow = true; 1721 $('.show-item-description').html('See Less <i class="fas fa-caret-down"></i>'); 1722 } else { 1723 console.log('showing'); 1724 console.log('var is ' + String(descriptionShow)); 1725 $('.product-descriptions').hide('slow'); 1726 $('.show-item-description').html('See More <i class="fas fa-caret-right"></i>'); 1727 descriptionShow = false;
1728 1729 } 1730 console.log(descriptionShow); 1731 1732 }); 1733 1734 1735 1736 $('.color-changers').mouseover(function(e) { 1737 e.preventDefault(); 1738 var modIds = String($(this).data('mod-ids')); 1739 console.log(modIds); 1740 if (modIds) { 1741 modIds = modIds.split(','); 1742 1743 console.log(modIds); 1744 var productId = $(this).data('product-id'); 1745 console.log(productId); 1746 var color = $(this).data('color'); 1747 console.log(color); 1748 1749 console.log(allModels); 1750 1751 1752 $.each(allModels, function(m, model){ 1753 if (model.product == productId) { 1754 $.each(model.items, function(i, item) { 1755 1756 console.log(color); 1757 console.log(item.color); 1758 1759 if (color == item.color) { 1760 if (color == item.color) { 1761 console.log('It is a match') 1762 } else { 1763 console.log('it is not a match'); 1764 } 1765 1766 var bgImage = "https://www.gearforears.com/cdn-cgi/image/width=480,height=400,format=auto,quality=70/" + item.image; 1767 var sku = item.sku; 1768 console.log(sku); 1769 console.log('color'); 1770 console.log(color); 1771 console.log('image url'); 1772 console.log(bgImage); 1773 var theEl = $('#model-id-' + model.id); 1774 console.log(theEl); 1775 // if (theEl.hasClass('active-hover')) { 1776 // console.log("found active hover"); 1777 // console.log(theEl); 1778 // console.log($('#main-img-product-' + productId)); 1779 // $('#main-img-product-' + productId).attr('src', bgImage).data('static-img', bgImage).data('hoverable-img', bgImage); 1780 // } 1781 theEl.children().children().attr('src', bgImage); 1782 theEl.data('link-path', '/products/' + model["slug"] + '/' + item["slug"]); 1783 theEl.data('item-color', color); 1784 theEl.data('static-img-src', bgImage); 1785 theEl.data('item-sku', sku) 1786 //theEl.data('hovered-imaage-src', item[]["url"]); 1787 } 1788 }); 1789 } 1790 }); 1791 } 1792 }); 1793 1794 1795 $('#quantity-sub').click(function(e) { 1796 e.preventDefault(); 1797 var quantity = shoppingModal.productQuantity; 1798 console.log(quantity); 1799 if (quantity > 1) { 1800 quantity = Number(quantity) - 1; 1801 shoppingModal.productQuantity = quantity; 1802 } 1803 }); 1804 1805 $('#quantity-plus').click(function(e) { 1806 e.preventDefault(); 1807 var quantity = shoppingModal.productQuantity; 1808 console.log(quantity); 1809 if (quantity < 10) { 1810 quantity = Number(quantity) + 1; 1811 shoppingModal.productQuantity = quantity; 1812 } 1813 }); 1814 1815 $('#close-cart').click(function(e) { 1816 e.preventDefault(); 1817 $('.modal').removeClass('is-active'); 1818 $('body').removeClass('blurred-body'); 1819 resetCartModal(); 1820 }); 1821 1822 function openingSnipcart() { 1823 if ($('.modal.is-active').length > 0) { 1824 console.log('Opening Cart!'); 1825 $('.modal').removeClass('is-active'); 1826 // resetCartModal(); 1827 setTimeout(function(){ 1828 Snipcart.api.theme.cart.open(); 1829 }, 100); 1830 } else { 1831 Snipcart.api.theme.cart.open(); 1832 } 1833 1834 1835 } 1836 1837 1838 1839 1840 1841 1842 1843 1844 $("input[name='rating']").change(function(e) { 1845 $('#number-of-stars').text(String($(this).val()) + " Stars"); 1846 }); 1847 1848 function updateCartNumber(oldCart) { 1849 console.log('updating cart number!', cart); 1850 var cart = Snipcart.store.getState(); 1851 if (cart) { 1852 1853 1854 var itemCount = cart.cart.items.count; 1855 console.log('itemCount', itemCount); 1856 1857 1858 var countHTML = '<span id="" class="fa-stack fa-lg has-badge snipcart-checkout" data-count="' + String(itemCount) + '"><i class="fa fa-circle fa-stack-2x fa-inverse snipcart-checkout"></i><i style="" class="fa fa-shopping-cart fa-stack-2x red-cart snipcart-checkout"></i></span>'; 1859 console.log('countHTML', countHTML); 1860 1861 $('.cart-badge-count').html(countHTML); 1862 } else { 1863 console.log('no cart'); 1864 } 1865 } 1866 1867 function updateCartIcon() { 1868 console.log('updating cart icon!') 1869 var cart = Snipcart.store.getState(); 1870 console.log('cart', cart); 1871 // cart = Snipcart.api.cart.get(); 1872 1873 var currentValue = cart; 1874 const unsubscribe = Snipcart.store.subscribe(() => { 1875 let previousValue = currentValue; 1876 currentValue = Snipcart.store.getState(); 1877 1878 if (previousValue !== currentValue) { 1879 console.log('stateChange', currentValue, previousValue); 1880 updateCartNumber(currentValue); 1881 $('.item-body-add-to-cart').text("ADD TO CART"); 1882 1883 $('.addCustomToCart').text("Add to Cart"); 1884 $('.snipcart-add-item').text('Add to Cart'); 1885 } 1886 }); 1887 1888 1889 } 1890 1891 1892 $('#review-form').submit(function (evt) { 1893 evt.preventDefault(); 1894 var rating = $("input[name='rating']:checked").val(); 1895 var reviewer_name = $('#reviewer_name').val(); 1896 var reviewer_email = $('#reviewer_email').val(); 1897 var review = $('#review').val(); 1898 var product = $('#product_id').val(); 1899 var slug = $('#product_slug').val(); 1900 var jsonData = JSON.stringify({ 1901 1902 "fields": { 1903 "rating": rating, 1904 "reviewer_name": reviewer_name, 1905 "reviewer_email": reviewer_email, 1906 "review": review, 1907 "product_id": product, 1908 "product_slug": slug 1909 } 1910 }); 1911 var settings = { 1912 "async": true, 1913 "crossDomain": true, 1914 "url": "https://server.pappalar.do/ear-gear/review/catch?siteKey=f7e9d15f-ad99-49be-96e0-4f554b4ffec6", 1915 "method": "POST", 1916 "headers": { 1917 "content-type": "application/json", 1918 "authorization": "Bearer" 1919 }, 1920 "processData": false, 1921 "data": jsonData 1922 }; 1923 $.ajax(settings).done(function(data) { 1924 1925 console.log('Finished!'); 1926 console.log(data); 1927 $('#review-card').html('<p class="is-size-3">Thanks for reviewing our product!'); 1928 }); 1929 }); 1930 1931 function changeCartHeader() { 1932 $('#snipcart-title').html('<img class="image" src="/images/ear_gear_logo.png">'); 1933 if ($('#snipcart-login-form-container').length > 0) { 1934 if ($('#snipcart-direct-to-partner-login').length == 0) { 1935 $('#snipcart-login-form-container').append('<p style="margin-top:25px;"><strong>Looking for the Partner Login? <a href="https://partners.gearforears.c
1935om" target="_blank"><u>Log in here</u></a></strong></p>'); 1936 } 1937 } 1938 } 1939 1940 document.addEventListener('snipcart.ready', () => { 1941 1942 // Snipcart.api.configure('show_continue_shopping', true).configure('show_cart_automatically', false).configure('split_firstname_and_lastname', true); 1943 1944 console.log('snipcart ready!'); 1945 updateCartIcon(); 1946 updateCartNumber(Snipcart.store.getState()); 1947 $('#cart-badge-count').show('fast'); 1948 $('#cart-details').show('fast'); 1949 Snipcart.events.on('page.validating', function(ev, data) { 1950 console.log(ev.type); 1951 if(ev.type == 'billing-address' && data.phone.length == 0) { 1952 ev.addError('phone', 'Please enter a jphone'); 1953 } 1954 }); 1955 1956 Snipcart.events.on('cart.closed', function (item) { 1957 updateCartIcon(); 1958 shoppingModal.addedToCart = false; 1959 shoppingModal.productButtonText = 'Add to Cart'; 1960 }); 1961 1962 Snipcart.events.on('page.changed', function (page) { 1963 console.log(page); 1964 if (page == 'order-details') { 1965 // $('#snipcart-title').text('Order #: ' + item.invoiceNumber); 1966 } else { 1967 changeCartHeader(); 1968 } 1969 if ($('#snipcart_custom_Custom-Pricing-dollar10').length > 0) { 1970 var els = $('#snipcart_custom_Custom-Pricing-dollar10'); 1971 $.each(els, function(i, item) { 1972 $(item).parent().parent().parent().hide(); 1973 }); 1974 } 1975 }); 1976 Snipcart.events.on('cart.opened', function() { 1977 console.log('Snipcart popup is visible'); 1978 changeCartHeader(); 1979 if ($('#snipcart_custom_Custom-Pricing-dollar10').length > 0) { 1980 var els = $('#snipcart_custom_Custom-Pricing-dollar10'); 1981 $.each(els, function(i, item) { 1982 $(item).parent().parent().parent().hide(); 1983 }); 1984 // $('#snipcart_custom_Custom-Pricing-dollar10').parent().parent().parent().hide(); 1985 } 1986 }); 1987 1988 $('.item-body-add-to-cart').click(function(e) { 1989 $(this).text("ADDING TO CART..."); 1990 var itemId = $(this).data('itemId'); 1991 var itemName = $(this).data('itemName'); 1992 var itemDescription = $(this).data('itemDescription'); 1993 var itemImage = $(this).data('itemImage'); 1994 var itemPrice = $(this).data('itemPrice'); 1995 var itemWeight = $(this).data('itemWeight'); 1996 var itemUrl = $(this).data('itemUrl'); 1997 1998 item = { 1999 "id": itemId, 2000 "name": itemName, 2001 "description": itemDescription, 2002 "url": itemUrl, 2003 "image": itemImage, 2004 "price": itemPrice, 2005 "categories": ["standard"], 2006 "dimensions": { 2007 "weight": 1, 2008 "width": 1, 2009 "height": 1, 2010 "length": 1 2011 }, 2012 "quantity": 1 2013 } 2014 Snipcart.api.cart.items.add(item).then (function (cartItem) { 2015 console.log(cartItem); 2016 Snipcart.api.theme.cart.open(); 2017 updateCartIcon(); 2018 }); 2019 2020 Snipcart.events.on('cart.closed', function (item) { 2021 $('.item-body-add-to-cart').text("ADD TO CART"); 2022 2023 $('.addCustomToCart').text("Add to Cart"); 2024 $('.snipcart-add-item').text('Add to Cart'); 2025 updateCartIcon(); 2026 }); 2027 Snipcart.events.on('cart.confirmed item.removed item.added', function (item) { 2028 updateCartIcon(); 2029 }); 2030 }); 2031 console.log('setupPopupListeners'); 2032 setupPopupListeners(); 2033 }); 2034 2035 2036 $(window).scroll( function(){ 2037 if ($('#homepageCallouts').length > 0) { 2038 console.log('home page') 2039 var hpCards = $('#homepageCardContainer').length > 0 ? $('#homepageCardContainer').offset().top - $(window).height() + 100 : 0; 2040 var hpCallouts = $('#homepageCallouts').length > 0 ? $('#homepageCallouts').offset().top - $(window).height() + 100 : 0; 2041 var hpVid = $('#hpVideo').length > 0 ? $('#hpVideo').offset().top - $(window).height() + 100 : 0; 2042 2043 $(window).scroll(function() { 2044 console.log($(window).scrollTop()); 2045 2046 console.log(hpCards); 2047 if (hpCards > 0 && $(window).scrollTop() > hpCards) { 2048 if ($('#homepageCards').length > 0 && $('#homepageCards').css('visibility') == "hidden") { 2049 $('#homepageCards').css('visibility','visible').hide().fadeIn('slow') 2050 } 2051 2052 } 2053 console.log(hpVid); 2054 if (hpVid > 0 && $(window).scrollTop() > hpVid) { 2055 if ($('#hpVideo').length > 0 && $('#hpVideo').css('visibility') == "hidden") { 2056 $('#hpVideo').css('visibility','visible').hide().fadeIn('slow') 2057 } 2058 } 2059 2060 console.log(hpCallouts); 2061 if (hpCallouts > 0 && $(window).scrollTop() > hpCallouts) { 2062 if ($('#homepageCallouts').length > 0 && $('#homepageCallouts').css('visibility') == "hidden") { 2063 $('#homepageCallouts').css('visibility','visible').hide().fadeIn('slow') 2064 } 2065 } 2066 }); 2067 } 2068 if ($('.storeItemCarousel').length > 0) { 2069 updateProductCarouselHeights(); 2070 } 2071 2072 }); 2073 function showCorded() { 2074 $('#corded-options').fadeIn(); 2075 } 2076 function showCordless() { 2077 $('#corded-options').fadeOut(); 2078 } 2079 2080 var buttonShown = false;
2081 var modId = ''; 2082 var cats = ''; 2083 var customVarChosen = false; 2084 2085 2086 2087 2088 $('.snipcart-add-alert').click(function(e) { 2089 e.preventDefault(); 2090 alert(JSON.stringify($(this).data())); 2091 }); 2092 2093 $('.addCustomToCart').click(function(e) { 2094 e.preventDefault(); 2095 $(this).text('Adding to Cart...'); 2096 Snipcart.events.on('item.added', function (item) { 2097 Snipcart.api.modal.show(); 2098 updateCartIcon(); 2099 }); 2100 2101 }); 2102 $('.notification .delete').click(function(e) { 2103 e.preventDefault(); 2104 $(this).parent().fadeOut(); 2105 }); 2106 2107 2108 2109 2110 $('.homepage-card-image').one("load", function() { 2111 loadHomepageBoxHeights(); 2112 }).each(function() { 2113 if(this.complete) { 2114 loadHomepageBoxHeights(); 2115 } 2116 }); 2117 2118 2119 function loadHomepageBoxHeights() { 2120 console.log("there are homepage Cards"); 2121 if (window.innerWidth > 768) { 2122 var minH = 0; 2123 $.each($('.homepage-card .card-name'), function(i, item ) { 2124 var thisHeight = $(this).height(); 2125 if (thisHeight > minH) { 2126 minH = thisHeight; 2127 } 2128 }); 2129 $.each($('.homepage-card .card-name'), function(i, item ) { 2130 var thisHeight = $(this).height(); 2131 if (thisHeight > minH) { 2132 minH = thisHeight; 2133 } 2134 }); 2135 $('.homepage-card .card-name').height(minH); 2136 $.each($('.homepage-card .card-summary'), function(i, item ) { 2137 var thisHeight = $(this).height(); 2138 if (thisHeight > minH) { 2139 minH = thisHeight; 2140 } 2141 }); 2142 $('.homepage-card .card-summary').height(minH); 2143 $.each($('.homepage-card'), function(i, item ) { 2144 var thisHeight = $(this).height(); 2145 if (thisHeight > minH) { 2146 minH = thisHeight; 2147 } 2148 }); 2149 $('.homepage-card').height(minH); 2150 } 2151 2152 } 2153 2154 2155 2156 2157 2158 2159 if ($('.variant-radio').length > 0 ) { 2160 var variantId = getUrlVars()["variant"]; 2161 console.log(variantId); 2162 if (variantId) { 2163 variantId = variantId.split('#')[0]; 2164 console.log('doing stuff'); 2165 $('.variant-radio').attr('checked', false); 2166 $('#variant-' + variantId).attr('checked', true); 2167 $('.snipcart-add-item').hide(); 2168 $('.btn-' + variantId).show(); 2169 console.log("button should be"); 2170 console.log("variant-btn-" + variantId); 2171 console.log($('#variant-btn-' + variantId)); 2172 if ($('.item-color-options').length > 0) { 2173 $.each($('.item-color-options'), function(c, color) { 2174 console.log('color options'); 2175 console.log($(this)); 2176 var colorLink = $(this).attr('href'); 2177 $(this).attr('href', colorLink + '?variant=' + variantId); 2178 }); 2179 } 2180 } else { 2181 console.log('not doing stuff'); 2182 } 2183 2184 $('.variant-radio').change(function(e) { 2185 var radioVal = $('input[name=variantRadio]:checked').attr('id'); 2186 $('.item-body-add-to-cart').hide(); 2187 console.log(radioVal); 2188 if (radioVal == "standard") { 2189 $('.btn-standard').show(); 2190 } else { 2191 radioVal = radioVal.replace('variant-', ''); 2192 console.log(radioVal); 2193 $('.btn-' + radioVal).show(); 2194 } 2195 }); 2196 } 2197 function customFormSubmitted(data) { 2198 console.log('is this thing on?'); 2199 console.log(data); 2200 $('#modal-continue-button .button').trigger('click'); 2201 showOptionsButton(); 2202 } 2203 2204 2205 $("#revenueSlide").on('input', function(e) { 2206 $('#revenue-quantity').text(String($('#revenueSlide').val())); 2207 $('#revenue-amount').text(String(($('#revenueSlide').val() * 18))) 2208 }); 2209 2210 function calculateSlide() { 2211 $('#sales-number').text(String($('#salesSlide').val())); 2212 var revenueGen = $('#salesSlide').val() * 360; 2213 $('#revenue-increase').text(String(revenueGen)); 2214 $('#service-number').text(String($('#serviceSlide').val())); 2215 var timeSaved = $('#serviceSlide').val() / 4; 2216 $('#unit-number').text(timeSaved.toFixed()); 2217 var revenueFromTime = $('#serviceSlide').val() * 45; 2218 $('#service-revenue-generated').text(String(revenueFromTime.toFixed())); 2219 var totalRev = (revenueGen + revenueFromTime).toFixed(); 2220 $('#total-revenue-generated').text(String(totalRev)); 2221 } 2222 $('#salesSlide').on('input', function(e) { 2223 calculateSlide(); 2224 }); 2225 $('#serviceSlide').on('input', function(e) { 2226 calculateSlide(); 2227 }); 2228 var productPresent = getUrlVars()["query"]; 2229 2230 2231 $('#trigger-search').click(function(e) { 2232 e.preventDefault(); 2233 $('#search-modal').addClass('is-active'); 2234 }); 2235 2236 $('#query-input').keyup(function(event) { 2237 console.log(event); 2238 console.log(event.keyCode); 2239 if (event.keyCode === 13 ) { 2240 event.preventDefault(); 2241 console.log('enter clicked!'); 2242 $('#query-form').submit(); 2243 } 2244 }); 2245 2246 var aptsChanged = false;
2247 var servChanged = false; 2248 var instChanged = false; 2249 2250 function figureRevenue() { 2251 var apts = $('#appointmentSlide').val(); 2252 $('#appointment-number').text(String(apts)); 2253 var meetingMinute = 420 / apts; 2254 var meetingsPerMonth = apts * 20; 2255 var serv = $('#serviceSlide').val(); 2256 2257 if (servChanged == false) { 2258 var s = (meetingsPerMonth * 0.075).toFixed(); 2259 $('#serviceSlide').val(s); 2260 serv = s; 2261 } 2262 var minutesServiced = (serv * 45).toFixed(); 2263 2264 $('#service-number').text(String(serv)); 2265 var inst = $('#instrumentSlide').val(); 2266 if (instChanged == false) { 2267 var mpm = meetingsPerMonth * 20; 2268 console.log(mpm); 2269 var instSold = ((mpm / 45) * 0.075) * 2; 2270 console.log(instSold); 2271 var i = instSold.toFixed(); 2272 $('#instrumentSlide').val(i); 2273 inst = i; 2274 } 2275 $('#instrument-number').text(String(inst)); 2276 2277 var hoursSaved = ((minutesServiced / 2) / 60).toFixed(); 2278 console.log('hours saved: ' + String(hoursSaved)); 2279 $('#unit-number').text(String(hoursSaved)); 2280 if (hoursSaved == 1) { 2281 $('#unit-units').text('hour'); 2282 } else { 2283 $('#unit-units').text('hours'); 2284 } 2285 2286 var hearingAidMinutes = ((meetingsPerMonth * 45) / inst); 2287 console.log(hearingAidMinutes); 2288 2289 2290 2291 2292 } 2293 2294 $('.revenue-slider').on('input', function(e) { 2295 if ($(this).is('#appointmentSlide')) { 2296 if (aptsChanged == false) { 2297 aptsChanged = true; 2298 } 2299 } else if ($(this).is("#serviceSlide")) { 2300 if (servChanged == false) { 2301 servChanged = true; 2302 } 2303 } else if ($(this).is("#instrumentSlide")) { 2304 if (instChanged == false) { 2305 instChanged = true; 2306 } 2307 } 2308 figureRevenue(); 2309 }); 2310 2311 if ($('#appointmentSlide').length > 0) { 2312 figureRevenue(); 2313 } 2314 2315 function filterFitList() { 2316 var searchTerm = $('#brand-search').val(); 2317 $.each($('.accordion'), function(i, item) { 2318 console.log('looping'); 2319 console.log($(this)); 2320 if ($(this).data('brandName').toLowerCase().includes(searchTerm.toLowerCase())) { 2321 console.log('includes search term!'); 2322 $(this).removeClass('is-hidden').addClass('is-shown'); 2323 } else { 2324 console.log('does not include search term!') 2325 $(this).addClass('is-hidden').removeClass('is-shown'); 2326 } 2327 $('.accordion').removeClass('is-active'); 2328 $('.accordion.is-shown:first').addClass('is-active'); 2329 }); 2330 } 2331 2332 $('#brand-select').change(function(e) { 2333 console.log($(this).val()); 2334 $('#brand-search').val($(this).val()); 2335 filterFitList(); 2336 }); 2337 2338 $('#brand-search').on('keyup', function(e) { 2339 console.log($(this).val()); 2340 filterFitList(); 2341 }); 2342 2343 $('#country_select').change(function(e) { 2344 // $('#dealerProvince').val(''); 2345 // $('#dealerState').val(''); 2346 console.log($(this).val()); 2347 if ($("#country_select").val() == "United States") { 2348 $('#state_select').removeClass('is-hidden'); 2349 $('#province_select').addClass('is-hidden'); 2350 $('#dealerProvince').val(""); 2351 } else if ($('#country_select').val() == "Canada") { 2352 $('#province_select').removeClass('is-hidden'); 2353 $('#state_select').addClass('is-hidden'); 2354 $('#dealerState').val(''); 2355 } else { 2356 $('#province_select').addClass('is-hidden').val(''); 2357 $('#state_select').addClass('is-hidden').val(''); 2358 } 2359 }); 2360 2361 2362 function filterDealers(dealerName, dealerCountry, dealerState, dealerProvince) { 2363 console.log(dealerName, dealerCountry, dealerState, dealerProvince); 2364 var setNewUrls = false; 2365 2366 $('.dealer-search').removeClass('is-hidden'); 2367 if (dealerName) { 2368 dealerName = dealerName.replace('+', ' '); 2369 console.log(dealerName); 2370 $.each($('.dealer-search'), function(i, item) { 2371 console.log($(this).data('dealer-name').toLowerCase()); 2372 if ($(this).data('dealer-name').toLowerCase().includes(dealerName.toLowerCase()) || $(this).data('dealer-country').toLowerCase().includes(dealerName.toLowerCase()) || $(this).data('dealer-state').toLowerCase().includes(dealerName.toLowerCase()) || $(this).data('dealer-city').toLowerCase().includes(dealerName.toLowerCase())) { 2373 2374 } else { 2375 $(this).addClass('is-hidden'); 2376 } 2377 2378 $(this).find('.dealerLink').attr("href", $(this).find('.dealerLink').data('bare-url') + "?newUrl=1&search=" + dealerName + "&country=" + dealerCountry + "&state=" + dealerState
2378+ "&province=" + dealerProvince); 2379 setNewUrls = true; 2380 }); 2381 } 2382 if (dealerCountry) { 2383 dealerCountry = dealerCountry.replace('+', ' '); 2384 console.log(dealerCountry); 2385 $.each($('.dealer-search'), function(i, item) { 2386 console.log($(this).data('dealer-country').toLowerCase()); 2387 if ($(this).data('dealer-country').toLowerCase() == dealerCountry.toLowerCase()) { 2388 } else { 2389 $(this).addClass('is-hidden'); 2390 } 2391 if (!setNewUrls) { 2392 $(this).find('.dealerLink').attr("href", $(this).find('.dealerLink').data('bare-url') + "?newUrl=1&search=" + dealerName + "&country=" + dealerCountry + "&state=" + dealerState + "&province=" + dealerProvince); 2393 setNewUrls = true; 2394 } 2395 }); 2396 } 2397 if (dealerState) { 2398 dealerState = dealerState.replace('+', ' '); 2399 console.log(dealerState); 2400 $.each($('.dealer-search'), function(i, item) { 2401 console.log($(this).data('dealer-state').toLowerCase()); 2402 if ($(this).data('dealer-state').toLowerCase() == dealerState.toLowerCase()) { 2403 } else { 2404 $(this).addClass('is-hidden'); 2405 } 2406 if (!setNewUrls) { 2407 $(this).find('.dealerLink').attr("href", $(this).find('.dealerLink').data('bare-url') + "?newUrl=1&search=" + dealerName + "&country=" + dealerCountry + "&state=" + dealerState + "&province=" + dealerProvince); 2408 setNewUrls = true; 2409 } 2410 }); 2411 } 2412 if (dealerProvince) { 2413 dealerProvince = dealerProvince.replace('+', ' '); 2414 console.log(dealerProvince); 2415 $.each($('.dealer-search'), function(i, item) { 2416 2417 console.log($(this).data('dealer-state').toLowerCase()); 2418 if ($(this).data('dealer-state').toLowerCase() == dealerProvince.toLowerCase()) { 2419 } else { 2420 $(this).addClass('is-hidden'); 2421 } 2422 if (!setNewUrls) { 2423 $(this).find('.dealerLink').attr("href", $(this).find('.dealerLink').data('bare-url') + "?newUrl=1&search=" + dealerName + "&country=" + dealerCountry + "&state=" + dealerState + "&province=" + dealerProvince); 2424 setNewUrls = true; 2425 } 2426 }); 2427 } 2428 if (!setNewUrls) { 2429 $.each($('.dealer-search'), function(i, item) { 2430 $(this).find('.dealerLink').attr("href", $(this).find('.dealerLink').data('bare-url')); 2431 }); 2432 } 2433 } 2434 2435 if (!!$('#dealerLocation').length) { 2436 console.log('internal dealer page'); 2437 if (!! getUrlVars()["newUrl"]) { 2438 var dealerName = getUrlVars()["search"]; 2439 var dealerCountry = getUrlVars()["country"]; 2440 var dealerState = getUrlVars()["state"]; 2441 var dealerProvince = getUrlVars()["province"]; 2442 $.each($('.dealer-search'), function(i, item) { 2443 $(this).find('.dealerLink').attr("href", $(this).find('.dealerLink').data('bare-url') + "?newUrl=1&search=" + dealerName + "&country=" + dealerCountry + "&state=" + dealerState + "&province=" + dealerProvince); 2444 }); 2445 $('#backToDealers').attr("href", "/dealers?search=" + dealerName.replace(" ", "+").replace("%20", "+") + "&country=" + dealerCountry.replace(" ", "+").replace("%20", "+") + "&state=" + dealerState.replace(" ", "+").replace("%20", "+") + "&province=" + dealerProvince.replace(" ", "+").replace("%20", "+")); 2446 } 2447 } 2448 2449 if ($('#country_select').length > 0) { 2450 console.log('find a dealer page'); 2451 var dealerName = getUrlVars()["search"]; 2452 var dealerCountry = getUrlVars()["country"]; 2453 var dealerState = getUrlVars()["state"]; 2454 var dealerProvince = getUrlVars()["province"]; 2455 filterDealers(dealerName, dealerCountry, dealerState, dealerProvince); 2456 if (!!dealerCountry) { 2457 $('#country_select').val(dealerCountry.replace('+', ' ')); 2458 } 2459 if (!!dealerState) { 2460 $("#dealerState").val(dealerState.replace('+', ' ')); 2461 } 2462 if (!!dealerProvince) { 2463 $('#dealerProvince').val(dealerProvince.replace("+", "")); 2464 } 2465 if (!!dealerName) { 2466 $('#dealerNameSearch').val(dealerName.replace("+", "")); 2467 } 2468 $('#country_select').change(); 2469 2470 } 2471 2472 $('.find-dealer-input').on('input keyup change', function(e) { 2473 var dealerName = $('#dealerNameSearch').val(); 2474 var dealerCountry = $('#country_select').val(); 2475 var dealerState = $('#dealerState').val(); 2476 var dealerProvince = $('#dealerProvince').val(); 2477 filterDealers(dealerName, dealerCountry, dealerState, dealerProvince); 2478 }); 2479 2480 $('.reveal-product-matrix').click(function(e) { 2481 e.preventDefault(); 2482 $('#product-matrix').addClass('is-active'); 2483 }); 2484 2485 $('.model-color-changers').click(function(e) { 2486 console.log('modelcolorchanger clicked'); 2487 e.preventDefault(); 2488 var itemId = $(this).data('item-id'); 2489 var productName = $(this).data('item-name'); 2490 var productImage = $(this).data('item-image'); 2491 var productUrl = $(this).data('item-url');
2492 var productColor = $(this).data('item-color'); 2493 var modelId = $(this).data('mod-id'); 2494 $('#model-image-' + modelId).attr('src', productImage); 2495 $('.modelItemLink-' + modelId).attr('href', productUrl); 2496 2497 }); 2498 2499 $('.product-color-changers').click(function(e) { 2500 e.preventDefault(); 2501 var itemId = $(this).data('item-id'); 2502 var productName = $(this).data('item-name'); 2503 var productImage = $(this).data('item-image'); 2504 var productUrl = $(this).data('item-url'); 2505 var productColor = $(this).data('item-color'); 2506 var modelId = $(this).data('mod-id'); 2507 $('#product-image-' + modelId).attr('src', productImage); 2508 $('#itemAddToCart-' + modelId).data('item-id', itemId).data('item-name', productName).data('item-image', productImage).data('item-url', productUrl); 2509 }); 2510 $('.product-add-to-cart-snipcart').click(function(e) { 2511 var itemId = $(this).data('item-id'); 2512 var itemName = $(this).data('item-name'); 2513 var itemDescription = $(this).data('item-description'); 2514 var itemImage = $(this).data('item-image'); 2515 var itemPrice = $(this).data('item-price'); 2516 var itemUrl = $(this).data('item-url'); 2517 2518 Snipcart.api.cart.items.add({ 2519 "id": itemId, 2520 "name": itemName, 2521 // "description": itemDescription, 2522 "url": itemUrl, 2523 "image": itemImage, 2524 "price": itemPrice, 2525 "dimensions": { 2526 "weight": 1, 2527 "width": 1, 2528 "height": 1, 2529 "length": 1 2530 }, 2531 "quantity": 1 2532 }) 2533 .then (function (cartItem) { 2534 console.log(cartItem); 2535 Snipcart.api.modal.show(); 2536 updateCartIcon(); 2537 }); 2538 }); 2539 2540 2541 2542 2543 console.log('snipcart_order_token', Cookies.get('snipcart_order_token')); 2544 if (Cookies.get('snipcart_order_token')) { 2545 var snipOrder = Cookies.get('snipcart_order_token'); 2546 Cookies.set('snipcart_order_token', snipOrder, { domain: 'gearforears.com' }); 2547 } 2548 2549 2550 2551 var sizingHelp = getUrlVars()["sizinghelp"]; 2552 if (sizingHelp == "show") { 2553 $('#find_your_ear_gear_quickview').addClass('is-active'); 2554 startSizingQv(helpTypeHtml, 1); 2555 } 2556 2557 2558 2559 var applyDiscount = getUrlVars()["applydiscount"]; 2560 if (applyDiscount) { 2561 Cookies.set('referral_code', applyDiscount.split('#')[0]); 2562 console.log('discount present. setting cookie', Cookies.get()); 2563 } 2564 2565 var upviralPresent = getUrlVars()["ref_id"]; 2566 if (upviralPresent) { 2567 console.log('referral tracking code is present!'); 2568 Cookies.set('ref_id', upviralPresent.split("#")[0]); 2569 } 2570 2571 if ($("#dealerListings").length > 0) { 2572 console.log('on the dealer listing page!'); 2573 var page = 1; 2574 } 2575 $('#numberExplanation').click(function(e) { 2576 e.preventDefault(); 2577 $('#numberExplanationText').toggleClass('is-hidden'); 2578 }); 2579 2580 2581 $('.shopSidebarOptionToggle').click(function(e) { 2582 e.preventDefault(); 2583 $('.shopSidebarOptions').toggleClass('is-hidden'); 2584 }); 2585 2586 2587 2588 2589 2590 2591 2592 if ($('#customProduct').length > 0) { 2593 console.log('custom is loaded!'); 2594 var productPresent = getUrlVars()["product"]; 2595 var modelPresent = getUrlVars()["model"]; 2596 if (productPresent) { 2597 var productParam = productPresent.split('#')[0]; 2598 var $productOption = $('#customProduct option[value="' + productParam + '"]'); 2599 if ($productOption.length === 0) { 2600 var legacyKey = productParam.replace(/ /g, ''); 2601 $productOption = $('#customProduct option').filter(function() { 2602 return $(this).data('legacy-key') === legacyKey; 2603 }); 2604 } 2605 if ($productOption.length > 0) { 2606 $('#customProduct').val($productOption.val()).trigger('change'); 2607 } 2608 } 2609 2610 2611 function evaluateCustomPrice() { 2612 2613 2614 2615 console.log("evaluating custom price!"); 2616 if ((customContainer.modalStage == 1 && customContainer.sleeve1Color == "") || (customContainer.modalStage == 2 && customContainer.sameColoredSleeves == "") || (customContainer.modalStage == 3 && customContainer.sleeve2Color == "") || (customContainer.modalStage == 4 && customContainer.cordColor == "") || (customContainer.modalStage == 5 && customContainer.oRingColor == "") || (customContainer.modalStage == 6 && customContainer.clipColor == "")) { 2617 console.log('disabling button'); 2618 customContainer.disabledButton = true; 2619 } else { 2620 console.log('enabling button'); 2621 if (customContainer.modalStage == "2") { 2622 console.log('modal stage 2'); 2623 } else { 2624 console.log('modal stage not 2', customContainer.modalStage); 2625 } 2626 if (customContainer.sameColoredSleeves == "") { 2627 console.log('same colored sleeve unknown'); 2628 } 2629 if (customContainer.modalStage == 2 && customContainer.sameColoredSleeves == "") { 2630 console.log('both are true') 2631 } 2632 console.log(customContainer.modalStage); 2633 customContainer.disabledButton = false;
2634 } 2635 var corded = false; 2636 customContainer.corded = ""; 2637 $.each(customContainer.modelCategories, function(i, item) { 2638 if (customContainer.corded != "mono") { 2639 if (item.name == "Corded") { 2640 console.log('corded, so keeping everything'); 2641 corded = true; 2642 customContainer.corded = "corded"; 2643 } else if (item.name == "Mono") { 2644 console.log('mono, so weird.'); 2645 corded = true; 2646 customContainer.corded = "mono"; 2647 } else { 2648 console.log('cordless so not keeping anything'); 2649 corded = false; 2650 } 2651 } 2652 2653 }); 2654 customContainer.additionalPrice = 0.00; 2655 if (customContainer.modalStage == 7) { 2656 if (customContainer.corded == "") { 2657 console.log("cordless in cart"); 2658 2659 if (customContainer.implantPricing) { 2660 if ((customContainer.sleeve1Color == "Standard Sleeve Beige" || customContainer.sleeve1Color == "Standard Sleeve Black" || customContainer.sleeve1Color == "Standard Sleeve Grey" || customContainer.sleeve1Color == "Standard Sleeve Chocolate Brown") && customContainer.sleeve1Color == customContainer.sleeve2Color ) { 2661 customContainer.isSameAsStandard = true; 2662 } else { 2663 customContainer.isSameAsStandard = false; 2664 if ((customContainer.sleeve1Color == "Standard Sleeve Beige" || customContainer.sleeve1Color == "Standard Sleeve Black" || customContainer.sleeve1Color == "Standard Sleeve Grey" || customContainer.sleeve1Color == "Standard Sleeve Chocolate Brown") && (customContainer.sleeve2Color == "Standard Sleeve Beige" || customContainer.sleeve2Color == "Standard Sleeve Black" || customContainer.sleeve2Color == "Standard Sleeve Grey" || customContainer.sleeve2Color == "Standard Sleeve Chocolate Brown")) { 2665 customContainer.additionalPrice = 10.00; 2666 } else if ((customContainer.sleeve1Color == "Standard Sleeve Beige" || customContainer.sleeve1Color == "Standard Sleeve Black" || customContainer.sleeve1Color == "Standard Sleeve Grey" || customContainer.sleeve1Color == "Standard Sleeve Chocolate Brown") || (customContainer.sleeve2Color == "Standard Sleeve Beige" || customContainer.sleeve2Color == "Standard Sleeve Black" || customContainer.sleeve2Color == "Standard Sleeve Grey" || customContainer.sleeve2Color == "Standard Sleeve Chocolate Brown")) { 2667 customContainer.additionalPrice = 15.00; 2668 } else { 2669 customContainer.additionalPrice = 20.00; 2670 } 2671 } 2672 } else { 2673 2674 if ((customContainer.sleeve1Color == customContainer.sleeve2Color) && (customContainer.sleeve1Type == "standard" && customContainer.sleeve2Type == "standard")) { 2675 customContainer.isSameAsStandard = true; 2676 } else { 2677 customContainer.isSameAsStandard = false; 2678 if (customContainer.sleeve1Type == "premium" && customContainer.sleeve2Type == "premium") { 2679 customContainer.additionalPrice = 20.00; 2680 } else if (customContainer.sleeve1Type == "premium" || customContainer.sleeve2Type == "premium") { 2681 customContainer.additionalPrice = 15.00; 2682 } else { 2683 customContainer.additionalPrice = 10.00; 2684 } 2685 } 2686 } 2687 } else if (customContainer.corded == "corded") { 2688 if (customContainer.implantPricing) { 2689 if ((customContainer.sleeve1Color == "Standard Sleeve Beige" || customContainer.sleeve1Color == "Standard Sleeve Black" || customContainer.sleeve1Color == "Standard Sleeve Grey" || customContainer.sleeve1Color == "Standard Sleeve Chocolate Brown") && ( customContainer.sleeve1Color == customContainer.sleeve2Color && customContainer.sleeve1Color.replace("Standard Sleeve ", "") == customContainer.cordColor.replace("Cord ", "") && customContainer.sleeve1Color.replace("Standard Sleeve ", "") == customContainer.oRingColor.replace("O-Ring ", "") && customContainer.sleeve1Color.replace("Standard Sleeve ", "") == customContainer.clipColor.replace("Clip ", "") ) ) { 2690 customContainer.isSameAsStandard = true; 2691 } else { 2692 customContainer.isSameAsStandard = false;
2693 if ((customContainer.sleeve1Color == "Standard Sleeve Beige" || customContainer.sleeve1Color == "Standard Sleeve Black" || customContainer.sleeve1Color == "Standard Sleeve Grey" || customContainer.sleeve1Color == "Standard Sleeve Chocolate Brown") && (customContainer.sleeve2Color == "Standard Sleeve Beige" || customContainer.sleeve2Color == "Standard Sleeve Black" || customContainer.sleeve2Color == "Standard Sleeve Grey" || customContainer.sleeve2Color == "Standard Sleeve Chocolate Brown")) { 2694 customContainer.additionalPrice = 15.00; 2695 } else { 2696 customContainer.additionalPrice = 25.00; 2697 } 2698 } 2699 } else { 2700 if (customContainer.sleeve1Type == "standard" && customContainer.sleeve2Type == "standard") { 2701 if ((customContainer.sleeve1Color.replace("Orange-Red", "Red") == customContainer.sleeve2Color.replace("Orange-Red", "Red")) && (customContainer.sleeve1Color.replace("Standard Sleeve ", "").replace("Orange-Red", "Red") == customContainer.cordColor.replace("Cord ", "").replace("Orange-Red", "Red")) && (customContainer.sleeve1Color.replace("Standard Sleeve ", "").replace('Orange-Red', "Red") == customContainer.oRingColor.replace("O-Ring ", "").replace('Orange-Red', "Red")) && (customContainer.sleeve1Color.replace("Standard Sleeve ", "").replace('Orange-Red', "Red") == customContainer.clipColor.replace("Clip ", "").replace('Orange-Red', "Red"))) { 2702 customContainer.isSameAsStandard = true; 2703 } else { 2704 2705 customContainer.isSameAsStandard = false; 2706 } 2707 customContainer.additionalPrice = 15.00; 2708 } else if (customContainer.sleeve1Type == "standard" || customContainer.sleeve2Type == "standard") { 2709 customContainer.additionalPrice = 20.00; 2710 } else { 2711 customContainer.additionalPrice = 25.00; 2712 } 2713 } 2714 2715 } else if (customContainer.corded == "mono") { 2716 if (customContainer.implantPricing) { 2717 if ((customContainer.sleeve1Color == "Standard Sleeve Beige" || customContainer.sleeve1Color == "Standard Sleeve Black" || customContainer.sleeve1Color == "Standard Sleeve Grey" || customContainer.sleeve1Color == "Standard Sleeve Chocolate Brown") && customContainer.sleeve1Color == customContainer.sleeve2Color ) { 2718 customContainer.isSameAsStandard = true; 2719 } else { 2720 customContainer.isSameAsStandard = false; 2721 if ((customContainer.sleeve1Color == "Standard Sleeve Beige" || customContainer.sleeve1Color == "Standard Sleeve Black" || customContainer.sleeve1Color == "Standard Sleeve Grey" || customContainer.sleeve1Color == "Standard Sleeve Chocolate Brown") && (customContainer.sleeve2Color == "Standard Sleeve Beige" || customContainer.sleeve2Color == "Standard Sleeve Black" || customContainer.sleeve2Color == "Standard Sleeve Grey" || customContainer.sleeve2Color == "Standard Sleeve Chocolate Brown")) { 2722 customContainer.additionalPrice = 15.00; 2723 } else { 2724 customContainer.additionalPrice = 20.00; 2725 } 2726 } 2727 } else { 2728 customContainer.isSameAsStandard = false; 2729 if (customContainer.sleeve1Type == "standard") { 2730 if ((customContainer.sleeve1Color.replace("Standard Sleeve ", "").replace("Orange-Red", "Red") == customContainer.cordColor.replace("Cord ", "").replace("Orange-Red", "Red")) && (customContainer.sleeve1Color.replace("Standard Sleeve ", "").replace('Orange-Red', "Red") == customContainer.clipColor.replace("Clip ", "").replace('Orange-Red', "Red"))) { 2731 customContainer.isSameAsStandard = true; 2732 } else { 2733 if (customContainer.sleeve1Color.replace("Standard Sleeve ", "").replace("Orange-Red", "Red") == customContainer.cordColor.replace("Cord ", "").replace("Orange-Red", "Red")) { 2734 console.log('cord is right'); 2735 } 2736 if (customContainer.sleeve1Color.replace("Standard Sleeve ", "").replace('Orange-Red', "Red") == customContainer.clipColor.replace("Clip ", "").replace('Orange-Red', "Red")) { 2737 console.log('clip is right'); 2738 } 2739 customContainer.isSameAsStandard = false;
2740 } 2741 customContainer.additionalPrice = 15.00; 2742 } else { 2743 customContainer.additionalPrice = 20.00; 2744 } 2745 } 2746 } 2747 customContainer.currentPrice = customContainer.basePrice + customContainer.additionalPrice; 2748 } 2749 } 2750 2751 var customContainer = new Vue({ 2752 el: '#customContainer', 2753 data: { 2754 buttonShown: false, 2755 modId: '', 2756 cats: '', 2757 productId: "", 2758 implantPricing: false, 2759 basePrice: 0.00, 2760 currentPrice: 0.00, 2761 additionalPrice: 0.00, 2762 sleeve1StandardPriceAddition: "$0.00", 2763 sleeve2StandardPriceAddition: "$0.00", 2764 sleeve1PremiumPriceAddition: "$0.00", 2765 sleeve2PremiumPriceAddition: "$0.00", 2766 customVarShow: false, 2767 mainImage: 'https://www.datocms-assets.com/12235/1585187319-ear-gear-transparent.png', 2768 modelOptions :[], 2769 customVariantOptions: [], 2770 customVariantChosen: "", 2771 showCustomizeButton: false, 2772 modelShow: false, 2773 modelSelected: "", 2774 additionalOptions :[], 2775 standardSleeveOptions: standardSleeveOptions, 2776 premiumSleeveOptions: premiumSleeveOptions, 2777 cordOptions: cordOptions, 2778 oRingOptions: oRingOptions, 2779 clipOptions: clipOptions, 2780 corded: "", 2781 sleeve1Color :"", 2782 sleeve1Image: "", 2783 sleeve1Type :"", 2784 sameColoredSleeves: "", 2785 sleeve2Color :"", 2786 sleeve2Type :"", 2787 sleeve2Image: "", 2788 cordColor :"", 2789 cordImage: "", 2790 oRingColor :"", 2791 oringImage: "", 2792 clipColor: "", 2793 clipImage: "", 2794 modalStage: 1, 2795 disabledButton: true, 2796 itemName: "", 2797 modelCategories: [], 2798 isSameAsStandard: false 2799 }, 2800 methods: { 2801 changeCustomProduct: function(event) { 2802 2803 this.customVarShow = false; 2804 resetProduct(); 2805 console.log('resetting product'); 2806 customContainer.buttonShown = false; 2807 customContainer.modId = ''; 2808 $("#customModel").val(""); 2809 customContainer.cats = ''; 2810 customContainer.productId = ""; 2811 customContainer.implantPricing = false; 2812 customContainer.basePrice = 0.00; 2813 customContainer.currentPrice = 0.00; 2814 customContainer.additionalPrice = 0.00; 2815 customContainer.sleeve1StandardPriceAddition = "$0.00"; 2816 customContainer.sleeve2StandardPriceAddition = "$0.00"; 2817 customContainer.sleeve1PremiumPriceAddition = "$0.00"; 2818 customContainer.sleeve2PremiumPriceAddition = "$0.00"; 2819 customContainer.customVarShow = false; 2820 customContainer.mainImage = 'https://www.datocms-assets.com/12235/1585187319-ear-gear-transparent.png?w=600&auto=compress&h=500&fit=crop&crop=entropy'; 2821 customContainer.modelOptions = []; 2822 customContainer.customVariantOptions = []; 2823 customContainer.customVariantChosen = ""; 2824 customContainer.showCustomizeButton = false; 2825 customContainer.modelShow = false; 2826 customContainer.modelSelected = ""; 2827 customContainer.additionalOptions =[]; 2828 customContainer.standardSleeveOptions = standardSleeveOptions; 2829 customContainer.premiumSleeveOptions = premiumSleeveOptions; 2830 customContainer.cordOptions = cordOptions; 2831 customContainer.oRingOptions = oRingOptions; 2832 customContainer.clipOptions = clipOptions; 2833 customContainer.corded = ""; 2834 customContainer.sleeve1Color =""; 2835 customContainer.sleeve1Image = ""; 2836 customContainer.sleeve1Type = ""; 2837 customContainer.sameColoredSleeves = ""; 2838 customContainer.sleeve2Color = ""; 2839 customContainer.sleeve2Type = ""; 2840 customContainer.sleeve2Image = ""; 2841 customContainer.cordColor = ""; 2842 customContainer.cordImage = ""; 2843 customContainer.oRingColor = ""; 2844 customContainer.oringImage = ""; 2845 customContainer.clipColor = ""; 2846 customContainer.clipImage = ""; 2847 customContainer.modalStage = 1; 2848 customContainer.disabledButton = true; 2849 customContainer.itemName = ""; 2850 customContainer.modelCategories = []; 2851 var $selectedProduct = $('#customProduct').find(':selected'); 2852 customContainer.productId = $('#customProduct').val(); 2853 customContainer.implantPricing = $selectedProduct.data('implant-pricing') === true || $selectedProduct.data('implant-pricing') === 'true'; 2854 2855 console.log("Custom Product is: " + customContainer.productId); 2856 if ($('#customProduct').val() != "") { 2857 customContainer.modelShow = true; 2858 customContainer.mainImage = $selectedProduct.data('image'); 2859 customContainer.modelOptions = []; 2860 customContainer.modelOptions.push({"value": "", "name": "Please Select", "image": "", "modelId": "", "categories": "", "price": 0 }); 2861 2862 $.each(allModels, function(i, item) { 2863 if (item.product == customContainer.productId) { 2864 var cats = JSON.stringify(item.category); 2865 customContainer.modelOptions.push({"value": item["title"], "name": item["title"], "image": item["items"][0]["image"], "id": item["items"][0]["sku"].replace("Custom-", ""), "categories": cats, "value": item["title"], "price": item["price"] }); 2866 } 2867 }); 2868 } else { 2869 customContainer.modelShow = false;
2870 $('#customModel').val(''); 2871 // $('#customModelContainer').fadeOut('slow'); 2872 } 2873 }, 2874 buildModel: function(event) { 2875 console.log('building model', event); 2876 console.log('building model', $(event)); 2877 }, 2878 changeModels: function(event) { 2879 // console.log("Model Changed", event.target.selectedOptions); 2880 // console.log($(this)); 2881 // console.log(this); 2882 console.log('changing models'); 2883 changeCustomModel(); 2884 }, 2885 changeVariant: function(event) { 2886 changeCustomVariant(); 2887 }, 2888 launchCustomizationModal: function(event) { 2889 console.log('launching modal'); 2890 $('#customModal').addClass('is-active'); 2891 evaluateCustomPrice(); 2892 }, 2893 addingCustomToCart: function(event) { 2894 $('#customAddToCart').html('<i class="fas fa-spinner fa-spin"></i> Adding to Cart'); 2895 Snipcart.events.on('item.added', function(ev, item) { 2896 $('#customAddToCart').text('Add to Cart'); 2897 $('.modal').removeClass('is-active'); 2898 2899 setTimeout(function(){ 2900 Snipcart.api.theme.cart.open(); 2901 }, 100); 2902 }); 2903 }, 2904 setCustomOption: function(name, standard, option, image) { 2905 console.log(name, standard, option, image); 2906 console.log(option); 2907 if (option == 'sleeve1') { 2908 customContainer.sleeve1Color = name; 2909 customContainer.sleeve1Type = standard; 2910 customContainer.sleeve1Image = image; 2911 evaluateCustomPrice(); 2912 } else if (option == 'sleeve2') { 2913 customContainer.sleeve2Color = name; 2914 customContainer.sleeve2Type = standard; 2915 customContainer.sleeve2Image = image; 2916 evaluateCustomPrice(); 2917 } else if (option == 'cord') { 2918 console.log('updating cord'); 2919 customContainer.cordColor = name; 2920 customContainer.cordImage = image; 2921 console.log('customContainer.cordColor = ', customContainer.cordColor); 2922 evaluateCustomPrice(); 2923 } else if (option == 'oring') { 2924 customContainer.oRingColor = name; 2925 customContainer.oringImage = image; 2926 evaluateCustomPrice(); 2927 } else if (option == 'clip') { 2928 customContainer.clipColor = name; 2929 customContainer.clipImage = image; 2930 evaluateCustomPrice(); 2931 } else if (option == 'same') { 2932 console.log('same') 2933 if (name == "same") { 2934 console.log('same'); 2935 customContainer.sleeve2Type = customContainer.sleeve1Type; 2936 customContainer.sleeve2Color = customContainer.sleeve1Color; 2937 customContainer.sleeve2Image = customContainer.sleeve1Image; 2938 customContainer.sameColoredSleeves = "true"; 2939 evaluateCustomPrice(); 2940 } else { 2941 console.log('different') 2942 customContainer.sleeve2Type = ""; 2943 customContainer.sleeve2Color = ""; 2944 customContainer.sleeve2Image = ""; 2945 customContainer.sameColoredSleeves = "false"; 2946 evaluateCustomPrice(); 2947 } 2948 } 2949 }, 2950 prevModalStage: function(event) { 2951 if (customContainer.corded == "corded") { 2952 customContainer.modalStage -= 1; 2953 } else if (customContainer.corded == "mono") { 2954 if (customContainer.modalStage == 4) { 2955 customContainer.modalStage = 1; 2956 } else if (customContainer.modalStage == 6) { 2957 customContainer.modalStage = 4; 2958 } else { 2959 customContainer.modalStage -= 1; 2960 } 2961 2962 } else { 2963 if (customContainer.modalStage == 7 && customContainer.sameColoredSleeves == 'true') { 2964 customContainer.modalStage = 1; 2965 } else if (customContainer.modalStage == 7) { 2966 customContainer.modalStage = 3; 2967 } else { 2968 customContainer.modalStage -= 1; 2969 } 2970 } 2971 }, 2972 nextModalStage: function(event) { 2973 if (customContainer.corded == "mono") { 2974 if (customContainer.modalStage == 1) { 2975 customContainer.modalStage = 4; 2976 } else if (customContainer.modalStage == 4) { 2977 customContainer.modalStage = 6; 2978 } else { 2979 customContainer.modalStage += 1; 2980 } 2981 } else if (customContainer.modalStage == 2 && customContainer.sameColoredSleeves == 'true' ) { 2982 console.log('modalStage 2 sameColoredSleeves true'); 2983 if (customContainer.corded == "corded") { 2984 console.log('corded'); 2985 customContainer.modalStage = 4; 2986 } else { 2987 console.log('cordless'); 2988 customContainer.modalStage = 7; 2989 } 2990 } 2991 else if (customContainer.modalStage < 3) { 2992 console.log('custom less than 3'); 2993 customContainer.modalStage += 1; 2994 } else { 2995 console.log('custom more than 3'); 2996 2997 if (customContainer.corded == "corded") { 2998 console.log('corded'); 2999 customContainer.modalStage += 1; 3000 } else { 3001 console.log('cordless'); 3002 customContainer.modalStage = 7; 3003 } 3004 } 3005 evaluateCustomPrice(); 3006 }, 3007 closeModal: function(event) { 3008 $('.modal').removeClass('is-active'); 3009 } 3010 3011 3012 } 3013 }) 3014 3015 3016 function resetProduct() { 3017 3018 } 3019 3020 3021 3022 // function showOptionsButton() { 3023 // $('.addCustomToCart').hide(); 3024 // if (buttonShown == false) { 3025 // buttonShown = true; 3026 // if (customVarChosen == false) { 3027 // $('#customAddToCart-' + modId).fadeIn(); 3028 // } else { 3029 // $('#customVarAddToCart-' + modId).fadeIn(); 3030 // } 3031 // 3032 // } else { 3033 // if (customVarChosen == false) { 3034 // $('#customAddToCart-' + modId).fadeIn(); 3035 // } else { 3036 // $('#customVarAddToCart-' + modId).fadeIn(); 3037 // } 3038 // } 3039 // $('#customShowOptions').fadeIn();
3040 // if (cats.includes('Corded')) { 3041 // console.log('corded selected'); 3042 // showCorded(); 3043 // } else { 3044 // console.log('cordless selected'); 3045 // showCordless(); 3046 // } 3047 // $('#customOptionContainer').fadeIn('slow'); 3048 // } 3049 3050 3051 function changeCustomModel() { 3052 3053 // $('#customVariantContainer').fadeOut(); 3054 // $('#customModalDisclaimer').fadeIn(); 3055 console.log('changing model'); 3056 //setting all the stuff back to blank 3057 customContainer.customVarShow = false; 3058 customContainer.clipColor = ""; customContainer.standard1Sleeve = ""; customContainer.premium1Sleeve = ""; customContainer.standard2Sleeve = ""; customContainer.premium2Sleeve = ""; customContainer.cordColor = ""; customContainer.oRingColor = ""; customContainer.customVariantChosen = ""; 3059 customContainer.modelCategories = []; 3060 var selectedModel = $('#customModel').find(':selected'); 3061 console.log('selectedModel', selectedModel); 3062 console.log('categories:'); 3063 var cats = $('#customModel').find(':selected').data('categories'); 3064 console.log(cats); 3065 customContainer.modId = selectedModel.data('id'); 3066 customContainer.itemName = selectedModel.val(); 3067 console.log(customContainer.modId, customContainer.itemName); 3068 if (selectedModel.val() != "") { 3069 customContainer.mainImage = selectedModel.data('image'); 3070 } 3071 customContainer.modalStage = 1; 3072 console.log('data price', selectedModel.data('price'), parseFloat(selectedModel.data('price'))); 3073 customContainer.basePrice = parseFloat(selectedModel.data('price')); 3074 customContainer.modelCategories = cats; 3075 customContainer.customVarShow = false; 3076 var customVO = []; 3077 3078 console.log('cats', cats); 3079 console.log('modelCategories', customContainer.modelCategories); 3080 console.log($('#customModel').find(':selected').data('categories')); 3081// if ($('#customModel').find(':selected')) { 3082// console.log('customModel', $('#customModel').find(':selected').data('categories')); 3083// $('#customModel').find(':selected').data('categories').forEach(function(cat) { 3084// console.log('cat', cat, cat.variant.length); 3085// if (cat.variant.length > 0) { 3086// console.log('at least one variant'); 3087// customContainer.customVarShow = true; 3088// console.log('customVarShow = true'); 3089// cat.variant.forEach(function(variant) { 3090// customVO.push(variant); 3091// console.log('variant', variant); 3092// }); 3093// } 3094// }); 3095// } 3096// 3097// customVO.push({"name": "Standard", "id": "standard", "slug": ""}); 3098// if (customContainer.customVarShow == false && customContainer.itemName != "") { 3099// customContainer.showCustomizeButton = true; 3100// } 3101// customContainer.customVariantOptions = customVO; 3102 customContainer.showCustomizeButton = true; 3103 } 3104 3105 function changeCustomVariant() { 3106 console.log("changing custom Variant"); 3107 var variantValue = $('#customVariant').val(); 3108 console.log(variantValue); 3109 3110 if ($('#customVariant').val() == "" ) { 3111 customContainer.showCustomizeButton = false; 3112 } else { 3113 customContainer.customVariantChosen = $('#customVariant').val(); 3114 customContainer.itemName = $('#customModel').find(':selected').text() + " - " + customContainer.customVariantChosen; 3115 customContainer.showCustomizeButton = true; 3116 } 3117 } 3118 3119 3120 $('#clipStyleSelect').change(function(e) { 3121 console.log($(this).val()); 3122 if ($(this).val() == "Plastic Clip") { 3123 $('#plasticClipColor').fadeIn(); 3124 $('#metalClipColor').fadeOut(); 3125 } else if ($(this).val() == "Metal Clip") { 3126 $('#plasticClipColor').fadeOut(); 3127 $('#metalClipColor').fadeIn(); 3128 } else { 3129 $('#plasticClipColor').fadeOut(); 3130 $('#metalClipColor').fadeOut(); 3131 } 3132 }) 3133 3134 $('#customSleeve1ColorSelect').change(function(e) { 3135 if ($('#differentColoredSleeveCheck').is(':checked')) { 3136 console.log(color); 3137 } else { 3138 var color = $('#customSleeve1ColorSelect').val(); 3139 $('#customSleeve2ColorSelect').val(color); 3140 }
3141 if (cats.includes('Cordless')) { 3142 if (($('#customSleeve1ColorSelect').val() == "Beige") || ($('#customSleeve1ColorSelect').val() == "Orange-Red") || ($('#customSleeve1ColorSelect').val() == "Royal Blue") || ($('#customSleeve1ColorSelect').val() == "Lipstick Pink") || ($('#customSleeve1ColorSelect').val() == "Black") || ($('#customSleeve1ColorSelect').val() == "Grey") || ($('#customSleeve1ColorSelect').val() == "Chocolate Brown") || ($('#customSleeve1ColorSelect').val() == "Camouflage")) { 3143 if (($('#customSleeve2ColorSelect').val() == "Beige") || ($('#customSleeve2ColorSelect').val() == "Orange-Red") || ($('#customSleeve2ColorSelect').val() == "Royal Blue") || ($('#customSleeve2ColorSelect').val() == "Lipstick Pink") || ($('#customSleeve2ColorSelect').val() == "Black") || ($('#customSleeve2ColorSelect').val() == "Grey") || ($('#customSleeve2ColorSelect').val() == "Chocolate Brown") || ($('#customSleeve2ColorSelect').val() == "Camouflage")) { 3144 $('#standardColorNotifier').fadeIn(); 3145 } else { 3146 $('#standardColorNotifier').fadeOut(); 3147 } 3148 } else { 3149 $('#standardColorNotifier').fadeOut(); 3150 } 3151 } else { 3152 $('#standardColorNotifier').fadeOut(); 3153 } 3154 }); 3155 3156 $('#differentColoredSleeveCheck').change(function(e) { 3157 if ($(this).is(':checked')) { 3158 $('#customSleeve2ColorContainer').fadeIn('slow'); 3159 $('#customSleeve1ColorLabel').text('Sleeve 1 Color'); 3160 } else { 3161 $('#customSleeve2ColorContainer').fadeOut('slow'); 3162 $('#customSleeve1ColorLabel').text('Sleeve Color'); 3163 } 3164 }); 3165 3166 3167 var customSizing = [ 3168 { 3169 "name": "Micro", 3170 "minSizeIn": 0.0, 3171 "maxSizeIn": 1.0, 3172 "minSizeCm": 0.0, 3173 "maxSizeCm": 2.5 3174 }, 3175 { 3176 "name": "Mini", 3177 "minSizeIn": 1.0, 3178 "maxSizeIn": 1.25, 3179 "minSizeCm": 2.5, 3180 "maxSizeCm": 3.2 3181 }, 3182 { 3183 "name": "Original", 3184 "minSizeIn": 1.25, 3185 "maxSizeIn": 2.0, 3186 "minSizeCm": 3.2, 3187 "maxSizeCm": 5.0 3188 }, 3189 { 3190 "name": "FM", 3191 "minSizeIn": 2.0, 3192 "maxSizeIn": 3.0, 3193 "minSizeCm": 5.0, 3194 "maxSizeCm": 7.6 3195 } 3196 // { 3197 // "name": "Cochlear", 3198 // "minSizeIn": 2.0, 3199 // "maxSizeIn": 3.0, 3200 // "minSizeCm": 5.0, 3201 // "maxSizeCm": 7.6 3202 // } 3203 ] 3204 3205 3206 // $('#customMetricSelector').change(function(e) { 3207 // if ($(this).val() == "In") { 3208 // $('#customLength').attr("min", ".5").attr("max", "2.5").attr("step", ".1").val("1"); 3209 // $('#customLengthOutput').text("1 In"); 3210 // } else { 3211 // $('#customLength').attr("min", "1").attr("max", "6").attr("step", ".25").val("2.5"); 3212 // $('#customLengthOutput').text("2.5 Cm"); 3213 // } 3214 // }); 3215 // function updateLength() { 3216 // var lengthMetric = $('#customLength').val(); 3217 // var lengthType = $('#customMetricSelector').val(); 3218 // $('#customLengthOutput').text(String(lengthMetric) + ' ' + lengthType); 3219 // } 3220 // $('#customLength').on('input', function(e) { 3221 // updateLength(); 3222 // }); 3223 // $('#customSizeChecker').click(function(e) { 3224 // e.preventDefault(); 3225 // var minLength; 3226 // var maxLength; 3227 // var message = ""; 3228 // console.log($('#customLength').val()); 3229 // var errorMsg = ''; 3230 // if (customProduct == "Micro" || customProduct == "Mini" || customProduct == "Original" || customProduct == "FM") { 3231 // if ($('#customLength').val()) { 3232 // 3233 // 3234 // $.each(customSizing, function(i, item) { 3235 // 3236 // 3237 // if (item.name == customProduct) { 3238 // console.log(item.name); 3239 // 3240 // if ($('#customMetricSelector').val() == "In") { 3241 // minLength = item.minSizeIn; 3242 // maxLength = item.maxSizeIn; 3243 // } else { 3244 // minLength = item.minSizeCm; 3245 // maxLength = item.maxSizeCm; 3246 // } 3247 // var correctSize = false; 3248 // console.log(minLength); 3249 // console.log(maxLength); 3250 // console.log($('#customLength').val()); 3251 // if ($('#customLength').val() >= minLength && $('#customLength').val() <= maxLength ) { 3252 // console.log("It's all good!"); 3253 // correctSize = true; 3254 // $('#continueMessage').html('Great! The Ear Gear ' + customProduct + ' should work for that size. If you have any questions before you place your order, please <a href="/support" target="_blank">contact us.</a> Otherwise, continue with your order.') 3255 // $('#customModalContinue').fadeIn();
3256 // $('#modal-continue-button').fadeIn(); 3257 // $('#modal-support-button').fadeOut(); 3258 // } else if ($('#customLength').val() < minLength) { 3259 // console.log('< minLength'); 3260 // message = 'Hmmm... That model of Ear Gear might be too small for your hearing aid.'; 3261 // } else if ($('#customLength').val() > minLength) { 3262 // console.log('> minLength'); 3263 // message = 'Hmmm... That model of Ear Gear might be too large for your hearing aid.'; 3264 // } 3265 // 3266 // 3267 // if (correctSize == false) { 3268 // var validItem = false; 3269 // $.each(customSizing, function(i, newItem) { 3270 // if ($('#customMetricSelector').val() == "In") { 3271 // console.log(newItem.minSizeIn); 3272 // console.log($('#customLength').val()); 3273 // console.log(newItem.maxSizeIn); 3274 // if ($('#customLength').val() >= newItem.minSizeIn && $('#customLength').val() < newItem.maxSizeIn ) { 3275 // message += "<br/>We'd recommend the Ear Gear " + newItem.name + '. <a href="/custom?product=' + newItem.name + '"><br/>Select this Model</a>.' 3276 // validItem = true; 3277 // } 3278 // } else { 3279 // if ($('#customLength').val() >= newItem.minSizeCm && $('#customLength').val() <= newItem.maxSizeCm ) { 3280 // 3281 // message += "We'd recommend the Ear Gear " + newItem.name + '. <a href="/custom?product=' + newItem.name + '</a>.' 3282 // } 3283 // // else { 3284 // // // message += "We're having trouble recommending an Ear Gear for that size. Would you like some help? <a href='/support' target='_blank'> Get Some Help</a>"; 3285 // // } 3286 // } 3287 // }); 3288 // if (validItem == false) { 3289 // message += "We're having trouble recommending an Ear Gear for that size. Would you like some help? <a href='/support' target='_blank'> Get Some Help</a>"; 3290 // } 3291 // $('#continueMessage').html(message); 3292 // $('#customModalContinue').fadeIn(); 3293 // $('#modal-continue-button').fadeOut(); 3294 // $('#modal-support-button').fadeIn(); 3295 // 3296 // } 3297 // 3298 // } 3299 // 3300 // 3301 // 3302 // }); 3303 // 3304 // } 3305 // } else { 3306 // $('#customLengthError').text("It's one of those other models so we'll do something different.").fadeIn(); 3307 // } 3308 // }); 3309 3310 $('#modal-continue-button .button').click(function(e) { 3311 e.preventDefault(); 3312 console.log("Ready to Customize!"); 3313 $('#customModalDisclaimer').fadeOut(); 3314 }); 3315 3316 function changeCustomModal(sectionId, step) { 3317 $('.modal-step').hide(); 3318 $('#modalContinue').data('modal-step', step); 3319 $('#modalBack').data('modal-step', step); 3320 $('#modalFooter').fadeIn(); 3321 $('#modalNormalActions').fadeIn(); 3322 $('#snip-add-button-container').fadeOut(); 3323 var element = $('#' + sectionId); 3324 element.fadeIn(); 3325 console.log('finding element', element.find('.is-selected')); 3326 if (element.find('.is-selected').length == 0) { 3327 $('#modalContinue').attr('disabled', true); 3328 } else { 3329 $('#modalContinue').attr('disabled', false); 3330 } 3331 3332 if (step == "review") { 3333 $('#modalNormalActions').fadeOut(); 3334 $('#snip-add-button-container').fadeIn(); 3335 var modData = $('#customAddToCart-' + modId).data(); 3336 console.log(modData); 3337 $('#reviewSleeve1').text(modData["itemCustom1Value"]); 3338 if (modData["itemCustom1Value"] == modData["itemCustom2Value"]) { 3339 $('#reviewSleeve2').text(modData["itemCustom2Value"]); 3340 $('.sleeveColor2Review').fadeIn(); 3341 } 3342 if (cats.find(item => item.name === "Corded")) { 3343 $('.cordedReview').fadeIn(); 3344 } 3345 } else if (step == "different-sleeves") { 3346 $('#modalFooter').fadeOut(); 3347 } 3348 } 3349 3350 $('#modalContinue').click(function(e) { 3351 e.preventDefault(); 3352 if ($(this).attr('disabled') == 'disabled') { 3353 console.log('it is disabled'); 3354 } else { 3355 3356 if ($(this).data('modal-step') == "sleeve-1") { 3357 changeCustomModal('customSleeve2Question', 'different-sleeves'); 3358 3359 } else if ($(this).data('modal-step') == "sleeve-2") { 3360 3361 if (cats.find(item => item.name === "Corded")) { 3362 console.log('includes corded'); 3363 changeCustomModal('customCordOptions', 'cord'); 3364 3365 } else if (cats.find(item => item.name === "Cordless")){ 3366 changeCustomModal('reviewAllOptions', 'review'); 3367 } else { 3368 3369 console.log('does not seem to be either'); 3370 3371 } 3372 } else if ($(this).data('modal-step') == "cord") { 3373 changeCustomModal('customOringOptioins', 'o-ring'); 3374 } else if ($(this).data('modal-step') == 'o-ring') { 3375 changeCustomModal('customClipOptions', 'clip'); 3376 } else if ($(this).data('modal-step') == 'clip') { 3377 changeCustomModal('reviewAllOptions', 'review'); 3378 3379 } 3380 3381 } 3382 }); 3383 3384 $('#modalBack').click(function(e) { 3385 e.preventDefault(); 3386 if ($(this).data('modal-step') == "review") { 3387 if (cats.find(item => item.name === "Corded")) { 3388 changeCustomModal('customClipOptions', 'clip'); 3389 } else { 3390 if ($('#customAddToCart-' + modId).data('itemCustom1Value') == $('#customAddToCart-' + modId).data('itemCustom2Value')) { 3391 changeCustomModal('customSleeve1ColorContainer', 'different-sleeves'); 3392 } else { 3393 changeCustomModal('customSleeve2ColorSelect', 'sleeve-2'); 3394 } 3395 } 3396 } else if ($(this).data('modal-step') == "clip") { 3397 changeCustomModal('customOringOptioins', 'o-ring'); 3398 } else if ($(this).data('modal-step') == "o-ring") { 3399 changeCustomModal('customCordOptions', 'cord'); 3400 } else if ($(this).data('modal-step') == "cord") { 3401 if ($('#customAddToCart-' + modId).data('itemCustom1Value') == $('#customAddToCart-' + modId).data('itemCustom2Value')) { 3402 changeCustomModal('customSleeve1ColorContainer', 'different-sleeves'); 3403 } else { 3404 changeCustomModal('customSleeve2ColorSelect', 'sleeve-2'); 3405 } 3406 } else if ($(this).data('modal-step') == "sleeve-2") { 3407 changeCustomModal('customSleeve1ColorContainer', 'sleeve-1'); 3408 } 3409 }); 3410 3411 3412 3413 $('.reviewChange').click(function(e) { 3414 e.preventDefault(); 3415 changeCustomModal($(this).data('element'), $(this).data('stage')); 3416 }) 3417 // 3418 // $('.custom-sleeve-colors').click(function(e) { 3419 // e.preventDefault(); 3420 // $('.custom-sleeve-colors-' + $(this).data('option-label')).removeClass('is-selected'); 3421 // $(this).addClass('is-selected'); 3422 // if ($(this).data('option-label') == "sleeve-1") { 3423 // console.log($(this).data('option-value')); 3424 // $('#modalContinue').attr('disabled', false); 3425 // $('#customAddToCart-' + modId).data('itemCustom1Value', $(this).data('option-value')); 3426 // } else if ($(this).data('option-label') == 'sleeve-2-different') { 3427 // $('#modalContinue').attr('disabled', false); 3428 // console.log($(this).data('option-value')); 3429 // if ($(this).data('option-value') == "same") { 3430 // $('#customAddToCart-' + modId).data('itemCustom2Value', $('#customAddToCart-' + modId).data('itemCustom1Value')); 3431 // changeCustomModal('customCordOptions', 'cord'); 3432 // // $('#customSleeve2Question').fadeOut(); 3433 // // $('#customCordOptions').fadeIn(); 3434 // // $('#modalFooter').fadeIn(); 3435 // // $('#modalContinue').attr('disabled', true); 3436 // } else { 3437 // changeCustomModal('customSleeve2ColorSelect', 'sleeve-2'); 3438 // // $('#customSleeve2Question').fadeOut(); 3439 // // $('#customSleeve2ColorSelect').fadeIn(); 3440 // // $('#modalFooter').fadeIn(); 3441 // // $('#modalContinue').attr('disabled', true); 3442 // } 3443 // } else if ($(this).data('option-label') == "sleeve-2") { 3444 // console.log($(this).data('option-value')); 3445 // $('#modalContinue').attr('disabled', false); 3446 // $('#modalContinue').data('modal-step', 'sleeve-2'); 3447 // $('#modalBack').data('modal-step', 'sleeve-2'); 3448 // $('#customAddToCart-' + modId).data('itemCustom2Value', $(this).data('option-value')); 3449 // 3450 // } else if ($(this).data('option-label') == "cord") { 3451 // console.log($(this).data('option-value')); 3452 // $('#modalContinue').attr('disabled', false); 3453 // $('#modalContinue').data('modal-step', 'cord'); 3454 // $('#modalBack').data('modal-step', 'cord'); 3455 // $('#customAddToCart-' + modId).data('itemCustom3Value', $(this).data('option-value')); 3456 // } else if ($(this).data('option-label') == "o-ring") { 3457 // console.log($(this).data('option-value')); 3458 // $('#modalContinue').attr('disabled', false); 3459 // $('#modalContinue').data('modal-step', 'o-ring'); 3460 // $('#modalBack').data('modal-step', 'o-ring'); 3461 // $('#customAddToCart-' + modId).data('itemCustom4Value', $(this).data('option-value')); 3462 // } else if ($(this).data('option-label') == "clip") { 3463 // console.log($(this).data('option-value')); 3464 // $('#modalContinue').attr('disabled', false); 3465 // $('#modalContinue').data('modal-step', 'clip'); 3466 // $('#modalBack').data('modal-step', 'clip'); 3467 // $('#customAddToCart-' + modId).data('itemCustom6Value', $(this).data('option-value')); 3468 // 3469 // } 3470 // }); 3471 3472 // $('#customSleeve1ColorSelect').change(function(e) { 3473 // $('#customAddToCart-' + modId).data('itemCustom1Options', $(this).val()); 3474 // if (!$('#differentColoredSleeveCheck').is(':checked')) { 3475 // $('#customAddToCart-' + modId).data('itemCustom2Options', $(this).val()); 3476 // } 3477 // customCheckOptions(); 3478 // }); 3479 $('#customSleeve2ColorSelect').change(function(e) { 3480 $('#customAddToCart-' + modId).data('itemCustom2Options', $(this).val());
3481 if (cats.includes('Cordless')) { 3482 customCheckOptions(); 3483 if (($('#customSleeve1ColorSelect').val() == "Beige") || ($('#customSleeve1ColorSelect').val() == "Orange-Red") || ($('#customSleeve1ColorSelect').val() == "Royal Blue") || ($('#customSleeve1ColorSelect').val() == "Lipstick Pink") || ($('#customSleeve1ColorSelect').val() == "Black") || ($('#customSleeve1ColorSelect').val() == "Grey") || ($('#customSleeve1ColorSelect').val() == "Chocolate Brown") || ($('#customSleeve1ColorSelect').val() == "Camouflage")) { 3484 if (($('#customSleeve2ColorSelect').val() == "Beige") || ($('#customSleeve2ColorSelect').val() == "Orange-Red") || ($('#customSleeve2ColorSelect').val() == "Royal Blue") || ($('#customSleeve2ColorSelect').val() == "Lipstick Pink") || ($('#customSleeve2ColorSelect').val() == "Black") || ($('#customSleeve2ColorSelect').val() == "Grey") || ($('#customSleeve2ColorSelect').val() == "Chocolate Brown") || ($('#customSleeve2ColorSelect').val() == "Camouflage")) { 3485 $('#standardColorNotifier').fadeIn(); 3486 } else { 3487 $('#standardColorNotifier').fadeOut(); 3488 } 3489 } else { 3490 $('#standardColorNotifier').fadeOut(); 3491 } 3492 } else { 3493 $('#standardColorNotifier').fadeOut(); 3494 } 3495 }); 3496 $('#cordColorSelect').change(function(e) { 3497 $('#customAddToCart-' + modId).data('itemCustom3Options', $(this).val()); 3498 customCheckOptions(); 3499 }); 3500 $('#oRingColorSelect').change(function(e) { 3501 $('#customAddToCart-' + modId).data('itemCustom4Options', $(this).val()); 3502 customCheckOptions(); 3503 }); 3504 $('#clipStyleSelect').change(function(e) { 3505 $('#customAddToCart-' + modId).data('itemCustom5Options', $(this).val()); 3506 customCheckOptions(); 3507 }); 3508 $('#metalClipColorSelect').change(function(e) { 3509 $('#customAddToCart-' + modId).data('itemCustom6Options', $(this).val()); 3510 customCheckOptions(); 3511 }); 3512 $('#plasticClipColorSelect').change(function(e) { 3513 $('#customAddToCart-' + modId).data('itemCustom6Options', $(this).val()); 3514 customCheckOptions(); 3515 }); 3516 3517 3518 function customCheckOptions() { 3519 if (cats.includes("Cordless")) { 3520 if (($('#customSleeve1ColorSelect').val() != "") && (($('#customSleeve2ColorSelect').val() != ""))) { 3521 $('.addCustomToCart').attr('disabled', false); 3522 } else { 3523 $('.addCustomToCart').attr('disabled', true); 3524 } 3525 } else { 3526 if (($('#customSleeve1ColorSelect').val() != "") && ($('#customSleeve2ColorSelect').val() != "") && ($('#cordColorSelect').val() != "") && ($('#oRingColorSelect').val() != "") && ($('#clipStyleSelect').val() != "") && (($('#metalClipColorSelect').val() != "") || ($('#plasticClipColorSelect').val() != ""))) { 3527 $('.addCustomToCart').attr('disabled', false); 3528 } else { 3529 $('.addCustomToCart').attr('disabled', true); 3530 } 3531 } 3532 }; 3533 3534 $('#customCarousel').slick({ 3535 autoplay:true, 3536 autoplaySpeed: 4000, 3537 centerMode: true, 3538 centerPadding: '60px', 3539 slidesToShow: 6, 3540 pauseOnHover: false, 3541 infinite: true 3542 }); 3543 $('#customCarousel').css('visibility','visible').hide().fadeIn('slow'); 3544 } 3545 3546 $('#closeProductHelper').click(function() { 3547 $('#productHelper').hide('slow'); 3548 }); 3549 3550 $('.videoIframeToggle').click(function(e) { 3551 e.preventDefault(); 3552 console.log($(this).data('video-id')); 3553 $('#iframeVideoIframe').attr('src', 'https://www.youtube.com/embed/' + $(this).data('video-id') ); 3554 document.getElementById("iframeVideoIframe").scrollIntoView({behavior: "smooth", block: "start", inline: "nearest"}); 3555 3556 }) 3557 3558}); 3559 3560 3561 3562$(window).on('load', function() { 3563 3564 function updateHomePageSlide(newSlide) { 3565 3566 var pageWidth = $(window).width(); 3567 pageWidth = pageWidth < 400 ? 400 : pageWidth < 640 ? 640 : pageWidth < 960 ? 960 : pageWidth < 1280 ? 1280 : 1500; 3568 var newUrl = $('#hp-image-scroll-' + String(newSlide)).data('image-url'); 3569 var desktopUrl = $('#hp-image-scroll-' + String(newSlide)).data('image-desktop-url'); 3570 var mobileUrl = $('#hp-image-scroll-' + String(newSlide)).data('image-mobile-url'); 3571 if (pageWidth == 1500) { 3572 newUrl = desktopUrl; 3573 } else if (pageWidth <= 640) { 3574 newUrl = mobileUrl; 3575 }
3576 var finalUrl = 'https://www.gearforears.com/cdn-cgi/image/'; 3577 finalUrl += 'format=auto,quality=90/'; 3578 finalUrl += newUrl; 3579 console.log('finalUrl', finalUrl); 3580 3581 var bg = { 3582 "background": "url('" + finalUrl + "')", 3583 "background-size": "cover", 3584 "background-position": "center center", 3585 } 3586 console.log('bg', bg); 3587 $('#homePageHeroContainer').css(bg); 3588 $('.hp-image-scroll').removeClass('active'); 3589 $('.hp-image-scroll-' + String(newSlide)).addClass('active'); 3590 } 3591 3592 3593 3594 var homePageHero__currentSlide = null; 3595 3596 function preloadHomepageVideo() { 3597 console.log('finding file types'); 3598 var mp4Link = $('#homepageHowToVideo').data('mp4-link'); 3599 var webmLink = $('#homepageHowToVideo').data('webm-link'); 3600 var oggLink = $('#homepageHowToVideo').data('ogg-link'); 3601 var poster = $('#homepageHowToVideo').attr('src'); 3602 3603 console.log(mp4Link, webmLink, oggLink, poster); 3604 var videoHtml = '<video class="has-shadow my-background-video jquery-background-video" loop autoplay muted playsinline poster="' + String(poster) + '" style="z-index:-1;">' 3605 videoHtml += '<source src="' + String(mp4Link) + '" type="video/mp4">'; 3606 videoHtml += '<source src="' + String(webmLink) + '" type="video/webm">'; 3607 videoHtml += '<source src="' + String(oggLink) + '" type="video/ogg">'; 3608 videoHtml += '</video>'; 3609 console.log(videoHtml); 3610 $('#homepageHowToVideoContainer').html(videoHtml); 3611 } 3612 3613 3614 3615 function startHomePageSlider() { 3616 homepageInterval = setInterval(updateHomePageSlider, 5000) 3617 } 3618 3619 3620 3621 function updateHomePageSlider() { 3622 var newSlide; 3623 3624 if (homePageHero__currentSlide == null) { 3625 newSlide = 0; 3626 } else { 3627 newSlide = homePageHero__currentSlide < (homepageHeroSlideLength - 1) ? homePageHero__currentSlide += 1 : homePageHero__currentSlide = 0; 3628 } 3629 homePageHero__currentSlide = newSlide; 3630 3631 console.log('newSlide', newSlide); 3632 updateHomePageSlide(newSlide); 3633 } 3634 3635 function preloadHomepageImages() { 3636 $.each($('.hp-image-scroll'), function(i, item) { 3637 3638 var pageWidth = $(window).width(); 3639 pageWidth = pageWidth < 400 ? 400 : pageWidth < 640 ? 640 : pageWidth < 960 ? 960 : pageWidth < 1280 ? 1280 : 1500; 3640 var newUrl = $(this).data('image-url'); 3641 var desktopUrl = $(this).data('image-desktop-url'); 3642 var mobileUrl = $(this).data('image-mobile-url'); 3643 if (pageWidth == 1500) { 3644 newUrl = desktopUrl; 3645 } else if (pageWidth == 400) { 3646 newUrl = mobileUrl; 3647 } 3648 var finalUrl = 'https://www.gearforears.com/cdn-cgi/image/'; 3649 finalUrl += 'format=auto,quality=90/'; 3650 finalUrl += newUrl; 3651 var img = new Image(); 3652 img.src = finalUrl; 3653 }); 3654 } 3655 3656 3657 3658 3659 if ($('#homePageHeroContainer').length > 0) { 3660 updateHomePageSlider(); 3661 preloadHomepageImages(); 3662 setTimeout(function(){ 3663 startHomePageSlider(); 3664 }, 5000); 3665 3666 $('.hp-image-scroll').click(function(e) { 3667 e.preventDefault(); 3668 clearInterval(homepageInterval); 3669 var currentSlide = Number($(this).data('index')); 3670 updateHomePageSlide(currentSlide); 3671 homePageHero__currentSlide = currentSlide; 3672 homepageInterval = setInterval(updateHomePageSlider, 5000) 3673 }); 3674 } 3675 3676 if ($("#homepageHowToVideo").length > 0) { 3677 console.log('preloadingHomepageVideo'); 3678 preloadHomepageVideo(); 3679 } 3680 3681 try { 3682 Sentry.init({ dsn: 'https://[email protected]/1878920' }); 3683 3684 } catch (error) { 3685 console.log('error with sentry, error', error); 3686 } 3687}); 3688 3689 3690 3691// Show sticky form when button is clicked 3692$('#sticky-form-button').click(function(e) { 3693 if ($(this).hasClass('is-expanded')) { 3694 // If already expanded, close it 3695 console.log('Closing sticky form via button'); 3696 $('.sticky-form-form').addClass('is-hidden'); 3697 $('.sticky-form-button').removeClass('is-expanded'); 3698 } else { 3699 // If not expanded, open it 3700 console.log('Opening sticky form'); 3701 $('.sticky-form-form').removeClass('is-hidden'); 3702 $('.sticky-form-button').addClass('is-expanded'); 3703 3704 // Track mobile popup interaction 3705 if (isMobile()) { 3706 markMobilePopupAsClicked(); 3707 console.log('Mobile popup clicked - user will see auto-expand on future visits'); 3708 } 3709 } 3710}); 3711 3712// Hide sticky form when delete/close button is clicked 3713$('.sticky-form-form-delete').click(function(e) { 3714 console.log('Closing sticky form'); 3715 $('.sticky-form-form').addClass('is-hidden'); 3716 $('.sticky-form-button').removeClass('is-expanded'); 3717}); 3718 3719// Session-based popup rotation system 3720(function() { 3721 'use strict'; 3722 3723 // Popup configurations 3724 const popupConfigs = { 3725 default: { 3726 buttonText: 'Save up to<br>25%!',
3727 headerTitle: 'ð Bundle & Save!', 3728 headerSubtitle: 'The more you buy... The more you save!', 3729 imageUrl: 'https://www.datocms-assets.com/12235/1752791829-buy-1.jpg', 3730 popupButtonText: 'Shop Now', 3731 buttonUrl: '/products', 3732 type: 'discount-tiers' // Special type for discount tiers UI 3733 }, 3734 mobile: { 3735 buttonText: 'Bundle<br>& Save!', 3736 headerTitle: 'ð Bundle & Save!', 3737 headerSubtitle: 'Tap to see savings!', 3738 imageUrl: 'https://www.datocms-assets.com/12235/1752791829-buy-1.jpg', 3739 popupButtonText: 'Shop Now', 3740 buttonUrl: '/products', 3741 type: 'discount-tiers', 3742 mobileOptimized: true 3743 }, 3744 alternative1: { 3745 buttonText: 'Join Ear<br>Gear Club!', 3746 headerTitle: 'Save 10% on your first order', 3747 headerSubtitle: 'When you join the Ear Gear Club!', 3748 // imageUrl: 'https://www.datocms-assets.com/12235/1752705218-more-you-buy-1.png', // You can change this 3749 description: 'Join the Ear Gear Club on Facebook and take 10% off your first order!', 3750 popupButtonText: 'Join the Club!', 3751 buttonUrl: 'https://www.facebook.com/groups/eargear', 3752 type: 'simple' // Simple description-based UI 3753 } 3754 // alternative2: { 3755 // buttonText: 'New<br>Arrivals!', 3756 // headerTitle: 'ð New Arrivals!', 3757 // headerSubtitle: 'Check out our latest products', 3758 // imageUrl: 'https://www.datocms-assets.com/12235/1752705218-more-you-buy-1.png', // You can change this 3759 // description: 'Discover our newest Ear Gear products!', 3760 // popupButtonText: 'Explore', 3761 // buttonUrl: '/products' 3762 // }, 3763 // alternative3: { 3764 // buttonText: 'Limited<br>Time!', 3765 // headerTitle: 'â° Limited Time!', 3766 // headerSubtitle: 'Special offer ends soon', 3767 // imageUrl: 'https://www.datocms-assets.com/12235/1752705218-more-you-buy-1.png', // You can change this 3768 // description: 'Don\'t miss out on this exclusive offer!', 3769 // popupButtonText: 'Shop Now', 3770 // buttonUrl: '/products' 3771 // } 3772 }; 3773 3774 // Mobile detection 3775 function isMobile() { 3776 return window.innerWidth <= 768 || /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); 3777 } 3778 3779 // Session management 3780 function getSessionCount() {
3781 let count = localStorage.getItem('earGearPopupSessionCount'); 3782 return count ? parseInt(count) : 0; 3783 } 3784 3785 function incrementSessionCount() { 3786 let count = getSessionCount(); 3787 count++; 3788 localStorage.setItem('earGearPopupSessionCount', count.toString()); 3789 return count; 3790 } 3791 3792 function shouldShowAlternativePopup() { 3793 const sessionCount = getSessionCount(); 3794 const lastPopupType = getCookie('earGearLastPopupType'); 3795 3796 // Show alternative only on 5th session (ensures gap between alternatives) 3797 const shouldShowAlt = sessionCount === 5; 3798 3799 // Don't show alternative if we just showed one (prevent consecutive alternatives) 3800 if (shouldShowAlt && lastPopupType === 'alternative') { 3801 return false; 3802 } 3803 3804 return shouldShowAlt; 3805 } 3806 3807 function getRandomAlternative() { 3808 const alternatives = ['alternative1']; // Only include active alternatives 3809 const randomIndex = Math.floor(Math.random() * alternatives.length); 3810 return alternatives[randomIndex]; 3811 } 3812 3813 function getCurrentPopupConfig() {
3814 let config; 3815 let popupType; 3816 3817 // Check for alternative popups first (applies to both mobile and desktop) 3818 if (shouldShowAlternativePopup()) { 3819 config = popupConfigs[getRandomAlternative()]; 3820 popupType = 'alternative'; 3821 } else { 3822 // Use mobile config on mobile devices, default on desktop 3823 if (isMobile()) { 3824 config = popupConfigs.mobile; 3825 popupType = 'mobile'; 3826 } else { 3827 config = popupConfigs.default; 3828 popupType = 'default'; 3829 } 3830 } 3831 3832 // Track which popup type we're showing 3833 setCookie('earGearLastPopupType', popupType, 7); // 7 days 3834 3835 return config; 3836 } 3837 3838 function updatePopupContent(config) { 3839 // Update button text 3840 const buttonContent = document.querySelector('#sticky-form-button .button-content-normal'); 3841 if (buttonContent) { 3842 buttonContent.innerHTML = config.buttonText; 3843 } 3844 3845 // Update header 3846 const headerTitle = document.querySelector('.sticky-form-form .card-header h4'); 3847 if (headerTitle) { 3848 headerTitle.innerHTML = config.headerTitle; 3849 } 3850 3851 const headerSubtitle = document.querySelector('.sticky-form-form .card-header p'); 3852 if (headerSubtitle) { 3853 headerSubtitle.innerHTML = config.headerSubtitle; 3854 } 3855 3856 // Update image - only show if imageUrl is provided 3857 const image = document.querySelector('.sticky-form-form img'); 3858 if (image) { 3859 if (config.imageUrl) { 3860 image.src = config.imageUrl; 3861 image.alt = config.headerTitle.replace(/[^\w\s]/gi, ''); // Remove emojis for alt text 3862 image.style.display = 'block'; 3863 } else { 3864 image.style.display = 'none'; 3865 } 3866 } 3867 3868 // Handle different UI types 3869 const cardContent = document.querySelector('.sticky-form-form .card-content'); 3870 if (cardContent) { 3871 if (config.type === 'discount-tiers') { 3872 // Show discount tiers UI (default HTML structure) 3873 cardContent.innerHTML = ` 3874 <img src="${config.imageUrl}" alt="${config.headerTitle.replace(/[^\w\s]/gi, '')}" style="max-width: 100%; height: auto; margin-bottom: 20px; border-radius: 8px;"> 3875 3876 <!-- Discount Tiers --> 3877 <div style="margin-bottom: 20px;"> 3878 <h5 style="margin: 0 0 15px 0; font-size: 1.1rem; font-weight: bold; color: #333;">Bundle Discounts:</h5> 3879 3880 <div style="display: flex; justify-content: space-between; gap: 10px; margin-bottom: 15px;"> 3881 <!-- 2 Items --> 3882 <a href="/products" style="flex: 1; background: #f8f9fa; border: 2px solid #e9ecef; border-radius: 8px; padding: 12px; text-align: center; text-decoration: none; transition: all 0.3s ease; display: block;"> 3883 <div style="font-size: 1.2rem; font-weight: bold; color: #28a745; margin-bottom: 5px;">15% OFF</div> 3884 <div style="font-size: 0.9rem; color: #666;">Buy 2</div> 3885 </a> 3886 3887 <!-- 3 Items --> 3888 <a href="/products" style="flex: 1; background: #f8f9fa; border: 2px solid #28a745; border-radius: 8px; padding: 12px; text-align: center; text-decoration: none; transition: all 0.3s ease; display: block;"> 3889 <div style="font-size: 1.2rem; font-weight: bold; color: #28a745; margin-bottom: 5px;">20% OFF</div> 3890 <div style="font-size: 0.9rem; color: #666;">Buy 3</div> 3891 </a> 3892 3893 <!-- 4+ Items --> 3894 <a href="/products" style="flex: 1; background: #d4edda; border: 2px solid #28a745; border-radius: 8px; padding: 12px; text-align: center; text-decoration: none; transition: all 0.3s ease; display: block;"> 3895 <div style="font-size: 1.2rem; font-weight: bold; color: #155724; margin-bottom: 5px;">25% OFF</div> 3896 <div style="font-size: 0.9rem; color: #666;">Buy 4+</div> 3897 </a> 3898 </div> 3899 3900 <p style="margin: 0; font-size: 0.95rem; color: #666; font-style: italic;">The more you buy, the more you save!</p> 3901 </div> 3902 3903 <a href="/products" class="button is-green" style="width: 100%; font-size: 1.1rem; font-weight: bold; padding: 15px; border-radius: 8px; text-decoration: none;"> 3904 ${config.popupButtonText} 3905 </a> 3906 `; 3907 } else { 3908 // Show simple description UI 3909 cardContent.innerHTML = ` 3910 ${config.imageUrl ? `<img src="${config.imageUrl}" alt="${config.headerTitle.replace(/[^\w\s]/gi, '')}" style="max-width: 100%; height: auto; margin-bottom: 20px; border-radius: 8px;">` : ''} 3911 <p style="margin: 5px 0 0 0; font-size: 1.3rem; font-weight: bold; opacity: 0.9; margin-bottom: 20px;">${config.description}</p> 3912 <a href="${config.buttonUrl}" class="button is-green" style="width: 100%; font-size: 1.1rem; font-weight: bold; padding: 15px; border-radius: 8px; text-decoration: none;"> 3913 ${config.popupButtonText} 3914 </a> 3915 `; 3916 } 3917 } 3918 } 3919 3920 // Cookie management for auto-expand 3921 function setCookie(name, value, days) { 3922 const expires = new Date(); 3923 expires.setTime(expires.getTime() + (days * 24 * 60 * 60 * 1000)); 3924 document.cookie = name + "=" + value + ";expires=" + expires.toUTCString() + ";path=/"; 3925 } 3926 3927 function getCookie(name) { 3928 const nameEQ = name + "="; 3929 const ca = document.cookie.split(';'); 3930 for(let i = 0; i < ca.length; i++) { 3931 let c = ca[i]; 3932 while (c.charAt(0) === ' ') c = c.substring(1, c.length); 3933 if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length); 3934 } 3935 return null; 3936 } 3937 3938 function shouldAutoExpand() { 3939 const lastShown = getCookie('earGearPopupLastShown'); 3940 const sessionCount = getSessionCount(); 3941 const hasClickedMobilePopup = getCookie('earGearMobilePopupClicked'); 3942 const autoExpandCount = getCookie('earGearAutoExpandCount') ? parseInt(getCookie('earGearAutoExpandCount')) : 0; 3943 3944 if (isMobile()) { 3945 // On mobile: only auto-expand if user has clicked before OR it's their 3rd+ pageview AND we haven't auto-expanded too many times 3946 const shouldExpand = hasClickedMobilePopup || (sessionCount >= 3 && autoExpandCount < 2); 3947 return shouldExpand; 3948 } 3949 3950 // Desktop behavior: auto-expand if never shown before 3951 return !lastShown; 3952 } 3953 3954 function markPopupAsShown() {
3955 setCookie('earGearPopupLastShown', new Date().toISOString(), 7); // 7 days 3956 3957 // Track auto-expand count for mobile users 3958 if (isMobile()) { 3959 const currentCount = getCookie('earGearAutoExpandCount') ? parseInt(getCookie('earGearAutoExpandCount')) : 0; 3960 setCookie('earGearAutoExpandCount', (currentCount + 1).toString(), 30); // 30 days 3961 } 3962 } 3963 3964 function markMobilePopupAsClicked() { 3965 setCookie('earGearMobilePopupClicked', 'true', 30); // 30 days 3966 } 3967 3968 // Initialize popup system 3969 function initializePopupSystem() { 3970 // Increment session count on page load 3971 incrementSessionCount(); 3972 3973 // Get current configuration 3974 const currentConfig = getCurrentPopupConfig(); 3975 3976 // Update popup content 3977 updatePopupContent(currentConfig); 3978 3979 // Check if we should auto-expand 3980 if (shouldAutoExpand()) { 3981 // Wait 3 seconds, then auto-expand 3982 setTimeout(function() { 3983 $('.sticky-form-form').removeClass('is-hidden'); 3984 $('.sticky-form-button').addClass('is-expanded'); 3985 markPopupAsShown(); 3986 console.log('Auto-expanded popup for first-time visitor'); 3987 }, 3000); 3988 } 3989 3990 // Log for debugging (remove in production) 3991 console.log('Popup session count:', getSessionCount()); 3992 console.log('Current popup config:', currentConfig); 3993 console.log('Should auto-expand:', shouldAutoExpand()); 3994 console.log('Is mobile:', isMobile()); 3995 console.log('Should show alternative:', shouldShowAlternativePopup()); 3996 console.log('Auto-expand count:', getCookie('earGearAutoExpandCount') ? parseInt(getCookie('earGearAutoExpandCount')) : 0); 3997 console.log('Last popup type:', getCookie('earGearLastPopupType')); 3998 } 3999 4000 // Initialize when DOM is ready 4001 if (document.readyState === 'loading') { 4002 document.addEventListener('DOMContentLoaded', initializePopupSystem); 4003 } else { 4004 initializePopupSystem(); 4005 } 4006 4007 4008 4009 // FAQ functionality 4010 $('.faq-question-heading').click(function(e) { 4011 e.preventDefault(); 4012 var questionId = $(this).data('faq-question-id'); 4013 $('#faq-answer-' + questionId).toggleClass('is-hidden'); 4014 }); 4015 4016 // Product thumbnail gallery functionality 4017 $('.thumbnail-item').click(function(e) { 4018 e.preventDefault(); 4019 4020 // Remove active class from all thumbnails 4021 $('.thumbnail-item').removeClass('active'); 4022 4023 // Add active class to clicked thumbnail 4024 $(this).addClass('active'); 4025 4026 // Get the image URL from data attribute 4027 var newImageUrl = $(this).data('image'); 4028 4029 // Update the main product image 4030 $('#main-product-image').attr('src', newImageUrl); 4031 4032 // Optional: Add a smooth transition effect 4033 $('#main-product-image').css('opacity', '0.7'); 4034 setTimeout(function() { 4035 $('#main-product-image').css('opacity', '1'); 4036 }, 150); 4037 }); 4038 4039})(); 4040
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.