1//////////////////////////////////////////////////////////////////////////////////// 2// http://javascript-compressor.com/ 3 4// UNIVERSAL VARIABLES 5var autoDeliveryState = 0; 6var manualDropdownControl = false; 7var activeDropdown = null; 8var pendingDropdown = null; 9var dropdownOpenTimeoutId = null; 10var dropdownCloseTimeoutId = null; 11var dropdownOpenDelay = 200; 12var dropdownCloseDelay = 200; 13 14 15//////////////////////////////////////////////////////////////////////////////////// 16// HEADER ROLLOVER PAUSE 17// ALL 18 19function shouldApplyDropdownBehavior() { 20 return window.innerWidth >= 768; 21} 22 23function clearDropdownOpenTimeout() { 24 if (dropdownOpenTimeoutId) { 25 clearTimeout(dropdownOpenTimeoutId); 26 dropdownOpenTimeoutId = null; 27 } 28} 29 30function clearDropdownCloseTimeout() { 31 if (dropdownCloseTimeoutId) { 32 clearTimeout(dropdownCloseTimeoutId); 33 dropdownCloseTimeoutId = null; 34 } 35} 36 37function setDropdownActiveState(dropdown, status) { 38 if (!dropdown) { 39 return; 40 } 41 42 if (status) { 43 dropdown.classList.add('dropdown-active'); 44 } else { 45 dropdown.classList.remove('dropdown-active'); 46 } 47} 48 49function closeActiveDropdown() { 50 clearDropdownOpenTimeout(); 51 clearDropdownCloseTimeout(); 52 pendingDropdown = null; 53 54 if (activeDropdown) { 55 setDropdownActiveState(activeDropdown, false); 56 activeDropdown = null; 57 } 58} 59 60function openDropdown(dropdown) { 61 if (!dropdown || !shouldApplyDropdownBehavior() || manualDropdownControl) { 62 return; 63 } 64 65 if (activeDropdown && activeDropdown !== dropdown) { 66 setDropdownActiveState(activeDropdown, false); 67 } 68 69 activeDropdown = dropdown; 70 setDropdownActiveState(dropdown, true); 71} 72 73function scheduleDropdownOpen(dropdown) { 74 if (!dropdown || !shouldApplyDropdownBehavior() || manualDropdownControl) { 75 return; 76 } 77 78 clearDropdownCloseTimeout(); 79 pendingDropdown = dropdown; 80 81 if (activeDropdown === dropdown) { 82 clearDropdownOpenTimeout(); 83 return; 84 } 85 86 clearDropdownOpenTimeout(); 87 dropdownOpenTimeoutId = setTimeout(function() { 88 if (pendingDropdown === dropdown) { 89 openDropdown(dropdown); 90 } 91 }, dropdownOpenDelay); 92} 93 94function scheduleDropdownClose(dropdown) { 95 if (!shouldApplyDropdownBehavior() || manualDropdownControl) { 96 return; 97 } 98 99 if (pendingDropdown === dropdown) { 100 pendingDropdown = null; 101 } 102 103 clearDropdownOpenTimeout(); 104 clearDropdownCloseTimeout(); 105 dropdownCloseTimeoutId = setTimeout(function() { 106 if (!pendingDropdown) { 107 closeActiveDropdown(); 108 } 109 }, dropdownCloseDelay); 110} 111 112function resetDropdownStylesForDesktop() { 113 var dropdowns = document.querySelectorAll('.dropdown'); 114 var dropdownContents = document.querySelectorAll('.dropdown-content'); 115 var dropdownButtons = document.querySelectorAll('button[data-dropdown]'); 116 117 dropdowns.forEach(function(dropdown) { 118 dropdown.style.display = ''; 119 dropdown.style.height = ''; 120 dropdown.style.overflow = ''; 121 dropdown.classList.remove('dropdown-active'); 122 }); 123 124 dropdownContents.forEach(function(dropdownContent) { 125 dropdownContent.style.display = ''; 126 }); 127 128 dropdownButtons.forEach(function(button) { 129 button.classList.remove('active'); 130 }); 131} 132 133function setupDropdowns() { 134 var dropdowns = document.querySelectorAll('.dropdown'); 135 136 dropdowns.forEach(function(dropdown) { 137 if (!dropdown.querySelector('.dropdown-content')) { 138 return; 139 } 140 141 if (dropdown.getAttribute('data-dropdown-ready') == '1') { 142 return; 143 } 144 145 dropdown.setAttribute('data-dropdown-ready', '1'); 146 147 dropdown.addEventListener('mouseenter', function() { 148 scheduleDropdownOpen(dropdown); 149 }); 150 151 dropdown.addEventListener('mouseleave', function() { 152 scheduleDropdownClose(dropdown); 153 }); 154 }); 155} 156 157document.addEventListener('DOMContentLoaded', setupDropdowns); 158window.addEventListener('resize', function() { 159 setupDropdowns(); 160 closeActiveDropdown(); 161 162 if (shouldApplyDropdownBehavior()) { 163 manualDropdownControl = false; 164 resetDropdownStylesForDesktop(); 165 } 166}); 167 168 169 170 171 172//////////////////////////////////////////////////////////////////////////////////// 173// MOBILE HEADER/FOOTER NAVIGATION 174// ALL 175 176function showHideMainNav() { 177 manualDropdownControl = true; 178 179 // CHANGE DISPLAY=> NONE for all dropdown-content 180 $('.dropdown-content').each(function(index, item) { 181 $(item).css('display', 'none'); 182 }); 183 184 if (document.getElementsByClassName("dropdown")[0].style.display != "block") { 185 $('.dropdown').animate({ height: 'show' }, 400, function() { 186 manualDropdownControl = true; 187 }); 188 } else { 189 $('.dropdown').animate({ height: 'hide' }, 400, function() { 190 manualDropdownControl = false;
191 }); 192 } 193 194} 195 196 197function navAction(url, dropdownId) { 198 if (window.innerWidth > 768) { 199 window.location.href = url; 200 } else { 201 var dropdown = document.getElementById(dropdownId); 202 var button = document.querySelector('button[data-dropdown="' + dropdownId + '"]'); 203 204 if (dropdown.style.display === "block") { 205 dropdown.style.display = "none"; 206 if (button) { 207 button.classList.remove('active'); 208 } 209 } else { 210 dropdown.style.display = "block"; 211 if (button) { 212 button.classList.add('active'); 213 } 214 } 215 } 216} 217 218 219 220 221 222 223//////////////////////////////////////////////////////////////////////////////////// 224// VOTE 225// EXISTING 226 227function reviewVote(reviewId, voteType) { 228 229 $.ajax({ 230 type: "POST", 231 url: "/ajax/reviewVote.html", 232 data: "reviewId=" + reviewId + "&voteType=" + voteType, 233 success: function(msg){ 234 var result = msg.split("***SPLIT***"); 235 if (result[0]) { 236 document.getElementById('vote_'+result[1]).innerHTML = result[0]; 237 } 238 } 239 }); 240 241} 242 243 244 245 246 247 248//////////////////////////////////////////////////////////////////////////////////// 249// NOTIFY ME 250// ALL 251 252function notifyOpen(teaId) { 253 254 $.ajax({ 255 type: "POST", 256 url: "/ajax/notify_open.html", 257 data: "item=" + teaId, 258 success: function(msg){ 259 var result = msg.split("***SPLIT***"); 260 document.getElementById('itemBlock_'+teaId).style.backgroundColor = "#f4f4f4"; 261 document.getElementById('itemBlock_'+teaId).innerHTML = msg; 262 } 263 }); 264 265} 266 267function notifyEmail(teaId, email, sku, address) { 268 269 $.ajax({ 270 type: "POST", 271 url: "/ajax/notify_email.html", 272 data: "item=" + teaId + "&email=" + email + "&sku=" + sku + "&address=" + address, 273 success: function(msg){ 274 var result = msg.split("***SPLIT***"); 275 document.getElementById('itemBlock_'+teaId).style.backgroundColor = "#f4f4f4"; 276 document.getElementById('itemBlock_'+teaId).innerHTML = msg; 277 } 278 }); 279 280} 281 282function notifyCancel(teaId, notifyId) { 283 284 $.ajax({ 285 type: "POST", 286 url: "/ajax/notify_cancel.html", 287 data: "item=" + teaId + "¬ifyId=" + notifyId, 288 success: function(msg){ 289 var result = msg.split("***SPLIT***"); 290 document.getElementById('itemBlock_'+teaId).style.backgroundColor = "#f4f4f4"; 291 document.getElementById('itemBlock_'+teaId).innerHTML = msg; 292 } 293 }); 294 295} 296 297function notifyMe(teaId, email) { 298 299 $.ajax({ 300 type: "POST", 301 url: "/ajax/notify_me.html", 302 data: "item=" + teaId + "&email=" + email, 303 success: function(msg){ 304 var result = msg.split("***SPLIT***"); 305 document.getElementById('notifyMe').innerHTML = "Thank you for choosing to be notified when this product is back in stock.<br><br>"; 306 } 307 }); 308 309} 310 311function notifyMeCancel(teaId, userId) { 312 313 $.ajax({ 314 type: "POST", 315 url: "/ajax/notify_me_cancel.html", 316 data: "item=" + teaId + "&userId=" + userId, 317 success: function(msg){ 318 var result = msg.split("***SPLIT***"); 319 statusMessage(result[0], 0, parseInt(result[1])); 320 if ($('#preorderNote').length > 0) { 321 $('#preorderNote').animate({opacity: 'hide'}, 200); 322 } 323 } 324 }); 325 326} 327 328 329 330//////////////////////////////////////////////////////////////////////////////////// 331// TWITTER UPDATE 332// EXISTING 333 334function twitterUpdate(twitter) { 335 336 $.ajax({ 337 type: "POST", 338 url: "/ajax/updateTwitter.html", 339 data: "twitter=" + twitter, 340 success: function(msg){ 341 var result = msg.split("***SPLIT***"); 342 document.getElementById('twitterCopy').innerHTML = "Thanks. We use direct messages for updates, so make sure to <A HREF='http://twitter.com/AdagioTeas' TARGET='_new'>follow us</A> to be notified each time your package moves more than 6 inches :)"; 343 document.getElementById('twitterForm').style.display = "none"; 344 } 345 }); 346 347} 348 349 350 351 352//////////////////////////////////////////////////////////////////////////////////// 353// VIEW QUOTE 354// ALL 355 356function viewQuote(id, friendsId, status) { 357 358 if (status == 1) { 359 360 $('#bubble_'+id+friendsId).animate({opacity: 'show'}, 200); 361 362 $.ajax({ 363 type: "POST", 364 url: "/ajax/view_quote_2017.html", 365 data: "id=" + id + "&friendsId=" + friendsId, 366 success: function(msg){ 367 document.getElementById('bubble_'+id+friendsId).innerHTML = msg; 368 } 369 }); 370 371 } else { 372 $('#bubble_'+id+friendsId).animate({opacity: 'hide'}, 200); 373 } 374 375} 376 377 378 379//////////////////////////////////////////////////////////////////////////////////// 380// QA 381// ALL 382 383function qa_Load_Answers (id) { 384 385 $('div[class="classReply"]').each(function(index,item){ 386 var numberPattern = /\d+/g; 387 qa_Load_Answers_Hide(($(item).get(0).id).match( numberPattern )); 388 $('#answerDiv_'+(($(item).get(0).id).match( numberPattern ))).animate({ height: 'hide' }, 250); 389 }); 390 391 document.getElementById('replyButton_'+ id).style.display = "none"; 392 document.getElementById('replyButtonDisabled_'+ id).style.display = "block"; 393 394 document.getElementById('answerButton_'+ id).style.display = "none"; 395 document.getElementById('answerButtonEnabled_'+ id).style.display = "block"; 396 397 document.getElementById('replyDiv_'+ id).innerHTML = "<img width='32' height='32' border='0' src='https://www.adagio.com/images4/wait_icon.gif'>"; 398 399 400 401 $.ajax({ 402 type: "POST", 403 url: "/ajax/qa_load_answers.html", 404 data: "id=" + id, 405 success: function(msg){ 406
407 var result = msg.split("***SPLIT***"); 408 document.getElementById('replyDiv_'+ id).style.display = "none"; 409 document.getElementById('replyDiv_'+ id).innerHTML = result[0]; 410 $('#replyDiv_'+ id).animate({ height: 'show', opacity: 'show' }, 250); 411 412 } 413 }); 414 415} 416 417function qa_Load_Answers_Hide (id) { 418 419 document.getElementById('replyButton_'+ id).style.display = "block"; 420 document.getElementById('replyButtonDisabled_'+ id).style.display = "none"; 421 422 document.getElementById('answerButton_'+ id).style.display = "block"; 423 document.getElementById('answerButtonEnabled_'+ id).style.display = "none"; 424 425 $('#replyDiv_'+ id).animate({ height: 'hide', opacity: 'hide' }, 250); 426 427} 428 429 430function qa_Question (productId, question) { 431 432 // FIX VARIOUS COPY ISSUES 433 question = encodeURIComponent(question); 434 435 if (question) { 436 $.ajax({ 437 type: "POST", 438 url: "/ajax/qa_question.html", 439 data: "productId=" + productId + "&question=" + question, 440 success: function(msg){ 441 442 var result = msg.split("***SPLIT***"); 443 444 $('#qa_new_div').animate({ height: 'hide', opacity: 'hide' }, 250); 445 statusMessage(result[0], 0, 0); 446 447 } 448 }); 449 } 450 451} 452 453//////////////////////////////////////////////////////////////////////////////////// 454// QA 455// EXISTING 456 457function qa_Answer (productId, answer) { 458 459 // FIX VARIOUS COPY ISSUES 460 answer = encodeURIComponent(answer); 461 462 if (answer) { 463 $.ajax({ 464 type: "POST", 465 url: "/ajax/qa_answer.html", 466 data: "productId=" + productId + "&answer=" + answer, 467 success: function(msg){ 468 469 var result = msg.split("***SPLIT***"); 470 471 $('#answerDiv_'+productId).animate({ height: 'hide', opacity: 'hide' }, 200); 472 statusMessage(result[0], 0, 0); 473 474 } 475 }); 476 } 477 478} 479 480function qa_Vote(id, voteType) { 481 482 $.ajax({ 483 type: "POST", 484 url: "/ajax/qa_vote.html", 485 data: "id=" + id + "&voteType=" + voteType, 486 success: function(msg){ 487 var result = msg.split("***SPLIT***"); 488 if (result[0]) { 489 document.getElementById('vote_'+result[1]).innerHTML = result[0]; 490 } 491 } 492 }); 493 494} 495 496 497//////////////////////////////////////////////////////////////////////////////////// 498// SEARCH SUGGESTION 499// ALL 500 501var counter = 0; 502var counterByTwo = 0; 503var copy; 504var searchCounter = -1; 505var searchTerm; 506 507function openSearch() { 508 $('#searchBoxDiv').animate({ top: '0' }, 250); 509 document.getElementById('search').focus(); 510} 511 512function closeSearch() { 513 $('#searchBoxDiv').animate({ top: '-155px' }, 250); 514 $('#searchResultsDiv').animate({ height: 'hide' }, 250); 515 document.getElementById('search').value=''; 516} 517 518function suggestNew(searchValue) { 519 520 if (searchValue.length >= 3) { 521 522 searchTerm = searchValue; 523 524 $.ajax({ 525 type: "POST", 526 url: "/ajax/search_suggestions.html", 527 data: "searchValue=" + searchValue, 528 success: function(msg){ 529 530 result = msg.split("***SPLIT***"); 531 532 $('#searchResultsDiv').html(result[0]); 533 document.getElementById('searchResultsDiv').style.display='inline-block'; 534 535 if (searchTerm != searchValue) { 536 suggestNew(searchTerm); 537 } 538 539 } 540 }); 541 542 } else { 543 544 document.getElementById('searchResultsDiv').style.display='none'; 545 546 } 547 548} 549 550function suggestClose() { 551 $('#searchSuggestion').animate({height: 'toggle'}, 500); 552 document.getElementById('searchSuggestionContent').innerHTML = ''; 553 document.getElementById('searchInput').value=""; 554} 555 556 557function notesClose() { 558 $('#notes').animate({height: 'toggle'}, 500); 559 document.getElementById('notesContent').innerHTML = ''; 560} 561 562function displayunicode(e,content) { 563 console.log(content); 564 var unicode=e.keyCode? e.keyCode : e.charCode 565 if (unicode == 13) { 566 window.location.assign("/search/index.html?query=" + content); 567 } else { 568 suggestNew(content); 569 } 570} 571 572function testInstantCouponKey(e,content) { 573 var unicodeTwo=e.keyCode? e.keyCode : e.charCode 574 if (unicodeTwo == 13) { 575 instantCouponEmail($('[name=instantCouponEmail]').val()); 576 } 577} 578 579function rolloverSearch(number) { 580 searchCounter = number; 581 resetAll(); 582 document.getElementById('counter_'+searchCounter).style.backgroundPosition = "0 -20px"; 583} 584 585function resetAll() { 586 for(var i=0; i<counter; i++) { 587 document.getElementById('counter_'+i).style.backgroundPosition = "0 0"; 588 } 589} 590 591 592 593 594//////////////////////////////////////////////////////////////////////////////////// 595// QUICK VIEW 596// EXISTING 597 598function addToCartOptions(pid, status) { 599 600 if (!$('#quickShop_'+pid).html()) { 601 602 $('#quickShop_'+pid).html('<center><img width="32" height="32" border="0" src="https://www.adagio.com/images4/wait_icon.gif"></center>'); 603 604 // GENERATE QUICK CART 605 $.ajax({ 606 type: "POST", 607 url: "/ajax/quick_add_skus.html", 608 data: "pid=" + pid, 609 success: function(msg){ 610 $('#quickShop_'+pid).html(msg); 611 } 612 }); 613 614 } 615 616 // DISPLAY 617 if (document.getElementById('productIndex_'+pid).style.top != "-80px") { 618 $('#productIndex_'+pid).animate({ top: '-80px' }, 500); 619 $('#productIndexButton_'+pid).animate({ top: '100px' }, 500); 620 document.getElementById('productIndexButton_'+pid).style.backgroundPosition = "center bottom"; 621 $('#productIndexSocial_'+pid).animate({ height: 'hide' }, 500); 622 $('#imageLink_'+pid).css('height', '45px'); 623 $('#imageLinkDiv_'+pid).css('top', '210px'); 624 $('#quickshop_button_'+pid).html(' close '); 625 } else { 626 $('#productIndex_'+pid).animate({ top: '0' }, 500); 627 $('#productIndexButton_'+pid).animate({ top: '20px' }, 500); 628 document.getElementById('productIndexButton_'+pid).style.backgroundPosition = "center top"; 629 $('#productIndexSocial_'+pid).animate({ height: 'show' }, 500); 630 $('#imageLink_'+pid).css('height', '200px'); 631 $('#imageLinkDiv_'+pid).css('top', '55px'); 632 $('#quickShop_'+pid).html(''); 633 $('#quickshop_button_'+pid).html('quick shop'); 634 } 635 636} 637 638 639 640//////////////////////////////////////////////////////////////////////////////////// 641// AUTO DELIVERY 642// EXISTING 643 644function toggleAutoDelivery(state) { 645 646 if (state == "on") { 647 648 autoDeliveryState = 1; 649 650 $('#autoDeliveryHeader') 651 .css({ display: 'flex', opacity: 0, height: 0, overflow: 'hidden' }) 652 .animate({ opacity: 1, height: $('#autoDeliveryHeader')[0].scrollHeight }, 500, function() { 653 $(this).css('height', ''); // reset to auto 654 }); 655 //$('#autoDeliveryFooter').animate({ height: 'show', opacity: 'show' }, 500); 656 $('#autoDeliveryDiv').animate({ height: 'hide', opacity: 'hide' }, 500); 657 658 var x = document.getElementsByClassName("autoDeliverable0"); 659 var i; 660 for (i = 0; i < x.length; i++) { 661 x[i].style.display = "none"; 662 } 663 664 var x = document.getElementsByClassName("addToCart"); 665 var i; 666 for (i = 0; i < x.length; i++) { 667 x[i].style.display = "none"; 668 } 669 670 var x = document.getElementsByClassName("addToWishlist"); 671 var i; 672 for (i = 0; i < x.length; i++) { 673 x[i].style.display = "none"; 674 } 675 676 var x = document.getElementsByClassName("addToAutoDelivery"); 677 var i; 678 for (i = 0; i < x.length; i++) { 679 x[i].style.display = "block"; 680 } 681 682 } 683 684 if (state == "off") { 685 686 autoDeliveryState = 0; 687 688 $('#autoDeliveryHeader').animate({ height: 'hide', opacity: 'hide' }, 500); 689 //$('#autoDeliveryFooter').animate({ height: 'hide', opacity: 'hide' }, 500); 690 $('#autoDeliveryDiv').animate({ height: 'show', opacity: 'show' }, 500); 691 692 var x = document.getElementsByClassName("autoDeliverable0"); 693 var i; 694 for (i = 0; i < x.length; i++) { 695 x[i].style.display = "block"; 696 } 697 698 var x = document.getElementsByClassName("addToCart"); 699 var i; 700 for (i = 0; i < x.length; i++) { 701 x[i].style.display = "block"; 702 } 703 704 705 706 var x = document.getElementsByClassName("addToAutoDelivery"); 707 var i; 708 for (i = 0; i < x.length; i++) { 709 x[i].style.display = "none"; 710 } 711 712 } 713 714} 715 716 717//////////////////////////////////////////////////////////////////////////////////// 718// TOGGLE FAVORITE 719// EXISTING 720 721function toggleFavorite(pid) { 722 723 $.ajax({ 724 type: "POST", 725 url: "/ajax/toggle_favorite.html", 726 data: "pid=" + pid, 727 success: function(msg){ 728
729 var result = msg.split("***SPLIT***"); 730 731 if (result[0] == 1) { 732 document.getElementById('favorite_'+pid).classList.remove('faveOff'); 733 document.getElementById('favorite_'+pid).classList.add('faveOn'); 734 statusMessage("favorite added",0,0); 735 } else { 736 document.getElementById('favorite_'+pid).classList.remove('faveOn'); 737 document.getElementById('favorite_'+pid).classList.add('faveOff'); 738 statusMessage("favorite removed",0,0); 739 } 740 741 } 742 }); 743 744} 745 746function toggleFavoriteRecipe(id) { 747 748 $.ajax({ 749 type: "POST", 750 url: "/ajax/toggle_favorite_recipe.html", 751 data: "id=" + id, 752 success: function(msg){ 753 754 var result = msg.split("***SPLIT***"); 755 756 if (result[0] == 1) { 757 document.getElementById('favorite_'+id).classList.remove('faveOff'); 758 document.getElementById('favorite_'+id).classList.add('faveOn'); 759 statusMessage("favorite added",0,0); 760 } else { 761 document.getElementById('favorite_'+id).classList.remove('faveOn'); 762 document.getElementById('favorite_'+id).classList.add('faveOff'); 763 statusMessage("favorite removed",0,0); 764 } 765 766 } 767 }); 768 769} 770 771 772 773 774 775 776 777//////////////////////////////////////////////////////////////////////////////////// 778// ADD TO CART 779// ALL 780 781cartStatus = 0; 782function addToCart(pid, hash, qty = 1) { 783 784 if (autoDeliveryState == 0) { 785 786 if (qty <= 1){qty = 1} 787 788 console.log(pid); 789 console.log(qty); 790 791 $.ajax({ 792 type: "POST", 793 url: "/ajax/add_to_cart.html", 794 data: "pid=" + pid + "&hash=" + hash + "&qty=" + qty, 795 success: function(msg){ 796 797 console.log(msg); 798 799 var result = msg.split("***SPLIT***"); 800 var prodid = result[0].trim(); 801 var prodidFull = result[8].trim(); 802 803 openCart(); 804 refreshCart(pid); 805 setTimeout(function() {closeCart();},3000); 806 807 // UPDATE CART QTY 808 document.getElementById("cartDivDiv").innerHTML = result[6]; // old cart div id 809 //document.getElementById("headerCart").innerHTML = result[6]; 810 811 // GOOGLE ANALYTICS 812 window.dataLayer.push({ ecommerce: null }); 813 window.dataLayer.push({'event': 'addToCart','ecommerce': { 814 'items': [{'item_name': result[9], 'item_id': prodid, 'price': parseFloat(result[4]), 'item_category': result[2], 'quantity': 1, 'item_variant': result[3], 'item_brand': 'selefina', 'item_name_full': result[1], 'item_id_full': prodidFull}] 815 } }); 816 817 console.log(result[2]); 818 819 //window.sessionRewind.logEvent("AddToCart", { type: "AddToCart", data: { item_id: prodid } }); 820 821 // PINTEREST ANALYTICS 822 //pintrk('track', 'AddToCart', {'value': parseFloat(result[4]), 'currency': 'USD'}); 823 pintrk('track', 'AddToCart', {'value': parseFloat(result[4]), 'currency': 'USD', 'line_items': [ { 'product_name': result[1], 'product_id': pid, 'product_price': parseFloat(result[4]), 'product_category': result[7], 'product_quantity': 1 }] }); 824 825 826 //gtag('event', 'add_to_cart', { ecomm_pagetype: 'cart' }); 827 // REMOVED 9/3/25 828 //ga('ec:addProduct', {'id': result[0], 'name': result[1], 'category': result[2], 'variant': result[3], 'metric2': result[4] }); 829 //ga('ec:setAction', 'add'); 830 //ga('send', 'event', 'UX', 'click', 'add to cart'); 831 832 // FACEBOOK ANALYTICS 833 //fbq('track', 'AddToCart', {'value': result[4], 'currency': 'USD'}); 834 835 836 837 // SEGMENT 838 //analytics.track('AddToCart', {'value': parseFloat(result[4]), 'currency': 'USD'}); 839 840 } 841 }); 842 843 } else { 844 845 $.ajax({ 846 type: "POST", 847 url: "/ajax/auto_delivery_modify.html", 848 //data: "action=add&productId=" + pid + "&frequency=" + document.getElementById("auto_delivery_timeframe").value, 849 data: "action=add&productId=" + pid + "&frequency=60", 850 success: function(msg){ 851 // window.location.assign("/pages/shopping_cart.html"); 852 statusMessage("This item has been added to your auto delivery", 0, 0); 853 $('#autoDeliveryFooter').animate({height: 'show', opacity: 'show'}, 250); 854 document.getElementById('auto_delivery_'+pid).style.backgroundPosition = "-398px -100px"; 855 } 856 }); 857 858 } 859 860} 861 862 863 864 865 866//////////////////////////////////////////////////////////////////////////////////// 867// SHOPPING CART 868// ALL 869 870function openCart() { 871 cartStatus = 1; 872 $('#shoppingCartDiv').animate({ opacity: 'show' }, 250); 873 $('#overlayMatte').animate({ opacity: 'show' }, 250); 874 document.body.style.overflow="hidden"; 875} 876 877function refreshCart(pid) { 878 879 $.ajax({ 880 type: "POST", 881 headers: { "cache-control": "no-cache" }, 882 url: "/ajax/refresh_cart.html", 883 success: function(msg){
884 result = msg.split("***SPLIT***"); 885 $('#shoppingCartDiv').html(result[0]); 886 $('#checkoutButton').html(result[1]); 887 $('#checkoutButtonOn').html(result[1]); 888 $('#checkoutButtonMobile').html(result[2]); 889// $("#cartScroll").scrollTop($("#cartScroll")[0].scrollHeight); 890 hilightCartItem(pid); 891 // set focus to the first element in the profile 892 document.getElementById('shoppingCartDiv').querySelector('button, a, input, [tabindex="0"]').focus(); 893 } 894 }); 895 896} 897 898function hilightCartItem(pid) { 899 900 // Ensure 'pid' is a string and check its length 901 if (!pid || String(pid).length !== 9) { 902 return; 903 } 904 905 var element = $('#pidDiv_' + pid); 906 if (element.length) { 907 // Apply the transition property for smooth transitions 908 element.css('transition', 'background-color 0.5s ease'); 909 910 setTimeout(function() { 911 element.css('background-color', '#d5d7d3'); 912 }, 200); 913 914 // After an additional 1 second (500ms animation + 500ms delay), change the color back 915 setTimeout(function() { 916 element.css('background-color', 'rgba(0,0,0,0)'); 917 }, 1200); // 1 second delay + 1 second for first color change 918 } 919} 920 921 922function closeCart() { 923 cartStatus = 0; 924 925 //document.getElementById('shoppingCartDiv').style.display = "none"; 926 $('#shoppingCartDiv').animate({ opacity: 'hide' }, 250); 927 $('#overlayMatte').animate({ opacity: 'hide' }, 250); 928 document.body.style.overflow="auto"; 929 930} 931 932function toggleCart() { 933 934 if (cartStatus) { 935 closeCart(); 936 } else { 937 openCart(); 938 } 939 940} 941 942function updatePidStatus(uniqueId) { 943 944 // document.getElementById('status_'+uniqueId).innerHTML = "<input type='checkbox' disabled>"; 945 946 $.ajax({ 947 type: "POST", 948 headers: { "cache-control": "no-cache" }, 949 url: "/ajax/update_pid_status.html", 950 data: "uniqueId=" + uniqueId, 951 success: function(msg){ 952 result = msg.split("***SPLIT***"); 953 document.getElementById('status_'+uniqueId).innerHTML = result[0]; 954 document.getElementById('itemCount').innerHTML = result[2]; 955 document.getElementById('subtotal').innerHTML = result[3]; 956 if (document.getElementById("shipping")) { 957 document.getElementById('shipping').innerHTML = result[4]; 958 } 959 if (document.getElementById("total")) { 960 document.getElementById('total').innerHTML = result[5]; 961 } 962 document.getElementById('cartDivDiv').innerHTML = result[1]; 963 // UPDATE PUDDLE 964 if (result[6] == 1) { 965 document.getElementById('puddle_'+uniqueId).classList.remove("cartItemDisabled"); 966 } else { 967 document.getElementById('puddle_'+uniqueId).classList.add("cartItemDisabled"); 968 } 969 } 970 }); 971 972} 973 974 975function modifyQty(uniqueId, action) { 976 977 $.ajax({ 978 type: "POST", 979 headers: { "cache-control": "no-cache" }, 980 url: "/ajax/update_cart_qty.html", 981 data: { 982 uniqueId: uniqueId, 983 action: action, 984 }, 985 dataType: "json", 986 success: function(response){ 987 document.getElementById('itemCount').innerHTML = response.cartCounterNewCopy; 988 document.getElementById('subtotal').innerHTML = "\$" + response.cartSubtotalNew; 989 if (document.getElementById("shipping")) { 990 document.getElementById('shipping').innerHTML = response.shippingcost; 991 } 992 if (document.getElementById("total")) { 993 document.getElementById('total').innerHTML = response.cartTotalNew; 994 } 995 document.getElementById('qty_'+uniqueId).innerHTML = response.qtyCopy; 996 } 997 }); 998 999} 1000 1001//////////////////////////////////////////////////////////////////////////////////// 1002// VIEW PROFILE 1003// ALL 1004 1005function viewProfile(uid, name, icon, section) { 1006 1007 $('#shoppingCartDiv').animate({ opacity: 'show' }, 250); 1008 $('#overlayMatte').animate({ opacity: 'show' }, 250); 1009 1010 if (icon.match(/jpg/g)) { 1011 $('#shoppingCartDiv').html("<div style='height:calc(100% - 65px);overflow:auto;text-align:left;'><div style='position:fixed;z-index:10;width:100%;'><div style='background-color:#eee;'><div style='height:50px;font-size:14px;background-color:#fff;width:33%;min-width:320px;'><div class='pointer' style='float:left;width:20%;height:50px;border-right:solid 1px #ccc;background-color:#db9034;color:#fff;'><div style='padding-top:15px;text-align:center;'> Profile </div></div><div class='pointer' style='float:left;width:20%;height:50px;border-right:solid 1px #ccc;color:#666;'><div style='padding-top:15px;text-align:center;'> Reviews </div></div><div class='pointer' style='float:left;width:20%;height:50px;border-right:solid 1px #ccc;color:#666;'><div style='padding-top:15px;text-align:center;'> Friends </div></div><div class='pointer' style='float:left;width:25%;height:50px;border-right:solid 1px #ccc;color:#666;'><div style='padding-top:15px;text-align:center;'> Messages </div></div><div class='pointer' style='float:left;width:10%;height:50px;' onclick='stopVideo();return false;'><div style='padding-top:15px;text-align:center;'><div class='closeDark' style='float:none;top:-5px;left:7px;'></div></div></div></div><div style='clear:both;'></div><div style='padding:15px 15px 10px 25px;'><div><div class='reviewBlock'><div class='icon'><img src='//images.adagio.com/images2/icons/"+icon+"' alt='user icon' class='userCircle'></div></div><div class='accountName' style='float:left;text-align:left;padding:18px 15px;'> "+name+" <br><a href='#' style='font-size:13px;color:#db9034;'> VIEW <span class='hide_1280'> FULL </span> PROFILE </a></div></div><div style='clear:both;'></div></div></div><div style='width:100;padding:70px 0 0 70px;'><img src='/images5/wait_200.gif'></div></div></div></div>"); 1012 } else { 1013 $('#shoppingCartDiv').html("<div style='height:calc(100% - 65px);overflow:auto;text-align:left;'><div style='position:fixed;z-index:10;width:100%;'><div style='background-color:#eee;'><div style='height:50px;font-size:14px;background-color:#fff;width:33%;min-width:320px;'><div class='pointer' style='float:left;width:20%;height:50px;border-right:solid 1px #ccc;background-color:#db9034;color:#fff;'><div style='padding-top:15px;text-align:center;'> Profile </div></div><div class='pointer' style='float:left;width:20%;height:50px;border-right:solid 1px #ccc;color:#666;'><div style='padding-top:15px;text-align:center;'> Reviews </div></div><div class='pointer' style='float:left;width:20%;height:50px;border-right:solid 1px #ccc;color:#666;'><div style='padding-top:15px;text-align:center;'> Friends </div></div><div class='pointer' style='float:left;width:25%;height:50px;border-right:solid 1px #ccc;color:#666;'><div style='padding-top:15px;text-align:center;'> Messages </div></div><div class='pointer' style='float:left;width:10%;height:50px;' onclick='stopVideo();return false;'><div style='padding-top:15px;text-align:center;'><div class='closeDark' style='float:none;top:-5px;left:7px;'></div></div></div></div><div style='clear:both;'></div><div style='padding:15px 15px 10px 25px;'><div><div class='reviewBlock'><div class='icon'><div style='background-color: hsl(35, 90%, "+icon+"%);' class='userCircle'><div>"+uid.replace(/\d/g,'')+"</div></div></div></div><div class='accountName' style='float:left;text-align:left;padding:18px 15px;'> "+name+" <br><a href='#' style='font-size:13px;color:#db9034;'> VIEW <span class='hide_1280'> FULL </span> PROFILE </a></div></div><div style='clear:both;'></div></div></div><div style='width:100;padding:70px 0 0 70px;'><img src='/images5/wait_200.gif'></div></div></div></div>"); 1014 } 1015 1016 $.ajax({ 1017 type: "POST", 1018 headers: { "cache-control": "no-cache" }, 1019 url: "/ajax/view_profile.html", 1020 data: "uid=" + uid + "§ion=" + section, 1021 success: function(msg){
1022 result = msg.split("***SPLIT***"); 1023 $('#shoppingCartDiv').html(result[0]); 1024 document.body.style.overflow="hidden"; 1025 if (section) { 1026 profile(section); 1027 } 1028 } 1029 }); 1030 1031} 1032 1033 1034function profile(section) { 1035 1036 document.getElementById('profile_profile').style.display = "none"; 1037 document.getElementById('profile_reviews').style.display = "none"; 1038 document.getElementById('profile_friends').style.display = "none"; 1039 document.getElementById('profile_messages').style.display = "none"; 1040 if (document.getElementById("profile_communiTEA")) { 1041 document.getElementById('profile_communiTEA').style.display = "none"; 1042 } 1043 1044 document.getElementById('profileHeader_profile').style.backgroundColor = "#fff"; 1045 document.getElementById('profileHeader_reviews').style.backgroundColor = "#fff"; 1046 document.getElementById('profileHeader_friends').style.backgroundColor = "#fff"; 1047 document.getElementById('profileHeader_messages').style.backgroundColor = "#fff"; 1048 if (document.getElementById("profileHeader_communiTEA")) { 1049 document.getElementById('profileHeader_communiTEA').style.backgroundColor = "#fff"; 1050 } 1051 1052 document.getElementById('profileHeader_profile').style.color = "#666"; 1053 document.getElementById('profileHeader_reviews').style.color = "#666"; 1054 document.getElementById('profileHeader_friends').style.color = "#666"; 1055 document.getElementById('profileHeader_messages').style.color = "#666"; 1056 if (document.getElementById("profileHeader_communiTEA")) { 1057 document.getElementById('profileHeader_communiTEA').style.color = "#666"; 1058 } 1059 1060 document.getElementById('profile_'+section).style.display = "block"; 1061 document.getElementById('profileHeader_'+section).style.backgroundColor = "#db9034"; 1062 document.getElementById('profileHeader_'+section).style.color = "#fff"; 1063 1064} 1065 1066//////////////////////////////////////////////////////////////////////////////////// 1067// VIEW PROFILE 1068// EXISTING 1069 1070function removeFriendQuickProfile (friendId) { 1071 1072 $.ajax({ 1073 type: "POST", 1074 url: "/ajax/remove_friend.html", 1075 data: "friendId=" + friendId, 1076 success: function(msg){ 1077 var result = msg.split("***SPLIT***"); 1078 statusMessage(result[0], 0, 0); 1079 } 1080 }); 1081 1082} 1083 1084 1085function addNewFriendQuickProfile (friendId) { 1086 1087 $.ajax({ 1088 type: "POST", 1089 url: "/ajax/add_friend.html", 1090 data: "friendId=" + friendId, 1091 success: function(msg){ 1092 var result = msg.split("***SPLIT***"); 1093 statusMessage(result[0], 0, 0); 1094 } 1095 }); 1096 1097} 1098 1099 1100 1101//////////////////////////////////////////////////////////////////////////////////// 1102// UNKNOWN 1103 1104function modifyCyclicalShoppingCart(action, productId, frequency) { 1105 1106 $.ajax({ 1107 type: "POST", 1108 url: "/ajax/auto_delivery_modify.html", 1109 data: "action=" + action + "&productId=" + productId + "&frequency=" + frequency, 1110 success: function(msg){ 1111 window.location.assign("/pages/shopping-cart.html"); 1112 } 1113 }); 1114 1115} 1116 1117
1118//////////////////////////////////////////////////////////////////////////////////// 1119// ADD TO AUTO DELIVERY 1120// EXISTING 1121 1122function addToAutoDelivery() { 1123 1124 $.ajax({ 1125 type: "POST", 1126 url: "/ajax/add_to_auto_delivery.html", 1127 success: function(msg){ 1128 var result = msg.split("**SPLIT**"); 1129 if (result[0] >= 1) { 1130 statusMessage(result[1], 0, 0); 1131 toggleCart(); 1132 refreshCart(); 1133 } else { 1134 statusMessage(result[1], 0, 1); 1135 } 1136 } 1137 }); 1138 1139} 1140 1141 1142 1143//////////////////////////////////////////////////////////////////////////////////// 1144// SORT INDEX PAGE PRODUCTS 1145// ALL 1146 1147function sortCategory(category, subCategory, sort) { 1148 1149 $('#sortCategoryWaitIcon').css('display', 'block'); 1150 1151 $.ajax({ 1152 type: "POST", 1153 url: "/ajax/sort_category.html", 1154 data: "category=" + category + "&sort=" + sort + "&subCategory=" + subCategory, 1155 success: function(msg){ 1156 result = msg.split("***SPLIT***"); 1157 $('#sortDivTemp').html(result[0]); 1158 $('#sortDiv').quicksand( $('#sortDivTemp > div') ); 1159 $('#sortCategoryWaitIcon').css('display', 'none'); 1160 $('#sortDivTemp').html(""); 1161 } 1162 }); 1163 1164} 1165 1166 1167function changeSortBy(id, sortByUpdate) { 1168 1169 console.log("load reviews"); 1170 console.log(id); 1171 console.log(sortByUpdate); 1172 1173 $('#reviewsDiv').html("<div class='loading' style='height:400px;text-align:center;'><div style='clear:both;'></div><img width='32' height='32' border='0' src='https://www.adagio.com/images4/wait_icon.gif' alt='wait icon'></div>"); 1174 1175 $.ajax({ 1176 type: "POST", 1177 url: "/ajax/load_reviews_recipes.html", 1178 data: "reviewCounter=0&teaId=" + id + "&reviewLoad=6&sortByUpdate=" + sortByUpdate, 1179 success: function(msg){ 1180 console.log(msg); 1181 results = msg.split("***SPLIT***"); 1182 $('#reviewsDiv').scrollTop(0); 1183 $('#reviewsDiv').html(results[0]); 1184 } 1185 }); 1186 reviewCounter = 6; 1187 1188} 1189 1190 1191//////////////////////////////////////////////////////////////////////////////////// 1192// SORT BY 1193function sortBy(method) { 1194 1195 var container = document.getElementById("filterDiv"); 1196 var divs = container.querySelectorAll(".sortableDiv"); 1197 1198 var sortedDivs = Array.from(divs).sort(function(a, b) { 1199 1200 var orderA; 1201 var orderB; 1202 1203 if (method == "alphabetical") { 1204 // Check if the items are sets 1205 var isSetA = a.classList.contains('anchor-SETS'); 1206 var isSetB = b.classList.contains('anchor-SETS'); 1207 1208 // Force sets to the bottom 1209 if (isSetA && !isSetB) return 1; 1210 if (!isSetA && isSetB) return -1; 1211 1212 // If both are sets or both are not sets, sort alphabetically 1213 orderA = a.dataset.alphabetical.toLowerCase(); 1214 orderB = b.dataset.alphabetical.toLowerCase(); 1215 if (orderA < orderB) return -1; 1216 if (orderA > orderB) return 1; 1217 return 0; 1218 } 1219 1220 if (method == "sellers") { 1221 orderA = parseInt(a.dataset.sellers); 1222 orderB = parseInt(b.dataset.sellers); 1223 return orderB - orderA; 1224 } 1225 1226 if (method == "releases") { 1227 orderA = parseInt(a.dataset.releases); 1228 orderB = parseInt(b.dataset.releases); 1229 return orderB - orderA; 1230 } 1231 1232 if (method == "rated") { 1233 orderA = parseInt(a.dataset.rated); 1234 orderB = parseInt(b.dataset.rated); 1235 return orderB - orderA; 1236 } 1237 1238 }); 1239 1240 sortedDivs.forEach(function(div) { 1241 container.appendChild(div); 1242 }); 1243 1244 if (document.getElementById("jumpTo")) { 1245 if (method == "alphabetical") { 1246 document.getElementById('jumpTo').style.display = "flex"; 1247 } else { 1248 document.getElementById('jumpTo').style.display = "none"; 1249 } 1250 } 1251 1252 $.ajax({ 1253 type: "POST", 1254 url: "/ajax/update_sort_method.html", 1255 data: "sort=" + method, 1256 success: function(msg){ 1257 console.log(msg); 1258 } 1259 }); 1260 1261} 1262 1263 1264//////////////////////////////////////////////////////////////////////////////////// 1265// TOP HEADER LINKS 1266// EXISTING 1267 1268function showPointsOptions() { 1269 1270 $('#overlayMatte').animate({ opacity: 'show' }, 250); 1271 1272// if (!$('#pointsContent').html()) { 1273 1274 $('#pointsContent').html('<center><img width="32" height="32" border="0" src="/images4/wait_icon.gif"></center>'); 1275 1276 $.ajax({ 1277 type: "POST", 1278 url: "/ajax/view_points_options.html", 1279 success: function(msg){ 1280 result = msg.split("***SPLIT***"); 1281 $('#pointsContent').html(result[0]); 1282 } 1283 }); 1284// } 1285 document.getElementById('pointsContent').style.display = "block"; 1286 document.getElementById('pointsContent').style.height = ($(window).height() - 125) + "px"; 1287 console.log($(window).height()); 1288 $('#pointsContent').animate({height: 'show'}, 500); 1289 1290} 1291 1292function showNotes() { 1293 1294 $('#overlayMatte').animate({ opacity: 'show' }, 250); 1295 1296 if (!$('#notesContent').html()) { 1297 1298 $('#notesContent').html('<center><br><br><img width="32" height="32" border="0" src="/images4/wait_icon.gif"></center>'); 1299 1300 $.ajax({ 1301 type: "POST", 1302 url: "/ajax/view_notes_2017.html", 1303 success: function(msg){
1304 result = msg.split("***SPLIT***"); 1305 $('#notesContent').html(result[0]); 1306 } 1307 }); 1308 } 1309 document.getElementById('notesContent').style.display = "block"; 1310 document.getElementById('notesContent').style.height = ($(window).height() - 125) + "px"; 1311 console.log($(window).height()); 1312 $('#notesContent').animate({height: 'show'}, 500); 1313 1314} 1315 1316 1317//////////////////////////////////////////////////////////////////////////////////// 1318// STATUS & DEBUG 1319// ALL 1320 1321function statusMessage(msg, timer, warning) { 1322 1323 if (timer == 0) { 1324 timer = msg.length * 50; 1325 } 1326 1327 if (warning) { 1328 $("#statusMessage").addClass("statusMessageWarning"); 1329 } else { 1330 $("#statusMessage").removeClass("statusMessageWarning"); 1331 } 1332 1333 $('#statusMessage').dequeue(); 1334 $('#statusMessage').css('bottom','0'); 1335 $('#statusMessage').html(msg); 1336 1337 $( "#statusMessage" ) 1338 .animate({ bottom: '75px', opacity: 'show' }, 500 ) 1339 .delay(timer) 1340 .animate({ bottom: '150px', opacity: 'hide' }, 500 ); 1341 1342} 1343 1344 1345function debug (page, action, error, tempOne, tempTwo, tempThree) { 1346 1347 $.ajax({ 1348 type: "POST", 1349 url: "../ajax/debug.html", 1350 data: "page=" + page + "&action=" + action + "&error=" + error + "&tempOne=" + tempOne + "&tempTwo=" + tempTwo + "&tempThree=" + tempThree, 1351 success: function(msg){ 1352 1353 } 1354 }); 1355 1356} 1357 1358 1359//////////////////////////////////////////////////////////////////////////////////// 1360// ADD BADGE 1361// ALL 1362 1363function addBadge (badgeDirId, badgeCounter, userId, message, noteType, noteTypeId) { 1364 1365 $.ajax({ 1366 type: "POST", 1367 url: "../ajax/add_badge.html", 1368 data: "badgeDirId=" + badgeDirId + "&badgeCounter=" + badgeCounter + "&userId=" + userId, 1369 success: function(msg){ 1370 1371 if (message) { 1372 statusMessage(message, 0, 0); 1373 } 1374 1375 if (noteType) { 1376 1377 $.ajax({ 1378 type: "POST", 1379 url: "../ajax/add_note.html", 1380 data: "userId=" + userId + "¬eType=" + noteType + "¬eTypeId=" + noteTypeId, 1381 success: function(msg){ 1382 1383 } 1384 }); 1385 1386 } 1387 1388 } 1389 }); 1390 1391} 1392 1393 1394 1395//////////////////////////////////////////////////////////////////////////////////// 1396// UPDATE FAVORITES 1397// EXISTING 1398 1399function updateFavorites(pid) { 1400 1401 $.ajax({ 1402 type: "POST", 1403 url: "../ajax/updateFavorites.html", 1404 data: "pid=" + pid, 1405 success: function(msg){ 1406 result = msg.split("***SPLIT***"); 1407 // document.getElementById('favoritesButton').innerHTML = result[0]; 1408 } 1409 }); 1410 1411} 1412 1413 1414 1415//////////////////////////////////////////////////////////////////////////////////// 1416// MODIFY WISHLIST 1417// EXISTING 1418 1419function modifyWishlist(productId, extra, quantity) { 1420 1421 $.ajax({ 1422 type: "POST", 1423 url: "/ajax/wishlist_modify.html", 1424 data: "productId=" + productId + "&extra=" + extra + "&quantity=" + quantity, 1425 success: function(msg){ 1426 1427 console.log(msg); 1428 1429 result = msg.split("***SPLIT***"); 1430 1431 if (result[3] == 1) { 1432 document.getElementById('addToWishlist').classList.remove('wishOff'); 1433 document.getElementById('addToWishlist').classList.add('wishOn'); 1434 } else { 1435 document.getElementById('addToWishlist').classList.remove('wishOn'); 1436 document.getElementById('addToWishlist').classList.add('wishOff'); 1437 } 1438 1439 statusMessage(result[0], 0, 0); 1440 1441 } 1442 }); 1443 1444} 1445 1446function modifyWishlistBottom(productId, extra, quantity) { 1447 1448 $.ajax({ 1449 type: "POST", 1450 url: "/ajax/wishlist_modify.html", 1451 data: "productId=" + productId + "&extra=" + extra + "&quantity=" + quantity, 1452 success: function(msg){ 1453 1454 result = msg.split("***SPLIT***"); 1455 1456 if (result[3] == 1) { 1457 document.getElementById('addToWishlistBottom').classList.remove('wishOffBottom'); 1458 document.getElementById('addToWishlistBottom').classList.add('wishOnBottom'); 1459 document.getElementById('addToWishlistBottom').innerHTML = "REMOVE FROM WISHLIST"; 1460 } else { 1461 document.getElementById('addToWishlistBottom').classList.remove('wishOnBottom'); 1462 document.getElementById('addToWishlistBottom').classList.add('wishOffBottom'); 1463 document.getElementById('addToWishlistBottom').innerHTML = "ADD TO WISHLIST"; 1464 } 1465 1466 statusMessage(result[0], 0, 0); 1467 1468 } 1469 }); 1470 1471} 1472 1473 1474 1475//////////////////////////////////////////////////////////////////////////////////// 1476// POST MESSAGE 1477// ALL 1478 1479function postMsg(recipientUserId, message, teaReference, publicPermission, privatePermission) { 1480 1481 // FIX VARIOUS COPY ISSUES 1482 message = encodeURIComponent(message); 1483 1484 $('#msgPlaceholder').animate({ height: 'hide' }, 'fast'); 1485 1486 $.ajax({ 1487 type: "POST", 1488 url: "/ajax/add_message.html", 1489 data: "recipientUserId=" + recipientUserId + "&message=" + message + "&teaReference=" + teaReference + "&publicPermission=" + publicPermission + "&privatePermission=" + privatePermission, 1490 success: function(msg){
1491 var result = msg.split("***SPLIT***"); 1492 if (result[0]) { 1493// document.getElementById('msgPlaceholder').innerHTML = result[1]; 1494// $('#msgPlaceholder').animate({ height: 'show' }, 'fast'); 1495// $('#msgDottedLine').animate({ height: 'hide' }, 'fast'); 1496 if (document.getElementById("messageCopyProfile")) { 1497 document.getElementById('messageCopyProfile').value = ""; 1498 } 1499 if (document.getElementById("messageCopy")) { 1500 document.getElementById('messageCopy').value = ""; 1501 } 1502 statusMessage(result[0], 0, 0); 1503 } 1504 } 1505 }); 1506 1507} 1508 1509//////////////////////////////////////////////////////////////////////////////////// 1510// SEND GIFT 1511// EXISTING 1512 1513function giveGiftPreview (id, image, cartCopy, pointsCost) { 1514 $('#giftGenericImage').animate({ height: 'hide' }, 250); 1515 $('#giftsList').animate({ height: 'hide' }, 500); 1516 $('#giftsDetail').animate({ height: 'show' }, 500); 1517 $('[name=giftsPid]').val(id); 1518 document.getElementById('giftsImage').src = image; 1519 document.getElementById('giftsName').innerHTML = cartCopy; 1520 if (pointsCost >= 1) { 1521 document.getElementById('giftsFinePrint').innerHTML = "this will deduct "+pointsCost+"<br>points from your account"; 1522 } else { 1523 document.getElementById('giftsFinePrint').innerHTML = "you may sent this gift for FREE"; 1524 } 1525} 1526 1527function giveGift (recipient, giftsNote) { 1528 1529 $.ajax({ 1530 type: "POST", 1531 url: "/ajax/send_gift.html", 1532 data: "recipient=" + recipient + "&giftsPid=" + $('[name=giftsPid]').val() + "&giftsNote=" + giftsNote, 1533 success: function(msg){ 1534 var result = msg.split("***SPLIT***"); 1535 if (result[0] == 1) { 1536 statusMessage(result[1], 0, 1); 1537 } else { 1538 statusMessage("Thanks. Your gift has been sent.", 0, 0); 1539 $('#giftsDiv').animate({ height: 'hide' }, 500); 1540 } 1541 } 1542 }); 1543 1544} 1545 1546 1547
1548//////////////////////////////////////////////////////////////////////////////////// 1549// EDIT PROFILE 1550// EXISTING 1551 1552function profile_edit_bio(bio) { 1553 1554 bio = encodeURIComponent(bio); 1555 1556 $.ajax({ 1557 type: "POST", 1558 url: "/ajax/profile_edit_bio.html", 1559 data: "bio=" + bio, 1560 success: function(msg){ 1561 var result = msg.split("***SPLIT***"); 1562 if (result[0]) { 1563 document.getElementById('bioPassive').innerHTML = result[0]; 1564 $('#bioPassiveDiv').animate({ height: 'show' }, 'fast'); 1565 $('#bioDynamicDiv').animate({ height: 'hide' }, 'fast'); 1566 statusMessage("You have updated your bio.", 0, 0); 1567 } 1568 } 1569 }); 1570 1571} 1572 1573 1574//////////////////////////////////////////////////////////////////////////////////// 1575// PLAY VIDEO 1576// ALL 1577 1578function playVideo (id) { 1579 $('#overlayMatte').animate({ opacity: 'show' }, 500); 1580 document.getElementById('overlayDiv').style.display = "block"; 1581 $("#frame").attr("src", "https://www.youtube.com/embed/"+ id +"?rel=0&autoplay=1"); 1582} 1583 1584function stopVideo () { 1585 1586 $('#overlayMatte').animate({ opacity: 'hide' }, 500); 1587 document.getElementById('overlayDiv').style.display = "none"; 1588 1589 // VIDEO FRAME 1590 $("#frame").attr("src", ""); 1591 1592 // NEWSFEED 1593 if (document.getElementById("notesContent")) { 1594 document.getElementById('notesContent').style.display = "none"; 1595 } 1596 1597 // EARN POINTS 1598 if (document.getElementById("pointsContent")) { 1599 document.getElementById('pointsContent').style.display = "none"; 1600 } 1601 1602 // CART PREVIEW 1603 if (document.getElementById("shoppingCartDiv")) { 1604 document.getElementById('shoppingCartDiv').style.display = "none"; 1605 } 1606 1607 // INSTANT COUPON 1608 if (document.getElementById("instantCouponDiv")) { 1609 document.getElementById('instantCouponDiv').style.display = "none"; 1610 } 1611 1612 // SB DETAILS 1613 if (document.getElementById("designer_artwork")) { 1614 document.getElementById('designer_artwork').style.display = "none"; 1615 } 1616 1617 // INTERNATIONAL INVITE 1618 if (document.getElementById("internationalInviteDiv")) { 1619 document.getElementById('internationalInviteDiv').style.display = "none"; 1620 } 1621 1622 // JOIN MAILING LIST 1623 if (document.getElementById("joinMailingListDiv")) { 1624 document.getElementById('joinMailingListDiv').style.display = "none"; 1625 } 1626 1627 // MISC POPUP 1628 if (document.getElementById("miscPopupDiv")) { 1629 document.getElementById('miscPopupDiv').style.display = "none"; 1630 } 1631 1632 // VOTE 2017 POPUP 1633 if (document.getElementById("vote2017Div")) { 1634 document.getElementById('vote2017Div').style.display = "none"; 1635 } 1636 1637 // chatWindowDialog 1638 if (!window.location.href.includes("help.html")) { 1639 if (document.getElementById("chatWindowDialog")) { 1640 document.getElementById('chatWindowDialog').style.display = "none"; 1641 } 1642 } 1643 1644 // GENERIC POPUP 1645 if (document.getElementById("genericPopupDiv")) { 1646 document.getElementById('genericPopupDiv').style.display = "none"; 1647 } 1648 1649 document.body.style.overflow="auto"; 1650 1651} 1652 1653 1654//////////////////////////////////////////////////////////////////////////////////// 1655// INTERNATIONAL INVITE 1656// ALL 1657 1658function internationalInvite() { 1659 $('#overlayMatte').animate({ opacity: 'show' }, 250); 1660} 1661 1662 1663 1664 1665 1666//////////////////////////////////////////////////////////////////////////////////// 1667// INSTANT COUPON 1668// NEW 1669 1670function instantCouponCookie() { 1671 1672 // SET COOKIE 1673 var today = new Date(); 1674 var expire = new Date(); 1675 expire.setTime(today.getTime() + 3600000*24*7); 1676 document.cookie = "instantCoupon="+escape(1) + ";expires="+expire.toGMTString()+";path=/"; 1677 1678} 1679 1680 1681 1682//////////////////////////////////////////////////////////////////////////////////// 1683// MAILING LIST 1684// NEW 1685 1686function joinMailingListOpen() { 1687 document.getElementById('joinMailingListDiv').style.display = "block"; 1688 $('#overlayMatte').animate({ opacity: 'show' }, 250); 1689} 1690 1691function joinMailingListClose() { 1692 document.getElementById('joinMailingListDiv').style.display = "none"; 1693 $('#overlayMatte').animate({ opacity: 'hide' }, 250); 1694} 1695 1696function joinMailingListEmail (email) { 1697 $.ajax({ 1698 type: "POST", 1699 url: "/ajax/join_mailing_list.html", 1700 data: "email=" + email, 1701 success: function(msg){ 1702 console.log(msg); 1703 var result = msg.split("***SPLIT***"); 1704 if (result[0] == 1) { 1705 $('#joinMailingList').animate({ height: 'hide', opacity: 'hide' }, 500); 1706 // statusMessage(result[1], 0, 0); 1707 1708 document.getElementById('genericPopupDiv').innerHTML = result[3]; 1709 1710 document.getElementById('overlayMatte').style.display = 'block'; 1711 document.getElementById('genericPopupDiv').style.display = 'block'; 1712 1713 } else { 1714 statusMessage(result[1], 0, 1); 1715 } 1716 } 1717 }); 1718} 1719 1720 1721 1722 1723 1724//////////////////////////////////////////////////////////////////////////////////// 1725// POST GIFT CERTIFICATE VIA SOCIAL 1726// EXISTING 1727 1728function footerPostGiftCertificateViaPinterest(uri, gcNumber, userId, email, firstName, lastName) { 1729 1730 // GENERATE GIFT CERTIFICATE 1731 $.ajax({ 1732 type: "POST", 1733 url: "/ajax/generate_gc.html",
1734 data: "gcProvided="+gcNumber+"&deliveryMethod=tweet&userId="+userId+"&senderEmail="+email+"&senderFirstName="+firstName+"&senderLastName="+lastName+"&recipientEmail=&recipientFirstName=&recipientLastName=", 1735 success: function(msg){ 1736 window.open("http://www.pinterest.com/pin/create/button/?url=https://www.selefina.com&media=https://www.adagio.com/images5/300x250.jpg&description=Yummy treat! Here is a $5 gift certificate to Selefina: "+gcNumber+". Expires in 24 hours. https://www.selefina.com/","Pinterest","width=500,height=400"); 1737 debug (uri, "Footer: Free GC Pinterest", "Success", "", "", ""); 1738 } 1739 }); 1740} 1741 1742function footerPostGiftCertificateViaTwitter(uri, gcNumber, userId, email, firstName, lastName) { 1743 1744 // GENERATE GIFT CERTIFICATE 1745 $.ajax({ 1746 type: "POST", 1747 url: "/ajax/generate_gc.html", 1748 data: "gcProvided="+gcNumber+"&deliveryMethod=tweet&userId="+userId+"&senderEmail="+email+"&senderFirstName="+firstName+"&senderLastName="+lastName+"&recipientEmail=&recipientFirstName=&recipientLastName=", 1749 success: function(msg){ 1750 window.open("https://www.adagio.com/twitter/tweet_gc.html?message=Yummy treat! Here is a $5 gift certificate to Selefina: "+gcNumber+". Expires in 24 hours. https://www.selefina.com","Twitter","width=500,height=400"); 1751 debug (uri, "Footer: Free GC Twitter", "Success", "", "", ""); 1752 } 1753 }); 1754} 1755 1756function footerPostGiftCertificateViaTumblr(uri, gcNumber, userId, email, firstName, lastName) { 1757 1758 // GENERATE GIFT CERTIFICATE 1759 $.ajax({ 1760 type: "POST", 1761 url: "/ajax/generate_gc.html", 1762 data: "gcProvided="+gcNumber+"&deliveryMethod=tweet&userId="+userId+"&senderEmail="+email+"&senderFirstName="+firstName+"&senderLastName="+lastName+"&recipientEmail=&recipientFirstName=&recipientLastName=&photo=1", 1763 success: function(msg){ 1764// window.open("http://www.tumblr.com/share/link?url=www.adagio.com&name=Adagio Teas&description=Yummy treat! Here is a $5 gift certificate to Adagio Teas: "+gcNumber+". Expires in 24 hours.","Tumblr","width=500,height=400"); 1765 window.open("http://www.tumblr.com/share/photo?source=https%3A%2F%2Fwww.adagio.com/images5/gc/gc_"+gcNumber+".jpg&caption=Yummy treat! Here is a $5 gift certificate to Selefina: "+gcNumber+". Expires in 24 hours.&click_thru=https%3A%2F%2Fwww.selefina.com","Tumblr","width=500,height=400"); 1766 debug (uri, "Footer: Free GC Tumblr", "Success", "", "", ""); 1767 } 1768 }); 1769} 1770 1771function footerPostGiftCertificateViaFacebook(uri, gcNumber, userId, email, firstName, lastName) { 1772 1773 FB.ui({ 1774 method: 'share', 1775 href: 'https://www.selefina.com', 1776 quote: 'Share my addiction with a $5 GC to Selefina, my favorite store for fresh spices: '+gcNumber+'. Good for 24 hours.' 1777 },function(response) { 1778 if (response.error_message) { 1779 1780 debug (uri, "Footer: Free GC Facebook", "Error: Post", "", "", ""); 1781 1782 } else { 1783 1784 // GENERATE GIFT CERTIFICATE 1785 $.ajax({ 1786 type: "POST", 1787 url: "/ajax/generate_gc.html", 1788 data: "gcProvided="+gcNumber+"&deliveryMethod=fbook&userId="+userId+"&senderEmail="+email+"&senderFirstName="+firstName+"&senderLastName="+lastName+"&recipientEmail=&recipientFirstName=&recipientLastName=", 1789 success: function(msg){ 1790 statusMessage('Thank you for sharing this with your friends. When redeemed, we will reward you with 10 Frequent Cup Points.', 0, 0); 1791 debug (uri, "Footer: Free GC Facebook", "Success", "", "", ""); 1792 } 1793 }); 1794 1795 } 1796 }); 1797 1798} 1799 1800function footerPostGiftCertificateFB(uri, gcNumber, userId, email, firstName, lastName) { 1801 1802 FB.api('/me/feed', 'post', { 1803 method: "feed", 1804 name: "Selefina", 1805 link: "https://www.selefina.com", 1806 picture: "https://www.adagio.com/images5/icon_facebook_tea.jpg", 1807 caption: "www.selefina.com", 1808 description: "Fresh spices and 275,000+ customer reviews. If you like spice, you'll love this place!", 1809 message: "Share my addiction with a $5 GC to Selefina, my favorite store for fresh spices: "+gcNumber+". Good for 24 hours." 1810 }, function(response) { 1811 if (!response || response.error) { 1812 debug (uri, "Footer: Free GC Facebook", "Error: Post", "", "", ""); 1813 } else { 1814 1815 // GENERATE GIFT CERTIFICATE 1816 $.ajax({ 1817 type: "POST", 1818 url: "/ajax/generate_gc.html",
1819 data: "gcProvided="+gcNumber+"&deliveryMethod=fbook&userId="+userId+"&senderEmail="+email+"&senderFirstName="+firstName+"&senderLastName="+lastName+"&recipientEmail=&recipientFirstName=&recipientLastName=", 1820 success: function(msg){ 1821 statusMessage('Thank you for sharing this with your friends. When redeemed, we will reward you with 10 Frequent Cup Points.', 0, 0); 1822 debug (uri, "Footer: Free GC Facebook", "Success", "", "", ""); 1823 } 1824 }); 1825 1826 } 1827 }); 1828 1829} 1830 1831function sbPostGiftCertificateViaFacebook(uri, gcNumber, userId, email, firstName, lastName, blendId, blendName, blendDesc) { 1832 1833 FB.getLoginStatus(function(response) { 1834 1835 if (response.status === 'connected') { 1836 1837 // TEST PERMISSION 1838 FB.api('/me/permissions', function (responsePerm) { 1839 1840 var i; 1841 var permission = 0; 1842 for (i = 0; i < responsePerm.data.length; i++) { 1843 if ((responsePerm.data[i].permission == "publish_actions") && (responsePerm.data[i].status == "granted")) { 1844 permission = 1; 1845 } 1846 } 1847 1848 if (permission == 1) { 1849 // PERMISSIONS VALID 1850 sbPostGiftCertificateFB(uri, gcNumber, userId, email, firstName, lastName, blendId, blendName, blendDesc); 1851 } else { 1852 // PERMISSIONS INVALID 1853 // LOG IN 1854 FB.login(function(response) { 1855 if (response.authResponse) { 1856 sbPostGiftCertificateFB(uri, gcNumber, userId, email, firstName, lastName, blendId, blendName, blendDesc); 1857 } else { 1858 debug (uri, "SB: Free GC Facebook", "Error: Permissions", "", "", ""); 1859 statusMessage("Please sign in via Facebook so we may share your blend.", 0, 1); 1860 } 1861 }, {scope:'publish_actions'}); 1862 } 1863 1864 }); 1865 1866 1867 } else { 1868 1869 FB.login(function(response) { 1870 if (response.authResponse) { 1871 sbPostGiftCertificateFB(uri, gcNumber, userId, email, firstName, lastName, blendId, blendName, blendDesc); 1872 } else { 1873 debug (uri, "SB: Free GC Facebook", "Error: Login", "", "", ""); 1874 statusMessage("Please sign in via Facebook so we may share your blend.", 0, 1); 1875 } 1876 }, {scope:'publish_actions'}); 1877 1878 } 1879 1880 }); 1881 1882} 1883 1884 1885 1886 1887 1888//////////////////////////////////////////////////////////////////////////////////// 1889// SOCIAL MEDIA 1890// EXISTING 1891 1892function socialRewardsTwitter(uri, shareCopy, shareCopyTwo, category, url) { 1893 1894 debug (uri, "Twitter: Drink", "Window Opened", "", "", ""); 1895 if (category) { 1896 window.open('http://twitter.com/intent/tweet?text='+shareCopy+' @AdagioTeas '+shareCopyTwo+'&url=https://www.adagio.com/'+category+'/'+url,'Twitter','width=500,height=250'); 1897 } else { 1898 window.open('http://twitter.com/intent/tweet?text='+shareCopy+' @AdagioTeas '+shareCopyTwo+'&url=https://www.adagio.com/'+url,'Twitter','width=500,height=250'); 1899 } 1900} 1901 1902var timelineActive = 0; 1903 1904 1905 1906 1907//////////////////////////////////////////////////////////////////////////////////// 1908// TIMELINE DRINK 1909// EXISTING 1910 1911function socialRewardsFacebookTwo(uri, displayed, description, image) { 1912 1913 debug (uri, "FB Timeline: Drink", "Clicked", uri, displayed, image); 1914 1915 timelineActive = 1; 1916 1917 FB.getLoginStatus(function(response) { 1918 1919 debug (uri, "FB Timeline: Drink", "Connection Test", response.authResponse.accessToken, "", ""); 1920 1921 if (response.status === 'connected') { 1922 1923 token = response.authResponse.accessToken; 1924 1925 debug (uri, "FB Timeline: Drink", "Logged In", "", "", ""); 1926 1927 // TEST PERMISSION 1928 FB.api('/me/permissions', function (responsePerm) { 1929 1930 var i; 1931 var permission = 0; 1932 for (i = 0; i < responsePerm.data.length; i++) { 1933 if ((responsePerm.data[i].permission == "publish_actions") && (responsePerm.data[i].status == "granted")) { 1934 permission = 1; 1935 } 1936 } 1937 1938 debug (uri, "FB Timeline: Drink", "Publish Action Permission", permission, "", ""); 1939 1940 if (permission == 1) { 1941 1942 debug (uri, "FB Timeline: Drink", "Publish Action Permission: Granted", "", "", ""); 1943 // PERMISSIONS VALID 1944 timelineDrinkTwo(token, uri, displayed, description, image); 1945 1946 } else { 1947 1948 debug (uri, "FB Timeline: Drink", "Publish Action Permission: Not Granted", "", "", ""); 1949 1950 // PERMISSIONS INVALID 1951 // LOG IN 1952 FB.login(function(response) { 1953 if (response.authResponse) { 1954 1955 debug (uri, "FB Timeline: Drink", "Publish Action Permission: Not Granted: Login", "", "", ""); 1956 timelineDrinkTwo(token, uri, displayed, description, image); 1957 1958 } else { 1959 statusMessage("Please sign in via Facebook so we may share what you are drinking.", 0, 1); 1960 debug (uri, "FB Timeline: Drink", "Error: Permissions", response.error.message, "", "GetLoginStatus"); 1961 } 1962 }, {scope:'publish_actions'}); 1963 1964 } 1965 1966 }); 1967 1968 1969 } else { 1970 1971 debug (uri, "FB Timeline: Drink", "Not Logged In", "", "", ""); 1972 1973 FB.login(function(response) { 1974 if (response.authResponse) { 1975 timelineDrinkTwo(response.authResponse.accessToken, uri, displayed, description, image); 1976 debug (uri, "FB Timeline: Drink", "Not Logged In: Login", "", "", ""); 1977 } else { 1978 statusMessage("Please sign in via Facebook so we may share what you are drinking.", 0, 1); 1979 debug (uri, "FB Timeline: Drink", "Error: Permissions", response.error.message, "", "GetLoginStatus"); 1980 } 1981 }, {scope:'publish_actions'}); 1982 1983 } 1984 1985 }); 1986 1987} 1988 1989 1990function timelineDrinkTwo(accessToken, uri, displayed, description, image) { 1991 1992 var params = {}; 1993 params['message'] = 'I am drinking '+displayed+' tea by Adagio Teas';
1994 params['name'] = displayed+' tea'; 1995 params['description'] = description; 1996 params['link'] = 'https://www.adagio.com/'+uri; 1997 params['picture'] = image; 1998 params['caption'] = 'from Adagio Teas'; 1999 2000 FB.api('/me/feed', 'post', params, function(response) { 2001 if (!response || response.error) { 2002 statusMessage("Please sign in via Facebook so we may share what you are drinking.", 0, 1); 2003 debug (uri, "FB Timeline: Drink", "Error: Permissions", response.error.message, "", "GetLoginStatus"); 2004 } else { 2005 2006 // ADD POINTS TO SOCIAL REWARDS 2007 if (timelineActive == 1) { 2008 $.ajax({ 2009 type: "POST", 2010 url: "/ajax/social_rewards_fb.html", 2011 success: function(msg){ 2012 var result = msg.split("***SPLIT***"); 2013 if (result[0]) { 2014 statusMessage(result[1], 0, 0); 2015 } else { 2016 statusMessage(result[1], 0, 1); 2017 } 2018 } 2019 }); 2020 timelineActive = 0; 2021 } 2022 2023 debug (uri, "FB Timeline: Drink", "Success", "", "", "GetLoginStatus"); 2024 } 2025 }); 2026 2027 2028 2029 2030} 2031 2032 2033 2034 2035 2036 2037 2038 2039//////////////////////////////////////////////////////////////////////////////////// 2040// SEND EMAIL 2041// ALL 2042 2043function sendEmail (name, email, sms1, sms2, sms3, message, consent) { 2044 2045 name = encodeURIComponent(name); 2046 email = encodeURIComponent(email); 2047 sms1 = encodeURIComponent(sms1); 2048 sms2 = encodeURIComponent(sms2); 2049 sms3 = encodeURIComponent(sms3); 2050 message = encodeURIComponent(message); 2051 2052 if (message) { 2053 2054 if (email) { 2055 2056 $.ajax({ 2057 type: "POST", 2058 url: "/ajax/email.html", 2059 data: "name=" + name + "&email=" + email + "&message=" + message, 2060 success: function(msg){ 2061 document.emailForm.Message.value = ""; 2062 if ($('#instaplyClose').length > 0) { 2063 document.getElementById('instaplyClose').style.display = 'none'; 2064 } 2065 if ($('#instaply').length > 0) { 2066 $('#instaply').animate({ bottom: '-256px'}, 250); 2067 } 2068 statusMessage("Your email has been sent. Please allow up to 24 hours for a response.", 0, 0); 2069 } 2070 }); 2071 2072 } 2073 2074 if ((sms1) && (sms2) && (sms3)) { 2075 2076 $.ajax({ 2077 type: "POST", 2078 url: "/ajax/sms.html", 2079 data: "name=" + name + "&sms1=" + sms1 + "&sms2=" + sms2 + "&sms3=" + sms3 + "&message=" + message + "&consent=" + consent, 2080 success: function(msg){ 2081 document.emailForm.Message.value = ""; 2082 if ($('#instaplyClose').length > 0) { 2083 document.getElementById('instaplyClose').style.display = 'none'; 2084 } 2085 if ($('#instaply').length > 0) { 2086 $('#instaply').animate({ bottom: '-256px'}, 250); 2087 } 2088 statusMessage("Your message has been sent. Please allow up to 24 hours for a response.", 0, 0); 2089 } 2090 }); 2091 2092 } 2093 2094 } else { 2095 2096 statusMessage("Please enter a message prior to sending.", 0, 1); 2097 2098 } 2099 2100} 2101 2102function sendFeedback (name, email, message) { 2103 2104 name = encodeURIComponent(name); 2105 email = encodeURIComponent(email); 2106 message = encodeURIComponent(message); 2107 2108 if (message) { 2109 2110 $.ajax({ 2111 type: "POST", 2112 url: "/ajax/feedback.html", 2113 data: "name=" + name + "&email=" + email + "&message=" + message, 2114 success: function(msg){ 2115 document.emailForm.Message.value = ""; 2116 if ($('#feedbackClose').length > 0) { 2117 document.getElementById('feedbackClose').style.display = 'none'; 2118 } 2119 if ($('#feedback').length > 0) { 2120 $('#feedback').animate({ bottom: '-256px'}, 250); 2121 } 2122 statusMessage("Thank you for providing us with your feedback", 0, 0); 2123 } 2124 }); 2125 2126 } else { 2127 2128 statusMessage("Please enter a message prior to sending.", 0, 1); 2129 2130 } 2131 2132} 2133 2134 2135function recipesMore(pid) { 2136 2137 console.log(pid); 2138 $.ajax({ 2139 type: "POST", 2140 url: "/ajax/recipes_more.html", 2141 data: { 2142 pid: pid, 2143 }, 2144 dataType: "json", 2145 success: function(response){ 2146 2147 if (document.getElementById('recipesDiv')) { 2148 document.getElementById('recipesDiv').innerHTML += response.recipesMore; 2149 } 2150 2151 } 2152 }); 2153 2154} 2155 2156 2157//////////////////////////////////////////////////////////////////////////////////// 2158// CHAT WINDOW 2159// ALL 2160 2161function askQuestionOpen() { 2162 console.log('opening'); 2163 $('#chat_opened').animate({ opacity: 'show' }, 250); 2164 $('#chat_question_div').animate({ height: 'show' }, 250); 2165 $('#chat_question_div').css({ display: 'grid' }); 2166 $('#chat_question_div').animate({ height: '130px' }); 2167 2168 $('#chatWindow').css("width","100%"); 2169// document.getElementById('chat_copy').innerHTML="Ask us a question. Anytime!"; 2170 document.getElementById('chat_copy').style.textAlign="left"; 2171 document.getElementById('chat_copy').style.padding="12px 20px"; 2172 document.getElementById('chat_copy').style.fontSize="18px"; 2173 $('#___ratingbadge_0').css({ display: 'none' }); 2174} 2175 2176function askQuestionClose() { 2177 console.log('closing'); 2178 $('#chat_opened').animate({ opacity: 'hide' }, 250); 2179 $('#chat_question_div').animate({ height: 'hide' }, 250); 2180 $('#chat_question_email_div').animate({ height: 'hide' }, 250); 2181 2182 $('#chatWindow').animate({ width: '165px' }, 250); 2183 document.getElementById('chat_copy').style.textAlign="right"; 2184 document.getElementById('chat_copy').style.padding="5px 10px"; 2185 document.getElementById('chat_copy').style.fontSize="14px"; 2186 $('#___ratingbadge_0').css({ display: 'auto' }); 2187 2188 $('#chat_answer').html(""); 2189} 2190 2191function askQuestion(question) { 2192 2193 // FIX VARIOUS COPY ISSUES 2194 question = encodeURIComponent(question); 2195 2196 $.ajax({ 2197 type: "POST", 2198 headers: { "cache-control": "no-cache" }, 2199 url: "/ajax/ask_question.html", 2200 data: "question=" + question, 2201 success: function(msg){
2202 result = msg.split("***SPLIT***"); 2203 $('#chat_answer').html(result[0]); 2204 document.getElementById('chat_question').value = ""; 2205 document.getElementById('chatWindow').style.height = "auto"; 2206 document.getElementById('chat_answer').style.height = "auto"; 2207 2208 $('#chat_question_div').animate({ height: 'hide' }, 250); 2209 if (result[1] == 1) { 2210 $('#chat_answer').animate({ height: 'hide' }, 250); 2211 $('#chat_question_email_div').animate({ height: 'show' }, 250); 2212 document.getElementById('chat_copy').innerHTML="Ask us a question. Anytime!"; 2213 document.getElementById('chat_response_header').innerHTML = "Where should we email the response?"; 2214 } else { 2215 document.getElementById('chat_copy').innerHTML="Here's your A.I. answer..."; 2216 } 2217 } 2218 }); 2219 2220} 2221 2222function askQuestionGetEmail(response, email) { 2223 2224 document.getElementById('chatResponse').value = response; 2225 2226 $('#chat_question_satisfied').animate({ height: 'hide' }, 250); 2227 2228 if (response == "no") { 2229 if (email) { 2230 askQuestionSendEmail(email); 2231 } else { 2232 $('#chat_question_div').animate({ height: 'hide' }, 250); 2233 $('#chat_answer').animate({ height: 'hide' }, 250); 2234 $('#chat_question_email_div').animate({ height: 'show' }, 250); 2235 document.getElementById('chat_copy').innerHTML="Here's your A.I. answer..."; 2236 } 2237 } else { 2238 askQuestionSendEmail(email); 2239 askQuestionClose(); 2240 } 2241 2242} 2243 2244function askQuestionSendEmail(email, emailName) { 2245 2246 $.ajax({ 2247 type: "POST", 2248 headers: { "cache-control": "no-cache" }, 2249 url: "/ajax/ask_question_email.html", 2250 data: "ref=" + window.location.pathname + "&email=" + email + "&emailName=" + emailName + "&chatSession=" + document.getElementById('chatSession').value + "&chatResponse=" + document.getElementById('chatResponse').value, 2251 success: function(msg){ 2252 result = msg.split("***SPLIT***"); 2253 askQuestionClose(); 2254 document.getElementById('chat_copy').innerHTML="Your question has been sent"; 2255 } 2256 }); 2257 2258} 2259 2260 2261 2262function sendFreeSpiceOffer(message, email) { 2263 2264 // FIX VARIOUS COPY ISSUES 2265 message = encodeURIComponent(message); 2266 email = encodeURIComponent(email); 2267 2268 $.ajax({ 2269 type: "POST", 2270 headers: { "cache-control": "no-cache" }, 2271 url: "/ajax/offer_free_spices.html", 2272 data: "message=" + message + "&email=" + email, 2273 success: function(msg){ 2274 result = msg.split("***SPLIT***"); 2275 console.log(msg); 2276 statusMessage("We hope your friend enjoys the free spices.", 0, 0); 2277 } 2278 }); 2279 2280} 2281 2282 2283 2284//////////////////////////////////////////////////////////////////////////////////// 2285// CHAT WINDOW 2286// ALL 2287 2288function askQuestionOpen2() { 2289 2290 console.log("retrieved chat"); 2291 2292 $.ajax({ 2293 type: "POST", 2294 headers: { "cache-control": "no-cache" }, 2295 url: "/ajax/ask_question_gpt_retrieve.html", 2296 data: "1=1", 2297 success: function(msg){ 2298 result = msg.split("***SPLIT***"); 2299 if (result[1] == 1) { 2300 document.getElementById('chat_answer').innerHTML = result[2]; 2301 $('#chat_answer').animate({ scrollTop: $('#chat_answer').prop('scrollHeight')}, 1000); 2302 } 2303 } 2304 }); 2305 2306 $('#chatWindowDialog').animate({ opacity: 'show' }, 250); 2307 $('#overlayMatte').animate({ opacity: 'show' }, 250); 2308 document.getElementById('chat_question').focus(); 2309} 2310 2311function askQuestionClose2() { 2312 $('#chatWindowDialog').animate({ opacity: 'hide' }, 250); 2313 $('#overlayMatte').animate({ opacity: 'hide' }, 250); 2314} 2315 2316function askQuestion2(question) { 2317 2318 // DISABLE QUESTION 2319 document.getElementById('chatQuestionDiv').style.display="none"; 2320 2321 // MIRROR QUESTION 2322 $("#chat_answer").append("<div class='chatUser'>"+question+"</div>"); 2323 2324 // ADD WAIT ICON 2325 $("#chat_answer").append("<div id='chat_wait_icon' class='chatAdagio' style='text-align:center;'><img src='https://www.adagio.com/images4/wait_icon.gif'></div>"); 2326 2327 // SCROLL ANSWER WINDOW 2328 $("#chat_answer").animate({ scrollTop: $('#chat_answer').prop("scrollHeight")}, 1000); 2329 2330 // FIX VARIOUS COPY ISSUES 2331 question = encodeURIComponent(question); 2332 2333 $.ajax({ 2334 type: "POST", 2335 headers: { "cache-control": "no-cache" }, 2336 url: "/ajax/ask_question_2.html", 2337 data: "question=" + question, 2338 success: function(msg){
2339 result = msg.split("***SPLIT***"); 2340 2341 // REMOVE WAIT ICON 2342 document.getElementById('chat_wait_icon').parentNode.removeChild(document.getElementById('chat_wait_icon')); 2343 2344 // POST RESPONSE 2345 $('#chat_answer').append(result[0]); 2346 document.getElementById('chat_question').value = ""; 2347 2348 // SCROLL ANSWER WINDOW 2349 $("#chat_answer").animate({ scrollTop: $('#chat_answer').prop("scrollHeight")}, 1000); 2350 2351 // ENABLE QUESTION 2352 document.getElementById('chatQuestionDiv').style.display="block"; 2353 2354 } 2355 }); 2356 2357} 2358 2359function askQuestionGetEmail2(response, email) { 2360 2361 document.getElementById('chatResponse').value = response; 2362 2363 if (response == "no") { 2364 if (email) { 2365 $("#chat_answer").append("<div class='chatAdagio'>Sorry about that. A flesh and blood human will soon answer you via email.</div>"); 2366 $("#chat_answer").animate({ scrollTop: $('#chat_answer').prop("scrollHeight")}, 1000); 2367 askQuestionSendEmail2(email, "", 0); 2368 } else { 2369 $("#chat_answer").append("<div id='chat_question_email_div'><div id='chat_response_header'><div class='chatAdagio'>A flesh and blood human will soon answer you via email. Where should we send the response?</div><div></div>"); 2370 $("#chat_answer").append("<div class='chatAdagio'> <label for='chat_question_name' style='display:none;'>Name</label><input name='chat_question_name' id='chat_question_name' style='width:92%;font-size:11pt;' placeholder='Name'><br> <label for='chat_question_email' style='display:none;'>Email</label> <input name='chat_question_email' id='chat_question_email' style='width:92%;font-size:11pt;' placeholder='Email address'><br> <div id='submitEmailDiv'><div class='pointer chatSubmit' onclick='document.getElementById(\"submitEmailDiv\").innerHTML=\"\";askQuestionSendEmail2(document.getElementById(\"chat_question_email\").value, document.getElementById(\"chat_question_name\").value, 1);return false;'>></div></div><div style='clear:both;'></div></div>"); 2371 2372 // SCROLL ANSWER WINDOW 2373 $("#chat_answer").animate({ scrollTop: $('#chat_answer').prop("scrollHeight")}, 1000); 2374 2375 } 2376 2377 } else { 2378 askQuestionSendEmail2(email, "", 0); 2379 askQuestionClose2(); 2380 } 2381 2382} 2383 2384function askQuestionSendEmail2(email, emailName, reply) { 2385 2386 if (reply) { 2387 2388 $("#chat_answer").append("<div id='chat_wait_icon' class='chatAdagio' style='text-align:center;'><img src='https://www.adagio.com/images4/wait_icon.gif'></div>"); 2389 2390 // SCROLL ANSWER WINDOW 2391 $("#chat_answer").animate({ scrollTop: $('#chat_answer').prop("scrollHeight")}, 1000); 2392 2393 } 2394 2395 $.ajax({ 2396 type: "POST", 2397 headers: { "cache-control": "no-cache" }, 2398 url: "/ajax/ask_question_email.html", 2399 data: "ref=" + window.location.pathname + "&email=" + email + "&emailName=" + emailName + "&chatSession=" + document.getElementById('chatSession').value + "&chatResponse=" + document.getElementById('chatResponse').value, 2400 success: function(msg){ 2401 result = msg.split("***SPLIT***"); 2402 2403 if (reply) { 2404 2405 // REMOVE WAIT ICON 2406 document.getElementById('chat_wait_icon').parentNode.removeChild(document.getElementById('chat_wait_icon')); 2407 2408 $("#chat_answer").append("<div class='chatAdagio'>Your question has been sent.</div>"); 2409 2410 // SCROLL ANSWER WINDOW 2411 $("#chat_answer").animate({ scrollTop: $('#chat_answer').prop("scrollHeight")}, 1000); 2412 2413 } 2414 2415 } 2416 }); 2417 2418} 2419 2420 2421 2422//////////////////////////////////////////////////////////////////////////////////// 2423// CHAT WINDOW GPT 2424// ALL 2425 2426let responseIncoming = ""; 2427let charQueue = []; 2428let isProcessingQueue = false; 2429let intervalId = null; 2430 2431// Define an array of witty terms 2432const wittyTerms = [ 2433"One moment, I'm grinding down the details...", 2434"Your patience is savory; I'm mixing up a flavorful reply!", 2435"Sifting through layers of information for you...", 2436"Hold tight, I'm marinating in thoughts!", 2437"Simmering over a pot of ideas for you...", 2438"Your answer is seasoning; good things come to those who wait!", 2439"Selecting the prime spices of wisdom for your response...", 2440"Gathering heat to deliver a spicy reply...", 2441"Waiting for the flavors of insight to meld perfectly...", 2442"Just a moment, I'm in the middle of a flavor fusion...", 2443"Infusing your reply with a pinch of insight and a dash of knowledge...", 2444"Like a masterful curry, some answers require time to develop their full flavor...", 2445"A good response is like a fine spice blend; it needs time to come together...", 2446"Almost there, just letting your answer simmer to perfection...", 2447"Crafting a response as rich and complex as a gourmet spice mix...", 2448"Ensuring your answer is as delightful as a perfectly seasoned dish...", 2449"Just a bit longer, I'm concocting a response you'll relish..." 2450]; 2451 2452function getRandomWittyTerm() { 2453 const index = Math.floor(Math.random() * wittyTerms.length); 2454 return wittyTerms[index]; 2455} 2456 2457 2458function askQuestionGPT(question, audioCheck) { 2459 2460 // DISABLE QUESTION 2461 if (document.getElementById('startAudioButton')) { 2462 document.getElementById('startAudioButton').style.display = "none"; 2463 } 2464 if (document.getElementById('chat_question')) { 2465 document.getElementById('chat_question').style.display = "none"; 2466 document.getElementById('chat_question').disabled = true; 2467 } 2468 if (document.getElementById('chatSubmit')) { 2469 document.getElementById('chatSubmit').style.display = "none"; 2470 } 2471 2472 // MIRROR QUESTION 2473 $("#chat_answer").append("<div class='chatUser'>"+question+"</div>"); 2474 2475 // CREATE AREA FOR RESPONSE 2476 $("#chat_answer").append("<div class='chatAdagio'>"+getRandomWittyTerm()+"<img class='gptCircle' src='/images6/gpt_circle.gif'></div>"); 2477 2478 // SCROLL ANSWER WINDOW 2479 $("#chat_answer").animate({ scrollTop: $('#chat_answer').prop("scrollHeight")}, 1000); 2480 2481 const evtSource = new EventSource("/ajax/ask_question_gpt.html?question=" + encodeURIComponent(question)); 2482 2483 evtSource.onerror = function(error) { 2484 console.error("EventSource failed:", error); 2485 evtSource.close(); 2486 }; 2487 2488 // DELTA 2489 evtSource.addEventListener('thread.message.delta', function(event) { 2490 2491 const data = JSON.parse(event.data); 2492 2493 // BYPASS SOURCE REFERENCE 2494 if (/\.txt/.test(data.delta.content[0].text.value)) { 2495 2496 } else { 2497 Array.prototype.push.apply(charQueue, data.delta.content[0].text.value.split('')); 2498 processQueue(); 2499 } 2500 2501 }); 2502 2503 // COMPLETED 2504 evtSource.addEventListener('thread.message.completed', function(event) { 2505 2506 if (intervalId !== null) { 2507 clearInterval(intervalId); // Stop the processing interval 2508 } 2509 charQueue = []; // Clear the character queue 2510 isProcessingQueue = false;
2511 2512 const data = JSON.parse(event.data); 2513 $.ajax({ 2514 type: "POST", 2515 headers: { "cache-control": "no-cache" }, 2516 url: "/ajax/ask_question_gpt_finalize.html", 2517 data: "thread=" + data.thread_id, 2518 success: function(msg){ 2519 2520 result = msg.split("***SPLIT***"); 2521 2522 console.log("FINALIZE"); 2523 2524 // EMPTY INCOMING 2525 responseIncoming = ""; 2526 2527 // SPEAK 2528 if (audioCheck == 1) { 2529 whisper(data.thread_id, result[1]); 2530 } 2531 2532 // POST RESPONSE 2533 const elements = document.querySelectorAll('.chatAdagio'); 2534 if (elements.length > 0) { 2535 elements[elements.length - 1].innerHTML = result[1]; 2536 } 2537 2538 2539 // RE-ENABLE QUESTION 2540 if (document.getElementById("chat_question")) { 2541 document.getElementById('chat_question').style.display = "block"; 2542 document.getElementById('chat_question').disabled = false; 2543 document.getElementById('chat_question').value = ""; 2544 document.getElementById("chat_question").focus(); 2545 } 2546 2547 if (document.getElementById("chatSubmit")) { 2548 document.getElementById('chatSubmit').style.display = "block"; 2549 } 2550 2551 if (document.getElementById("chatMicrophoneOn")) { 2552 document.getElementById('chatMicrophoneOn').style.display = "none"; 2553 } 2554 2555 if (document.getElementById("startAudioButton")) { 2556 document.getElementById('startAudioButton').style.display = "block"; 2557 } 2558 2559 // SCROLL ANSWER WINDOW 2560 if (window.location.href.includes("help.html")) { 2561 scrollGPT(); 2562 } else { 2563 $('#chat_answer').scrollTop($('#chat_answer')[0].scrollHeight); 2564 } 2565 2566 } 2567 }); 2568 2569 }); 2570 2571 // DONE 2572 evtSource.addEventListener('done', function(event) { 2573 2574 console.log("DONE"); 2575 evtSource.close(); 2576 2577 }); 2578 2579} 2580 2581function scrollGPT() { 2582 // SCROLL ANSWER WINDOW 2583 var divOffset = $('#chatQuestionDiv').offset().top; 2584 var divHeight = $('#chatQuestionDiv').outerHeight(); 2585 var windowHeight = $(window).height(); 2586 var scrollToPosition = divOffset - windowHeight + divHeight + 60; 2587 $('html, body').animate({scrollTop: scrollToPosition}, 1000); 2588} 2589 2590function processQueue() { 2591 if (isProcessingQueue) return; // Exit if already processing the queue 2592 isProcessingQueue = true; 2593 2594 intervalId = setInterval(() => { 2595 if (charQueue.length === 0) { 2596 clearInterval(intervalId); // Stop the interval when the queue is empty 2597 isProcessingQueue = false; // Reset the flag 2598 return; 2599 } 2600 2601 // Get the next character from the queue 2602 let char = charQueue.shift(); 2603 responseIncoming += char; 2604 2605 // Apply transformations 2606 let formattedResponse = formatResponse(responseIncoming); 2607 2608 // Update the last .chatAdagio element with formattedResponse 2609 const elements = document.querySelectorAll('.chatAdagio'); 2610 if (elements.length > 0) { 2611 let chatElement = elements[elements.length - 1]; 2612 chatElement.innerHTML = formattedResponse + "<img class='gptCircle' src='/images6/gpt_circle.gif'>"; 2613 2614 // Scroll the div to the bottom 2615 let $chatContainer = $('#chat_answer'); // Assuming this is your chat container 2616 $chatContainer.scrollTop($chatContainer.prop("scrollHeight")); 2617 } 2618 2619 }, 8); 2620} 2621 2622function formatResponse(response) { 2623 let formatted = response; 2624 formatted = formatted.replace(/\*\*(.*?)\*\*/g, "<b>$1</b>"); 2625 formatted = formatted.replace(/\n/g, "<br>"); 2626 formatted = formatted.replace(/ã.*?ã/g, ''); 2627 return formatted; 2628} 2629 2630 2631function whisper(thread, audio) { 2632 2633 $.ajax({ 2634 type: "POST", 2635 headers: { "cache-control": "no-cache" }, 2636 url: "/ajax/ask_question_gpt_audio.html", 2637 data: "thread=" + thread + "&audio=" + audio, 2638 success: function(msg){ 2639 2640 result = msg.split("***SPLIT***"); 2641 2642 if (result[1]) { 2643 2644 var audioFilePath = "https://www.selefina.com/audio/" + result[1] + ".mp3"; 2645 var audio = new Audio(audioFilePath); 2646 2647 audio.play() 2648 .then(() => { 2649 console.log("Audio playback started successfully"); 2650 }) 2651 .catch(error => { 2652 console.error("Error occurred during audio playback:", error); 2653 }); 2654 2655 } 2656 2657 } 2658 }); 2659 2660} 2661 2662 2663//////////////////////////////////////////////////////////////////////////////////// 2664// MOBILE HEADER/FOOTER NAVIGATION 2665// ALL 2666 2667function showHideFooter(section) { 2668 2669 for (i = 2; i < 8; i++) { 2670 if (document.getElementById("footer").children[section].children[i]) { 2671 if (document.getElementById("footer").children[section].children[i].style.display == "block") { 2672 document.getElementById("footer").children[section].children[i].style.display = "none"; 2673 } else { 2674 document.getElementById("footer").children[section].children[i].style.display = "block"; 2675 } 2676 } 2677 } 2678 2679} 2680 2681function showHideNav() { 2682 var count = $('#accountNav')[0].childElementCount; 2683 for (i = 1; i < count; i++) { 2684 var patt = new RegExp("hide_768"); 2685 if (patt.test(document.getElementById("accountNav").children[i].className)) { 2686 if (document.getElementById("accountNav").children[i].style.display == "block") { 2687 document.getElementById("accountNav").children[i].style.display = "none"; 2688 } else { 2689 document.getElementById("accountNav").children[i].style.display = "block"; 2690 } 2691 } 2692 } 2693 2694} 2695 2696 2697 2698 2699//////////////////////////////////////////////////////////////////////////////////// 2700// ACCOUNT 2701// EXISTING 2702 2703 2704 2705//////////////////////////////////////////////////////////////////////////////////// 2706// CHAT WINDOW 2707 2708var chatPercentage; 2709var chatHeight; 2710 2711$(window).scroll(function() { 2712 2713 if ((document.getElementById("chatWindow")) && (document.getElementById("footer"))) { 2714 2715 var hT = $('#footer').offset().top, hH = $('#footer').outerHeight(), wH = $(window).height(), wS = $(this).scrollTop(); 2716 2717 chatPercentage = (1 - (wS / (hT-wH))) * 5; 2718 if (chatPercentage > 1){chatPercentage = 1} 2719 if (chatPercentage < 0){chatPercentage = 0} 2720 2721 chatHeight = (100 - Math.floor(chatPercentage * 100)) + "px"; 2722 document.getElementById('chatWindow').style.bottom = chatHeight; 2723 2724 } 2725 2726}); 2727 2728 2729 2730//////////////////////////////////////////////////////////////////////////////////// 2731// PACKAGING POPUP 2732 2733function viewPackaging() { 2734 2735 $.ajax({ 2736 type: "POST", 2737 url: "/ajax/popup_packaging.html", 2738 success: function(msg){ 2739 2740 document.getElementById('overlayMatte').style.display = 'block'; 2741 document.getElementById('genericPopupDiv').innerHTML = msg; 2742 document.getElementById('genericPopupDiv').style.display = 'block'; 2743 document.getElementById('genericPopupDiv').style.maxWidth = '1000px'; 2744 2745 } 2746 }); 2747 2748} 2749 2750function viewPackagingJars() { 2751 2752 $.ajax({ 2753 type: "POST", 2754 url: "/ajax/popup_packaging_jars.html", 2755 success: function(msg){ 2756 2757 document.getElementById('overlayMatte').style.display = 'block'; 2758 document.getElementById('genericPopupDiv').innerHTML = msg; 2759 document.getElementById('genericPopupDiv').style.display = 'block'; 2760 document.getElementById('genericPopupDiv').style.maxWidth = '235px'; 2761 2762 } 2763 }); 2764 2765} 2766 2767 2768function viewSpiceRack() { 2769 2770 $.ajax({ 2771 type: "POST", 2772 url: "/ajax/popup_spice_rack.html", 2773 success: function(msg){ 2774 2775// const template = document.createElement('div'); 2776// template.innerHTML = msg; 2777// document.body.appendChild(template); 2778 2779 document.getElementById('overlayMatte').style.display = 'block'; 2780 document.getElementById('genericPopupDiv').innerHTML = msg; 2781 document.getElementById('genericPopupDiv').style.display = 'block'; 2782 document.getElementById('genericPopupDiv').style.maxWidth = '1000px'; 2783 2784 } 2785 }); 2786 2787} 2788 2789 2790 2791 2792//////////////////////////////////////////////////////////////////////////////////// 2793// CHAT 2794 2795function initializeChat_DISABLED() { 2796 2797 const startButton = document.getElementById('startAudioButton'); 2798 const recognition = new webkitSpeechRecognition(); 2799 recognition.lang = 'en-US'; 2800 recognition.interimResults = false;
2801 recognition.continuous = true; 2802 2803 const synthesis = window.speechSynthesis; 2804 2805 function speak(text) { 2806 const utterance = new SpeechSynthesisUtterance(text); 2807 synthesis.speak(utterance); 2808 utterance.onend = () => { 2809 recognition.start(); 2810 }; 2811 recognition.stop(); 2812 } 2813 2814 recognition.onresult = async function (event) { 2815 const userInput = event.results[event.results.length - 1][0].transcript; 2816 recognition.stop(); 2817 2818 const openaiResponse = await callOpenAI(userInput); 2819 console.log(`OpenAI said: ${openaiResponse}`); 2820 2821 speak(openaiResponse); 2822 // recognition.start(); 2823 }; 2824 2825 recognition.onerror = function (event) { 2826 console.error(event.error); 2827 }; 2828 2829 startButton.addEventListener('click', () => { 2830 recognition.start(); 2831 2832 document.getElementById('chat_question').style.display = "none"; 2833 document.getElementById('chatSubmit').style.display = "none"; 2834 document.getElementById('chatMicrophoneOn').style.display = "block"; 2835 2836 }); 2837 2838 async function callOpenAI(userInput) { 2839 askQuestionGPT(userInput, 1); 2840 } 2841 2842} 2843 2844if (document.readyState === 'loading') { 2845 // The document is still loading, wait for the DOMContentLoaded event 2846 if (document.getElementById("chatWindow")) { 2847 //document.addEventListener('DOMContentLoaded', initializeChat); 2848 } 2849} else { 2850 // The DOMContentLoaded event has already fired, run the function now 2851 if (document.getElementById("chatWindow")) { 2852 //initializeChat(); 2853 } 2854}
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.