prokat/api/jquery/plugins/lightGallery/2.7.2/lg-autoplay.umd.min.js
2025-06-16 18:28:08 +05:00

1 line
3.8 KiB
JavaScript
Executable File

!function(t,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):(t="undefined"!=typeof globalThis?globalThis:t||self).lgAutoplay=o()}(this,function(){"use strict";var o=function(){return(o=Object.assign||function(t){for(var o,e=1,s=arguments.length;e<s;e++)for(var r in o=arguments[e])Object.prototype.hasOwnProperty.call(o,r)&&(t[r]=o[r]);return t}).apply(this,arguments)},e="lgSlideItemLoad",s="lgBeforeSlide",r="lgAfterSlide",i="lgDragStart",a="lgDragEnd",l="lgAutoplay",n="lgAutoplayStart",t="lgAutoplayStop",u={autoplay:!0,slideShowAutoplay:!1,slideShowInterval:5e3,progressBar:!0,forceSlideShowAutoplay:!1,autoplayControls:!0,appendAutoplayControlsTo:".lg-toolbar",autoplayPluginStrings:{toggleAutoplay:"Toggle Autoplay"}};function p(t){return this.core=t,this.settings=o(o({},u),this.core.settings),this}return p.prototype.init=function(){var t=this;this.settings.autoplay&&(this.interval=!1,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.settings.slideShowAutoplay&&this.core.LGel.once(e+".autoplay",function(){t.startAutoPlay()}),this.core.LGel.on(i+".autoplay touchstart.lg.autoplay",function(){t.interval&&(t.stopAutoPlay(),t.pausedOnTouchDrag=!0)}),this.core.LGel.on(a+".autoplay touchend.lg.autoplay",function(){!t.interval&&t.pausedOnTouchDrag&&(t.startAutoPlay(),t.pausedOnTouchDrag=!1)}),this.core.LGel.on(s+".autoplay",function(){t.showProgressBar(),!t.fromAuto&&t.interval?(t.stopAutoPlay(),t.pausedOnSlideChange=!0):t.pausedOnSlideChange=!1,t.fromAuto=!1}),this.core.LGel.on(r+".autoplay",function(){t.pausedOnSlideChange&&!t.interval&&t.settings.forceSlideShowAutoplay&&(t.startAutoPlay(),t.pausedOnSlideChange=!1)}),this.showProgressBar())},p.prototype.showProgressBar=function(){var t,o,e=this;this.settings.progressBar&&this.fromAuto&&(t=this.core.outer.find(".lg-progress-bar"),o=this.core.outer.find(".lg-progress"),this.interval&&(o.removeAttr("style"),t.removeClass("lg-start"),setTimeout(function(){o.css("transition","width "+(e.core.settings.speed+e.settings.slideShowInterval)+"ms ease 0s"),t.addClass("lg-start")},20)))},p.prototype.controls=function(){var t=this,o='<button aria-label="'+this.settings.autoplayPluginStrings.toggleAutoplay+'" type="button" class="lg-autoplay-button lg-icon"></button>';this.core.outer.find(this.settings.appendAutoplayControlsTo).append(o),this.core.outer.find(".lg-autoplay-button").first().on("click.lg.autoplay",function(){t.core.outer.hasClass("lg-show-autoplay")?t.stopAutoPlay():t.interval||t.startAutoPlay()})},p.prototype.startAutoPlay=function(){var t=this;this.core.outer.find(".lg-progress").css("transition","width "+(this.core.settings.speed+this.settings.slideShowInterval)+"ms ease 0s"),this.core.outer.addClass("lg-show-autoplay"),this.core.outer.find(".lg-progress-bar").addClass("lg-start"),this.core.LGel.trigger(n,{index:this.core.index}),this.interval=setInterval(function(){t.core.index+1<t.core.galleryItems.length?t.core.index++:t.core.index=0,t.core.LGel.trigger(l,{index:t.core.index}),t.fromAuto=!0,t.core.slide(t.core.index,!1,!1,"next")},this.core.settings.speed+this.settings.slideShowInterval)},p.prototype.stopAutoPlay=function(){this.interval&&(this.core.LGel.trigger(t,{index:this.core.index}),this.core.outer.find(".lg-progress").removeAttr("style"),this.core.outer.removeClass("lg-show-autoplay"),this.core.outer.find(".lg-progress-bar").removeClass("lg-start")),clearInterval(this.interval),this.interval=!1},p.prototype.closeGallery=function(){this.stopAutoPlay()},p.prototype.destroy=function(){this.settings.autoplay&&this.core.outer.find(".lg-progress-bar").remove(),this.core.LGel.off(".lg.autoplay"),this.core.LGel.off(".autoplay")},p});