mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-09 08:17:53 +08:00
f5a444aa14
Cleanup lightgallery
4 lines
6.2 KiB
JavaScript
4 lines
6.2 KiB
JavaScript
/*! lightgallery - v1.2.21 - 2016-06-28
|
|
* http://sachinchoolur.github.io/lightGallery/
|
|
* Copyright (c) 2016 Sachin N; Licensed Apache 2.0 */
|
|
((e,t)=>{"use strict";var o={scale:1,zoom:!0,actualSize:!0,enableZoomAfter:300};e.fn.lightGallery.modules.zoom=class{constructor(a){return this.core=e(a).data("lightGallery"),this.core.s=e.extend({},o,this.core.s),this.core.s.zoom&&this.core.doCss()&&(this.init(),this.zoomabletimeout=!1,this.pageX=e(t).width()/2,this.pageY=e(t).height()/2+e(t).scrollTop()),this}init(){var o=this,a='<span id="lg-zoom-in" class="lg-icon"></span><span id="lg-zoom-out" class="lg-icon"></span>';o.core.s.actualSize&&(a+='<span id="lg-actual-size" class="lg-icon"></span>'),this.core.$outer.find(".lg-toolbar").append(a),o.core.$el.on("onSlideItemLoad.lg.tm.zoom",function(t,a,r){var i=o.core.s.enableZoomAfter+r;e("body").hasClass("lg-from-hash")&&r?i=0:e("body").removeClass("lg-from-hash"),o.zoomabletimeout=setTimeout(function(){o.core.$slide.eq(a).addClass("lg-zoomable")},i+30)});var r=1,i=function(a){var r=o.core.$outer.find(".lg-current .lg-image"),i=(e(t).width()-r.width())/2,s=(e(t).height()-r.height())/2+e(t).scrollTop(),l=(a-1)*(o.pageX-i),c=(a-1)*(o.pageY-s);r.css("transform","scale3d("+a+", "+a+", 1)").attr("data-scale",a),r.parent().css({left:-l+"px",top:-c+"px"}).attr("data-x",l).attr("data-y",c)},s=function(){r>1?o.core.$outer.addClass("lg-zoomed"):o.resetZoom(),r<1&&(r=1),i(r)},l=function(a,i,l,c){var g,n=i.width();g=o.core.s.dynamic?o.core.s.dynamicEl[l].width||i[0].naturalWidth||n:o.core.$items.eq(l).attr("data-width")||i[0].naturalWidth||n,o.core.$outer.hasClass("lg-zoomed")?r=1:g>n&&(r=g/n||2),c?(o.pageX=e(t).width()/2,o.pageY=e(t).height()/2+e(t).scrollTop()):(o.pageX=a.pageX||a.originalEvent.targetTouches[0].pageX,o.pageY=a.pageY||a.originalEvent.targetTouches[0].pageY),s(),setTimeout(function(){o.core.$outer.removeClass("lg-grabbing").addClass("lg-grab")},10)},c=!1;o.core.$el.on("onAferAppendSlide.lg.tm.zoom",function(e,t){var a=o.core.$slide.eq(t).find(".lg-image");a.on("dblclick",function(e){l(e,a,t)}),a.on("touchstart",function(e){c?(clearTimeout(c),c=null,l(e,a,t)):c=setTimeout(function(){c=null},300),e.preventDefault()})}),e(t).on("resize.lg.zoom scroll.lg.zoom orientationchange.lg.zoom",function(){o.pageX=e(t).width()/2,o.pageY=e(t).height()/2+e(t).scrollTop(),i(r)}),e("#lg-zoom-out").on("click.lg",function(){o.core.$outer.find(".lg-current .lg-image").length&&(r-=o.core.s.scale,s())}),e("#lg-zoom-in").on("click.lg",function(){o.core.$outer.find(".lg-current .lg-image").length&&(r+=o.core.s.scale,s())}),e("#lg-actual-size").on("click.lg",function(e){l(e,o.core.$slide.eq(o.core.index).find(".lg-image"),o.core.index,!0)}),o.core.$el.on("onBeforeSlide.lg.tm",function(){r=1,o.resetZoom()}),o.core.isTouch||o.zoomDrag(),o.core.isTouch&&o.zoomSwipe()}resetZoom(){this.core.$outer.removeClass("lg-zoomed"),this.core.$slide.find(".lg-img-wrap").removeAttr("style data-x data-y"),this.core.$slide.find(".lg-image").removeAttr("style data-scale"),this.pageX=e(t).width()/2,this.pageY=e(t).height()/2+e(t).scrollTop()}zoomSwipe(){var e=this,t={},o={},a=!1,r=!1,i=!1;e.core.$slide.on("touchstart.lg",function(o){if(e.core.$outer.hasClass("lg-zoomed")){var a=e.core.$slide.eq(e.core.index).find(".lg-object");i=a.outerHeight()*a.attr("data-scale")>e.core.$outer.find(".lg").height(),((r=a.outerWidth()*a.attr("data-scale")>e.core.$outer.find(".lg").width())||i)&&(o.preventDefault(),t={x:o.originalEvent.targetTouches[0].pageX,y:o.originalEvent.targetTouches[0].pageY})}}),e.core.$slide.on("touchmove.lg",function(s){if(e.core.$outer.hasClass("lg-zoomed")){var l,c,g=e.core.$slide.eq(e.core.index).find(".lg-img-wrap");s.preventDefault(),a=!0,o={x:s.originalEvent.targetTouches[0].pageX,y:s.originalEvent.targetTouches[0].pageY},e.core.$outer.addClass("lg-zoom-dragging"),c=i?-Math.abs(g.attr("data-y"))+(o.y-t.y):-Math.abs(g.attr("data-y")),l=r?-Math.abs(g.attr("data-x"))+(o.x-t.x):-Math.abs(g.attr("data-x")),(Math.abs(o.x-t.x)>15||Math.abs(o.y-t.y)>15)&&g.css({left:l+"px",top:c+"px"})}}),e.core.$slide.on("touchend.lg",function(){e.core.$outer.hasClass("lg-zoomed")&&a&&(a=!1,e.core.$outer.removeClass("lg-zoom-dragging"),e.touchendZoom(t,o,r,i))})}zoomDrag(){var o=this,a={},r={},i=!1,s=!1,l=!1,c=!1;o.core.$slide.on("mousedown.lg.zoom",function(t){var r=o.core.$slide.eq(o.core.index).find(".lg-object");c=r.outerHeight()*r.attr("data-scale")>o.core.$outer.find(".lg").height(),l=r.outerWidth()*r.attr("data-scale")>o.core.$outer.find(".lg").width(),o.core.$outer.hasClass("lg-zoomed")&&e(t.target).hasClass("lg-object")&&(l||c)&&(t.preventDefault(),a={x:t.pageX,y:t.pageY},i=!0,o.core.$outer.scrollLeft+=1,o.core.$outer.scrollLeft-=1,o.core.$outer.removeClass("lg-grab").addClass("lg-grabbing"))}),e(t).on("mousemove.lg.zoom",function(e){if(i){var t,g,n=o.core.$slide.eq(o.core.index).find(".lg-img-wrap");s=!0,r={x:e.pageX,y:e.pageY},o.core.$outer.addClass("lg-zoom-dragging"),g=c?-Math.abs(n.attr("data-y"))+(r.y-a.y):-Math.abs(n.attr("data-y")),t=l?-Math.abs(n.attr("data-x"))+(r.x-a.x):-Math.abs(n.attr("data-x")),n.css({left:t+"px",top:g+"px"})}}).on("mouseup.lg.zoom",function(e){i&&(i=!1,o.core.$outer.removeClass("lg-zoom-dragging"),!s||a.x===r.x&&a.y===r.y||(r={x:e.pageX,y:e.pageY},o.touchendZoom(a,r,l,c)),s=!1),o.core.$outer.removeClass("lg-grabbing").addClass("lg-grab")})}touchendZoom(e,t,o,a){var r=this.core.$slide.eq(this.core.index).find(".lg-img-wrap"),i=this.core.$slide.eq(this.core.index).find(".lg-object"),s=-Math.abs(r.attr("data-x"))+(t.x-e.x),l=-Math.abs(r.attr("data-y"))+(t.y-e.y),c=(this.core.$outer.find(".lg").height()-i.outerHeight())/2,g=Math.abs(i.outerHeight()*Math.abs(i.attr("data-scale"))-this.core.$outer.find(".lg").height()+c),n=(this.core.$outer.find(".lg").width()-i.outerWidth())/2,d=Math.abs(i.outerWidth()*Math.abs(i.attr("data-scale"))-this.core.$outer.find(".lg").width()+n);(Math.abs(t.x-e.x)>15||Math.abs(t.y-e.y)>15)&&(a&&(l<=-g?l=-g:l>=-c&&(l=-c)),o&&(s<=-d?s=-d:s>=-n&&(s=-n)),a?r.attr("data-y",Math.abs(l)):l=-Math.abs(r.attr("data-y")),o?r.attr("data-x",Math.abs(s)):s=-Math.abs(r.attr("data-x")),r.css({left:s+"px",top:l+"px"}))}destroy(){this.core.$el.off(".lg.zoom"),e(t).off(".lg.zoom"),this.core.$slide.off(".lg.zoom"),this.core.$el.off(".lg.tm.zoom"),this.resetZoom(),clearTimeout(this.zoomabletimeout),this.zoomabletimeout=!1}}})(jQuery,window);
|