zoomora 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +69 -26
- package/dist/zoomora.css +4 -2
- package/dist/zoomora.es.js +1307 -1280
- package/dist/zoomora.es.js.map +1 -1
- package/dist/zoomora.es.min.js +547 -10
- package/dist/zoomora.umd.js +1308 -1276
- package/dist/zoomora.umd.js.map +1 -1
- package/dist/zoomora.umd.min.js +554 -10
- package/package.json +4 -4
- package/src/styles/zoomora.scss +26 -7
- package/src/zoomora.js +150 -40
- package/dist/zoomora.es.min.js.map +0 -1
- package/dist/zoomora.umd.min.js.map +0 -1
package/dist/zoomora.umd.min.js
CHANGED
|
@@ -1,10 +1,554 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
t="undefined"!=typeof window?window:void 0,e=function(){class t{static get defaults(){return{selector:"[data-zoomora]",showCounter:!0,showThumbnails:!0,showFullscreen:!0,showZoom:!0,transition:"fade",useHref:!1,maxZoomScale:3,zoomStep:.1,animationDuration:300,closeOnBackgroundClick:!0,onOpen:null,onClose:null,onNext:null,onPrev:null,showAutoHideToggle:!0,autoHideDelay:3e3,autoHideEnabled:!1}}constructor(e={}){this.options=h(h({},t.defaults),e),this.currentIndex=0,this.items=[],this.isZoomed=!1,this.isFullscreen=!1,this.isDragging=!1,this.thumbnailsVisible=!0,this.startX=0,this.startY=0,this.currentX=0,this.currentY=0,this.currentScale=1,this.isInitialized=!1,this.eventListeners=new Map,this.autoHideEnabled=!1,this.autoHideTimeout=null,this.autoHideDelay=3e3,this.isControlsVisible=!0,this.idleTimer=null,this.lastDragTime=0,this.boundMethods={handleDocumentClick:this.handleDocumentClick.bind(this),handleKeydown:this.handleKeydown.bind(this),handleFullscreenChange:this.handleFullscreenChange.bind(this),handleZoomoraClick:this.handleZoomoraClick.bind(this),handleContentClick:this.handleContentClick.bind(this),handleMouseDown:this.handleMouseDown.bind(this),handleMouseMove:this.handleMouseMove.bind(this),handleMouseUp:this.handleMouseUp.bind(this),handleTouchStart:this.handleTouchStart.bind(this),handleTouchMove:this.handleTouchMove.bind(this),handleTouchEnd:this.handleTouchEnd.bind(this)},this.init()}init(){if(!this.isInitialized)try{this.createLightbox(),this.bindEvents(),this.isInitialized=!0}catch(t){}}static bind(e,s={}){const n=(a=h({},s),i(a,o({selector:e,useHref:!0})));var a;return new t(n)}createLightbox(){if(document.getElementById("zoomoraLightbox"))return;const t=this.options.showAutoHideToggle?'\n <button class="zoomora-btn" id="zoomoraAutoHideBtn" title="Toggle Auto-Hide Controls">\n <i class="zoomorai-controls-off"></i>\n </button>\n ':"",e=`\n <div class="zoomora" id="zoomoraLightbox">\n <div class="zoomora-container">\n <div class="zoomora-header" id="zoomoraHeader">\n <div class="zoomora-counter" id="zoomoraCounter" ${this.options.showCounter?"":'style="opacity:0;visibility:hidden;"'}>1 / 1</div>\n <div class="zoomora-controls">\n ${this.options.showThumbnails?'\n <button class="zoomora-btn" id="zoomoraThumbnailBtn" title="Toggle Thumbnails">\n <i class="zoomorai-thumbnails"></i>\n </button>\n ':""}\n ${t}\n ${this.options.showZoom?'\n <button class="zoomora-btn" id="zoomoraZoomBtn" title="Zoom">\n <i class="zoomorai-zoom"></i>\n </button>\n ':""}\n ${this.options.showFullscreen?'\n <button class="zoomora-btn" id="zoomoraFullscreenBtn" title="Fullscreen">\n <i class="zoomorai-expand"></i>\n </button>\n <button class="zoomora-btn" id="zoomoraCollapseBtn" title="Exit Fullscreen" style="display: none;">\n <i class="zoomorai-collapse"></i>\n </button>\n ':""}\n <button class="zoomora-btn" id="zoomoraCloseBtn" title="Close">\n <i class="zoomorai-close"></i>\n </button>\n </div>\n </div>\n \n <div class="zoomora-content" id="zoomoraContent">\n <div class="zoomora-loading" id="zoomoraLoading"></div>\n <div class="zoomora-slides-container" id="zoomoraSlidesContainer"></div>\n </div>\n \n <button class="zoomora-nav prev" id="zoomoraPrevBtn">\n <i class="zoomorai-arrow-left"></i>\n </button>\n <button class="zoomora-nav next" id="zoomoraNextBtn">\n <i class="zoomorai-arrow-right"></i>\n </button>\n \n <div class="zoomora-caption" id="zoomoraCaption" ${this.options.showThumbnails?"":'style="bottom:20px;"'}></div>\n <div class="zoomora-thumbnails" id="zoomoraThumbs" ${this.options.showThumbnails?"":'style="display:none;"'}></div>\n </div>\n </div>\n `;if(document.body.insertAdjacentHTML("beforeend",e),this.zoomora=document.getElementById("zoomoraLightbox"),this.header=document.getElementById("zoomoraHeader"),this.content=document.getElementById("zoomoraContent"),this.slidesContainer=document.getElementById("zoomoraSlidesContainer"),this.counter=document.getElementById("zoomoraCounter"),this.thumbs=document.getElementById("zoomoraThumbs"),this.loading=document.getElementById("zoomoraLoading"),this.caption=document.getElementById("zoomoraCaption"),this.prevBtn=document.getElementById("zoomoraPrevBtn"),this.nextBtn=document.getElementById("zoomoraNextBtn"),!(this.zoomora&&this.content&&this.counter&&this.thumbs&&this.loading&&this.caption))throw new Error("Failed to create required DOM elements")}bindEvents(){this.addEventListener(document,"click",this.boundMethods.handleDocumentClick),this.addEventListener(document.getElementById("zoomoraCloseBtn"),"click",()=>this.close()),this.addEventListener(document.getElementById("zoomoraPrevBtn"),"click",()=>this.prev()),this.addEventListener(document.getElementById("zoomoraNextBtn"),"click",()=>this.next()),this.options.showZoom&&this.addEventListener(document.getElementById("zoomoraZoomBtn"),"click",()=>this.toggleZoom()),this.options.showFullscreen&&(this.addEventListener(document.getElementById("zoomoraFullscreenBtn"),"click",()=>this.toggleFullscreen()),this.addEventListener(document.getElementById("zoomoraCollapseBtn"),"click",()=>this.exitFullscreen())),this.options.showThumbnails&&this.addEventListener(document.getElementById("zoomoraThumbnailBtn"),"click",()=>this.toggleThumbnails()),this.addEventListener(document,"fullscreenchange",this.boundMethods.handleFullscreenChange),this.addEventListener(document,"webkitfullscreenchange",this.boundMethods.handleFullscreenChange),this.addEventListener(document,"mozfullscreenchange",this.boundMethods.handleFullscreenChange),this.addEventListener(document,"MSFullscreenChange",this.boundMethods.handleFullscreenChange),this.addEventListener(document,"keydown",this.boundMethods.handleKeydown),this.addEventListener(this.zoomora,"click",this.boundMethods.handleZoomoraClick),this.addEventListener(this.content,"click",this.boundMethods.handleContentClick),this.addEventListener(this.content,"mousedown",this.boundMethods.handleMouseDown),this.addEventListener(this.content,"mousemove",this.boundMethods.handleMouseMove),this.addEventListener(this.content,"mouseup",this.boundMethods.handleMouseUp),this.addEventListener(this.content,"mouseleave",this.boundMethods.handleMouseUp),this.addEventListener(this.content,"touchstart",this.boundMethods.handleTouchStart,{passive:!1}),this.addEventListener(this.content,"touchmove",this.boundMethods.handleTouchMove,{passive:!1}),this.addEventListener(this.content,"touchend",this.boundMethods.handleTouchEnd),this.options.showAutoHideToggle&&(this.addEventListener(document.getElementById("zoomoraAutoHideBtn"),"click",()=>this.toggleAutoHide()),this.addEventListener(this.zoomora,"mousemove",()=>this.handleUserActivity()),this.addEventListener(this.zoomora,"touchstart",()=>this.handleUserActivity()),this.addEventListener(this.zoomora,"keydown",()=>this.handleUserActivity()))}addEventListener(t,e,s,i={}){if(!t)return;t.addEventListener(e,s,i);const o=`${t.constructor.name}_${e}`;this.eventListeners.has(o)||this.eventListeners.set(o,[]),this.eventListeners.get(o).push({element:t,event:e,handler:s,options:i})}handleDocumentClick(t){const e=t.target.closest(this.options.selector);e&&(t.preventDefault(),this.open(e))}handleKeydown(t){if(this.zoomora.classList.contains("active"))switch(t.key){case"Escape":this.isFullscreen?this.exitFullscreen():this.close();break;case"ArrowLeft":this.prev();break;case"ArrowRight":this.next();break;case"z":case"Z":this.toggleZoom();break;case"f":case"F":this.toggleFullscreen();break;case"t":case"T":this.toggleThumbnails()}}handleFullscreenChange(){const t=!!(document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement);!t&&this.isFullscreen?(this.isFullscreen=!1,this.zoomora.classList.remove("fullscreen"),this.updateButtons()):t&&!this.isFullscreen&&(this.isFullscreen=!0,this.zoomora.classList.add("fullscreen"),this.updateButtons())}handleZoomoraClick(t){t.target===this.zoomora&&this.options.closeOnBackgroundClick&&this.close()}handleContentClick(t){if(Date.now()-this.lastDragTime<200)return;if(this.header&&this.header.contains(t.target))return;if(t.target.closest("button"))return;const e=t.target.closest(".zoomora-media, .zoomora-video, .zoomora-iframe");if(e)return void(e.classList.contains("zoomora-media")&&!e.classList.contains("no-zoom")&&this.toggleZoom());if(t.target.closest(".zoomora-video-container")){if(t.target.closest(".zoomora-play-button"))return;return void(this.options.closeOnBackgroundClick&&this.close())}const s=t.target;((s.classList.contains("zoomora-content")||s.classList.contains("zoomora-slide-container")||s.classList.contains("zoomora-slide")||s.classList.contains("zoomora-slides-container")||"zoomoraContent"===s.id||"zoomoraSlidesContainer"===s.id)&&this.options.closeOnBackgroundClick||this.options.closeOnBackgroundClick)&&this.close()}handleMouseDown(t){this.startDrag(t)}handleMouseMove(t){this.drag(t)}handleMouseUp(){this.endDrag()}handleTouchStart(t){this.startDrag(t)}handleTouchMove(t){this.drag(t)}handleTouchEnd(){this.endDrag()}getImageSource(t){const e=t.dataset.src||t.src||t.getAttribute("src");return"video"===(t.dataset.type||"image")&&e?this.convertToEmbedUrl(e):e}convertToEmbedUrl(t){if(t.includes("youtube.com/embed/"))return t;let e=null,s=null;if(t.includes("youtube.com/watch")){const i=new URLSearchParams(t.split("?")[1]);e=i.get("v");const o=i.get("t");o&&(s=o.replace("s",""))}else if(t.includes("youtu.be/")){const i=t.split("/"),o=i[i.length-1];if(o.includes("?")){e=o.split("?")[0];const t=new URLSearchParams(o.split("?")[1]).get("t");t&&(s=t.replace("s",""))}else e=o}if(e){let t=`https://www.youtube.com/embed/${e}`;const i=new URLSearchParams;return s&&i.append("start",s),i.append("rel","0"),i.append("modestbranding","1"),i.toString()&&(t+="?"+i.toString()),t}return t}getThumbnailSource(t){return"video"===(t.dataset.type||"image")?t.src||t.getAttribute("src"):t.dataset.src||t.src||t.getAttribute("src")}getGroup(t){return this.options.useHref?t.dataset.lightbox||t.dataset.gallery||"default":t.dataset.zoomora||"default"}open(t){if(!t)return;const e=this.getGroup(t);let s;s=this.options.useHref?t.dataset.lightbox?`[data-lightbox="${e}"]`:t.dataset.gallery?`[data-gallery="${e}"]`:this.options.selector:`[data-zoomora="${e}"]`,this.items=Array.from(document.querySelectorAll(s)),this.currentIndex=Math.max(0,this.items.indexOf(t)),this.isZoomed=!1,this.isFullscreen=!1,this.thumbnailsVisible=!0,this.currentX=0,this.currentY=0,this.currentScale=1,this.zoomora.classList.add("active"),document.body.style.overflow="hidden",this.loadContent(),this.updateThumbnails(),this.updateCounter(),this.updateNavigation(),this.updateCaption(),this.updateButtons(),this.autoHideEnabled?this.startAutoHideTimer():this.showControls(),"function"==typeof this.options.onOpen&&this.options.onOpen(t,this.currentIndex)}close(){this.isFullscreen&&this.exitFullscreen(),this.zoomora.classList.remove("active"),document.body.style.overflow="",this.isZoomed=!1,this.isFullscreen=!1,this.currentX=0,this.currentY=0,this.currentScale=1;const t=this.content.querySelector(".zoomora-media");t&&(t.classList.remove("zoomed"),t.style.transform="",t.style.cursor=""),this.zoomora.classList.remove("fullscreen"),this.updateButtons(),this.stopAutoHideTimer(),this.showControls(),"function"==typeof this.options.onClose&&this.options.onClose(this.currentIndex)}prev(){this.currentIndex>0&&(this.currentIndex--,this.loadContent(),this.updateCounter(),this.updateThumbnails(),this.updateNavigation(),this.updateCaption(),"function"==typeof this.options.onPrev&&this.options.onPrev(this.currentIndex))}next(){this.currentIndex<this.items.length-1&&(this.currentIndex++,this.loadContent(),this.updateCounter(),this.updateThumbnails(),this.updateNavigation(),this.updateCaption(),"function"==typeof this.options.onNext&&this.options.onNext(this.currentIndex))}loadContent(){if(!this.items[this.currentIndex])return;const t=this.items[this.currentIndex],e=this.getImageSource(t),s=t.dataset.type||"image";e&&(this.isZoomed=!1,this.currentX=0,this.currentY=0,this.currentScale=1,this.loading.style.display="block",this.slidesContainer&&(this.slidesContainer.innerHTML=""),setTimeout(()=>{this.renderContent(e,s,t)},100))}renderContent(t,e,s){const i=document.createElement("div");i.className="zoomora-slide-container";const o=document.createElement("div");let n;o.className="zoomora-slide "+("slide"===this.options.transition?"slide-effect":"fade-effect"),o.style.opacity="0",o.style.transform="slide"===this.options.transition?"translateX(100%)":"scale(0.8)";try{switch(e){case"video":if(t.endsWith(".mp4")||t.endsWith(".webm")||t.endsWith(".ogg")){const e=document.createElement("div");e.className="zoomora-video-container",n=document.createElement("video"),n.src=t,n.className="zoomora-video",n.setAttribute("preload","metadata");const o=s.src||s.getAttribute("src");o&&n.setAttribute("poster",o);const a=document.createElement("div");a.className="zoomora-play-button",a.innerHTML='<svg viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>',a.addEventListener("click",()=>{n.play(),a.style.display="none",n.setAttribute("controls","")}),n.addEventListener("ended",()=>{a.style.display="flex"}),e.appendChild(n),e.appendChild(a),i.appendChild(e)}else n=document.createElement("iframe"),n.src=t,n.className="zoomora-video",n.setAttribute("allowfullscreen",""),n.setAttribute("frameborder","0"),i.appendChild(n);break;case"iframe":n=document.createElement("iframe"),n.src=t,n.className="zoomora-iframe",n.setAttribute("frameborder","0"),i.appendChild(n);break;default:n=document.createElement("img"),n.src=t,n.className="zoomora-media",n.alt=s.alt||s.title||"",n.onload=()=>{this.loading.style.display="none",this.checkZoomability(n),this.animateSlideIn(o)},n.onerror=()=>{this.loading.style.display="none",this.animateSlideIn(o)},i.appendChild(n)}o.appendChild(i),this.slidesContainer.innerHTML="",this.slidesContainer.appendChild(o),"image"!==e&&(this.loading.style.display="none",this.animateSlideIn(o))}catch(t){this.loading.style.display="none"}}animateSlideIn(t){t.offsetHeight,t.classList.add("active"),"slide"===this.options.transition?(t.style.transition=`transform ${this.options.animationDuration}ms ease, opacity ${this.options.animationDuration}ms ease`,t.style.transform="translateX(0)",t.style.opacity="1"):(t.style.transition=`transform ${this.options.animationDuration}ms ease, opacity ${this.options.animationDuration}ms ease`,t.style.transform="scale(1)",t.style.opacity="1")}toggleAutoHide(){this.autoHideEnabled=!this.autoHideEnabled;const t=document.getElementById("zoomoraAutoHideBtn");this.autoHideEnabled?(t.classList.add("active"),t.title="Disable Auto-Hide Controls",this.startAutoHideTimer()):(t.classList.remove("active"),t.title="Enable Auto-Hide Controls",this.stopAutoHideTimer(),this.showControls())}handleUserActivity(){this.autoHideEnabled&&(this.showControls(),this.startAutoHideTimer())}startAutoHideTimer(){this.stopAutoHideTimer(),this.autoHideTimeout=setTimeout(()=>{this.hideControls()},this.options.autoHideDelay)}stopAutoHideTimer(){this.autoHideTimeout&&(clearTimeout(this.autoHideTimeout),this.autoHideTimeout=null)}showControls(){this.isControlsVisible||(this.isControlsVisible=!0,this.zoomora.classList.remove("controls-hidden"),this.header&&(this.header.style.transform="translateY(0)",this.header.style.opacity="1"),this.caption&&(this.caption.style.transform="translateX(-50%) translateY(0)",this.caption.style.opacity="1"),this.thumbs&&(this.thumbs.style.transform="translateX(-50%) translateY(0)",this.thumbs.style.opacity="1"),this.prevBtn&&(this.prevBtn.style.transform="translateX(0)",this.prevBtn.style.opacity="1"),this.nextBtn&&(this.nextBtn.style.transform="translateX(0)",this.nextBtn.style.opacity="1"))}hideControls(){this.isControlsVisible&&(this.isControlsVisible=!1,this.zoomora.classList.add("controls-hidden"),this.header&&(this.header.style.transform="translateY(-100%)",this.header.style.opacity="0"),this.caption&&(this.caption.style.transform="translateX(-50%) translateY(100%)",this.caption.style.opacity="0"),this.thumbs&&(this.thumbs.style.transform="translateX(-50%) translateY(100%)",this.thumbs.style.opacity="0"),this.prevBtn&&(this.prevBtn.style.transform="translateX(-100%)",this.prevBtn.style.opacity="0"),this.nextBtn&&(this.nextBtn.style.transform="translateX(100%)",this.nextBtn.style.opacity="0"))}checkZoomability(t){if(!t||!t.naturalWidth||!t.naturalHeight)return;const e=t.getBoundingClientRect(),s=e.width,i=e.height,o=t.naturalWidth,n=t.naturalHeight,a=o>s||n>i,r=o/s,l=n/i,h=Math.max(r,l);t.dataset.zoomRatio=h,t.dataset.naturalWidth=o,t.dataset.naturalHeight=n,t.dataset.renderedWidth=s,t.dataset.renderedHeight=i,a&&h>1.1?t.classList.remove("no-zoom"):t.classList.add("no-zoom")}calculateZoomLevels(t){if(!t||!t.naturalWidth||!t.naturalHeight)return{canZoom:!1,levels:[],currentLevel:0};const e=this.content.getBoundingClientRect(),s=e.width,i=e.height,o=t.naturalWidth,n=t.naturalHeight,a=s/o,r=i/n,l=Math.min(a,r);if(l>=.95)return{canZoom:!1,levels:[],currentLevel:0};const h=[1];1.5*l<=1&&h.push(1.5),2*l<=1&&h.push(2),3*l<=1&&h.push(3);const c=1/l;return c>h[h.length-1]&&h.push(c),{canZoom:h.length>1,levels:h,currentLevel:0,baseScale:l,naturalWidth:o,naturalHeight:n}}updateCounter(){this.options.showCounter&&this.counter&&(this.counter.textContent=`${this.currentIndex+1} / ${this.items.length}`)}updateCaption(){if(!this.caption||!this.items[this.currentIndex])return;const t=this.items[this.currentIndex],e=t.dataset.caption||t.title||"";e?(this.caption.textContent=e,this.caption.style.transform="translateX(-50%) translateY(0)",this.caption.style.opacity="1",this.caption.style.pointerEvents="auto",this.caption.style.transition="opacity 0.3s ease, transform 0.3s ease"):(this.caption.style.transform="translateX(-50%) translateY(100%)",this.caption.style.opacity="0",this.caption.style.pointerEvents="none",this.caption.style.transition="opacity 0.3s ease, transform 0.3s ease")}updateThumbnails(){if(this.options.showThumbnails&&this.thumbs){if(1===this.items.length)return this.caption.classList.add("single-item-thumbnail"),void(this.thumbs.style.display="none");this.caption.classList.remove("single-item-thumbnail"),this.thumbs.style.display="flex",this.thumbs.innerHTML="",this.items.forEach((t,e)=>{const s=document.createElement("div");s.className="zoomora-thumb",e===this.currentIndex&&s.classList.add("active");const i=document.createElement("img"),o=this.getThumbnailSource(t);o&&(i.src=o,i.alt=t.alt||t.title||"",i.onerror=()=>{s.style.display="none"}),s.appendChild(i),s.addEventListener("click",()=>{this.currentIndex=e,this.loadContent(),this.updateCounter(),this.updateThumbnails(),this.updateNavigation(),this.updateCaption()}),this.thumbs.appendChild(s)})}}updateNavigation(){const t=document.getElementById("zoomoraPrevBtn"),e=document.getElementById("zoomoraNextBtn");t&&(t.style.display=this.currentIndex>0?"flex":"none"),e&&(e.style.display=this.currentIndex<this.items.length-1?"flex":"none")}updateButtons(){const t=document.getElementById("zoomoraFullscreenBtn"),e=document.getElementById("zoomoraCollapseBtn");t&&e&&(this.isFullscreen?(t.style.display="none",e.style.display="flex"):(t.style.display="flex",e.style.display="none"))}toggleZoom(){const t=this.content.querySelector(".zoomora-media");if(!t||"IMG"!==t.tagName)return;const e=this.calculateZoomLevels(t);if(!e.canZoom)return;t.dataset.zoomLevel||(t.dataset.zoomLevel="0");let s=parseInt(t.dataset.zoomLevel)||0;s++,s>=e.levels.length&&(s=0);const i=e.levels[s];t.dataset.zoomLevel=s.toString(),0===s?(this.isZoomed=!1,this.isDragging=!1,t.classList.remove("dragging"),t.style.transform="",t.style.cursor="pointer",t.classList.remove("zoomed"),this.currentX=0,this.currentY=0,this.currentScale=1):(this.isZoomed=!0,this.currentScale=i,this.currentX=0,this.currentY=0,t.style.transform=`translate(0px, 0px) scale(${i})`,t.style.cursor="grab",t.classList.add("zoomed"))}updateImageTransform(t){if(t)if(1===this.currentScale)t.style.transform="";else{const e=this.currentX/this.currentScale,s=this.currentY/this.currentScale;t.style.transform=`scale(${this.currentScale}) translate(${e}px, ${s}px)`}}toggleFullscreen(){this.isFullscreen?this.exitFullscreen():this.enterFullscreen()}enterFullscreen(){const t=this.zoomora;try{t.requestFullscreen?t.requestFullscreen().then(()=>{this.isFullscreen=!0,this.zoomora.classList.add("fullscreen"),this.updateButtons()}).catch(t=>{this.fallbackFullscreen()}):t.webkitRequestFullscreen?(t.webkitRequestFullscreen(),this.isFullscreen=!0,this.zoomora.classList.add("fullscreen"),this.updateButtons()):t.mozRequestFullScreen?(t.mozRequestFullScreen(),this.isFullscreen=!0,this.zoomora.classList.add("fullscreen"),this.updateButtons()):t.msRequestFullscreen?(t.msRequestFullscreen(),this.isFullscreen=!0,this.zoomora.classList.add("fullscreen"),this.updateButtons()):this.fallbackFullscreen()}catch(t){this.fallbackFullscreen()}}exitFullscreen(){if(document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement)try{document.exitFullscreen?document.exitFullscreen().then(()=>{this.isFullscreen=!1,this.zoomora.classList.remove("fullscreen"),this.updateButtons()}).catch(t=>{this.fallbackExitFullscreen()}):document.webkitExitFullscreen?(document.webkitExitFullscreen(),this.isFullscreen=!1,this.zoomora.classList.remove("fullscreen"),this.updateButtons()):document.mozCancelFullScreen?(document.mozCancelFullScreen(),this.isFullscreen=!1,this.zoomora.classList.remove("fullscreen"),this.updateButtons()):document.msExitFullscreen?(document.msExitFullscreen(),this.isFullscreen=!1,this.zoomora.classList.remove("fullscreen"),this.updateButtons()):this.fallbackExitFullscreen()}catch(t){this.fallbackExitFullscreen()}else this.fallbackExitFullscreen()}fallbackFullscreen(){this.isFullscreen=!0,this.zoomora.classList.add("fullscreen"),this.updateButtons()}fallbackExitFullscreen(){this.isFullscreen=!1,this.zoomora.classList.remove("fullscreen"),this.updateButtons()}toggleThumbnails(){if(1!==this.items.length&&(this.thumbnailsVisible=!this.thumbnailsVisible,this.thumbs)){if(this.thumbs.classList.toggle("thumbs-hidden",!this.thumbnailsVisible),!this.caption||!this.items[this.currentIndex])return;const t=this.items[this.currentIndex];(t.dataset.caption||t.title)&&this.thumbs.classList.contains("thumbs-hidden")?(this.caption.style.bottom="20px",this.caption.style.transition="bottom 0.3s ease, transform 0.3s ease"):this.caption.style.bottom="120px"}}startDrag(t){const e=this.content.querySelector(".zoomora-media");if(!e||!this.isZoomed)return;this.isDragging=!0,e.classList.add("dragging"),e.style.cursor="grabbing",this.startX=t.clientX||t.touches&&t.touches[0].clientX||0,this.startY=t.clientY||t.touches&&t.touches[0].clientY||0;const s=window.getComputedStyle(e).transform;if(s&&"none"!==s){const t=new DOMMatrix(s);this.currentX=t.m41,this.currentY=t.m42}else this.currentX=0,this.currentY=0;t.preventDefault()}drag(t){if(!this.isDragging)return;t.preventDefault();const e=this.content.querySelector(".zoomora-media");if(!e)return;const s=t.clientX||t.touches&&t.touches[0].clientX||0,i=t.clientY||t.touches&&t.touches[0].clientY||0,o=s-this.startX,n=i-this.startY;let a=this.currentX+o,r=this.currentY+n;const l=this.content.getBoundingClientRect(),h=e.getBoundingClientRect(),c=Math.max(0,(h.width-l.width)/2),d=Math.max(0,(h.height-l.height)/2);a=c>0?Math.max(-c,Math.min(c,a)):0,r=d>0?Math.max(-d,Math.min(d,r)):0,e.style.transform=`translate(${a}px, ${r}px) scale(${this.currentScale})`,this.startX=s,this.startY=i,this.currentX=a,this.currentY=r}endDrag(){if(!this.isDragging)return;this.isDragging=!1,this.lastDragTime=Date.now();const t=this.content.querySelector(".zoomora-media");t&&(t.classList.remove("dragging"),this.isZoomed&&(t.style.cursor="grab"))}goTo(t){t<0||t>=this.items.length||(this.currentIndex=t,this.loadContent(),this.updateCounter(),this.updateThumbnails(),this.updateNavigation(),this.updateCaption())}getCurrentIndex(){return this.currentIndex}getTotalItems(){return this.items.length}isOpen(){return this.zoomora&&this.zoomora.classList.contains("active")}updateOptions(t){this.options=h(h({},this.options),t)}refresh(){if(this.isOpen()){const t=this.items[this.currentIndex];t&&this.open(t)}}destroy(){this.isInitialized&&(this.isOpen()&&this.close(),this.stopAutoHideTimer(),this.eventListeners.forEach((t,e)=>{t.forEach(({element:t,event:e,handler:s,options:i})=>{t&&t.removeEventListener&&t.removeEventListener(e,s,i)})}),this.eventListeners.clear(),this.zoomora&&this.zoomora.parentNode&&this.zoomora.parentNode.removeChild(this.zoomora),this.isInitialized=!1,this.items=[],this.currentIndex=0,this.zoomora=null,this.content=null,this.counter=null,this.thumbs=null,this.loading=null,this.caption=null)}}return t},"object"==typeof module&&"object"==typeof module.exports?module.exports=e():"function"==typeof define&&define.amd?define(e):t.Zoomora=e()});
|
|
10
|
-
|
|
1
|
+
(function(t, e) {
|
|
2
|
+
"object" == typeof exports && "undefined" != typeof module ? module.exports = e() : "function" == typeof define && define.amd ? define([], e) : (t = "undefined" != typeof globalThis ? globalThis : t || self).Zoomora = e();
|
|
3
|
+
})(this, function() {
|
|
4
|
+
var t = (t, e, s) => () => {
|
|
5
|
+
if (s) throw s[0];
|
|
6
|
+
try {
|
|
7
|
+
return t && (e = t(t = 0)), e;
|
|
8
|
+
} catch (t) {
|
|
9
|
+
throw s = [t], t;
|
|
10
|
+
}
|
|
11
|
+
}, e = (t, e) => () => (e || (t((e = { exports: {} }).exports, e), t = null), e.exports), s = t(() => {});
|
|
12
|
+
function o(t) {
|
|
13
|
+
return o = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) {
|
|
14
|
+
return typeof t;
|
|
15
|
+
} : function(t) {
|
|
16
|
+
return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t;
|
|
17
|
+
}, o(t);
|
|
18
|
+
}
|
|
19
|
+
var i = t(() => {});
|
|
20
|
+
var n = t(() => {
|
|
21
|
+
i();
|
|
22
|
+
});
|
|
23
|
+
function a(t) {
|
|
24
|
+
var e = function(t, e) {
|
|
25
|
+
if ("object" != o(t) || !t) return t;
|
|
26
|
+
var s = t[Symbol.toPrimitive];
|
|
27
|
+
if (void 0 !== s) {
|
|
28
|
+
var i = s.call(t, e || "default");
|
|
29
|
+
if ("object" != o(i)) return i;
|
|
30
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
31
|
+
}
|
|
32
|
+
return ("string" === e ? String : Number)(t);
|
|
33
|
+
}(t, "string");
|
|
34
|
+
return "symbol" == o(e) ? e : e + "";
|
|
35
|
+
}
|
|
36
|
+
var r = t(() => {
|
|
37
|
+
i(), n();
|
|
38
|
+
});
|
|
39
|
+
function l(t, e, s) {
|
|
40
|
+
return (e = a(e)) in t ? Object.defineProperty(t, e, {
|
|
41
|
+
value: s,
|
|
42
|
+
enumerable: !0,
|
|
43
|
+
configurable: !0,
|
|
44
|
+
writable: !0
|
|
45
|
+
}) : t[e] = s, t;
|
|
46
|
+
}
|
|
47
|
+
var h = t(() => {
|
|
48
|
+
r();
|
|
49
|
+
});
|
|
50
|
+
function c(t, e) {
|
|
51
|
+
var s = Object.keys(t);
|
|
52
|
+
if (Object.getOwnPropertySymbols) {
|
|
53
|
+
var o = Object.getOwnPropertySymbols(t);
|
|
54
|
+
e && (o = o.filter(function(e) {
|
|
55
|
+
return Object.getOwnPropertyDescriptor(t, e).enumerable;
|
|
56
|
+
})), s.push.apply(s, o);
|
|
57
|
+
}
|
|
58
|
+
return s;
|
|
59
|
+
}
|
|
60
|
+
function d(t) {
|
|
61
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
62
|
+
var s = null != arguments[e] ? arguments[e] : {};
|
|
63
|
+
e % 2 ? c(Object(s), !0).forEach(function(e) {
|
|
64
|
+
l(t, e, s[e]);
|
|
65
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(t, Object.getOwnPropertyDescriptors(s)) : c(Object(s)).forEach(function(e) {
|
|
66
|
+
Object.defineProperty(t, e, Object.getOwnPropertyDescriptor(s, e));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return t;
|
|
70
|
+
}
|
|
71
|
+
var u = t(() => {
|
|
72
|
+
h();
|
|
73
|
+
});
|
|
74
|
+
return e((t, e) => {
|
|
75
|
+
s(), u(), function(t, s) {
|
|
76
|
+
"use strict";
|
|
77
|
+
/*!
|
|
78
|
+
* Zoomora Lightbox Plugin v1.3.0
|
|
79
|
+
* A modern, responsive lightbox plugin with zoom, fullscreen, and gallery features
|
|
80
|
+
*
|
|
81
|
+
* Copyright (c) 2026 Faruk Ahmed (FrontTheme)
|
|
82
|
+
* Licensed under MIT License
|
|
83
|
+
*/
|
|
84
|
+
"object" == typeof e && "object" == typeof e.exports ? e.exports = s() : "function" == typeof define && define.amd ? define(s) : t.Zoomora = s();
|
|
85
|
+
}("undefined" != typeof window ? window : t, function() {
|
|
86
|
+
"use strict";
|
|
87
|
+
class t {
|
|
88
|
+
static get defaults() {
|
|
89
|
+
return {
|
|
90
|
+
selector: "[data-zoomora]",
|
|
91
|
+
showCounter: !0,
|
|
92
|
+
showThumbnails: !0,
|
|
93
|
+
showFullscreen: !0,
|
|
94
|
+
showZoom: !0,
|
|
95
|
+
transition: "fade",
|
|
96
|
+
useHref: !1,
|
|
97
|
+
maxZoomScale: 3,
|
|
98
|
+
zoomStep: .1,
|
|
99
|
+
animationDuration: 300,
|
|
100
|
+
closeOnBackgroundClick: !0,
|
|
101
|
+
onOpen: null,
|
|
102
|
+
onClose: null,
|
|
103
|
+
onNext: null,
|
|
104
|
+
onPrev: null,
|
|
105
|
+
showAutoHideToggle: !0,
|
|
106
|
+
autoHideDelay: 3e3,
|
|
107
|
+
autoHideEnabled: !1
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
constructor(e = {}) {
|
|
111
|
+
this.options = d(d({}, t.defaults), e), this.currentIndex = 0, this.items = [], this.isZoomed = !1, this.isFullscreen = !1, this.isDragging = !1, this.thumbnailsVisible = !0, this.startX = 0, this.startY = 0, this.currentX = 0, this.currentY = 0, this.currentScale = 1, this.isInitialized = !1, this.eventListeners = /* @__PURE__ */ new Map(), this.autoHideEnabled = !1, this.autoHideTimeout = null, this.autoHideDelay = 3e3, this.isControlsVisible = !0, this.lastDragTime = 0, this.boundMethods = {
|
|
112
|
+
handleDocumentClick: this.handleDocumentClick.bind(this),
|
|
113
|
+
handleKeydown: this.handleKeydown.bind(this),
|
|
114
|
+
handleFullscreenChange: this.handleFullscreenChange.bind(this),
|
|
115
|
+
handleZoomoraClick: this.handleZoomoraClick.bind(this),
|
|
116
|
+
handleContentClick: this.handleContentClick.bind(this),
|
|
117
|
+
handleMouseDown: this.handleMouseDown.bind(this),
|
|
118
|
+
handleMouseMove: this.handleMouseMove.bind(this),
|
|
119
|
+
handleMouseUp: this.handleMouseUp.bind(this),
|
|
120
|
+
handleTouchStart: this.handleTouchStart.bind(this),
|
|
121
|
+
handleTouchMove: this.handleTouchMove.bind(this),
|
|
122
|
+
handleTouchEnd: this.handleTouchEnd.bind(this),
|
|
123
|
+
handleWheel: this.handleWheel.bind(this)
|
|
124
|
+
}, this.init();
|
|
125
|
+
}
|
|
126
|
+
init() {
|
|
127
|
+
if (!this.isInitialized) try {
|
|
128
|
+
this.createLightbox(), this.bindEvents(), this.isInitialized = !0;
|
|
129
|
+
} catch (t) {}
|
|
130
|
+
}
|
|
131
|
+
static bind(e, s = {}) {
|
|
132
|
+
return new t(d(d({}, s), {}, {
|
|
133
|
+
selector: e,
|
|
134
|
+
useHref: !0
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
createLightbox() {
|
|
138
|
+
if (document.getElementById("zoomoraLightbox")) return;
|
|
139
|
+
const t = this.options.showAutoHideToggle ? "\n <button class=\"zoomora-btn\" id=\"zoomoraAutoHideBtn\" title=\"Toggle Auto-Hide Controls\">\n <i class=\"zoomorai-controls-off\"></i>\n </button>\n " : "", e = `\n <div class="zoomora" id="zoomoraLightbox">\n <div class="zoomora-container">\n <div class="zoomora-header" id="zoomoraHeader">\n <div class="zoomora-counter" id="zoomoraCounter" ${this.options.showCounter ? "" : "style=\"opacity:0;visibility:hidden;\""}>1 / 1</div>\n <div class="zoomora-controls">\n ${this.options.showThumbnails ? "\n <button class=\"zoomora-btn\" id=\"zoomoraThumbnailBtn\" title=\"Toggle Thumbnails\">\n <i class=\"zoomorai-thumbnails\"></i>\n </button>\n " : ""}\n ${t}\n ${this.options.showZoom ? "\n <button class=\"zoomora-btn\" id=\"zoomoraZoomBtn\" title=\"Zoom\">\n <i class=\"zoomorai-zoom\"></i>\n </button>\n " : ""}\n ${this.options.showFullscreen ? "\n <button class=\"zoomora-btn\" id=\"zoomoraFullscreenBtn\" title=\"Fullscreen\">\n <i class=\"zoomorai-expand\"></i>\n </button>\n <button class=\"zoomora-btn\" id=\"zoomoraCollapseBtn\" title=\"Exit Fullscreen\" style=\"display: none;\">\n <i class=\"zoomorai-collapse\"></i>\n </button>\n " : ""}\n <button class="zoomora-btn" id="zoomoraCloseBtn" title="Close">\n <i class="zoomorai-close"></i>\n </button>\n </div>\n </div>\n \n <div class="zoomora-content" id="zoomoraContent">\n <div class="zoomora-loading" id="zoomoraLoading"></div>\n <div class="zoomora-slides-container" id="zoomoraSlidesContainer"></div>\n </div>\n \n <button class="zoomora-nav prev" id="zoomoraPrevBtn">\n <i class="zoomorai-arrow-left"></i>\n </button>\n <button class="zoomora-nav next" id="zoomoraNextBtn">\n <i class="zoomorai-arrow-right"></i>\n </button>\n \n <div class="zoomora-caption" id="zoomoraCaption" ${this.options.showThumbnails ? "" : "style=\"bottom:20px;\""}></div>\n <div class="zoomora-thumbnails" id="zoomoraThumbs" ${this.options.showThumbnails ? "" : "style=\"display:none;\""}></div>\n </div>\n </div>\n `;
|
|
140
|
+
if (document.body.insertAdjacentHTML("beforeend", e), this.zoomora = document.getElementById("zoomoraLightbox"), this.header = document.getElementById("zoomoraHeader"), this.content = document.getElementById("zoomoraContent"), this.slidesContainer = document.getElementById("zoomoraSlidesContainer"), this.counter = document.getElementById("zoomoraCounter"), this.thumbs = document.getElementById("zoomoraThumbs"), this.loading = document.getElementById("zoomoraLoading"), this.caption = document.getElementById("zoomoraCaption"), this.prevBtn = document.getElementById("zoomoraPrevBtn"), this.nextBtn = document.getElementById("zoomoraNextBtn"), !(this.zoomora && this.content && this.counter && this.thumbs && this.loading && this.caption)) throw new Error("Failed to create required DOM elements");
|
|
141
|
+
}
|
|
142
|
+
bindEvents() {
|
|
143
|
+
this.addEventListener(document, "click", this.boundMethods.handleDocumentClick), this.addEventListener(document.getElementById("zoomoraCloseBtn"), "click", () => this.close()), this.addEventListener(document.getElementById("zoomoraPrevBtn"), "click", () => this.prev()), this.addEventListener(document.getElementById("zoomoraNextBtn"), "click", () => this.next()), this.options.showZoom && this.addEventListener(document.getElementById("zoomoraZoomBtn"), "click", () => this.toggleZoom()), this.options.showFullscreen && (this.addEventListener(document.getElementById("zoomoraFullscreenBtn"), "click", () => this.toggleFullscreen()), this.addEventListener(document.getElementById("zoomoraCollapseBtn"), "click", () => this.exitFullscreen())), this.options.showThumbnails && this.addEventListener(document.getElementById("zoomoraThumbnailBtn"), "click", () => this.toggleThumbnails()), this.addEventListener(document, "fullscreenchange", this.boundMethods.handleFullscreenChange), this.addEventListener(document, "webkitfullscreenchange", this.boundMethods.handleFullscreenChange), this.addEventListener(document, "mozfullscreenchange", this.boundMethods.handleFullscreenChange), this.addEventListener(document, "MSFullscreenChange", this.boundMethods.handleFullscreenChange), this.addEventListener(document, "keydown", this.boundMethods.handleKeydown), this.addEventListener(this.zoomora, "click", this.boundMethods.handleZoomoraClick), this.addEventListener(this.content, "click", this.boundMethods.handleContentClick), this.addEventListener(this.content, "mousedown", this.boundMethods.handleMouseDown), this.addEventListener(this.content, "mousemove", this.boundMethods.handleMouseMove), this.addEventListener(this.content, "mouseup", this.boundMethods.handleMouseUp), this.addEventListener(this.content, "mouseleave", this.boundMethods.handleMouseUp), this.addEventListener(this.content, "touchstart", this.boundMethods.handleTouchStart, { passive: !1 }), this.addEventListener(this.content, "touchmove", this.boundMethods.handleTouchMove, { passive: !1 }), this.addEventListener(this.content, "touchend", this.boundMethods.handleTouchEnd), this.options.showZoom && this.addEventListener(this.content, "wheel", this.boundMethods.handleWheel, { passive: !1 }), this.options.showAutoHideToggle && (this.addEventListener(document.getElementById("zoomoraAutoHideBtn"), "click", () => this.toggleAutoHide()), this.addEventListener(this.zoomora, "mousemove", () => this.handleUserActivity()), this.addEventListener(this.zoomora, "touchstart", () => this.handleUserActivity()), this.addEventListener(this.zoomora, "keydown", () => this.handleUserActivity()));
|
|
144
|
+
}
|
|
145
|
+
addEventListener(t, e, s, o = {}) {
|
|
146
|
+
if (!t) return;
|
|
147
|
+
t.addEventListener(e, s, o);
|
|
148
|
+
const i = `${t.constructor.name}_${e}`;
|
|
149
|
+
this.eventListeners.has(i) || this.eventListeners.set(i, []), this.eventListeners.get(i).push({
|
|
150
|
+
element: t,
|
|
151
|
+
event: e,
|
|
152
|
+
handler: s,
|
|
153
|
+
options: o
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
handleDocumentClick(t) {
|
|
157
|
+
const e = t.target.closest(this.options.selector);
|
|
158
|
+
e && (t.preventDefault(), this.open(e));
|
|
159
|
+
}
|
|
160
|
+
handleKeydown(t) {
|
|
161
|
+
if (this.zoomora.classList.contains("active")) switch (t.key) {
|
|
162
|
+
case "Escape":
|
|
163
|
+
this.isFullscreen ? this.exitFullscreen() : this.close();
|
|
164
|
+
break;
|
|
165
|
+
case "ArrowLeft":
|
|
166
|
+
this.prev();
|
|
167
|
+
break;
|
|
168
|
+
case "ArrowRight":
|
|
169
|
+
this.next();
|
|
170
|
+
break;
|
|
171
|
+
case "z":
|
|
172
|
+
case "Z":
|
|
173
|
+
this.toggleZoom();
|
|
174
|
+
break;
|
|
175
|
+
case "f":
|
|
176
|
+
case "F":
|
|
177
|
+
this.toggleFullscreen();
|
|
178
|
+
break;
|
|
179
|
+
case "t":
|
|
180
|
+
case "T": this.toggleThumbnails();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
handleFullscreenChange() {
|
|
184
|
+
const t = !!(document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement);
|
|
185
|
+
!t && this.isFullscreen ? (this.isFullscreen = !1, this.zoomora.classList.remove("fullscreen"), this.updateButtons()) : t && !this.isFullscreen && (this.isFullscreen = !0, this.zoomora.classList.add("fullscreen"), this.updateButtons());
|
|
186
|
+
}
|
|
187
|
+
handleZoomoraClick(t) {
|
|
188
|
+
t.target === this.zoomora && this.options.closeOnBackgroundClick && this.close();
|
|
189
|
+
}
|
|
190
|
+
handleContentClick(t) {
|
|
191
|
+
if (Date.now() - this.lastDragTime < 200) return;
|
|
192
|
+
if (this.header && this.header.contains(t.target)) return;
|
|
193
|
+
if (t.target.closest("button")) return;
|
|
194
|
+
const e = t.target.closest(".zoomora-media, .zoomora-video, .zoomora-iframe");
|
|
195
|
+
if (e) return void (e.classList.contains("zoomora-media") && !e.classList.contains("no-zoom") && this.toggleZoom());
|
|
196
|
+
if (t.target.closest(".zoomora-video-container")) {
|
|
197
|
+
if (t.target.closest(".zoomora-play-button")) return;
|
|
198
|
+
this.options.closeOnBackgroundClick && this.close();
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const s = t.target;
|
|
202
|
+
((s.classList.contains("zoomora-content") || s.classList.contains("zoomora-slide-container") || s.classList.contains("zoomora-slide") || s.classList.contains("zoomora-slides-container") || "zoomoraContent" === s.id || "zoomoraSlidesContainer" === s.id) && this.options.closeOnBackgroundClick || this.options.closeOnBackgroundClick) && this.close();
|
|
203
|
+
}
|
|
204
|
+
handleMouseDown(t) {
|
|
205
|
+
this.startDrag(t);
|
|
206
|
+
}
|
|
207
|
+
handleMouseMove(t) {
|
|
208
|
+
this.drag(t);
|
|
209
|
+
}
|
|
210
|
+
handleMouseUp() {
|
|
211
|
+
this.endDrag();
|
|
212
|
+
}
|
|
213
|
+
handleTouchStart(t) {
|
|
214
|
+
this.startDrag(t);
|
|
215
|
+
}
|
|
216
|
+
handleTouchMove(t) {
|
|
217
|
+
this.drag(t);
|
|
218
|
+
}
|
|
219
|
+
handleTouchEnd() {
|
|
220
|
+
this.endDrag();
|
|
221
|
+
}
|
|
222
|
+
handleWheel(t) {
|
|
223
|
+
const e = this.content.querySelector(".zoomora-media");
|
|
224
|
+
if (!e || "IMG" !== e.tagName) return;
|
|
225
|
+
const s = this.calculateZoomLevels(e);
|
|
226
|
+
if (!s.canZoom) return;
|
|
227
|
+
t.preventDefault();
|
|
228
|
+
const o = s.levels[s.levels.length - 1], i = this.options.zoomStep || .1, n = t.deltaY < 0 ? 1 : -1;
|
|
229
|
+
let a = (this.currentScale || 1) + n * i * o;
|
|
230
|
+
if (a = Math.max(1, Math.min(o, a)), a === this.currentScale) return;
|
|
231
|
+
this.currentScale = a, this.isZoomed = a > 1, this.currentX = 0, this.currentY = 0, this.isZoomed ? (e.style.transform = `scale(${a})`, e.style.cursor = "grab", e.classList.add("zoomed")) : (e.style.transform = "", e.style.cursor = "pointer", e.classList.remove("zoomed"));
|
|
232
|
+
let r = 0;
|
|
233
|
+
s.levels.forEach((t, e) => {
|
|
234
|
+
Math.abs(t - a) < Math.abs(s.levels[r] - a) && (r = e);
|
|
235
|
+
}), e.dataset.zoomLevel = r.toString();
|
|
236
|
+
}
|
|
237
|
+
getImageSource(t) {
|
|
238
|
+
const e = t.dataset.src || t.src || t.getAttribute("src");
|
|
239
|
+
return "video" === (t.dataset.type || "image") && e ? this.convertToEmbedUrl(e) : e;
|
|
240
|
+
}
|
|
241
|
+
convertToEmbedUrl(t) {
|
|
242
|
+
if (t.includes("youtube.com/embed/")) return t;
|
|
243
|
+
let e = null, s = null;
|
|
244
|
+
if (t.includes("youtube.com/watch")) {
|
|
245
|
+
const o = new URLSearchParams(t.split("?")[1]);
|
|
246
|
+
e = o.get("v");
|
|
247
|
+
const i = o.get("t");
|
|
248
|
+
i && (s = i.replace("s", ""));
|
|
249
|
+
} else if (t.includes("youtu.be/")) {
|
|
250
|
+
const o = t.split("/"), i = o[o.length - 1];
|
|
251
|
+
if (i.includes("?")) {
|
|
252
|
+
e = i.split("?")[0];
|
|
253
|
+
const t = new URLSearchParams(i.split("?")[1]).get("t");
|
|
254
|
+
t && (s = t.replace("s", ""));
|
|
255
|
+
} else e = i;
|
|
256
|
+
}
|
|
257
|
+
if (e) {
|
|
258
|
+
let t = `https://www.youtube.com/embed/${e}`;
|
|
259
|
+
const o = new URLSearchParams();
|
|
260
|
+
return s && o.append("start", s), o.append("rel", "0"), o.append("modestbranding", "1"), o.toString() && (t += "?" + o.toString()), t;
|
|
261
|
+
}
|
|
262
|
+
return t;
|
|
263
|
+
}
|
|
264
|
+
getThumbnailSource(t) {
|
|
265
|
+
return "video" === (t.dataset.type || "image") ? t.src || t.getAttribute("src") : t.dataset.src || t.src || t.getAttribute("src");
|
|
266
|
+
}
|
|
267
|
+
getGroup(t) {
|
|
268
|
+
return this.options.useHref ? t.dataset.lightbox || t.dataset.gallery || "default" : t.dataset.zoomora || "default";
|
|
269
|
+
}
|
|
270
|
+
open(t) {
|
|
271
|
+
if (!t) return;
|
|
272
|
+
const e = this.getGroup(t);
|
|
273
|
+
let s;
|
|
274
|
+
s = this.options.useHref ? t.dataset.lightbox ? `[data-lightbox="${e}"]` : t.dataset.gallery ? `[data-gallery="${e}"]` : this.options.selector : `[data-zoomora="${e}"]`, this.items = Array.from(document.querySelectorAll(s)), this.currentIndex = Math.max(0, this.items.indexOf(t)), this._activateLightbox(), "function" == typeof this.options.onOpen && this.options.onOpen(t, this.currentIndex);
|
|
275
|
+
}
|
|
276
|
+
openImage(t, e = {}) {
|
|
277
|
+
const s = Array.isArray(t) ? t : [t];
|
|
278
|
+
this.items = s.map((t) => this.createVirtualItem("string" == typeof t ? { src: t } : t)), this.currentIndex = Math.max(0, Math.min(e.startIndex || 0, this.items.length - 1)), this._activateLightbox(), "function" == typeof this.options.onOpen && this.options.onOpen(this.items[this.currentIndex], this.currentIndex);
|
|
279
|
+
}
|
|
280
|
+
createVirtualItem({ src: t, thumb: e, type: s = "image", caption: o = "", alt: i = "" }) {
|
|
281
|
+
const n = e || t;
|
|
282
|
+
return {
|
|
283
|
+
dataset: {
|
|
284
|
+
src: t,
|
|
285
|
+
type: s,
|
|
286
|
+
caption: o
|
|
287
|
+
},
|
|
288
|
+
src: n,
|
|
289
|
+
alt: i,
|
|
290
|
+
title: o,
|
|
291
|
+
getAttribute: (t) => "src" === t ? n : null
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
_activateLightbox() {
|
|
295
|
+
this.isZoomed = !1, this.isFullscreen = !1, this.thumbnailsVisible = !0, this.currentX = 0, this.currentY = 0, this.currentScale = 1, this.zoomora.classList.add("active"), document.body.style.overflow = "hidden", this.loadContent(), this.updateThumbnails(), this.updateCounter(), this.updateNavigation(), this.updateCaption(), this.updateButtons(), this.autoHideEnabled ? this.startAutoHideTimer() : this.showControls();
|
|
296
|
+
}
|
|
297
|
+
close() {
|
|
298
|
+
this.isFullscreen && this.exitFullscreen(), this.zoomora.classList.remove("active"), document.body.style.overflow = "", this.isZoomed = !1, this.isFullscreen = !1, this.currentX = 0, this.currentY = 0, this.currentScale = 1;
|
|
299
|
+
const t = this.content.querySelector(".zoomora-media");
|
|
300
|
+
t && (t.classList.remove("zoomed"), t.style.transform = "", t.style.cursor = ""), this.zoomora.classList.remove("fullscreen"), this.updateButtons(), this.stopAutoHideTimer(), this.showControls(), "function" == typeof this.options.onClose && this.options.onClose(this.currentIndex);
|
|
301
|
+
}
|
|
302
|
+
prev() {
|
|
303
|
+
this.currentIndex > 0 && (this.currentIndex--, this.loadContent(), this.updateCounter(), this.updateThumbnails(), this.updateNavigation(), this.updateCaption(), "function" == typeof this.options.onPrev && this.options.onPrev(this.currentIndex));
|
|
304
|
+
}
|
|
305
|
+
next() {
|
|
306
|
+
this.currentIndex < this.items.length - 1 && (this.currentIndex++, this.loadContent(), this.updateCounter(), this.updateThumbnails(), this.updateNavigation(), this.updateCaption(), "function" == typeof this.options.onNext && this.options.onNext(this.currentIndex));
|
|
307
|
+
}
|
|
308
|
+
loadContent() {
|
|
309
|
+
if (!this.items[this.currentIndex]) return;
|
|
310
|
+
const t = this.items[this.currentIndex], e = this.getImageSource(t), s = t.dataset.type || "image";
|
|
311
|
+
e && (this.isZoomed = !1, this.currentX = 0, this.currentY = 0, this.currentScale = 1, this.loading.style.display = "block", this.slidesContainer && (this.slidesContainer.innerHTML = ""), setTimeout(() => {
|
|
312
|
+
this.renderContent(e, s, t);
|
|
313
|
+
}, 100));
|
|
314
|
+
}
|
|
315
|
+
renderContent(t, e, s) {
|
|
316
|
+
const o = document.createElement("div");
|
|
317
|
+
o.className = "zoomora-slide-container";
|
|
318
|
+
const i = document.createElement("div");
|
|
319
|
+
let n;
|
|
320
|
+
i.className = "zoomora-slide " + ("slide" === this.options.transition ? "slide-effect" : "fade-effect"), i.style.opacity = "0", i.style.transform = "slide" === this.options.transition ? "translateX(100%)" : "scale(0.8)";
|
|
321
|
+
try {
|
|
322
|
+
switch (e) {
|
|
323
|
+
case "video":
|
|
324
|
+
if (t.endsWith(".mp4") || t.endsWith(".webm") || t.endsWith(".ogg")) {
|
|
325
|
+
const e = document.createElement("div");
|
|
326
|
+
e.className = "zoomora-video-container", n = document.createElement("video"), n.src = t, n.className = "zoomora-video", n.setAttribute("preload", "metadata");
|
|
327
|
+
const i = s.src || s.getAttribute("src");
|
|
328
|
+
i && n.setAttribute("poster", i);
|
|
329
|
+
const a = document.createElement("div");
|
|
330
|
+
a.className = "zoomora-play-button", a.innerHTML = "<svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M8 5v14l11-7z\"/></svg>", a.addEventListener("click", () => {
|
|
331
|
+
n.play(), a.style.display = "none", n.setAttribute("controls", "");
|
|
332
|
+
}), n.addEventListener("ended", () => {
|
|
333
|
+
a.style.display = "flex";
|
|
334
|
+
}), e.appendChild(n), e.appendChild(a), o.appendChild(e);
|
|
335
|
+
} else n = document.createElement("iframe"), n.src = t, n.className = "zoomora-video", n.setAttribute("allowfullscreen", ""), n.setAttribute("frameborder", "0"), o.appendChild(n);
|
|
336
|
+
break;
|
|
337
|
+
case "iframe":
|
|
338
|
+
n = document.createElement("iframe"), n.src = t, n.className = "zoomora-iframe", n.setAttribute("frameborder", "0"), o.appendChild(n);
|
|
339
|
+
break;
|
|
340
|
+
default: n = document.createElement("img"), n.src = t, n.className = "zoomora-media", n.alt = s.alt || s.title || "", n.onload = () => {
|
|
341
|
+
this.loading.style.display = "none", this.checkZoomability(n), this.animateSlideIn(i);
|
|
342
|
+
}, n.onerror = () => {
|
|
343
|
+
this.loading.style.display = "none", this.animateSlideIn(i);
|
|
344
|
+
}, o.appendChild(n);
|
|
345
|
+
}
|
|
346
|
+
i.appendChild(o), this.slidesContainer.innerHTML = "", this.slidesContainer.appendChild(i), "image" !== e && (this.loading.style.display = "none", this.animateSlideIn(i));
|
|
347
|
+
} catch (t) {
|
|
348
|
+
this.loading.style.display = "none";
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
animateSlideIn(t) {
|
|
352
|
+
t.offsetHeight, t.classList.add("active"), "slide" === this.options.transition ? (t.style.transition = `transform ${this.options.animationDuration}ms ease, opacity ${this.options.animationDuration}ms ease`, t.style.transform = "translateX(0)", t.style.opacity = "1") : (t.style.transition = `transform ${this.options.animationDuration}ms ease, opacity ${this.options.animationDuration}ms ease`, t.style.transform = "scale(1)", t.style.opacity = "1");
|
|
353
|
+
}
|
|
354
|
+
toggleAutoHide() {
|
|
355
|
+
this.autoHideEnabled = !this.autoHideEnabled;
|
|
356
|
+
const t = document.getElementById("zoomoraAutoHideBtn");
|
|
357
|
+
this.autoHideEnabled ? (t.classList.add("active"), t.title = "Disable Auto-Hide Controls", this.startAutoHideTimer()) : (t.classList.remove("active"), t.title = "Enable Auto-Hide Controls", this.stopAutoHideTimer(), this.showControls());
|
|
358
|
+
}
|
|
359
|
+
handleUserActivity() {
|
|
360
|
+
this.autoHideEnabled && (this.showControls(), this.startAutoHideTimer());
|
|
361
|
+
}
|
|
362
|
+
startAutoHideTimer() {
|
|
363
|
+
this.stopAutoHideTimer(), this.autoHideTimeout = setTimeout(() => {
|
|
364
|
+
this.hideControls();
|
|
365
|
+
}, this.options.autoHideDelay);
|
|
366
|
+
}
|
|
367
|
+
stopAutoHideTimer() {
|
|
368
|
+
this.autoHideTimeout && (clearTimeout(this.autoHideTimeout), this.autoHideTimeout = null);
|
|
369
|
+
}
|
|
370
|
+
showControls() {
|
|
371
|
+
this.isControlsVisible || (this.isControlsVisible = !0, this.zoomora.classList.remove("controls-hidden"), this.header && (this.header.style.transform = "translateY(0)", this.header.style.opacity = "1"), this.caption && (this.caption.style.transform = "translateX(-50%) translateY(0)", this.caption.style.opacity = "1"), this.thumbs && (this.thumbs.style.transform = "translateX(-50%) translateY(0)", this.thumbs.style.opacity = "1"), this.prevBtn && (this.prevBtn.style.transform = "translateX(0)", this.prevBtn.style.opacity = "1"), this.nextBtn && (this.nextBtn.style.transform = "translateX(0)", this.nextBtn.style.opacity = "1"));
|
|
372
|
+
}
|
|
373
|
+
hideControls() {
|
|
374
|
+
this.isControlsVisible && (this.isControlsVisible = !1, this.zoomora.classList.add("controls-hidden"), this.header && (this.header.style.transform = "translateY(-100%)", this.header.style.opacity = "0"), this.caption && (this.caption.style.transform = "translateX(-50%) translateY(100%)", this.caption.style.opacity = "0"), this.thumbs && (this.thumbs.style.transform = "translateX(-50%) translateY(100%)", this.thumbs.style.opacity = "0"), this.prevBtn && (this.prevBtn.style.transform = "translateX(-100%)", this.prevBtn.style.opacity = "0"), this.nextBtn && (this.nextBtn.style.transform = "translateX(100%)", this.nextBtn.style.opacity = "0"));
|
|
375
|
+
}
|
|
376
|
+
checkZoomability(t) {
|
|
377
|
+
if (!t || !t.naturalWidth || !t.naturalHeight) return;
|
|
378
|
+
const e = t.getBoundingClientRect(), s = e.width, o = e.height, i = t.naturalWidth, n = t.naturalHeight, a = i > s || n > o, r = i / s, l = n / o, h = Math.max(r, l);
|
|
379
|
+
t.dataset.zoomRatio = h.toString(), t.dataset.naturalWidth = i.toString(), t.dataset.naturalHeight = n.toString(), t.dataset.renderedWidth = s.toString(), t.dataset.renderedHeight = o.toString(), a && h > 1.1 ? t.classList.remove("no-zoom") : t.classList.add("no-zoom");
|
|
380
|
+
}
|
|
381
|
+
calculateZoomLevels(t) {
|
|
382
|
+
if (!t || !t.naturalWidth || !t.naturalHeight) return {
|
|
383
|
+
canZoom: !1,
|
|
384
|
+
levels: [],
|
|
385
|
+
currentLevel: 0
|
|
386
|
+
};
|
|
387
|
+
const e = this.content.getBoundingClientRect(), s = e.width, o = e.height, i = t.naturalWidth, n = t.naturalHeight, a = s / i, r = o / n, l = Math.min(a, r);
|
|
388
|
+
if (l >= .95) return {
|
|
389
|
+
canZoom: !1,
|
|
390
|
+
levels: [],
|
|
391
|
+
currentLevel: 0
|
|
392
|
+
};
|
|
393
|
+
const h = Number(this.options.maxZoomScale), c = Number.isFinite(h) && h > 0 ? Math.max(1, h) : 3, d = [1];
|
|
394
|
+
[
|
|
395
|
+
1.5,
|
|
396
|
+
2,
|
|
397
|
+
3,
|
|
398
|
+
4,
|
|
399
|
+
5
|
|
400
|
+
].forEach((t) => {
|
|
401
|
+
t <= c && l * t <= 1 && d.push(t);
|
|
402
|
+
});
|
|
403
|
+
const u = Math.min(1 / l, c);
|
|
404
|
+
return u > d[d.length - 1] && d.push(u), {
|
|
405
|
+
canZoom: d.length > 1,
|
|
406
|
+
levels: d,
|
|
407
|
+
currentLevel: 0,
|
|
408
|
+
baseScale: l,
|
|
409
|
+
naturalWidth: i,
|
|
410
|
+
naturalHeight: n
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
updateCounter() {
|
|
414
|
+
this.options.showCounter && this.counter && (this.counter.textContent = `${this.currentIndex + 1} / ${this.items.length}`);
|
|
415
|
+
}
|
|
416
|
+
updateCaption() {
|
|
417
|
+
if (!this.caption || !this.items[this.currentIndex]) return;
|
|
418
|
+
const t = this.items[this.currentIndex], e = t.dataset.caption || t.title || "";
|
|
419
|
+
e ? (this.caption.textContent = e, this.caption.style.transform = "translateX(-50%) translateY(0)", this.caption.style.opacity = "1", this.caption.style.pointerEvents = "auto", this.caption.style.transition = "opacity 0.3s ease, transform 0.3s ease") : (this.caption.style.transform = "translateX(-50%) translateY(100%)", this.caption.style.opacity = "0", this.caption.style.pointerEvents = "none", this.caption.style.transition = "opacity 0.3s ease, transform 0.3s ease");
|
|
420
|
+
}
|
|
421
|
+
updateThumbnails() {
|
|
422
|
+
if (this.options.showThumbnails && this.thumbs) {
|
|
423
|
+
if (1 === this.items.length) return this.caption.classList.add("single-item-thumbnail"), void (this.thumbs.style.display = "none");
|
|
424
|
+
this.caption.classList.remove("single-item-thumbnail"), this.thumbs.style.display = "flex", this.thumbs.innerHTML = "", this.items.forEach((t, e) => {
|
|
425
|
+
const s = document.createElement("div");
|
|
426
|
+
s.className = "zoomora-thumb", e === this.currentIndex && s.classList.add("active");
|
|
427
|
+
const o = document.createElement("img"), i = this.getThumbnailSource(t);
|
|
428
|
+
i && (o.src = i, o.alt = t.alt || t.title || "", o.onerror = () => {
|
|
429
|
+
s.style.display = "none";
|
|
430
|
+
}), s.appendChild(o), s.addEventListener("click", () => {
|
|
431
|
+
this.currentIndex = e, this.loadContent(), this.updateCounter(), this.updateThumbnails(), this.updateNavigation(), this.updateCaption();
|
|
432
|
+
}), this.thumbs.appendChild(s);
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
updateNavigation() {
|
|
437
|
+
const t = document.getElementById("zoomoraPrevBtn"), e = document.getElementById("zoomoraNextBtn");
|
|
438
|
+
t && (t.style.display = this.currentIndex > 0 ? "flex" : "none"), e && (e.style.display = this.currentIndex < this.items.length - 1 ? "flex" : "none");
|
|
439
|
+
}
|
|
440
|
+
updateButtons() {
|
|
441
|
+
const t = document.getElementById("zoomoraFullscreenBtn"), e = document.getElementById("zoomoraCollapseBtn");
|
|
442
|
+
t && e && (this.isFullscreen ? (t.style.display = "none", e.style.display = "flex") : (t.style.display = "flex", e.style.display = "none"));
|
|
443
|
+
}
|
|
444
|
+
toggleZoom() {
|
|
445
|
+
const t = this.content.querySelector(".zoomora-media");
|
|
446
|
+
if (!t || "IMG" !== t.tagName) return;
|
|
447
|
+
const e = this.calculateZoomLevels(t);
|
|
448
|
+
if (!e.canZoom) return;
|
|
449
|
+
t.dataset.zoomLevel || (t.dataset.zoomLevel = "0");
|
|
450
|
+
let s = parseInt(t.dataset.zoomLevel) || 0;
|
|
451
|
+
s++, s >= e.levels.length && (s = 0);
|
|
452
|
+
const o = e.levels[s];
|
|
453
|
+
t.dataset.zoomLevel = s.toString(), 0 === s ? (this.isZoomed = !1, this.isDragging = !1, t.classList.remove("dragging"), t.style.transform = "", t.style.cursor = "pointer", t.classList.remove("zoomed"), this.currentX = 0, this.currentY = 0, this.currentScale = 1) : (this.isZoomed = !0, this.currentScale = o, this.currentX = 0, this.currentY = 0, t.style.transform = `translate(0px, 0px) scale(${o})`, t.style.cursor = "grab", t.classList.add("zoomed"));
|
|
454
|
+
}
|
|
455
|
+
toggleFullscreen() {
|
|
456
|
+
this.isFullscreen ? this.exitFullscreen() : this.enterFullscreen();
|
|
457
|
+
}
|
|
458
|
+
enterFullscreen() {
|
|
459
|
+
const t = this.zoomora;
|
|
460
|
+
try {
|
|
461
|
+
t.requestFullscreen ? t.requestFullscreen().then(() => {
|
|
462
|
+
this.isFullscreen = !0, this.zoomora.classList.add("fullscreen"), this.updateButtons();
|
|
463
|
+
}).catch((t) => {
|
|
464
|
+
this.fallbackFullscreen();
|
|
465
|
+
}) : t.webkitRequestFullscreen ? (t.webkitRequestFullscreen(), this.isFullscreen = !0, this.zoomora.classList.add("fullscreen"), this.updateButtons()) : t.mozRequestFullScreen ? (t.mozRequestFullScreen(), this.isFullscreen = !0, this.zoomora.classList.add("fullscreen"), this.updateButtons()) : t.msRequestFullscreen ? (t.msRequestFullscreen(), this.isFullscreen = !0, this.zoomora.classList.add("fullscreen"), this.updateButtons()) : this.fallbackFullscreen();
|
|
466
|
+
} catch (t) {
|
|
467
|
+
this.fallbackFullscreen();
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
exitFullscreen() {
|
|
471
|
+
if (document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement) try {
|
|
472
|
+
document.exitFullscreen ? document.exitFullscreen().then(() => {
|
|
473
|
+
this.isFullscreen = !1, this.zoomora.classList.remove("fullscreen"), this.updateButtons();
|
|
474
|
+
}).catch((t) => {
|
|
475
|
+
this.fallbackExitFullscreen();
|
|
476
|
+
}) : document.webkitExitFullscreen ? (document.webkitExitFullscreen(), this.isFullscreen = !1, this.zoomora.classList.remove("fullscreen"), this.updateButtons()) : document.mozCancelFullScreen ? (document.mozCancelFullScreen(), this.isFullscreen = !1, this.zoomora.classList.remove("fullscreen"), this.updateButtons()) : document.msExitFullscreen ? (document.msExitFullscreen(), this.isFullscreen = !1, this.zoomora.classList.remove("fullscreen"), this.updateButtons()) : this.fallbackExitFullscreen();
|
|
477
|
+
} catch (t) {
|
|
478
|
+
this.fallbackExitFullscreen();
|
|
479
|
+
}
|
|
480
|
+
else this.fallbackExitFullscreen();
|
|
481
|
+
}
|
|
482
|
+
fallbackFullscreen() {
|
|
483
|
+
this.isFullscreen = !0, this.zoomora.classList.add("fullscreen"), this.updateButtons();
|
|
484
|
+
}
|
|
485
|
+
fallbackExitFullscreen() {
|
|
486
|
+
this.isFullscreen = !1, this.zoomora.classList.remove("fullscreen"), this.updateButtons();
|
|
487
|
+
}
|
|
488
|
+
toggleThumbnails() {
|
|
489
|
+
if (1 !== this.items.length && (this.thumbnailsVisible = !this.thumbnailsVisible, this.thumbs)) {
|
|
490
|
+
if (this.thumbs.classList.toggle("thumbs-hidden", !this.thumbnailsVisible), !this.caption || !this.items[this.currentIndex]) return;
|
|
491
|
+
const t = this.items[this.currentIndex];
|
|
492
|
+
(t.dataset.caption || t.title) && this.thumbs.classList.contains("thumbs-hidden") ? (this.caption.style.bottom = "20px", this.caption.style.transition = "bottom 0.3s ease, transform 0.3s ease") : this.caption.style.bottom = "120px";
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
startDrag(t) {
|
|
496
|
+
const e = this.content.querySelector(".zoomora-media");
|
|
497
|
+
if (!e || !this.isZoomed) return;
|
|
498
|
+
this.isDragging = !0, e.classList.add("dragging"), e.style.cursor = "grabbing", this.startX = t.clientX || t.touches && t.touches[0].clientX || 0, this.startY = t.clientY || t.touches && t.touches[0].clientY || 0;
|
|
499
|
+
const s = window.getComputedStyle(e).transform;
|
|
500
|
+
if (s && "none" !== s) {
|
|
501
|
+
const t = new DOMMatrix(s);
|
|
502
|
+
this.currentX = t.m41, this.currentY = t.m42;
|
|
503
|
+
} else this.currentX = 0, this.currentY = 0;
|
|
504
|
+
t.preventDefault();
|
|
505
|
+
}
|
|
506
|
+
drag(t) {
|
|
507
|
+
if (!this.isDragging) return;
|
|
508
|
+
t.preventDefault();
|
|
509
|
+
const e = this.content.querySelector(".zoomora-media");
|
|
510
|
+
if (!e) return;
|
|
511
|
+
const s = t.clientX || t.touches && t.touches[0].clientX || 0, o = t.clientY || t.touches && t.touches[0].clientY || 0, i = s - this.startX, n = o - this.startY;
|
|
512
|
+
let a = this.currentX + i, r = this.currentY + n;
|
|
513
|
+
const l = this.content.getBoundingClientRect(), h = e.getBoundingClientRect(), c = Math.max(0, (h.width - l.width) / 2), d = Math.max(0, (h.height - l.height) / 2);
|
|
514
|
+
a = c > 0 ? Math.max(-c, Math.min(c, a)) : 0, r = d > 0 ? Math.max(-d, Math.min(d, r)) : 0, e.style.transform = `translate(${a}px, ${r}px) scale(${this.currentScale})`, this.startX = s, this.startY = o, this.currentX = a, this.currentY = r;
|
|
515
|
+
}
|
|
516
|
+
endDrag() {
|
|
517
|
+
if (!this.isDragging) return;
|
|
518
|
+
this.isDragging = !1, this.lastDragTime = Date.now();
|
|
519
|
+
const t = this.content.querySelector(".zoomora-media");
|
|
520
|
+
t && (t.classList.remove("dragging"), this.isZoomed && (t.style.cursor = "grab"));
|
|
521
|
+
}
|
|
522
|
+
goTo(t) {
|
|
523
|
+
t < 0 || t >= this.items.length || (this.currentIndex = t, this.loadContent(), this.updateCounter(), this.updateThumbnails(), this.updateNavigation(), this.updateCaption());
|
|
524
|
+
}
|
|
525
|
+
getCurrentIndex() {
|
|
526
|
+
return this.currentIndex;
|
|
527
|
+
}
|
|
528
|
+
getTotalItems() {
|
|
529
|
+
return this.items.length;
|
|
530
|
+
}
|
|
531
|
+
isOpen() {
|
|
532
|
+
return this.zoomora && this.zoomora.classList.contains("active");
|
|
533
|
+
}
|
|
534
|
+
updateOptions(t) {
|
|
535
|
+
this.options = d(d({}, this.options), t);
|
|
536
|
+
}
|
|
537
|
+
refresh() {
|
|
538
|
+
if (this.isOpen()) {
|
|
539
|
+
const t = this.items[this.currentIndex];
|
|
540
|
+
t && this.open(t);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
destroy() {
|
|
544
|
+
this.isInitialized && (this.isOpen() && this.close(), this.stopAutoHideTimer(), this.eventListeners.forEach((t, e) => {
|
|
545
|
+
t.forEach(({ element: t, event: e, handler: s, options: o }) => {
|
|
546
|
+
t && t.removeEventListener && t.removeEventListener(e, s, o);
|
|
547
|
+
});
|
|
548
|
+
}), this.eventListeners.clear(), this.zoomora && this.zoomora.parentNode && this.zoomora.parentNode.removeChild(this.zoomora), this.isInitialized = !1, this.items = [], this.currentIndex = 0, this.zoomora = null, this.content = null, this.counter = null, this.thumbs = null, this.loading = null, this.caption = null);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
return t;
|
|
552
|
+
});
|
|
553
|
+
})();
|
|
554
|
+
});
|