lightgallery
Version:
lightGallery is a feature-rich, modular JavaScript gallery plugin for building beautiful image and video galleries for the web and the mobile
9 lines (7 loc) • 3.73 kB
JavaScript
/**
* lightgallery | 2.1.7 | July 1st 2021
* http://www.lightgalleryjs.com/
* Copyright (c) 2020 Sachin Neravath;
* @license GPLv3
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).lgAutoplay=e()}(this,function(){"use strict";var e=function(){return(e=Object.assign||function(t){for(var e,o=1,s=arguments.length;o<s;o++)for(var r in e=arguments[o])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)},o="lgSlideItemLoad",s="lgBeforeSlide",r="lgAfterSlide",i="lgDragStart",a="lgDragEnd",n={autoplay:!0,slideShowAutoplay:!1,slideShowInterval:5e3,progressBar:!0,forceSlideShowAutoplay:!1,autoplayControls:!0,appendAutoplayControlsTo:".lg-toolbar"};function t(t){return this.core=t,this.settings=e(e({},n),this.core.settings),this}return t.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.$lgContent.append('<div class="lg-progress-bar"><div class="lg-progress"></div></div>'),this.settings.slideShowAutoplay&&this.core.LGel.once(o+".autoplay",function(){t.startAuto()}),this.core.LGel.on(i+".autoplay touchstart.lg.autoplay",function(){t.interval&&(t.cancelAuto(),t.pausedOnTouchDrag=!0)}),this.core.LGel.on(a+".autoplay touchend.lg.autoplay",function(){!t.interval&&t.pausedOnTouchDrag&&(t.startAuto(),t.pausedOnTouchDrag=!1)}),this.core.LGel.on(s+".autoplay",function(){t.showProgressBar(),!t.fromAuto&&t.interval?(t.cancelAuto(),t.pausedOnSlideChange=!0):t.pausedOnSlideChange=!1,t.fromAuto=!1}),this.core.LGel.on(r+".autoplay",function(){t.pausedOnSlideChange&&!t.interval&&t.settings.forceSlideShowAutoplay&&(t.startAuto(),t.pausedOnSlideChange=!1)}),this.showProgressBar())},t.prototype.showProgressBar=function(){var t,e,o=this;this.settings.progressBar&&this.fromAuto&&(t=this.core.outer.find(".lg-progress-bar"),e=this.core.outer.find(".lg-progress"),this.interval&&(e.removeAttr("style"),t.removeClass("lg-start"),setTimeout(function(){e.css("transition","width "+(o.core.settings.speed+o.settings.slideShowInterval)+"ms ease 0s"),t.addClass("lg-start")},20)))},t.prototype.controls=function(){var t=this;this.core.outer.find(this.settings.appendAutoplayControlsTo).append('<button aria-label="Toggle autoplay" type="button" class="lg-autoplay-button lg-icon"></button>'),this.core.outer.find(".lg-autoplay-button").first().on("click.lg.autoplay",function(){t.core.outer.hasClass("lg-show-autoplay")?t.cancelAuto():t.interval||t.startAuto()})},t.prototype.startAuto=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.interval=setInterval(function(){t.core.index+1<t.core.galleryItems.length?t.core.index++:t.core.index=0,t.fromAuto=!0,t.core.slide(t.core.index,!1,!1,"next")},this.core.settings.speed+this.settings.slideShowInterval)},t.prototype.cancelAuto=function(){this.interval&&(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},t.prototype.closeGallery=function(){this.cancelAuto()},t.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")},t});