/******/ (() => { // webpackBootstrap /*!*******************************************************************!*\ !*** ./resources/js/templates/remax-template/property-gallery.js ***! \*******************************************************************/ (function () { // Gallery variables var galleryImages = []; var currentImageIndex = 0; var touchStartX = 0; var touchEndX = 0; // Generate thumbnails function generateThumbnails() { var thumbnailsTrack = document.getElementById('thumbnails-track'); if (!thumbnailsTrack) return; thumbnailsTrack.innerHTML = ''; galleryImages.forEach(function (image, index) { var thumb = document.createElement('div'); thumb.className = "gallery-thumbnail ".concat(index === 0 ? 'active' : ''); thumb.onclick = function () { return showImage(index); }; thumb.innerHTML = "\"Thumbnail"); thumbnailsTrack.appendChild(thumb); }); } // Preload images for smoother experience function preloadImages() { galleryImages.forEach(function (src) { var img = new Image(); img.src = src; }); } // Open gallery window.openCarousel = function () { var gallery = document.getElementById('photo-gallery'); if (!gallery) return; gallery.style.display = 'flex'; document.body.style.overflow = 'hidden'; showImage(0); addKeyboardListeners(); addTouchListeners(); }; // Open gallery Mobile window.openCarouselMobile = function () { if (window.innerWidth <= 768) { openCarousel(); } }; // Close gallery window.closeGallery = function () { var gallery = document.getElementById('photo-gallery'); if (!gallery) return; gallery.style.display = 'none'; document.body.style.overflow = 'auto'; removeKeyboardListeners(); removeTouchListeners(); }; // Show specific image function showImage(index) { currentImageIndex = index; var mainImage = document.getElementById('gallery-main-image'); var thumbnails = document.querySelectorAll('.gallery-thumbnail'); if (!mainImage) return; // Update main image with loading state mainImage.classList.remove('loaded'); mainImage.src = galleryImages[index]; mainImage.onload = function () { mainImage.classList.add('loaded'); }; // Update counter var currentIndexEl = document.getElementById('current-index'); var totalCountEl = document.getElementById('total-count'); if (currentIndexEl) currentIndexEl.textContent = index + 1; if (totalCountEl) totalCountEl.textContent = galleryImages.length; // Update active thumbnail thumbnails.forEach(function (thumb, i) { thumb.classList.toggle('active', i === index); }); // Scroll thumbnail into view var activeThumb = thumbnails[index]; if (activeThumb) { activeThumb.scrollIntoView({ behavior: 'smooth', inline: 'center', block: 'nearest' }); } } // Navigate gallery window.navigateGallery = function (direction) { var newIndex = (currentImageIndex + direction + galleryImages.length) % galleryImages.length; showImage(newIndex); }; // Scroll thumbnails window.scrollThumbnails = function (direction) { var container = document.getElementById('thumbnails-track'); if (!container) return; var scrollAmount = 200; container.scrollBy({ left: scrollAmount * direction, behavior: 'smooth' }); }; // Keyboard navigation function handleKeyPress(e) { var gallery = document.getElementById('photo-gallery'); if (gallery && gallery.style.display === 'flex') { switch (e.key) { case 'ArrowRight': navigateGallery(1); break; case 'ArrowLeft': navigateGallery(-1); break; case 'Escape': closeGallery(); break; } } } function addKeyboardListeners() { document.addEventListener('keydown', handleKeyPress); } function removeKeyboardListeners() { document.removeEventListener('keydown', handleKeyPress); } // Touch gestures for mobile function handleTouchStart(e) { touchStartX = e.changedTouches[0].screenX; } function handleTouchEnd(e) { touchEndX = e.changedTouches[0].screenX; handleSwipe(); } function handleSwipe() { var swipeThreshold = 50; var diff = touchStartX - touchEndX; if (Math.abs(diff) > swipeThreshold) { if (diff > 0) { navigateGallery(1); // Swipe left, go next } else { navigateGallery(-1); // Swipe right, go previous } } } function addTouchListeners() { var stage = document.querySelector('.gallery-stage'); if (stage) { stage.addEventListener('touchstart', handleTouchStart); stage.addEventListener('touchend', handleTouchEnd); } } function removeTouchListeners() { var stage = document.querySelector('.gallery-stage'); if (stage) { stage.removeEventListener('touchstart', handleTouchStart); stage.removeEventListener('touchend', handleTouchEnd); } } // Gallery actions window.toggleFullscreen = function () { var gallery = document.getElementById('photo-gallery'); if (!gallery) return; if (!document.fullscreenElement) { gallery.requestFullscreen()["catch"](function (err) { console.log("Error attempting to enable fullscreen: ".concat(err.message)); }); } else { document.exitFullscreen(); } }; window.shareGallery = function () { var _window$propertyGalle; var shareData = { title: ((_window$propertyGalle = window.propertyGalleryConfig) === null || _window$propertyGalle === void 0 ? void 0 : _window$propertyGalle.propertyAddress) || 'Beautiful Property', text: 'Check out this amazing property!', url: window.location.href }; if (navigator.share) { navigator.share(shareData)["catch"](function (err) { return console.log('Error sharing:', err); }); } else { // Fallback: Copy to clipboard navigator.clipboard.writeText(window.location.href); alert('Link copied to clipboard!'); } }; window.downloadImage = function () { if (galleryImages.length === 0) return; var currentImage = galleryImages[currentImageIndex]; var link = document.createElement('a'); link.href = currentImage; link.download = "property-image-".concat(currentImageIndex + 1, ".jpg"); link.target = '_blank'; document.body.appendChild(link); link.click(); document.body.removeChild(link); }; // Initialize gallery function that accepts images window.initPropertyGallery = function (images, config) { galleryImages = images || []; window.propertyGalleryConfig = config || {}; // Initialize components generateThumbnails(); preloadImages(); }; // Auto-initialize if DOM is ready and gallery data exists document.addEventListener('DOMContentLoaded', function () { if (window.propertyGalleryImages) { window.initPropertyGallery(window.propertyGalleryImages, window.propertyGalleryConfig); } }); })(); /******/ })() ;