// Revival Product Interactive Features v12 // Upload to: /Portals/0/revival-product-v12.txt (function() { console.log('===== REVIVAL PRODUCT V12 LOADED ====='); var initAttempts = 0; var maxAttempts = 50; function initRevivalProduct() { initAttempts++; if (typeof jQuery === 'undefined') { if (initAttempts < maxAttempts) { setTimeout(initRevivalProduct, 100); } return; } if (typeof jQuery.fn.magnificPopup === 'undefined') { if (initAttempts < maxAttempts) { setTimeout(initRevivalProduct, 100); } return; } console.log('Revival: jQuery + Magnific Popup ready'); var $ = jQuery; var currentVideoUrl = ''; var photoArray = []; var currentPhotoIndex = 0; // Get video URL on page load var $videoThumb = $('.revival-video-thumb').first(); if ($videoThumb.length) { currentVideoUrl = $videoThumb.data('video'); console.log('Revival: Video URL initialized:', currentVideoUrl); } // HOVER ZOOM $('.revival-product-media') .on('mousemove', function(e) { if (window.innerWidth <= 992) return; var rect = $('#revivalMainImage')[0].getBoundingClientRect(); var x = e.clientX - rect.left; var y = e.clientY - rect.top; if (x > 0 && y > 0 && x < rect.width && y < rect.height) { $('.revival-zoom-panel').addClass('active'); var px = (x / rect.width) * 100; var py = (y / rect.height) * 100; $('#revivalZoomImg').css('transform-origin', px + '% ' + py + '%'); } }) .on('mouseenter', function() { $('#revivalZoomImg').attr('src', $('#revivalMainImage').attr('src')); }) .on('mouseleave', function() { $('.revival-zoom-panel').removeClass('active'); }); // THUMBNAIL CLICKS $(document).on('click', '.revival-thumb-item[data-type="photo"]', function(e) { e.stopPropagation(); $('.revival-thumb-item').removeClass('active'); $(this).addClass('active'); var src = $(this).data('img'); $('#revivalMainImage, #revivalZoomImg').attr('src', src); }); // QUANTITY CONTROLS $(document).on('click', '.revival-quantity em', function() { var $input = $(this).siblings('input'); var val = parseInt($input.val()); if ($(this).hasClass('fa-plus')) { val++; } else if (val > 1) { val--; } $input.val(val); }); // SHARE BUTTON $(document).on('click', '#revivalShareProduct', function() { var productTitle = 'Premium Hemp-Infused Honey – 500 mg'; var productUrl = window.location.href; if (navigator.share) { navigator.share({ title: productTitle, text: 'Check out this product!', url: productUrl }).catch(function(error) { if (error.name !== 'AbortError') { console.log('Revival: Share failed:', error); } }); } else { var tempInput = document.createElement('input'); tempInput.value = productUrl; document.body.appendChild(tempInput); tempInput.select(); document.execCommand('copy'); document.body.removeChild(tempInput); var $span = $(this).find('span'); var originalText = $span.text(); $span.text('Link copied!'); $(this).css('color', '#28a745'); setTimeout(function() { $span.text(originalText); $(this).css('color', ''); }.bind(this), 2000); } }); // LIGHTBOX FUNCTIONS function buildLightboxPhotoThumbs() { var $container = $('.revival-lightbox-photo-thumbs'); $container.empty(); photoArray = []; // Only select desktop thumbnails OR the first set to avoid duplicates var $photoThumbs = $('.revival-desktop-only .revival-thumb-item[data-type="photo"]'); if ($photoThumbs.length === 0) { $photoThumbs = $('.revival-thumb-item[data-type="photo"]').slice(0, 4); } $photoThumbs.each(function(index) { var src = $(this).data('img'); photoArray.push(src); var $img = $('').attr('src', src).attr('data-full', src).attr('data-index', index); if ($(this).hasClass('active')) { $img.addClass('active'); currentPhotoIndex = index; } $container.append($img); }); console.log('Revival: Built', photoArray.length, 'photo thumbnails'); } function switchLightboxTab(tab) { console.log('Revival: Switching to tab:', tab); // Update tab UI $('.revival-lightbox-tab').removeClass('active'); $('.revival-lightbox-tab[data-tab="' + tab + '"]').addClass('active'); // Show/hide content areas using .active class $('#revival-lightbox-photos').removeClass('active'); $('#revival-lightbox-video').removeClass('active'); if (tab === 'photos') { $('#revival-lightbox-photos').addClass('active'); // STOP VIDEO when switching to photos $('#revival-lightbox-video iframe').attr('src', ''); console.log('Revival: Video stopped (switched to photos)'); } else if (tab === 'video') { $('#revival-lightbox-video').addClass('active'); } } function navigatePhoto(direction) { if (photoArray.length === 0) return; currentPhotoIndex += direction; // Wrap around if (currentPhotoIndex < 0) { currentPhotoIndex = photoArray.length - 1; } else if (currentPhotoIndex >= photoArray.length) { currentPhotoIndex = 0; } var src = photoArray[currentPhotoIndex]; $('#revival-lightbox-main-img').attr('src', src); // Update thumbnail active state $('.revival-lightbox-photo-thumbs img').removeClass('active'); $('.revival-lightbox-photo-thumbs img[data-index="' + currentPhotoIndex + '"]').addClass('active'); console.log('Revival: Navigated to photo', currentPhotoIndex + 1, 'of', photoArray.length); } function openCustomLightbox(tab) { console.log('Revival: Opening lightbox on tab:', tab); // Build thumbnails fresh each time buildLightboxPhotoThumbs(); $.magnificPopup.open({ items: { src: '#revival-lightbox-content' }, type: 'inline', mainClass: 'mfp-fade', removalDelay: 300, closeBtnInside: false, closeOnBgClick: true, closeMarkup: '', callbacks: { open: function() { console.log('Revival: Lightbox opened'); // Clear any previous state $('#revival-lightbox-photos').removeClass('active'); $('#revival-lightbox-video').removeClass('active'); // Switch to requested tab switchLightboxTab(tab); if (tab === 'video') { if (currentVideoUrl) { var videoSrc = currentVideoUrl + '?autoplay=1'; $('#revival-lightbox-video iframe').attr('src', videoSrc); console.log('Revival: Video loaded:', videoSrc); } } else if (tab === 'photos') { var activeSrc = $('.revival-thumb-item.active[data-type="photo"]').first().data('img'); if (!activeSrc) { activeSrc = $('.revival-thumb-item[data-type="photo"]').first().data('img'); } $('#revival-lightbox-main-img').attr('src', activeSrc); console.log('Revival: Main photo loaded:', activeSrc); } // Close button $('.revival-custom-close-btn').off('click').on('click', function() { $.magnificPopup.close(); }); }, close: function() { console.log('Revival: Lightbox closed'); $('#revival-lightbox-video iframe').attr('src', ''); } } }); } // MAIN IMAGE CLICK - prevent DNN hijacking $('#revivalMainImage').on('click', function(e) { e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation(); console.log('Revival: Main image clicked'); openCustomLightbox('photos'); return false; }); // +MORE BUTTON $('.revival-more-thumbs').on('click', function(e) { e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation(); console.log('Revival: +More clicked'); openCustomLightbox('photos'); return false; }); // VIDEO THUMBNAIL $('.revival-video-thumb').on('click', function(e) { e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation(); currentVideoUrl = $(this).data('video'); console.log('Revival: Video thumb clicked, URL:', currentVideoUrl); openCustomLightbox('video'); return false; }); // TAB SWITCHING INSIDE LIGHTBOX $(document).on('click', '.revival-lightbox-tab', function() { var tab = $(this).data('tab'); console.log('Revival: Tab clicked:', tab); switchLightboxTab(tab); if (tab === 'video') { if (currentVideoUrl) { $('#revival-lightbox-video iframe').attr('src', currentVideoUrl + '?autoplay=1'); console.log('Revival: Switched to video, loading:', currentVideoUrl); } } else if (tab === 'photos') { var activeSrc = $('.revival-lightbox-photo-thumbs img.active').data('full'); if (!activeSrc) { activeSrc = $('.revival-lightbox-photo-thumbs img:first').data('full'); } $('#revival-lightbox-main-img').attr('src', activeSrc); } }); // PHOTO THUMB CLICKS IN LIGHTBOX $(document).on('click', '.revival-lightbox-photo-thumbs img', function() { $('.revival-lightbox-photo-thumbs img').removeClass('active'); $(this).addClass('active'); currentPhotoIndex = parseInt($(this).data('index')); var src = $(this).data('full'); $('#revival-lightbox-main-img').attr('src', src); console.log('Revival: Lightbox thumb clicked:', src); }); // NAVIGATION ARROWS $(document).on('click', '.revival-lightbox-nav-prev', function(e) { e.stopPropagation(); navigatePhoto(-1); }); $(document).on('click', '.revival-lightbox-nav-next', function(e) { e.stopPropagation(); navigatePhoto(1); }); // KEYBOARD NAVIGATION $(document).on('keydown', function(e) { if (!$('#revival-lightbox-content').is(':visible')) return; // Only navigate if Photos tab is active if (!$('#revival-lightbox-photos').hasClass('active')) return; if (e.key === 'ArrowLeft') { e.preventDefault(); navigatePhoto(-1); } else if (e.key === 'ArrowRight') { e.preventDefault(); navigatePhoto(1); } }); // ZOOM TOGGLE IN LIGHTBOX $(document).on('click', '.revival-lightbox-main-photo', function(e) { // Don't toggle zoom if clicking nav arrows if ($(e.target).hasClass('revival-lightbox-nav')) return; $(this).toggleClass('zoomed'); }); console.log('Revival: ===== V12 INIT COMPLETE ====='); } initRevivalProduct(); })();