7 lines
26 KiB
JavaScript
7 lines
26 KiB
JavaScript
/*!
|
|
By André Rinas, www.andrerinas.de
|
|
Documentation, www.simplelightbox.de
|
|
Available for use under the MIT License
|
|
Version 2.1.2
|
|
*/
|
|
"use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function _createClass(t,e,i){return e&&_defineProperties(t.prototype,e),i&&_defineProperties(t,i),t}function _defineProperty(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}var SimpleLightbox=function(){function n(t,e){var i=this;_classCallCheck(this,n),_defineProperty(this,"a",{sourceAttr:"href",overlay:!0,spinner:!0,nav:!0,navText:["‹","›"],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|webp",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",rtl:!1}),_defineProperty(this,"b",void 0),_defineProperty(this,"c",!1),_defineProperty(this,"d","ontouchstart"in window),_defineProperty(this,"e",void 0),_defineProperty(this,"f","pushState"in history),_defineProperty(this,"g",!1),_defineProperty(this,"h",!1),_defineProperty(this,"i",!1),_defineProperty(this,"j",!1),_defineProperty(this,"k",!1),_defineProperty(this,"l",!1),_defineProperty(this,"m",null),_defineProperty(this,"n",void 0),_defineProperty(this,"o","simplelightbox"),_defineProperty(this,"p",{}),_defineProperty(this,"q",[]),_defineProperty(this,"r",0),_defineProperty(this,"s",0),_defineProperty(this,"t",null),_defineProperty(this,"u",0),_defineProperty(this,"v",{a:0,b:0,c:0,d:0,e:0,f:0,g:!1,h:0,i:!1,j:0,k:0,l:0,m:0,n:0,o:0,p:!1,q:0,r:0,s:0,t:0,u:0,v:0,w:1,x:0,y:0,z:0,A:0,B:0,C:0,D:0,E:0,F:0,G:0,H:0,I:0,J:0,K:0,L:0,M:!1,N:0}),this.options=Object.assign(this.a,e),"string"==typeof t?(this.t=t,this.elements=Array.from(document.querySelectorAll(t))):this.elements=void 0!==t.length&&0<t.length?Array.from(t):[t],this.relatedElements=[],this.b=this.calculateTransitionPrefix(),this.c=!1!==this.b,this.e=this.hash,this.options.rel&&(this.elements=this.getRelated(this.options.rel)),this.createDomNodes(),this.options.close&&this.p.a.appendChild(this.p.b),this.options.nav&&this.p.a.appendChild(this.p.d),this.options.spinner&&this.p.a.appendChild(this.p.e),this.addEventListener(this.elements,"click."+this.o,function(t){if(i.isValidLink(t.currentTarget)){if(t.preventDefault(),i.h)return!1;i.r=i.elements.indexOf(t.currentTarget),i.openImage(t.currentTarget)}}),this.options.docClose&&this.addEventListener(this.p.f,["click."+this.o,"touchstart."+this.o],function(t){i.g&&i.close()}),this.options.disableRightClick&&this.addEventListener(document.body,"contextmenu."+this.o,function(t){t.target.classList.contains("sl-overlay")&&t.preventDefault()}),this.options.enableKeyboard&&this.addEventListener(document.body,"keyup."+this.o,this.throttle(function(t){if(i.v.a=0,i.h&&"Escape"===t.key)return i.n.setAttribute("src",""),i.h=!1,i.close();i.g&&(t.preventDefault(),"Escape"===t.key&&i.close(),!i.h&&-1<["ArrowLeft","ArrowRight"].indexOf(t.key)&&i.loadImage("ArrowRight"===t.key?1:-1))},this.options.throttleInterval)),this.addEvents()}return _createClass(n,[{key:"createDomNodes",value:function(){this.p.f=document.createElement("div"),this.p.f.classList.add("sl-overlay"),this.p.f.dataset.opacityTarget=".7",this.p.b=document.createElement("button"),this.p.b.classList.add("sl-close"),this.p.b.innerHTML=this.options.closeText,this.p.e=document.createElement("div"),this.p.e.classList.add("sl-spinner"),this.p.e.innerHTML="<div></div>",this.p.d=document.createElement("div"),this.p.d.classList.add("sl-navigation"),this.p.d.innerHTML='<button class="sl-prev">'.concat(this.options.navText[0],'</button><button class="sl-next">').concat(this.options.navText[1],"</button>"),this.p.c=document.createElement("div"),this.p.c.classList.add("sl-counter"),this.p.c.innerHTML='<span class="sl-current"></span>/<span class="sl-total"></span>',this.p.g=document.createElement("div"),this.p.g.classList.add("sl-caption","pos-"+this.options.captionPosition),this.options.captionClass&&this.p.g.classList.add(this.options.captionClass),this.p.h=document.createElement("div"),this.p.h.classList.add("sl-image"),this.p.a=document.createElement("div"),this.p.a.classList.add("sl-wrapper"),this.options.className&&this.p.a.classList.add(this.options.className),this.options.rtl&&this.p.a.classList.add("sl-dir-rtl")}},{key:"throttle",value:function(t,e){var i;return function(){i||(t.apply(this,arguments),i=!0,setTimeout(function(){return i=!1},e))}}},{key:"isValidLink",value:function(t){return!this.options.fileExt||"pathname"in t&&new RegExp("("+this.options.fileExt+")$","i").test(t.pathname)}},{key:"calculateTransitionPrefix",value:function(){var t=(document.body||document.documentElement).style;return"transition"in t?"":"WebkitTransition"in t?"-webkit-":"MozTransition"in t?"-moz-":"OTransition"in t&&"-o"}},{key:"toggleScrollbar",value:function(t){var e=0;if("hide"===t){var i=window.innerWidth;if(!i){var n=document.documentElement.getBoundingClientRect();i=n.right-Math.abs(n.left)}if(document.body.clientWidth<i){var s=document.createElement("div"),o=parseInt(document.body.style.paddingRight||0,10);s.classList.add("sl-scrollbar-measure"),document.body.appendChild(s),e=s.offsetWidth-s.clientWidth,document.body.removeChild(s),document.body.dataset.originalPaddingRight=o,0<e&&(document.body.classList.add("hidden-scroll"),document.body.style.paddingRight=o+e+"px")}}else document.body.classList.remove("hidden-scroll"),document.body.style.paddingRight=document.body.dataset.originalPaddingRight;return e}},{key:"close",value:function(){var t=this;if(!this.g||this.h||this.i)return!1;this.i=!0;var e=this.relatedElements[this.nIndex];for(var i in e.dispatchEvent(new Event("close.simplelightbox")),this.options.history&&(this.l=!1,this.k||this.resetHash()),this.fadeOut(document.querySelectorAll(".sl-image img, .sl-overlay, .sl-close, .sl-navigation, .sl-image .sl-caption, .sl-counter"),300,function(){t.options.disableScroll&&t.toggleScrollbar("show"),t.options.htmlClass&&""!==t.options.htmlClass&&document.querySelector("html").classList.remove(t.options.htmlClass),document.body.removeChild(t.p.a),document.body.removeChild(t.p.f),t.p.i=null,e.dispatchEvent(new Event("closed.simplelightbox")),t.i=!1}),this.n=null,this.g=!1,this.h=!1,this.v)this.v[i]=0;this.v.g=!1,this.v.i=!1,this.v.p=!1,this.v.w=this.minMax(1,1,this.options.maxZoom),this.v.M=!1}},{key:"preload",value:function(){var i=this,n=this.nIndex,t=this.relatedElements.length,e=n+1<0?t-1:t-1<=n+1?0:n+1,s=n-1<0?t-1:t-1<=n-1?0:n-1,o=new Image,a=new Image;o.addEventListener("load",function(t){var e=t.target.getAttribute("src");-1===i.q.indexOf(e)&&i.q.push(e),i.relatedElements[n].dispatchEvent(new Event("nextImageLoaded."+i.o))}),o.setAttribute("src",this.relatedElements[e].getAttribute(this.options.sourceAttr)),a.addEventListener("load",function(t){var e=t.target.getAttribute("src");-1===i.q.indexOf(e)&&i.q.push(e),i.relatedElements[n].dispatchEvent(new Event("prevImageLoaded."+i.o))}),a.setAttribute("src",this.relatedElements[s].getAttribute(this.options.sourceAttr))}},{key:"loadImage",value:function(t){var e=this,i=t;this.options.rtl&&(t=-t),this.relatedElements[this.nIndex].dispatchEvent(new Event("change."+this.o)),this.relatedElements[this.nIndex].dispatchEvent(new Event((1===t?"next":"prev")+"."+this.o));var n=this.nIndex+t;if(this.h||(n<0||n>=this.relatedElements.length)&&!1===this.options.loop)return!1;this.nIndex=n<0?this.relatedElements.length-1:n>this.relatedElements.length-1?0:n,this.p.c.querySelector(".sl-current").innerHTML=this.nIndex+1,this.options.animationSlide&&this.slide(this.options.animationSpeed/1e3,-100*i-this.v.a+"px"),this.fadeOut(this.p.h,300,function(){e.h=!0,setTimeout(function(){var t=e.relatedElements[e.nIndex];e.n.setAttribute("src",t.getAttribute(e.options.sourceAttr)),-1===e.q.indexOf(t.getAttribute(e.options.sourceAttr))&&e.show(e.p.e),e.p.h.contains(e.p.g)&&e.p.h.removeChild(e.p.g),e.adjustImage(i),e.options.preloading&&e.preload()},100)})}},{key:"adjustImage",value:function(a){var r=this;if(!this.n)return!1;var t=new Image,l=window.innerWidth*this.options.widthRatio,h=window.innerHeight*this.options.heightRatio;t.setAttribute("src",this.n.getAttribute("src")),this.n.dataset.scale=1,this.n.dataset.translateX=0,this.n.dataset.translateY=0,this.zoomPanElement(0,0,1),t.addEventListener("error",function(t){r.relatedElements[r.nIndex].dispatchEvent(new Event("error."+r.o)),r.h=!1,r.g=!1,r.p.e.style.display="none";var e=1===a||-1===a;if(r.r===r.nIndex&&e)return r.close();r.options.alertError&&alert(r.options.alertErrorMessage),r.loadImage(e?a:1)}),t.addEventListener("load",function(t){void 0!==a&&(r.relatedElements[r.nIndex].dispatchEvent(new Event("changed."+r.o)),r.relatedElements[r.nIndex].dispatchEvent(new Event((1===a?"nextDone":"prevDone")+"."+r.o))),r.options.history&&r.updateURL(),-1===r.q.indexOf(r.n.getAttribute("src"))&&r.q.push(r.n.getAttribute("src"));var e=t.target.width,i=t.target.height;if(r.options.scaleImageToRatio||l<e||h<i){var n=l/h<e/i?e/l:i/h;e/=n,i/=n}r.p.h.style.top=(window.innerHeight-i)/2+"px",r.p.h.style.left=(window.innerWidth-e-r.u)/2+"px",r.p.h.style.width=e+"px",r.p.h.style.height=i+"px",r.p.e.style.display="none",r.fadeIn(r.n,300),r.g=!0;var s,o="self"===r.options.captionSelector?r.relatedElements[r.nIndex]:r.relatedElements[r.nIndex].querySelector(r.options.captionSelector);r.options.captions&&o&&(s="data"===r.options.captionType?o.dataset[r.options.captionsData]:"text"===r.options.captionType?o.innerHTML:o.getAttribute(r.options.captionsData)),r.options.loop||(0===r.nIndex&&r.hide(r.p.d.querySelector(".sl-prev")),r.nIndex>=r.relatedElements.length-1&&r.hide(r.p.d.querySelector(".sl-next")),0<r.nIndex&&r.show(r.p.d.querySelector(".sl-prev")),r.nIndex<r.relatedElements.length-1&&r.show(r.p.d.querySelector(".sl-next"))),1===r.relatedElements.length?r.hide(r.p.d.querySelectorAll(".sl-prev, .sl-next")):r.show(r.p.d.querySelectorAll(".sl-prev, .sl-next")),1===a||-1===a?(r.options.animationSlide&&(r.slide(0,100*a+"px"),setTimeout(function(){r.slide(r.options.animationSpeed/1e3,"0px")},50)),r.fadeIn(r.p.h,300,function(){r.h=!1,r.setCaption(s,e)})):(r.h=!1,r.setCaption(s,e)),r.options.additionalHtml&&!r.p.i&&(r.p.i=document.createElement("div"),r.p.i.classList.add("sl-additional-html"),r.p.i.innerHTML=r.options.additionalHtml,r.p.h.appendChild(r.p.i))})}},{key:"zoomPanElement",value:function(t,e,i){this.n.style[this.b+"transform"]="translate("+t+","+e+") scale("+i+")"}},{key:"minMax",value:function(t,e,i){return t<e?e:i<t?i:t}},{key:"setZoomData",value:function(t,e,i){this.n.dataset.scale=t,this.n.dataset.translateX=e,this.n.dataset.translateY=i}},{key:"hashchangeHandler",value:function(){this.g&&this.hash===this.e&&(this.k=!0,this.close())}},{key:"addEvents",value:function(){var i=this;this.addEventListener(window,"resize."+this.o,function(t){i.g&&i.adjustImage()}),this.addEventListener(this.p.b,["click."+this.o,"touchstart."+this.o],this.close.bind(this)),this.options.history&&setTimeout(function(){i.addEventListener(window,"hashchange."+i.o,function(t){i.g&&i.hashchangeHandler()})},40),this.addEventListener(this.p.d,"click."+this.o,function(t){if(!t.target.tagName.match(/button/i))return!0;t.preventDefault(),i.v.a=0,i.loadImage(t.target.classList.contains("sl-next")?1:-1)}),this.addEventListener(this.p.h,["touchstart."+this.o,"mousedown."+this.o],function(t){if("A"===t.target.tagName&&"touchstart"===t.type)return!0;if("mousedown"===t.type)i.v.s=t.clientX,i.v.t=t.clientY,i.v.j=i.getDimensions(i.p.h).height,i.v.k=i.getDimensions(i.p.h).width,i.v.n=i.getDimensions(i.n).height,i.v.o=i.getDimensions(i.n).width,i.v.l=i.p.h.offsetLeft,i.v.m=i.p.h.offsetTop,i.v.q=parseFloat(i.n.dataset.translateX),i.v.r=parseFloat(i.n.dataset.translateY),i.v.p=!0;else{if(i.v.L=t.touches.length,i.v.s=t.touches[0].clientX,i.v.t=t.touches[0].clientY,i.v.j=i.getDimensions(i.p.h).height,i.v.k=i.getDimensions(i.p.h).width,i.v.n=i.getDimensions(i.n).height,i.v.o=i.getDimensions(i.n).width,i.v.l=i.p.h.offsetLeft,i.v.m=i.p.h.offsetTop,1===i.v.L){if(i.v.M)return i.n.classList.add("sl-transition"),i.v.i?(i.v.w=1,i.setZoomData(0,0,i.v.w),i.zoomPanElement("0px","0px",i.v.w),i.v.i=!1):(i.v.w=i.options.doubleTapZoom,i.setZoomData(0,0,i.v.w),i.zoomPanElement("0px","0px",i.v.w),i.p.g.style.opacity||"none"===i.p.g.style.display||i.fadeOut(i.p.g,200),i.v.i=!0),setTimeout(function(){i.n&&i.n.classList.remove("sl-transition")},200),!1;i.v.M=!0,setTimeout(function(){i.v.M=!1},300),i.vinitialOffsetX=parseFloat(i.n.dataset.translateX),i.vinitialOffsetY=parseFloat(i.n.dataset.translateY)}else 2===i.v.L&&(i.v.s2=t.touches[1].clientX,i.v.t2=t.touches[1].clientY,i.vinitialOffsetX=parseFloat(i.n.dataset.translateX),i.vinitialOffsetY=parseFloat(i.n.dataset.translateY),i.v.F=(i.v.s+i.v.s2)/2,i.v.G=(i.v.t+i.v.t2)/2,i.v.x=Math.sqrt((i.v.s-i.v.s2)*(i.v.s-i.v.s2)+(i.v.t-i.v.t2)*(i.v.t-i.v.t2)));i.v.p=!0}return!!i.v.g||(i.c&&(i.v.h=parseInt(i.p.h.style.left,10)),i.v.g=!0,i.v.a=0,i.v.b=0,i.v.c=t.pageX||t.touches[0].pageX,i.v.e=t.pageY||t.touches[0].pageY,!1)}),this.addEventListener(this.p.h,["touchmove."+this.o,"mousemove."+this.o,"MSPointerMove"],function(t){if(!i.v.g)return!0;if(t.preventDefault(),"touchmove"===t.type){if(!1===i.v.p)return!1;i.v.y=t.touches[0].clientX,i.v.z=t.touches[0].clientY,i.v.L=t.touches.length,i.v.N++,1<i.v.L?(i.v.y2=t.touches[1].clientX,i.v.z2=t.touches[1].clientY,i.v.K=Math.sqrt((i.v.y-i.v.y2)*(i.v.y-i.v.y2)+(i.v.z-i.v.z2)*(i.v.z-i.v.z2)),null===i.v.x&&(i.v.x=i.v.K),1<=Math.abs(i.v.x-i.v.K)&&(i.v.E=i.minMax(i.v.K/i.v.x*i.v.w,1,i.options.maxZoom),i.v.H=(i.v.o*i.v.E-i.v.k)/2,i.v.I=(i.v.n*i.v.E-i.v.j)/2,i.v.J=i.v.E-i.v.w,i.v.C=i.v.o*i.v.E<=i.v.k?0:i.minMax(i.v.q-(i.v.F-i.v.l-i.v.k/2-i.v.q)/(i.v.E-i.v.J)*i.v.J,-1*i.v.H,i.v.H),i.v.D=i.v.n*i.v.E<=i.v.j?0:i.minMax(i.v.r-(i.v.G-i.v.m-i.v.j/2-i.v.r)/(i.v.E-i.v.J)*i.v.J,-1*i.v.I,i.v.I),i.zoomPanElement(i.v.C+"px",i.v.D+"px",i.v.E),1<i.v.E&&(i.v.i=!0,i.p.g.style.opacity||"none"===i.p.g.style.display||i.fadeOut(i.p.g,200)),i.v.x=i.v.K,i.v.w=i.v.E,i.v.q=i.v.C,i.v.r=i.v.D)):(i.v.E=i.v.w,i.v.H=(i.v.o*i.v.E-i.v.k)/2,i.v.I=(i.v.n*i.v.E-i.v.j)/2,i.v.C=i.v.o*i.v.E<=i.v.k?0:i.minMax(i.v.y-(i.v.s-i.v.q),-1*i.v.H,i.v.H),i.v.D=i.v.n*i.v.E<=i.v.j?0:i.minMax(i.v.z-(i.v.t-i.v.r),-1*i.v.I,i.v.I),Math.abs(i.v.C)===Math.abs(i.v.H)&&(i.v.q=i.v.C,i.v.s=i.v.y),Math.abs(i.v.D)===Math.abs(i.v.I)&&(i.v.r=i.v.D,i.v.t=i.v.z),i.setZoomData(i.v.w,i.v.C,i.v.D),i.zoomPanElement(i.v.C+"px",i.v.D+"px",i.v.E))}if("mousemove"===t.type&&i.v.g){if("touchmove"==t.type)return!0;if(!1===i.v.p)return!1;i.v.y=t.clientX,i.v.z=t.clientY,i.v.E=i.v.w,i.v.H=(i.v.o*i.v.E-i.v.k)/2,i.v.I=(i.v.n*i.v.E-i.v.j)/2,i.v.C=i.v.o*i.v.E<=i.v.k?0:i.minMax(i.v.y-(i.v.s-i.v.q),-1*i.v.H,i.v.H),i.v.D=i.v.n*i.v.E<=i.v.j?0:i.minMax(i.v.z-(i.v.t-i.v.r),-1*i.v.I,i.v.I),Math.abs(i.v.C)===Math.abs(i.v.H)&&(i.v.q=i.v.C,i.v.s=i.v.y),Math.abs(i.v.D)===Math.abs(i.v.I)&&(i.v.r=i.v.D,i.v.t=i.v.z),i.setZoomData(i.v.w,i.v.C,i.v.D),i.zoomPanElement(i.v.C+"px",i.v.D+"px",i.v.E)}i.v.i||(i.v.d=t.pageX||t.touches[0].pageX,i.v.f=t.pageY||t.touches[0].pageY,i.v.a=i.v.c-i.v.d,i.v.b=i.v.e-i.v.f,i.options.animationSlide&&i.slide(0,-i.v.a+"px"))}),this.addEventListener(this.p.h,["touchend."+this.o,"mouseup."+this.o,"touchcancel."+this.o,"mouseleave."+this.o,"pointerup","pointercancel","MSPointerUp","MSPointerCancel"],function(t){if(i.d&&"touchend"===t.type&&(i.v.L=t.touches.length,0===i.v.L?(i.setZoomData(i.v.w,i.v.C,i.v.D),1===i.v.w&&(i.v.i=!1,"none"===i.p.g.style.display&&i.fadeIn(i.p.g,200)),i.v.x=null,i.v.p=!1):1===i.v.L?(i.v.s=t.touches[0].clientX,i.v.t=t.touches[0].clientY):1<i.v.L&&(i.v.x=null)),i.v.g){var e=!(i.v.g=!1);i.options.loop||(0===i.nIndex&&i.v.a<0&&(e=!1),i.nIndex>=i.relatedElements.length-1&&0<i.v.a&&(e=!1)),Math.abs(i.v.a)>i.options.swipeTolerance&&e?i.loadImage(0<i.v.a?1:-1):i.options.animationSlide&&i.slide(i.options.animationSpeed/1e3,"0px"),i.options.swipeClose&&50<Math.abs(i.v.b)&&Math.abs(i.v.a)<i.options.swipeTolerance&&i.close()}}),this.addEventListener(this.p.h,["dblclick"],function(t){return i.v.s=t.clientX,i.v.t=t.clientY,i.v.j=i.getDimensions(i.p.h).height,i.v.k=i.getDimensions(i.p.h).width,i.v.n=i.getDimensions(i.n).height,i.v.o=i.getDimensions(i.n).width,i.v.l=i.p.h.offsetLeft,i.v.m=i.p.h.offsetTop,i.n.classList.add("sl-transition"),i.v.i?(i.v.w=1,i.setZoomData(i.v.w,0,0),i.zoomPanElement("0px","0px",i.v.w),i.v.i=!1,"none"===i.p.g.style.display&&i.fadeIn(i.p.g,200)):(i.v.w=i.options.doubleTapZoom,i.setZoomData(i.v.w,0,0),i.zoomPanElement("0px","0px",i.v.w),i.p.g.style.opacity||"none"===i.p.g.style.display||i.fadeOut(i.p.g,200),i.v.i=!0),setTimeout(function(){i.n&&i.n.classList.remove("sl-transition")},200),!(i.v.p=!0)})}},{key:"getDimensions",value:function(t){var e=window.getComputedStyle(t),i=t.offsetHeight,n=t.offsetWidth,s=parseFloat(e.borderTopWidth);return{height:i-parseFloat(e.borderBottomWidth)-s-parseFloat(e.paddingTop)-parseFloat(e.paddingBottom),width:n-parseFloat(e.borderLeftWidth)-parseFloat(e.borderRightWidth)-parseFloat(e.paddingLeft)-parseFloat(e.paddingRight)}}},{key:"updateHash",value:function(){var t="pid="+(this.nIndex+1),e=window.location.href.split("#")[0]+"#"+t;this.k=!1,this.f?window.history[this.l?"replaceState":"pushState"]("",document.title,e):this.l?window.location.replace(e):window.location.hash=t,this.l||(this.j=!0),this.l=!0}},{key:"resetHash",value:function(){this.k=!0,this.j?history.back():this.f?history.pushState("",document.title,window.location.pathname+window.location.search):window.location.hash="",clearTimeout(this.m)}},{key:"updateURL",value:function(){clearTimeout(this.m),this.l?this.m=setTimeout(this.updateHash.bind(this),800):this.updateHash()}},{key:"setCaption",value:function(t,e){var i=this;this.options.captions&&t&&""!==t&&void 0!==t&&(this.hide(this.p.g),this.p.g.style.width=e+"px",this.p.g.innerHTML=t,this.p.h.appendChild(this.p.g),setTimeout(function(){i.fadeIn(i.p.g,300)},this.options.captionDelay))}},{key:"slide",value:function(t,e){if(!this.c)return this.p.h.style.left=e;this.p.h.style[this.b+"transform"]="translateX("+e+")",this.p.h.style[this.b+"transition"]=this.b+"transform "+t+"s linear"}},{key:"getRelated",value:function(e){return e&&!1!==e&&"nofollow"!==e?Array.from(this.elements).filter(function(t){return t.getAttribute("rel")===e}):this.elements}},{key:"openImage",value:function(t){var e=this;t.dispatchEvent(new Event("show."+this.o)),this.options.disableScroll&&(this.u=this.toggleScrollbar("hide")),this.options.htmlClass&&""!==this.options.htmlClass&&document.querySelector("html").classList.add(this.options.htmlClass),document.body.appendChild(this.p.a),this.p.a.appendChild(this.p.h),this.options.overlay&&document.body.appendChild(this.p.f),this.relatedElements=this.getRelated(t.rel),this.options.showCounter&&(1==this.relatedElements.length&&this.p.a.contains(this.p.c)?this.p.a.removeChild(this.p.c):1<this.relatedElements.length&&!this.p.a.contains(this.p.c)&&this.p.a.appendChild(this.p.c)),this.h=!0,this.nIndex=this.relatedElements.indexOf(t);var i=t.getAttribute(this.options.sourceAttr);this.n=document.createElement("img"),this.n.style.display="none",this.n.setAttribute("src",i),this.n.dataset.scale=1,this.n.dataset.translateX=0,this.n.dataset.translateY=0,-1===this.q.indexOf(i)&&this.q.push(i),this.p.h.innerHTML="",this.p.h.setAttribute("style",""),this.p.h.appendChild(this.n),this.fadeIn(this.p.f,300),this.fadeIn([this.p.c,this.p.d,this.p.b],300),this.show(this.p.e),this.p.c.querySelector(".sl-current").innerHTML=this.nIndex+1,this.p.c.querySelector(".sl-total").innerHTML=this.relatedElements.length,this.adjustImage(),this.options.preloading&&this.preload(),setTimeout(function(){t.dispatchEvent(new Event("shown."+e.o))},this.options.animationSpeed)}},{key:"addEventListener",value:function(t,e,i,n){t=this.wrap(t),e=this.wrap(e);var s=!0,o=!1,a=void 0;try{for(var r,l=t[Symbol.iterator]();!(s=(r=l.next()).done);s=!0){var h=r.value;h.namespaces||(h.namespaces={});var v=!0,d=!1,p=void 0;try{for(var c,u=e[Symbol.iterator]();!(v=(c=u.next()).done);v=!0){var m=c.value,f=n||!1;h.namespaces[m]=i,h.addEventListener(m.split(".")[0],i,f)}}catch(t){d=!0,p=t}finally{try{v||null==u.return||u.return()}finally{if(d)throw p}}}}catch(t){o=!0,a=t}finally{try{s||null==l.return||l.return()}finally{if(o)throw a}}}},{key:"removeEventListener",value:function(t,e){t=this.wrap(t),e=this.wrap(e);var i=!0,n=!1,s=void 0;try{for(var o,a=t[Symbol.iterator]();!(i=(o=a.next()).done);i=!0){var r=o.value,l=!0,h=!1,v=void 0;try{for(var d,p=e[Symbol.iterator]();!(l=(d=p.next()).done);l=!0){var c=d.value;r.removeEventListener(c.split(".")[0],r.namespaces[c]),delete r.namespaces[c]}}catch(t){h=!0,v=t}finally{try{l||null==p.return||p.return()}finally{if(h)throw v}}}}catch(t){n=!0,s=t}finally{try{i||null==a.return||a.return()}finally{if(n)throw s}}}},{key:"fadeOut",value:function(c,t,u){var m=this;c=this.wrap(c);var e=!0,i=!1,n=void 0;try{for(var s,o=c[Symbol.iterator]();!(e=(s=o.next()).done);e=!0){s.value.style.opacity=1}}catch(t){i=!0,n=t}finally{try{e||null==o.return||o.return()}finally{if(i)throw n}}var f=16.66666/(t||300);!function t(){var e=parseFloat(c[0].style.opacity);if((e-=f)<0){var i=!0,n=!1,s=void 0;try{for(var o,a=c[Symbol.iterator]();!(i=(o=a.next()).done);i=!0){var r=o.value;r.style.display="none",r.style.opacity=""}}catch(t){n=!0,s=t}finally{try{i||null==a.return||a.return()}finally{if(n)throw s}}u&&u.call(m,c)}else{var l=!0,h=!1,v=void 0;try{for(var d,p=c[Symbol.iterator]();!(l=(d=p.next()).done);l=!0){d.value.style.opacity=e}}catch(t){h=!0,v=t}finally{try{l||null==p.return||p.return()}finally{if(h)throw v}}requestAnimationFrame(t)}}()}},{key:"fadeIn",value:function(p,t,c,e){var u=this;p=this.wrap(p);var i=!0,n=!1,s=void 0;try{for(var o,a=p[Symbol.iterator]();!(i=(o=a.next()).done);i=!0){var r=o.value;r.style.opacity=0,r.style.display=e||"block"}}catch(t){n=!0,s=t}finally{try{i||null==a.return||a.return()}finally{if(n)throw s}}var m=parseFloat(p[0].dataset.opacityTarget||1),f=16.66666*m/(t||300);!function t(){var e=parseFloat(p[0].style.opacity);if((e+=f)>m){var i=!0,n=!1,s=void 0;try{for(var o,a=p[Symbol.iterator]();!(i=(o=a.next()).done);i=!0){o.value.style.opacity=""}}catch(t){n=!0,s=t}finally{try{i||null==a.return||a.return()}finally{if(n)throw s}}c&&c.call(u,p)}else{var r=!0,l=!1,h=void 0;try{for(var v,d=p[Symbol.iterator]();!(r=(v=d.next()).done);r=!0){v.value.style.opacity=e}}catch(t){l=!0,h=t}finally{try{r||null==d.return||d.return()}finally{if(l)throw h}}requestAnimationFrame(t)}}()}},{key:"hide",value:function(t){t=this.wrap(t);var e=!0,i=!1,n=void 0;try{for(var s,o=t[Symbol.iterator]();!(e=(s=o.next()).done);e=!0){var a=s.value;a.dataset.initialDisplay=a.style.display,a.style.display="none"}}catch(t){i=!0,n=t}finally{try{e||null==o.return||o.return()}finally{if(i)throw n}}}},{key:"show",value:function(t,e){t=this.wrap(t);var i=!0,n=!1,s=void 0;try{for(var o,a=t[Symbol.iterator]();!(i=(o=a.next()).done);i=!0){var r=o.value;r.style.display=r.dataset.initialDisplay||e||"block"}}catch(t){n=!0,s=t}finally{try{i||null==a.return||a.return()}finally{if(n)throw s}}}},{key:"wrap",value:function(t){return"function"==typeof t[Symbol.iterator]&&"string"!=typeof t?t:[t]}},{key:"on",value:function(t,e){t=this.wrap(t);var i=!0,n=!1,s=void 0;try{for(var o,a=this.elements[Symbol.iterator]();!(i=(o=a.next()).done);i=!0){var r=o.value;r.fullyNamespacedEvents||(r.fullyNamespacedEvents={});var l=!0,h=!1,v=void 0;try{for(var d,p=t[Symbol.iterator]();!(l=(d=p.next()).done);l=!0){var c=d.value;r.fullyNamespacedEvents[c]=e,r.addEventListener(c,e)}}catch(t){h=!0,v=t}finally{try{l||null==p.return||p.return()}finally{if(h)throw v}}}}catch(t){n=!0,s=t}finally{try{i||null==a.return||a.return()}finally{if(n)throw s}}return this}},{key:"off",value:function(t){t=this.wrap(t);var e=!0,i=!1,n=void 0;try{for(var s,o=this.elements[Symbol.iterator]();!(e=(s=o.next()).done);e=!0){var a=s.value,r=!0,l=!1,h=void 0;try{for(var v,d=t[Symbol.iterator]();!(r=(v=d.next()).done);r=!0){var p=v.value;p in a.fullyNamespacedEvents&&a.removeEventListener(p,a.fullyNamespacedEvents[p])}}catch(t){l=!0,h=t}finally{try{r||null==d.return||d.return()}finally{if(l)throw h}}}}catch(t){i=!0,n=t}finally{try{e||null==o.return||o.return()}finally{if(i)throw n}}return this}},{key:"open",value:function(t){t=t||this.elements[0],this.r=this.elements.indexOf(t),this.openImage(t)}},{key:"next",value:function(){this.loadImage(1)}},{key:"prev",value:function(){this.loadImage(-1)}},{key:"destroy",value:function(){this.off(["close."+this.o,"closed."+this.o,"nextImageLoaded."+this.o,"prevImageLoaded."+this.o,"change."+this.o,"nextDone."+this.o,"prevDone."+this.o,"error."+this.o,"changed."+this.o,"next."+this.o,"prev."+this.o,"show."+this.o,"shown."+this.o]),this.removeEventListener(this.elements,"click."+this.o),this.removeEventListener(document.body,"contextmenu."+this.o),this.removeEventListener(document.body,"keyup."+this.o),this.removeEventListener(this.p.d,"click."+this.o),this.removeEventListener(this.p.b,"click."+this.o),this.removeEventListener(window,"resize."+this.o),this.removeEventListener(window,"hashchange."+this.o),this.close(),this.g&&(document.body.removeChild(this.p.a),document.body.removeChild(this.p.f)),this.elements=null}},{key:"refresh",value:function(){if(!this.t)throw"refreshing only works when you initialize using a selector!";var t=this.options,e=this.t;return this.destroy(),this.constructor(e,t),this}},{key:"hash",get:function(){return window.location.hash.substring(1)}}]),n}();!function(t){t.fn.simpleLightbox=function(t){return new SimpleLightbox(this.get(),t)}}(jQuery,(window,document)); |