UNPKG

lightgallery

Version:

lightGallery is a feature-rich, modular JavaScript gallery plugin for building beautiful image and video galleries for the web and the mobile

2 lines (1 loc) • 5.35 kB
!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?module.exports=s():"function"==typeof define&&define.amd?define(s):(t="undefined"!=typeof globalThis?globalThis:t||self).lgAutoplay=s()}(this,function(){"use strict";const t={autoplayPlay:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024" fill="currentColor"><path transform="translate(0, 960) scale(1, -1)" d="M512 84.667q140 0 241 101t101 241-101 241-241 101-241-101-101-241 101-241 241-101zM512 852.667q176 0 301-125t125-301-125-301-301-125-301 125-125 301 125 301 301 125zM426 234.667v384l256-192z"/></svg>',autoplayPause:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024" fill="currentColor"><path transform="translate(0, 960) scale(1, -1)" d="M554 256.667v340h86v-340h-86zM512 84.667q140 0 241 101t101 241-101 241-241 101-241-101-101-241 101-241 241-101zM512 852.667q176 0 301-125t125-301-125-301-301-125-301 125-125 301 125 301 301 125zM384 256.667v340h86v-340h-86z"/></svg>'},s="lgSlideItemLoad",e="lgBeforeSlide",i="lgAfterSlide",o="lgDragStart",r="lgDragEnd",l="lgAutoplay",a="lgAutoplayStart",n="lgAutoplayStop",h={autoplay:!0,slideShowAutoplay:!1,slideShowInterval:5e3,progressBar:!0,forceSlideShowAutoplay:!1,autoplayControls:!0,appendAutoplayControlsTo:".lg-toolbar"};var u=Object.defineProperty,g=Object.getOwnPropertySymbols,c=Object.prototype.hasOwnProperty,d=Object.prototype.propertyIsEnumerable,p=(t,s,e)=>s in t?u(t,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[s]=e,y=(t,s)=>{for(var e in s||(s={}))c.call(s,e)&&p(t,e,s[e]);if(g)for(var e of g(s))d.call(s,e)&&p(t,e,s[e]);return t};return class{constructor(t){return this.running=!1,this.timer=null,this.progressTimer=null,this.waitingFor=null,this.startedFromLoad=!1,this.core=t,this.settings=y(y({},h),this.core.settings),this}init(){this.core.registerDefaultIcons(t),this.settings.autoplay&&(this.fromAuto=!0,this.pausedOnTouchDrag=!1,this.pausedOnSlideChange=!1,this.settings.autoplayControls&&this.controls(),this.settings.progressBar&&this.core.outer.append('<div class="lg-progress-bar"><div class="lg-progress"></div></div>'),this.core.LGel.on(`${s}.autoplay`,t=>{if(this.settings.slideShowAutoplay&&!this.startedFromLoad)return this.startedFromLoad=!0,void this.startAutoPlay();this.running&&this.waitingFor===t.detail.index&&this.countdown()}),this.core.LGel.on(`${o}.autoplay touchstart.lg.autoplay`,()=>{this.running&&(this.stopAutoPlay(),this.pausedOnTouchDrag=!0)}),this.core.LGel.on(`${r}.autoplay touchend.lg.autoplay`,()=>{!this.running&&this.pausedOnTouchDrag&&(this.startAutoPlay(),this.pausedOnTouchDrag=!1)}),this.core.LGel.on(`${e}.autoplay`,()=>{!this.fromAuto&&this.running?(this.stopAutoPlay(),this.pausedOnSlideChange=!0):this.pausedOnSlideChange=!1,this.fromAuto=!1}),this.core.LGel.on(`${i}.autoplay`,()=>{this.pausedOnSlideChange&&!this.running&&this.settings.forceSlideShowAutoplay&&(this.startAutoPlay(),this.pausedOnSlideChange=!1)}))}cycleDuration(){return this.core.settings.speed+this.settings.slideShowInterval}showProgressBar(){this.settings.progressBar&&(this.resetProgressBar(),this.progressTimer=setTimeout(()=>{this.progressTimer=null,this.running&&null!==this.timer&&(this.core.outer.find(".lg-progress").css("transition","width "+this.cycleDuration()+"ms ease 0s"),this.core.outer.find(".lg-progress-bar").addClass("lg-start"))},20))}resetProgressBar(){null!==this.progressTimer&&(clearTimeout(this.progressTimer),this.progressTimer=null),this.core.outer.find(".lg-progress").removeAttr("style"),this.core.outer.find(".lg-progress-bar").removeClass("lg-start")}controls(){var t,s;const e=`<button aria-label="${null!=(s=null==(t=this.settings.autoplayPluginStrings)?void 0:t.toggleAutoplay)?s:this.core.settings.strings.toggleAutoplay}" type="button" class="lg-autoplay-button lg-icon"></button>`;this.core.outer.find(this.settings.appendAutoplayControlsTo).append(e),this.core.outer.find(".lg-autoplay-button").first().on("click.lg.autoplay",()=>{this.core.outer.hasClass("lg-show-autoplay")?this.stopAutoPlay():this.running||this.startAutoPlay()})}isSlideLoaded(t){return this.core.getSlideItem(t).hasClass("lg-complete_")}clearTimer(){null!==this.timer&&(clearTimeout(this.timer),this.timer=null),this.waitingFor=null}schedule(t){this.clearTimer(),this.isSlideLoaded(t)?this.countdown():(this.waitingFor=t,this.resetProgressBar())}countdown(){this.clearTimer(),this.timer=setTimeout(()=>{this.timer=null,this.advance()},this.cycleDuration()),this.showProgressBar()}advance(){this.core.lgBusy?this.countdown():(this.core.index+1<this.core.galleryItems.length?this.core.index++:this.core.index=0,this.core.LGel.trigger(l,{index:this.core.index}),this.fromAuto=!0,this.core.slide(this.core.index,!1,!1,"next"),this.running&&this.schedule(this.core.index))}startAutoPlay(){this.running||(this.running=!0,this.core.outer.addClass("lg-show-autoplay"),this.core.LGel.trigger(a,{index:this.core.index}),this.schedule(this.core.index))}stopAutoPlay(){this.running&&(this.core.LGel.trigger(n,{index:this.core.index}),this.core.outer.removeClass("lg-show-autoplay")),this.running=!1,this.clearTimer(),this.resetProgressBar()}closeGallery(){this.stopAutoPlay()}destroy(){this.stopAutoPlay(),this.settings.autoplay&&this.core.outer.find(".lg-progress-bar").remove(),this.core.LGel.off(".lg.autoplay"),this.core.LGel.off(".autoplay")}}});