mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-09 08:17:53 +08:00
f5a444aa14
Cleanup lightgallery
4 lines
16 KiB
JavaScript
4 lines
16 KiB
JavaScript
/*! lightgallery - v1.2.21 - 2016-06-28
|
|
* http://sachinchoolur.github.io/lightGallery/
|
|
* Copyright (c) 2016 Sachin N; Licensed Apache 2.0 */
|
|
((e,s)=>{"use strict";var t={mode:"lg-slide",cssEasing:"ease",easing:"linear",speed:600,height:"100%",width:"100%",addClass:"",startClass:"lg-start-zoom",backdropDuration:150,hideBarsDelay:6e3,useLeft:!1,closable:!0,loop:!0,escKey:!0,keyPress:!0,controls:!0,slideEndAnimatoin:!0,hideControlOnEnd:!1,mousewheel:!0,getCaptionFromTitleOrAlt:!0,appendSubHtmlTo:".lg-sub-html",subHtmlSelectorRelative:!1,preload:1,showAfterLoad:!0,selector:"",selectWithin:"",nextHtml:"",prevHtml:"",index:!1,iframeMaxWidth:"100%",download:!0,counter:!0,appendCounterTo:".lg-toolbar",swipeThreshold:50,enableSwipe:!0,enableDrag:!0,dynamic:!1,dynamicEl:[],galleryId:1};class l{constructor(s,l){if(this.el=s,this.$el=e(s),this.s=e.extend({},t,l),this.s.dynamic&&"undefined"!==this.s.dynamicEl&&this.s.dynamicEl.constructor===Array&&!this.s.dynamicEl.length)throw"When using dynamic mode, you must also define dynamicEl as an Array.";return this.modules={},this.lGalleryOn=!1,this.lgBusy=!1,this.hideBartimeout=!1,this.isTouch="ontouchstart"in document.documentElement,this.s.slideEndAnimatoin&&(this.s.hideControlOnEnd=!1),this.s.dynamic?this.$items=this.s.dynamicEl:"this"===this.s.selector?this.$items=this.$el:""!==this.s.selector?this.s.selectWithin?this.$items=e(this.s.selectWithin).find(this.s.selector):this.$items=this.$el.find(e(this.s.selector)):this.$items=this.$el.children(),this.$slide="",this.$outer="",this.init(),this}init(){var s=this;s.s.preload>s.$items.length&&(s.s.preload=s.$items.length);var t=location.hash;t.indexOf("lg="+this.s.galleryId)>0&&(s.index=parseInt(t.split("&slide=")[1],10),e("body").addClass("lg-from-hash"),e("body").hasClass("lg-on")||setTimeout(()=>{s.build(s.index),e("body").addClass("lg-on")})),s.s.dynamic?(s.$el.trigger("onBeforeOpen.lg"),s.index=s.s.index||0,e("body").hasClass("lg-on")||setTimeout(()=>{s.build(s.index),e("body").addClass("lg-on")})):s.$items.on("click.lgcustom",function(t){t.preventDefault(),s.$el.trigger("onBeforeOpen.lg"),s.index=s.s.index||s.$items.index(this),e("body").hasClass("lg-on")||(s.build(s.index),e("body").addClass("lg-on"))})}build(s){var t=this;t.structure(),e.each(e.fn.lightGallery.modules,s=>t.modules[s]=new e.fn.lightGallery.modules[s](t.el)),t.slide(s,!1,!1),t.s.keyPress&&t.keyPress(),t.$items.length>1&&(t.arrow(),setTimeout(()=>{t.enableDrag(),t.enableSwipe()},50),t.s.mousewheel&&t.mousewheel()),t.counter(),t.closeGallery(),t.$el.trigger("onAfterOpen.lg"),t.$outer.on("mousemove.lg click.lg touchstart.lg",()=>{t.$outer.removeClass("lg-hide-items"),clearTimeout(t.hideBartimeout),t.hideBartimeout=setTimeout(()=>t.$outer.addClass("lg-hide-items"),t.s.hideBarsDelay)})}structure(){var t,l="",i="",a=0,d="",o=this;for(e("body").append('<div class="lg-backdrop"></div>'),e(".lg-backdrop").css("transition-duration",this.s.backdropDuration+"ms"),a=0;a<this.$items.length;a++)l+='<div class="lg-item"></div>';if(this.s.controls&&this.$items.length>1&&(i='<div class="lg-actions"><div class="lg-prev lg-icon">'+this.s.prevHtml+'</div><div class="lg-next lg-icon">'+this.s.nextHtml+"</div></div>"),".lg-sub-html"===this.s.appendSubHtmlTo&&(d='<div class="lg-sub-html"></div>'),t='<div class="lg-outer '+this.s.addClass+" "+this.s.startClass+'"><div class="lg" style="width:'+this.s.width+"; height:"+this.s.height+'"><div class="lg-inner">'+l+'</div><div class="lg-toolbar group"><span class="lg-close lg-icon"></span></div>'+i+d+"</div></div>",e("body").append(t),this.$outer=e(".lg-outer"),this.$slide=this.$outer.find(".lg-item"),this.s.useLeft?(this.$outer.addClass("lg-use-left"),this.s.mode="lg-slide"):this.$outer.addClass("lg-use-css3"),o.setTop(),e(s).on("resize.lg orientationchange.lg",()=>setTimeout(()=>o.setTop(),100)),this.$slide.eq(this.index).addClass("lg-current"),this.doCss()?this.$outer.addClass("lg-css3"):(this.$outer.addClass("lg-css"),this.s.speed=0),this.$outer.addClass(this.s.mode),this.s.enableDrag&&this.$items.length>1&&this.$outer.addClass("lg-grab"),this.s.showAfterLoad&&this.$outer.addClass("lg-show-after-load"),this.doCss()){var r=this.$outer.find(".lg-inner");r.css("transition-timing-function",this.s.cssEasing),r.css("transition-duration",this.s.speed+"ms")}e(".lg-backdrop").addClass("in"),setTimeout(()=>o.$outer.addClass("lg-visible"),this.s.backdropDuration),this.s.download&&this.$outer.find(".lg-toolbar").append('<a id="lg-download" target="_blank" download class="lg-download lg-icon"></a>'),this.prevScrollTop=e(s).scrollTop()}setTop(){if("100%"!==this.s.height){var t=e(s).height(),l=(t-parseInt(this.s.height,10))/2,i=this.$outer.find(".lg");t>=parseInt(this.s.height,10)?i.css("top",l+"px"):i.css("top","0px")}}doCss(){return!0}isVideo(e,s){var t;if(t=this.s.dynamic?this.s.dynamicEl[s].html:this.$items.eq(s).attr("data-html"),!e&&t)return{html5:!0}}counter(){this.s.counter&&e(this.s.appendCounterTo).append('<div id="lg-counter"><span id="lg-counter-current">'+(parseInt(this.index,10)+1)+'</span> / <span id="lg-counter-all">'+this.$items.length+"</span></div>")}addHtml(s){var t,l,i=null;if(this.s.dynamic?this.s.dynamicEl[s].subHtmlUrl?t=this.s.dynamicEl[s].subHtmlUrl:i=this.s.dynamicEl[s].subHtml:(l=this.$items.eq(s)).attr("data-sub-html-url")?t=l.attr("data-sub-html-url"):(i=l.attr("data-sub-html"),this.s.getCaptionFromTitleOrAlt&&!i&&(i=l.attr("title")||l.find("img").first().attr("alt"))),!t)if(null!=i){var a=i.substring(0,1);"."!==a&&"#"!==a||(i=this.s.subHtmlSelectorRelative&&!this.s.dynamic?l.find(i).html():e(i).html())}else i="";".lg-sub-html"===this.s.appendSubHtmlTo?t?this.$outer.find(this.s.appendSubHtmlTo).load(t):this.$outer.find(this.s.appendSubHtmlTo).html(i):t?this.$slide.eq(s).load(t):this.$slide.eq(s).append(i),null!=i&&(""===i?this.$outer.find(this.s.appendSubHtmlTo).addClass("lg-empty-html"):this.$outer.find(this.s.appendSubHtmlTo).removeClass("lg-empty-html")),this.$el.trigger("onAfterAppendSubHtml.lg",[s])}preload(e){var s=1,t=1;for(s=1;s<=this.s.preload&&!(s>=this.$items.length-e);s++)this.loadContent(e+s,!1,0);for(t=1;t<=this.s.preload&&!(e-t<0);t++)this.loadContent(e-t,!1,0)}loadContent(t,l,i){var a,d,o,r,n,g,h=this,m=!1,u=t=>{for(var l=[],i=[],a=0;a<t.length;a++){var o=t[a].split(" ");""===o[0]&&o.splice(0,1),i.push(o[0]),l.push(o[1])}for(var r=e(s).width(),n=0;n<l.length;n++)if(parseInt(l[n],10)>r){d=i[n];break}};if(h.s.dynamic){if(h.s.dynamicEl[t].poster&&(m=!0,o=h.s.dynamicEl[t].poster),g=h.s.dynamicEl[t].html,d=h.s.dynamicEl[t].src,h.s.dynamicEl[t].responsive)u(h.s.dynamicEl[t].responsive.split(","));r=h.s.dynamicEl[t].srcset,n=h.s.dynamicEl[t].sizes}else{if(h.$items.eq(t).attr("data-poster")&&(m=!0,o=h.$items.eq(t).attr("data-poster")),g=h.$items.eq(t).attr("data-html"),d=h.$items.eq(t).attr("href")||h.$items.eq(t).attr("data-src"),h.$items.eq(t).attr("data-responsive"))u(h.$items.eq(t).attr("data-responsive").split(","));r=h.$items.eq(t).attr("data-srcset"),n=h.$items.eq(t).attr("data-sizes")}var c=!1;h.s.dynamic?h.s.dynamicEl[t].iframe&&(c=!0):"true"===h.$items.eq(t).attr("data-iframe")&&(c=!0);var p=h.isVideo(d,t);h.$slide.eq(t).hasClass("lg-loaded")||(c?h.$slide.eq(t).prepend('<div class="lg-video-cont" style="max-width:'+h.s.iframeMaxWidth+'"><div class="lg-video"><iframe class="lg-object" frameborder="0" src="'+d+'" allowfullscreen="true"></iframe></div></div>'):m?h.$slide.eq(t).prepend('<div class="lg-video-cont lg-has-html5"><div class="lg-video"><span class="lg-video-play"></span><img class="lg-object lg-has-poster" src="'+o+'" /></div></div>'):p?(h.$slide.eq(t).prepend('<div class="lg-video-cont "><div class="lg-video"></div></div>'),h.$el.trigger("hasVideo.lg",[t,d,g])):h.$slide.eq(t).prepend('<div class="lg-img-wrap"><img class="lg-object lg-image" src="'+d+'" /></div>'),h.$el.trigger("onAferAppendSlide.lg",[t]),a=h.$slide.eq(t).find(".lg-object"),n&&a.attr("sizes",n),r&&a.attr("srcset",r),".lg-sub-html"!==this.s.appendSubHtmlTo&&h.addHtml(t),h.$slide.eq(t).addClass("lg-loaded")),h.$slide.eq(t).find(".lg-object").on("load.lg error.lg",()=>{var s=0;i&&!e("body").hasClass("lg-from-hash")&&(s=i),setTimeout(()=>{h.$slide.eq(t).addClass("lg-complete"),h.$el.trigger("onSlideItemLoad.lg",[t,i||0])},s)}),p&&p.html5&&!m&&h.$slide.eq(t).addClass("lg-complete"),!0===l&&(h.$slide.eq(t).hasClass("lg-complete")?h.preload(t):h.$slide.eq(t).find(".lg-object").on("load.lg error.lg",()=>h.preload(t)))}slide(s,t,l){var i=this.$outer.find(".lg-current").index(),a=this;if(!a.lGalleryOn||i!==s){var d=this.$slide.length,o=a.lGalleryOn?this.s.speed:0,r=!1,n=!1;if(!a.lgBusy){var g;if(this.s.download)(g=a.s.dynamic?!1!==a.s.dynamicEl[s].downloadUrl&&(a.s.dynamicEl[s].downloadUrl||a.s.dynamicEl[s].src):"false"!==a.$items.eq(s).attr("data-download-url")&&(a.$items.eq(s).attr("data-download-url")||a.$items.eq(s).attr("href")||a.$items.eq(s).attr("data-src")))?(e("#lg-download").attr("href",g),a.$outer.removeClass("lg-hide-download")):a.$outer.addClass("lg-hide-download");if(this.$el.trigger("onBeforeSlide.lg",[i,s,t,l]),a.lgBusy=!0,clearTimeout(a.hideBartimeout),".lg-sub-html"===this.s.appendSubHtmlTo&&setTimeout(()=>a.addHtml(s),o),this.arrowDisable(s),t){var h=s-1,m=s+1;0===s&&i===d-1?(m=0,h=d-1):s===d-1&&0===i&&(m=0,h=d-1),this.$slide.removeClass("lg-prev-slide lg-current lg-next-slide"),a.$slide.eq(h).addClass("lg-prev-slide"),a.$slide.eq(m).addClass("lg-next-slide"),a.$slide.eq(s).addClass("lg-current")}else a.$outer.addClass("lg-no-trans"),this.$slide.removeClass("lg-prev-slide lg-next-slide"),s<i?(n=!0,0!==s||i!==d-1||l||(n=!1,r=!0)):s>i&&(r=!0,s!==d-1||0!==i||l||(n=!0,r=!1)),n?(this.$slide.eq(s).addClass("lg-prev-slide"),this.$slide.eq(i).addClass("lg-next-slide")):r&&(this.$slide.eq(s).addClass("lg-next-slide"),this.$slide.eq(i).addClass("lg-prev-slide")),setTimeout(()=>{a.$slide.removeClass("lg-current"),a.$slide.eq(s).addClass("lg-current"),a.$outer.removeClass("lg-no-trans")},50);a.lGalleryOn?(setTimeout(()=>a.loadContent(s,!0,0),this.s.speed+50),setTimeout(()=>{a.lgBusy=!1,a.$el.trigger("onAfterSlide.lg",[i,s,t,l])},this.s.speed)):(a.loadContent(s,!0,a.s.backdropDuration),a.lgBusy=!1,a.$el.trigger("onAfterSlide.lg",[i,s,t,l])),a.lGalleryOn=!0,this.s.counter&&e("#lg-counter-current").text(s+1)}}}goToNextSlide(e){var s=this;s.lgBusy||(s.index+1<s.$slide.length?(s.index++,s.$el.trigger("onBeforeNextSlide.lg",[s.index]),s.slide(s.index,e,!1)):s.s.loop?(s.index=0,s.$el.trigger("onBeforeNextSlide.lg",[s.index]),s.slide(s.index,e,!1)):s.s.slideEndAnimatoin&&(s.$outer.addClass("lg-right-end"),setTimeout(()=>s.$outer.removeClass("lg-right-end"),400)))}goToPrevSlide(e){var s=this;s.lgBusy||(s.index>0?(s.index--,s.$el.trigger("onBeforePrevSlide.lg",[s.index,e]),s.slide(s.index,e,!1)):s.s.loop?(s.index=s.$items.length-1,s.$el.trigger("onBeforePrevSlide.lg",[s.index,e]),s.slide(s.index,e,!1)):s.s.slideEndAnimatoin&&(s.$outer.addClass("lg-left-end"),setTimeout(()=>s.$outer.removeClass("lg-left-end"),400)))}keyPress(){var t=this;this.$items.length>1&&e(s).on("keyup.lg",e=>{t.$items.length>1&&(37===e.keyCode&&(e.preventDefault(),t.goToPrevSlide()),39===e.keyCode&&(e.preventDefault(),t.goToNextSlide()))}),e(s).on("keydown.lg",e=>{!0===t.s.escKey&&27===e.keyCode&&(e.preventDefault(),t.$outer.hasClass("lg-thumb-open")?t.$outer.removeClass("lg-thumb-open"):t.destroy())})}arrow(){var e=this;this.$outer.find(".lg-prev").on("click.lg",()=>e.goToPrevSlide()),this.$outer.find(".lg-next").on("click.lg",()=>e.goToNextSlide())}arrowDisable(e){!this.s.loop&&this.s.hideControlOnEnd&&(e+1<this.$slide.length?this.$outer.find(".lg-next").removeAttr("disabled").removeClass("disabled"):this.$outer.find(".lg-next").attr("disabled","disabled").addClass("disabled"),e>0?this.$outer.find(".lg-prev").removeAttr("disabled").removeClass("disabled"):this.$outer.find(".lg-prev").attr("disabled","disabled").addClass("disabled"))}setTranslate(e,s,t){this.s.useLeft?e.css("left",s):e.css({transform:"translate3d("+s+"px, "+t+"px, 0px)"})}touchMove(s,t){var l=t-s;Math.abs(l)>15&&(this.$outer.addClass("lg-dragging"),this.setTranslate(this.$slide.eq(this.index),l,0),this.setTranslate(e(".lg-prev-slide"),-this.$slide.eq(this.index).width()+l,0),this.setTranslate(e(".lg-next-slide"),this.$slide.eq(this.index).width()+l,0))}touchEnd(e){var s=this;"lg-slide"!==s.s.mode&&s.$outer.addClass("lg-slide"),this.$slide.not(".lg-current, .lg-prev-slide, .lg-next-slide").css("opacity","0"),setTimeout(()=>{s.$outer.removeClass("lg-dragging"),e<0&&Math.abs(e)>s.s.swipeThreshold?s.goToNextSlide(!0):e>0&&Math.abs(e)>s.s.swipeThreshold?s.goToPrevSlide(!0):Math.abs(e)<5&&s.$el.trigger("onSlideClick.lg"),s.$slide.removeAttr("style")}),setTimeout(()=>{s.$outer.hasClass("lg-dragging")||"lg-slide"===s.s.mode||s.$outer.removeClass("lg-slide")},s.s.speed+100)}enableSwipe(){var e=this,s=0,t=0,l=!1;e.s.enableSwipe&&e.isTouch&&e.doCss()&&e.$slide.on("touchstart.lg",t=>{e.$outer.hasClass("lg-zoomed")||e.lgBusy||(t.preventDefault(),e.manageSwipeClass(),s=t.originalEvent.targetTouches[0].pageX)}).on("touchmove.lg",i=>{e.$outer.hasClass("lg-zoomed")||(i.preventDefault(),t=i.originalEvent.targetTouches[0].pageX,e.touchMove(s,t),l=!0)}).on("touchend.lg",()=>{e.$outer.hasClass("lg-zoomed")||(l?(l=!1,e.touchEnd(t-s)):e.$el.trigger("onSlideClick.lg"))})}enableDrag(){var t=this,l=0,i=0,a=!1,d=!1;t.s.enableDrag&&!t.isTouch&&t.doCss()&&(t.$slide.on("mousedown.lg",s=>{t.$outer.hasClass("lg-zoomed")||(e(s.target).hasClass("lg-object")||e(s.target).hasClass("lg-video-play"))&&(s.preventDefault(),t.lgBusy||(t.manageSwipeClass(),l=s.pageX,a=!0,t.$outer.scrollLeft+=1,t.$outer.scrollLeft-=1,t.$outer.removeClass("lg-grab").addClass("lg-grabbing"),t.$el.trigger("onDragstart.lg")))}),e(s).on("mousemove.lg",e=>{a&&(d=!0,i=e.pageX,t.touchMove(l,i),t.$el.trigger("onDragmove.lg"))}).on("mouseup.lg",s=>{d?(d=!1,t.touchEnd(i-l),t.$el.trigger("onDragend.lg")):(e(s.target).hasClass("lg-object")||e(s.target).hasClass("lg-video-play"))&&t.$el.trigger("onSlideClick.lg"),a&&(a=!1,t.$outer.removeClass("lg-grabbing").addClass("lg-grab"))}))}manageSwipeClass(){var e=this.index+1,s=this.index-1,t=this.$slide.length;this.s.loop&&(0===this.index?s=t-1:this.index===t-1&&(e=0)),this.$slide.removeClass("lg-next-slide lg-prev-slide"),s>-1&&this.$slide.eq(s).addClass("lg-prev-slide"),this.$slide.eq(e).addClass("lg-next-slide")}mousewheel(){var e=this;e.$outer.on("mousewheel.lg",s=>{s.deltaY&&(s.deltaY>0?e.goToPrevSlide():e.goToNextSlide(),s.preventDefault())})}closeGallery(){var s=this,t=!1;this.$outer.find(".lg-close").on("click.lg",()=>s.destroy()),s.s.closable&&(s.$outer.on("mousedown.lg",s=>{t=!!(e(s.target).is(".lg-outer")||e(s.target).is(".lg-item ")||e(s.target).is(".lg-img-wrap"))}),s.$outer.on("mouseup.lg",l=>{(e(l.target).is(".lg-outer")||e(l.target).is(".lg-item ")||e(l.target).is(".lg-img-wrap")&&t)&&(s.$outer.hasClass("lg-dragging")||s.destroy())}))}destroy(t){var l=this;t||l.$el.trigger("onBeforeClose.lg"),e(s).scrollTop(l.prevScrollTop),t&&(l.s.dynamic||this.$items.off("click.lg click.lgcustom"),e.removeData(l.el,"lightGallery")),this.$el.off(".lg.tm"),e.each(e.fn.lightGallery.modules,e=>{l.modules[e]&&l.modules[e].destroy()}),this.lGalleryOn=!1,clearTimeout(l.hideBartimeout),this.hideBartimeout=!1,e(s).off(".lg"),e("body").removeClass("lg-on lg-from-hash"),l.$outer&&l.$outer.removeClass("lg-visible"),e(".lg-backdrop").removeClass("in"),setTimeout(()=>{l.$outer&&l.$outer.remove(),e(".lg-backdrop").remove(),t||l.$el.trigger("onCloseAfter.lg")},l.s.backdropDuration+50)}}e.fn.lightGallery=function(s){return this.each(function(){if(e.data(this,"lightGallery"))try{e(this).data("lightGallery").init()}catch(e){console.error("lightGallery has not initiated properly")}else e.data(this,"lightGallery",new l(this,s))})},e.fn.lightGallery.modules={}})(jQuery,window);
|