mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-09 08:17:53 +08:00
f5a444aa14
Cleanup lightgallery
4 lines
6.9 KiB
JavaScript
4 lines
6.9 KiB
JavaScript
/*! lightgallery - v1.2.21 - 2016-06-28
|
|
* http://sachinchoolur.github.io/lightGallery/
|
|
* Copyright (c) 2016 Sachin N; Licensed Apache 2.0 */
|
|
((t,e)=>{"use strict";var i={thumbnail:!0,animateThumb:!0,currentPagerPosition:"middle",thumbWidth:100,thumbContHeight:100,thumbMargin:5,exThumbImage:!1,showThumbByDefault:!0,toogleThumb:!0,pullCaptionUp:!0,enableThumbDrag:!0,enableThumbSwipe:!0,swipeThreshold:50,loadYoutubeThumbnail:!0,youtubeThumbSize:1,loadVimeoThumbnail:!0,vimeoThumbSize:"thumbnail_small",loadDailymotionThumbnail:!0};t.fn.lightGallery.modules.Thumbnail=class{constructor(e){return this.core=t(e).data("lightGallery"),this.core.s=t.extend({},i,this.core.s),this.$el=t(e),this.$thumbOuter=null,this.thumbOuterWidth=0,this.thumbTotalWidth=this.core.$items.length*(this.core.s.thumbWidth+this.core.s.thumbMargin),this.thumbIndex=this.core.index,this.left=0,this.init(),this}init(){var t=this;this.core.s.thumbnail&&this.core.$items.length>1&&(this.core.s.showThumbByDefault&&setTimeout(function(){t.core.$outer.addClass("lg-thumb-open")},700),this.core.s.pullCaptionUp&&this.core.$outer.addClass("lg-pull-caption-up"),this.build(),this.core.s.animateThumb?(this.core.s.enableThumbDrag&&!this.core.isTouch&&this.core.doCss()&&this.enableThumbDrag(),this.core.s.enableThumbSwipe&&this.core.isTouch&&this.core.doCss()&&this.enableThumbSwipe(),this.thumbClickable=!1):this.thumbClickable=!0,this.toogle(),this.thumbkeyPress())}build(){var i,h=this,o="",s="";switch(this.core.s.vimeoThumbSize){case"thumbnail_large":s="640";break;case"thumbnail_medium":s="200x150";break;case"thumbnail_small":s="100x75"}function u(t,e,i){var u,r=h.core.isVideo(t,i)||{},a="";r.youtube||r.vimeo||r.dailymotion?r.youtube?u=h.core.s.loadYoutubeThumbnail?"//img.youtube.com/vi/"+r.youtube[1]+"/"+h.core.s.youtubeThumbSize+".jpg":e:r.vimeo?h.core.s.loadVimeoThumbnail?(u="//i.vimeocdn.com/video/error_"+s+".jpg",a=r.vimeo[1]):u=e:r.dailymotion&&(u=h.core.s.loadDailymotionThumbnail?"//www.dailymotion.com/thumbnail/video/"+r.dailymotion[1]:e):u=e,o+='<div data-vimeo-id="'+a+'" class="lg-thumb-item" style="width:'+h.core.s.thumbWidth+"px; margin-right: "+h.core.s.thumbMargin+'px"><img src="'+u+'" /></div>',a=""}if(h.core.$outer.addClass("lg-has-thumb"),h.core.$outer.find(".lg").append('<div class="lg-thumb-outer"><div class="lg-thumb group"></div></div>'),h.$thumbOuter=h.core.$outer.find(".lg-thumb-outer"),h.thumbOuterWidth=h.$thumbOuter.width(),h.core.s.animateThumb&&h.core.$outer.find(".lg-thumb").css({width:h.thumbTotalWidth+"px",position:"relative"}),this.core.s.animateThumb&&h.$thumbOuter.css("height",h.core.s.thumbContHeight+"px"),h.core.s.dynamic)for(var r=0;r<h.core.s.dynamicEl.length;r++)u(h.core.s.dynamicEl[r].src,h.core.s.dynamicEl[r].thumb,r);else h.core.$items.each(function(e){h.core.s.exThumbImage?u(t(this).attr("href")||t(this).attr("data-src"),t(this).attr(h.core.s.exThumbImage),e):u(t(this).attr("href")||t(this).attr("data-src"),t(this).find("img").attr("src"),e)});h.core.$outer.find(".lg-thumb").html(o),(i=h.core.$outer.find(".lg-thumb-item")).each(function(){var e=t(this),i=e.attr("data-vimeo-id");i&&t.getJSON("//www.vimeo.com/api/v2/video/"+i+".json?callback=?",{format:"json"},function(t){e.find("img").attr("src",t[0][h.core.s.vimeoThumbSize])})}),i.eq(h.core.index).addClass("active"),h.core.$el.on("onBeforeSlide.lg.tm",function(){i.removeClass("active"),i.eq(h.core.index).addClass("active")}),i.on("click.lg touchend.lg",function(){var e=t(this);setTimeout(function(){(h.thumbClickable&&!h.core.lgBusy||!h.core.doCss())&&(h.core.index=e.index(),h.core.slide(h.core.index,!1,!0))},50)}),h.core.$el.on("onBeforeSlide.lg.tm",function(){h.animateThumb(h.core.index)}),t(e).on("resize.lg.thumb orientationchange.lg.thumb",function(){setTimeout(function(){h.animateThumb(h.core.index),h.thumbOuterWidth=h.$thumbOuter.width()},200)})}setTranslate(t){this.core.$outer.find(".lg-thumb").css({transform:"translate3d(-"+t+"px, 0px, 0px)"})}animateThumb(t){var e=this.core.$outer.find(".lg-thumb");if(this.core.s.animateThumb){var i;switch(this.core.s.currentPagerPosition){case"left":i=0;break;case"middle":i=this.thumbOuterWidth/2-this.core.s.thumbWidth/2;break;case"right":i=this.thumbOuterWidth-this.core.s.thumbWidth}this.left=(this.core.s.thumbWidth+this.core.s.thumbMargin)*t-1-i,this.left>this.thumbTotalWidth-this.thumbOuterWidth&&(this.left=this.thumbTotalWidth-this.thumbOuterWidth),this.left<0&&(this.left=0),this.core.lGalleryOn?(e.hasClass("on")||this.core.$outer.find(".lg-thumb").css("transition-duration",this.core.s.speed+"ms"),this.core.doCss()||e.animate({left:-this.left+"px"},this.core.s.speed)):this.core.doCss()||e.css("left",-this.left+"px"),this.setTranslate(this.left)}}enableThumbDrag(){var i=this,h=0,o=0,s=!1,u=!1,r=0;i.$thumbOuter.addClass("lg-grab"),i.core.$outer.find(".lg-thumb").on("mousedown.lg.thumb",function(t){i.thumbTotalWidth>i.thumbOuterWidth&&(t.preventDefault(),h=t.pageX,s=!0,i.core.$outer.scrollLeft+=1,i.core.$outer.scrollLeft-=1,i.thumbClickable=!1,i.$thumbOuter.removeClass("lg-grab").addClass("lg-grabbing"))}),t(e).on("mousemove.lg.thumb",function(t){s&&(r=i.left,u=!0,o=t.pageX,i.$thumbOuter.addClass("lg-dragging"),(r-=o-h)>i.thumbTotalWidth-i.thumbOuterWidth&&(r=i.thumbTotalWidth-i.thumbOuterWidth),r<0&&(r=0),i.setTranslate(r))}).on("mouseup.lg.thumb",function(){u?(u=!1,i.$thumbOuter.removeClass("lg-dragging"),i.left=r,Math.abs(o-h)<i.core.s.swipeThreshold&&(i.thumbClickable=!0)):i.thumbClickable=!0,s&&(s=!1,i.$thumbOuter.removeClass("lg-grabbing").addClass("lg-grab"))})}enableThumbSwipe(){var t=this,e=0,i=0,h=!1,o=0;t.core.$outer.find(".lg-thumb").on("touchstart.lg",function(i){t.thumbTotalWidth>t.thumbOuterWidth&&(i.preventDefault(),e=i.originalEvent.targetTouches[0].pageX,t.thumbClickable=!1)}),t.core.$outer.find(".lg-thumb").on("touchmove.lg",function(s){t.thumbTotalWidth>t.thumbOuterWidth&&(s.preventDefault(),i=s.originalEvent.targetTouches[0].pageX,h=!0,t.$thumbOuter.addClass("lg-dragging"),o=t.left,(o-=i-e)>t.thumbTotalWidth-t.thumbOuterWidth&&(o=t.thumbTotalWidth-t.thumbOuterWidth),o<0&&(o=0),t.setTranslate(o))}),t.core.$outer.find(".lg-thumb").on("touchend.lg",function(){t.thumbTotalWidth>t.thumbOuterWidth&&h?(h=!1,t.$thumbOuter.removeClass("lg-dragging"),Math.abs(i-e)<t.core.s.swipeThreshold&&(t.thumbClickable=!0),t.left=o):t.thumbClickable=!0})}toogle(){var t=this;t.core.s.toogleThumb&&(t.core.$outer.addClass("lg-can-toggle"),t.$thumbOuter.append('<span class="lg-toogle-thumb lg-icon"></span>'),t.core.$outer.find(".lg-toogle-thumb").on("click.lg",function(){t.core.$outer.toggleClass("lg-thumb-open")}))}thumbkeyPress(){var i=this;t(e).on("keydown.lg.thumb",function(t){38===t.keyCode?(t.preventDefault(),i.core.$outer.addClass("lg-thumb-open")):40===t.keyCode&&(t.preventDefault(),i.core.$outer.removeClass("lg-thumb-open"))})}destroy(){this.core.s.thumbnail&&this.core.$items.length>1&&(t(e).off("resize.lg.thumb orientationchange.lg.thumb keydown.lg.thumb"),this.$thumbOuter.remove(),this.core.$outer.removeClass("lg-has-thumb"))}}})(jQuery,window);
|