ZwiiCMS/core/vendor/simplelightbox/simple-lightbox.min.js

8 lines
12 KiB
JavaScript
Raw Normal View History

/*
By André Rinas, www.andrerinas.de
Documentation, www.simplelightbox.de
Available for use under the MIT License
1.17.0
*/
!function(st,lt,rt,t){"use strict";st.fn.simpleLightbox=function(P){P=st.extend({sourceAttr:"href",overlay:!0,spinner:!0,nav:!0,navText:["&lsaquo;","&rsaquo;"],captions:!0,captionDelay:0,captionSelector:"img",captionType:"attr",captionsData:"title",captionPosition:"bottom",captionClass:"",close:!0,closeText:"×",swipeClose:!0,showCounter:!0,fileExt:"png|jpg|jpeg|gif",animationSlide:!0,animationSpeed:250,preloading:!0,enableKeyboard:!0,loop:!0,rel:!1,docClose:!0,swipeTolerance:50,className:"simple-lightbox",widthRatio:.8,heightRatio:.9,scaleImageToRatio:!1,disableRightClick:!1,disableScroll:!0,alertError:!0,alertErrorMessage:"Image not found, next image will be loaded",additionalHtml:!1,history:!0,throttleInterval:0,doubleTapZoom:2,maxZoom:10,htmlClass:"has-lightbox"},P);var h,t,Z="ontouchstart"in lt,z=(lt.navigator.pointerEnabled||lt.navigator.msPointerEnabled,0),H=0,L=st(),i=function(){var t=rt.body||rt.documentElement;return""===(t=t.style).WebkitTransition?"-webkit-":""===t.MozTransition?"-moz-":""===t.OTransition?"-o-":""===t.transition&&""},N=!1,p=[],j=P.rel&&!1!==P.rel?(t=P.rel,st(this).filter(function(){return st(this).attr("rel")===t})):this,d=(i=i(),0),K=!1!==i,a="pushState"in history,u=!1,n=lt.location,$=function(){return n.hash.substring(1)},B=$(),f=function(){$();var t="pid="+(J+1),e=n.href.split("#")[0]+"#"+t;a?history[u?"replaceState":"pushState"]("",rt.title,e):u?n.replace(e):n.hash=t,u=!0},Q=function(e,a){var n;return function(){var t=arguments;n||(e.apply(this,t),n=!0,setTimeout(function(){return n=!1},a))}},U="simplelb",e=st("<div>").addClass("sl-overlay"),o=st("<button>").addClass("sl-close").html(P.closeText),g=st("<div>").addClass("sl-spinner").html("<div></div>"),G=st("<div>").addClass("sl-navigation").html('<button class="sl-prev">'+P.navText[0]+'</button><button class="sl-next">'+P.navText[1]+"</button>"),s=st("<div>").addClass("sl-counter").html('<span class="sl-current"></span>/<span class="sl-total"></span>'),m=!1,J=0,v=0,l=st("<div>").addClass("sl-caption "+P.captionClass+" pos-"+P.captionPosition),V=st("<div>").addClass("sl-image"),r=st("<div>").addClass("sl-wrapper").addClass(P.className),c=function(t){t.trigger(st.Event("show.simplelightbox")),P.disableScroll&&(d=C("hide")),P.htmlClass&&""!=P.htmlClass&&st("html").addClass(P.htmlClass),r.appendTo("body"),V.appendTo(r),P.overlay&&e.appendTo(st("body")),m=!0,J=j.index(t),L=st("<img/>").hide().attr("src",t.attr(P.sourceAttr)).attr("data-scale",1).attr("data-translate-x",0).attr("data-translate-y",0),-1==p.indexOf(t.attr(P.sourceAttr))&&p.push(t.attr(P.sourceAttr)),V.html("").attr("style",""),L.appendTo(V),b(),e.fadeIn("fast"),st(".sl-close").fadeIn("fast"),g.show(),G.fadeIn("fast"),st(".sl-wrapper .sl-counter .sl-current").text(J+1),s.fadeIn("fast"),_(),P.preloading&&y(),setTimeout(function(){t.trigger(st.Event("shown.simplelightbox"))},P.animationSpeed)},_=function(s){if(L.length){var l=new Image,r=lt.innerWidth*P.widthRatio,c=lt.innerHeight*P.heightRatio;l.src=L.attr("src"),L.data("scale",1),L.data("translate-x",0),L.data("translate-y",0),et(0,0,1),st(l).on("error",function(t){j.eq(J).trigger(st.Event("error.simplelightbox")),N=!(m=!1),g.hide();var e=1==s||-1==s;v===J&&e?ot():(P.alertError&&alert(P.alertErrorMessage),it(e?s:1))}),l.onload=function(){void 0!==s&&j.eq(J).trigger(st.Event("changed.simplelightbox")).trigger(st.Event((1===s?"nextDone":"prevDone")+".simplelightbox")),P.history&&(u?h=setTimeout(f,800):f()),-1==p.indexOf(L.attr("src"))&&p.push(L.attr("src"));var t=l.width,e=l.height;if(P.scaleImageToRatio||r<t||c<e){var a=r/c<t/e?t/r:e/c;t/=a,e/=a}st(".sl-image").css({top:(lt.innerHeight-e)/2+"px",left:(lt.innerWidth-t-d)/2+"px",width:t+"px",height:e+"px"}),g.hide(),L.fadeIn("fast"),N=!0;var n,i="self"==P.captionSelector?j.eq(J):j.eq(J).find(P.captionSelector);if(n="data"==P.captionType?i.data(P.captionsData):"text"==P.captionType?i.html():i.prop(P.captionsData),P.loop||(0===J&&st(".sl-prev").hide(),J>=j.length-1&&st(".sl-next").hide(),0<J&&st(".sl-prev").show(),J<j.length-1&&st(".sl-next").show()),1==j.length&&st(".sl-prev, .sl-ne