-
Notifications
You must be signed in to change notification settings - Fork 7
/
abigimage.jquery.min.js
2 lines (2 loc) · 9.99 KB
/
abigimage.jquery.min.js
1
2
/*! abigimage v2.1.1 (2018-01-20) */
!function(a){function b(a){a.preventDefault(),a.stopPropagation()}function c(){function c(a){D&&null!==V&&(U?B(V*D.zoomVelocity*(a-U)):U=a,Pa(c))}function d(a,b,c){a.addEventListener(b,c)}function e(b,c){a.extend(this,a.fn.abigimage.defaults,c),this.elements=b,this.overlay=ga,this.layout=ha,this.wrapper=ia,this.prevBtnBox=ka,this.closeBtnBox=la,this.box=ja,this.top=ma,this.prevBtn=na,this.nextBtn=oa,this.zoomInBtn=sa,this.zoomOutBtn=ra,this.closeBtn=qa,this.counter=pa,this.bottomBox=ta,this.bottom=ua,this.index=-1,this.distance=0,this.opened=null}function f(b,c){return a("<img>").addClass(b).attr("src",c).appendTo(ja)}function g(a){D&&D.key(a.which)&&b(a)}function h(a){D&&(a||!Ka)&&(D.imgNext[0].complete&&D.imgNext.show(),D.imgPrev[0].complete&&D.imgPrev.show())}function i(){D&&(Ka=!0)}function j(){D&&(Ka=!1,h(!0))}function k(a){D&&(j(),a.touches.length>1?(L=o(a),D.layout.addClass(ya)):(aa=null,H=K,X=Y,Y=(new Date).getTime(),Z=.34*ja.width(),$=ja.height(),_=D.slideWidth*Z,p()),E=I,F=J,G=K,M=0,N=0,ba=a.touches,b(a),W&&(clearTimeout(W),W=null),1==a.touches.length&&(W=setTimeout(function(){D.layout.toggleClass(xa),W=null},D.doubleTapInterval)))}function l(a){if(D){if(a.touches.length>1&&(K=G*(o(a)/L),1>K&&(K=.333*K*K*K+.666,v(K)),K>H&&(H=K)),M=(Q-n(ba,"X"))/G-(Q-n(a.touches,"X"))/K,N=(R-n(ba,"Y"))/G-(R-n(a.touches,"Y"))/K,I=E+M,J=F+N,W&&(M>1||-1>M||N>1||-1>N)&&(clearTimeout(W),W=null),1==K&&1==a.touches.length){if(null===aa){var c=Math.abs(N)-Math.abs(M);Math.abs(c)>2&&(aa=c>0),aa===!1&&i()}aa?(I=0,v(1-Math.abs(N)/$)):J=0}u(I,J,K),b(a)}}function m(a){if(D){var c=(new Date).getTime(),d=c-Y;if(a.touches.length)E=I,F=J,G=K;else if(K<=D.zoomMin)if(1>=d||M>=-1&&1>=M&&N>=-1&&1>=N)if(Y-X<=D.doubleTapInterval){K=D.zoomMax;var e=n(ba,"X"),f=n(ba,"Y");I+=(Q-e)/G-(Q-e)/K,J+=(R-f)/G-(R-f)/K,S=O-Q/K,T=P-R/K,I=0>=S?0:Math.max(-S,Math.min(S,I)),J=0>=T?0:Math.max(-T,Math.min(T,J)),W&&(clearTimeout(W),W=null),D.layout.addClass(ya),u(I,J,K,!0)}else s();else if(1==H)if(K<D.zoomClose)t();else if(aa){var g=Math.abs(N);g>_?t(N):g/d>D.slideVelocity?t(N):s()}else-_>M?q():M>_?r():Math.abs(M)/d>D.slideVelocity?0>M?q():r():s();else s();else c-X<=D.doubleTapInterval?(W&&(clearTimeout(W),W=null),s()):(K=Math.max(1,Math.min(D.zoomMax,K)),S=O-Q/K,T=P-R/K,I=0>=S?0:Math.max(-S,Math.min(S,I)),J=0>=T?0:Math.max(-T,Math.min(T,J)),u(I,J,K,!0));ba=a.touches,b(a)}}function n(a,b){for(var c=0,d=0,e=a.length;e>d;d++)c+=a[d]["client"+b];return c/e}function o(a){return Math.sqrt(Math.pow(a.touches[0].pageX-a.touches[1].pageX,2)+Math.pow(a.touches[0].pageY-a.touches[1].pageY,2))}function p(){O=D.img.width()/2,P=D.img.height()/2,Q=Ea.width()/2,R=(Ea.height()-D.top.height()-D.bottomBox.height())/2}function q(){u(-Z,0,1,!0,function(){D.next()}),ha.animate({scrollTop:0},D.duration)}function r(){u(Z,0,1,!0,function(){D.prev()}),ha.animate({scrollTop:0},D.duration)}function s(){u(0,0,1,!0,function(){D.layout.removeClass(ya),j()}),v(1,!0)}function t(a){a?u(I,Math.sign(a)*(Ea.height()/2+P),K,!0,function(){D.close()}):u(I,J,0,!0,function(){D.close()}),v(0,!0),ha.addClass(wa)}function u(a,b,c,d,e){I=a,J=b,K=c,ca=d,da=e;var f="scale("+K+") translate3d("+I+"px, "+J+"px, 0)";Na.transition=d?"all "+D.duration+"ms ease-out":"none",Na.webkitTransform=f,Na.mozTransform=f,Na.msTransform=f,Na.oTransform=f,Na.transform=f}function v(a,b){Oa.transition=b?"opacity "+D.duration+"ms ease-out":"none",Oa.opacity=a;var c="translate3d(0, 0, 0)";Oa.webkitTransform=c,Oa.mozTransform=c,Oa.msTransform=c,Oa.oTransform=c,Oa.transform=c}function w(){Oa.transition=null,Oa.opacity=null}function x(){if(ca=!1,da){var a=da;da=null,a()}}function y(a){if(D){var c=-a.deltaY||0;return 1==a.deltaMode?c*=D.zoomVelocity*D.duration:2==a.deltaMode&&(c*=$),ha.scrollTop()||1==K&&0>c?void(La?b(a):(fa&&clearTimeout(fa),Ma=!0,fa=setTimeout(function(){Ma=!1,fa=null},D.duration))):void(Ma||(ea&&clearTimeout(ea),La=!0,ea=setTimeout(function(){La=!1,ea=null},D.duration),A(a,c)))}}function z(a){D&&1!=K&&A(a,0)}function A(a,c){p(),I=(Q-a.clientX)/(D.zoomMoveViewport*Q/O)-(Q-a.clientX)/K,J=(R-a.clientY)/(D.zoomMoveViewport*R/P)-(R-a.clientY)/K,B(c,!0),b(a)}function B(a,b){D&&(K*=(P+a)/P,K=Math.max(1,Math.min(D.zoomMax,K)),S=O-Q/K,T=P-R/K,I=S>0?Math.max(-S,Math.min(S,I)):0,J=T>0?Math.max(-T,Math.min(T,J)):0,u(I,J,K,b))}var C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,$,_,aa,ba,ca,da,ea,fa,ga=a("<div>").addClass("abigimage-overlay").appendTo("body"),ha=a("<div>").addClass("abigimage-layout").appendTo("body"),ia=a("<div>").addClass("abigimage-wrapper").appendTo(ha),ja=a("<div>").addClass("abigimage-box").appendTo(ia),ka=a("<div>").addClass("abigimage-prevBtnBox").appendTo(ja),la=a("<div>").addClass("abigimage-closeBtnBox").appendTo(ja),ma=a("<div>").addClass("abigimage-top").appendTo(ha),na=a("<div>").addClass("abigimage-prevBtn").appendTo(ma),oa=a("<div>").addClass("abigimage-nextBtn").appendTo(ma),pa=a("<div>").addClass("abigimage-counter").appendTo(ma),qa=a("<div>").addClass("abigimage-closeBtn").appendTo(ma),ra=a("<div>").addClass("abigimage-zoomOutBtn").appendTo(ma),sa=a("<div>").addClass("abigimage-zoomInBtn").appendTo(ma),ta=a("<div>").addClass("abigimage-bottomBox").appendTo(ha),ua=a("<div>").addClass("abigimage-bottom").appendTo(ta),va="abigimage-layout-active",wa="abigimage-layout-fadeout",xa="abigimage-layout-full",ya="abigimage-layout-zoom",za="abigimage-overlay-active",Aa="abigimage-prevBtn-hover",Ba="abigimage-nextBtn-hover",Ca="abigimage-closeBtn-hover",Da=ja[0],Ea=a(window),Fa=a("html"),Ga=a(document),Ha=a(document.body),Ia=null,Ja=null,Ka=!1,La=!1,Ma=!1,Na=Da.style,Oa=ga[0].style;a.fn.abigimage.defaults={duration:200,slideWidth:.4,slideVelocity:.4,zoomMin:1.5,zoomMax:5,zoomClose:.9,zoomMoveViewport:.9,zoomVelocity:.04,doubleTapInterval:400,prevBtnHtml:"←",nextBtnHtml:"→",zoomInBtnHtml:"+",zoomOutBtnHtml:"−",closeBtnHtml:"×",keyNext:[13,32,39,40],keyPrev:[8,37,38],keyClose:[27,35,36],onopen:null,onclose:null},a.abigimage={overlay:ga,layout:ha,wrapper:ia,box:ja,prevBtnBox:ka,closeBtnBox:la,top:ma,prevBtn:na,nextBtn:oa,zoomInBtn:sa,zoomOutBtn:ra,closeBtn:qa,counter:pa,bottomBox:ta,bottom:ua,open:function(a,b,c){(c&&c._abigimage||D||C).open(a,b)},close:function(a){(a&&a._abigimage||D||C).close()},next:function(a){(a&&a._abigimage||D||C).next()},prev:function(a){(a&&a._abigimage||D||C).prev()},unbind:function(a){(a&&a._abigimage||D||C).unbind()}},ka.click(function(a){b(a),D&&D.prev()}).hover(function(){na.addClass(Aa)},function(){na.removeClass(Aa)}),la.click(function(a){b(a),D&&D.close()}).hover(function(){qa.addClass(Ca)},function(){qa.removeClass(Ca)}),na.click(function(a){b(a),D&&D.prev()}),oa.click(function(a){b(a),D&&D.next()});var Pa=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame||function(a){setTimeout(function(){a((new Date).getTime())},1e3/60)};return sa.mousedown(function(a){b(a),p(),U=null,V=1,Pa(c)}).mouseup(function(a){b(a),V=null}).mouseout(function(){V=null}).click(function(a){b(a),D&&B(D.zoomVelocity*D.duration,!0)}),ra.mousedown(function(a){b(a),p(),U=null,V=-1,Pa(c)}).mouseup(function(a){b(a),V=null}).mouseout(function(){V=null}).click(function(a){b(a),D&&B(-D.zoomVelocity*D.duration,!0)}),qa.click(function(a){b(a),D&&D.close()}),Da.addEventListener&&(d(Da,"touchstart",k),d(Da,"touchmove",l),d(Da,"touchend",m),d(Da,"touchcancel",m),d(Da,"webkitTransitionEnd",x),d(Da,"mozTransitionEnd",x),d(Da,"msTransitionEnd",x),d(Da,"oTransitionEnd",x),d(Da,"transitionend",x),d(Da,"wheel",y),d(Da,"mousemove",z)),e.prototype.open=function(c,d){D=this;var e;if("number"==typeof c){if(d=c,d==this.index||0>d||d>this.elements.length-1)return;e=a(this.elements[d]),c=e.data("href")||e.attr("href")}else if("number"!=typeof d)d=this.index;else if(d==this.index)return;this.index=d,this.opened=e,this.prevBtn.html(this.prevBtnHtml),this.nextBtn.html(this.nextBtnHtml),this.zoomInBtn.html(this.zoomInBtnHtml),this.zoomOutBtn.html(this.zoomOutBtnHtml),this.closeBtn.html(this.closeBtnHtml),this.bottom.html(""),this.counter.html(d>=0?d+1+" / "+this.elements.length:""),a("img",this.box).remove(),w(),this.overlay.addClass(za),this.layout.addClass(va).removeClass(wa).scrollTop(0),u(0,0,1),this.img=f("abigimage-img",c).click(function(a){b(a),D&&D.next()}).hover(function(){oa.addClass(Ba)},function(){oa.removeClass(Ba)}).one("load",function(){h()});var i=a(this.elements[this.nextIndex()]);this.imgNext=f("abigimage-imgNext",i.data("href")||i.attr("href")).hide().one("load",function(){h()});var j=a(this.elements[this.prevIndex()]);this.imgPrev=f("abigimage-imgPrev",j.data("href")||j.attr("href")).hide().one("load",function(){h()}),h(!0),Ga.unbind("keydown",g).bind("keydown",g),null===Ia&&null===Ja&&(Ia=Fa.css("padding-right"),Ja=Ha.css("overflow-y"),Fa.css("padding-right",parseInt(Ia)+window.innerWidth-Ea.width()+"px"),Ha.css("overflow-y","hidden")),this.onopen&&this.onopen.call(this,this.opened)},e.prototype.next=function(){this.distance==this.elements.length-1?this.close():(++this.distance,this.elements[this.nextIndex()].click())},e.prototype.prev=function(){this.distance==1-this.elements.length?this.close():(--this.distance,this.elements[this.prevIndex()].click())},e.prototype.close=function(){D&&(Ga.unbind("keydown",g),Fa.css("padding-right",Ia),Ha.css("overflow-y",Ja),Ia=null,Ja=null,ga.removeClass(za),ha.removeClass(va),this.onclose&&this.onclose.call(this,this.opened),this.index=-1,this.distance=0,D=null)},e.prototype.unbind=function(){this.close(),this.elements.each(function(){a(this).unbind("click.abigimage")})},e.prototype.key=function(a){if(-1!=this.keyNext.indexOf(a))this.next();else if(-1!=this.keyPrev.indexOf(a))this.prev();else{if(-1==this.keyClose.indexOf(a))return!1;this.close()}return!0},e.prototype.nextIndex=function(){var a=this.index+1;return a>=this.elements.length&&(a=0),a},e.prototype.prevIndex=function(){var a=this.index-1;return 0>a&&(a=this.elements.length-1),a},e}var d;a.fn.abigimage=function(e){d||(d=c());var f=new d(this,e);return this._abigimage=f,last=f,this.each(function(c){a(this).unbind("click.abigimage").bind("click.abigimage",function(a){b(a),f.open(c)})})}}(jQuery);