(function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof module&&module.exports?module.exports=t():e.Tobi=t()})(this,function(){"use strict";const e=function(e){const t=window,n=['a[href]:not([tabindex^="-"]):not([inert])','area[href]:not([tabindex^="-"]):not([inert])',"input:not([disabled]):not([inert])","select:not([disabled]):not([inert])","textarea:not([disabled]):not([inert])","button:not([disabled]):not([inert])",'iframe:not([tabindex^="-"]):not([inert])','audio:not([tabindex^="-"]):not([inert])','video:not([tabindex^="-"]):not([inert])','[contenteditable]:not([tabindex^="-"]):not([inert])','[tabindex]:not([tabindex^="-"]):not([inert])'],r=[],o=[],i={gallery:[],slider:null,sliderElements:[],elementsLength:0,currentIndex:0,x:0};let a={},s=0,d=null,l=null,c=null,u=null,p=null,b={},f=!1,h=!1,m=!1,g=null,y=null,v=null,A=null,x=null,w=!1,E=!1,L=0,_={},C=null,S=null;const I=function(e){const t={selector:".lightbox",captions:!0,captionsSelector:"img",captionAttribute:"alt",nav:"auto",navText:['',''],navLabel:["Previous image","Next image"],close:!0,closeText:'',closeLabel:"Close lightbox",loadingIndicatorLabel:"Image loading",counter:!0,download:!1,downloadText:"",downloadLabel:"Download image",keyboard:!0,zoom:!0,zoomText:'',docClose:!0,swipeClose:!0,hideScrollbar:!0,draggable:!0,threshold:100,rtl:!1,loop:!1,autoplayVideo:!1};return e&&Object.keys(e).forEach(function(n){t[n]=e[n]}),t},T={image:{checkSupport:function(e){return!e.hasAttribute("data-type")&&e.href.match(/\.(png|jpe?g|tiff|tif|gif|bmp|webp|svg|ico)(\?.*)?$/i)},init:function(e,t){const n=document.createElement("figure"),r=document.createElement("figcaption"),o=document.createElement("img"),i=e.querySelector("img"),d=document.createElement("div");o.style.opacity="0",i&&(o.alt=i.alt||""),o.setAttribute("src",""),o.setAttribute("data-src",e.href),n.appendChild(o),a.captions&&(r.style.opacity="0","self"===a.captionsSelector&&e.getAttribute(a.captionAttribute)?r.textContent=e.getAttribute(a.captionAttribute):"img"===a.captionsSelector&&i&&i.getAttribute(a.captionAttribute)&&(r.textContent=i.getAttribute(a.captionAttribute)),r.textContent&&(r.id="tobi-figcaption-"+s,n.appendChild(r),o.setAttribute("aria-labelledby",r.id),++s)),t.appendChild(n),d.className="tobi-loader",d.setAttribute("role","progressbar"),d.setAttribute("aria-label",a.loadingIndicatorLabel),t.appendChild(d),t.setAttribute("data-type","image")},onPreload:function(e){T.image.onLoad(e)},onLoad:function(e){const t=e.querySelector("img");if(!t.hasAttribute("data-src"))return;const n=e.querySelector("figcaption"),r=e.querySelector(".tobi-loader");t.onload=function(){e.removeChild(r),t.style.opacity="1",n&&(n.style.opacity="1")},t.setAttribute("src",t.getAttribute("data-src")),t.removeAttribute("data-src")},onLeave:function(e){},onCleanup:function(e){}},html:{checkSupport:function(e){return pe(e,"html")},init:function(e,t){const n=e.hasAttribute("href")?e.getAttribute("href"):e.getAttribute("data-target"),r=document.querySelector(n);if(!r)throw new Error("Ups, I can't find the target "+n+".");t.appendChild(r),t.setAttribute("data-type","html")},onPreload:function(e){},onLoad:function(e){const t=e.querySelector("video");t&&(t.hasAttribute("data-time")&&t.readyState>0&&(t.currentTime=t.getAttribute("data-time")),a.autoplayVideo&&t.play())},onLeave:function(e){const t=e.querySelector("video");t&&(t.paused||t.pause(),t.readyState>0&&t.setAttribute("data-time",t.currentTime))},onCleanup:function(e){const t=e.querySelector("video");if(t&&t.readyState>0&&t.readyState<3&&t.duration!==t.currentTime){const n=t.cloneNode(!0);be(t),t.load(),t.parentNode.removeChild(t),e.appendChild(n)}}},iframe:{checkSupport:function(e){return pe(e,"iframe")},init:function(e,t){const n=document.createElement("iframe"),r=e.hasAttribute("href")?e.getAttribute("href"):e.getAttribute("data-target");n.setAttribute("frameborder","0"),n.setAttribute("src",""),n.setAttribute("data-src",r),e.getAttribute("data-width")&&(n.style.maxWidth=e.getAttribute("data-width")+"px"),e.getAttribute("data-height")&&(n.style.maxHeight=e.getAttribute("data-height")+"px"),t.appendChild(n),t.setAttribute("data-type","iframe")},onPreload:function(e){},onLoad:function(e){const t=e.querySelector("iframe");t.setAttribute("src",t.getAttribute("data-src"))},onLeave:function(e){},onCleanup:function(e){}},youtube:{checkSupport:function(e){return pe(e,"youtube")},init:function(e,t){const n=document.createElement("div");t.appendChild(n),o[L]=new window.YT.Player(n,{host:"https://www.youtube-nocookie.com",height:e.getAttribute("data-height")||"360",width:e.getAttribute("data-width")||"640",videoId:e.getAttribute("data-id"),playerVars:{controls:e.getAttribute("data-controls")||1,rel:0,playsinline:1}}),t.setAttribute("data-player",L),t.setAttribute("data-type","youtube"),L++},onPreload:function(e){},onLoad:function(e){a.autoplayVideo&&o[e.getAttribute("data-player")].playVideo()},onLeave:function(e){1===o[e.getAttribute("data-player")].getPlayerState()&&o[e.getAttribute("data-player")].pauseVideo()},onCleanup:function(e){1===o[e.getAttribute("data-player")].getPlayerState()&&o[e.getAttribute("data-player")].pauseVideo()}}};Object.entries||(Object.entries=function(e){const t=Object.keys(e);let n=t.length;const r=new Array(n);for(;n--;)r[n]=[t[n],e[t[n]]];return r});const O=function(e){a=I(e),d||M();const t=document.querySelectorAll(a.selector);if(!t)throw new Error("Ups, I can't find the selector "+a.selector+".");Array.prototype.forEach.call(t,function(e){k(e)})},k=function(e,t){if(null===document.querySelector('[data-type="youtube"]')||E)P(e,t);else{if(null===document.getElementById("iframe_api")){const e=document.createElement("script"),t=document.getElementsByTagName("script")[0];e.id="iframe_api",e.src="https://www.youtube.com/iframe_api",t.parentNode.insertBefore(e,t)}-1===r.indexOf(e)&&r.push(e),window.onYouTubePlayerAPIReady=function(){Array.prototype.forEach.call(r,function(e){P(e,t)}),E=!0}}},q=function(e){return e.hasAttribute("data-group")?e.getAttribute("data-group"):"default"},N=function(e){return JSON.parse(JSON.stringify(e))},P=function(e,t){if(C=q(e),Object.prototype.hasOwnProperty.call(_,C)||(_[C]=N(i),Y()),-1!==_[C].gallery.indexOf(e))throw new Error("Ups, element already added to the lightbox.");if(_[C].gallery.push(e),_[C].elementsLength++,a.zoom&&e.querySelector("img")){const t=document.createElement("div");t.className="tobi-zoom__icon",t.innerHTML=a.zoomText,e.classList.add("tobi-zoom"),e.appendChild(t)}e.addEventListener("click",Q),j(e),ve()&&C===S&&(fe(),me()),t&&t.call(this)},X=function(e,t){const n=q(e);if(-1===_[n].gallery.indexOf(e));else{const r=_[n].gallery.indexOf(e),o=_[n].sliderElements[r];if(_[n].elementsLength--,a.zoom&&e.querySelector(".tobi-zoom__icon")){const t=e.querySelector(".tobi-zoom__icon");t.parentNode.classList.remove("tobi-zoom"),t.parentNode.removeChild(t)}e.removeEventListener("click",Q),o.parentNode.removeChild(o),ve()&&n===S&&(fe(),me()),t&&t.call(this)}},M=function(){d=document.createElement("div"),d.setAttribute("role","dialog"),d.setAttribute("aria-hidden","true"),d.className="tobi",l=document.createElement("button"),l.className="tobi__prev",l.setAttribute("type","button"),l.setAttribute("aria-label",a.navLabel[0]),l.innerHTML=a.navText[0],d.appendChild(l),c=document.createElement("button"),c.className="tobi__next",c.setAttribute("type","button"),c.setAttribute("aria-label",a.navLabel[1]),c.innerHTML=a.navText[1],d.appendChild(c),u=document.createElement("button"),u.className="tobi__close",u.setAttribute("type","button"),u.setAttribute("aria-label",a.closeLabel),u.innerHTML=a.closeText,d.appendChild(u),p=document.createElement("div"),p.className="tobi__counter",d.appendChild(p),t.addEventListener("resize",function(){w||(w=!0,t.requestAnimationFrame(function(){G(),w=!1}))}),document.body.appendChild(d)},Y=function(){_[C].slider=document.createElement("div"),_[C].slider.className="tobi__slider",d.appendChild(_[C].slider)},j=function(e){for(let t in T)if(Object.prototype.hasOwnProperty.call(T,t)&&T[t].checkSupport(e)){const n=document.createElement("div"),r=document.createElement("div");n.className="tobi__slide",n.style.position="absolute",n.style.left=100*_[C].x+"%",T[t].init(e,r),n.appendChild(r),_[C].slider.appendChild(n),_[C].sliderElements.push(n),++_[C].x;break}},z=function(e,t){if(S=null!==S?S:C,ve()||e||(e=0),ve()){if(!e)throw new Error("Ups, Tobi is aleady open.");if(e===_[S].currentIndex)throw new Error("Ups, slide "+e+" is already selected.")}if(-1===e||e>=_[S].elementsLength)throw new Error("Ups, I can't find slide "+e+".");a.hideScrollbar&&(document.documentElement.classList.add("tobi-is-open"),document.body.classList.add("tobi-is-open")),fe(),a.close||(u.disabled=!1,u.setAttribute("aria-hidden","true")),g=document.activeElement,_[S].currentIndex=e,F(),ce(),V(_[S].currentIndex),d.setAttribute("aria-hidden","false"),me(),U(_[S].currentIndex+1),U(_[S].currentIndex-1),t&&t.call(this)},D=function(e){if(!ve())throw new Error("Tobi is already closed.");a.hideScrollbar&&(document.documentElement.classList.remove("tobi-is-open"),document.body.classList.remove("tobi-is-open")),ue(),g.focus();const t=_[S].sliderElements[_[S].currentIndex].querySelector("[data-type]"),n=t.getAttribute("data-type");T[n].onLeave(t),T[n].onCleanup(t),d.setAttribute("aria-hidden","true"),_[S].currentIndex=0,e&&e.call(this)},U=function(e){if(void 0===_[S].sliderElements[e])return;const t=_[S].sliderElements[e].querySelector("[data-type]"),n=t.getAttribute("data-type");T[n].onPreload(t)},V=function(e){if(void 0===_[S].sliderElements[e])return;const t=_[S].sliderElements[e].querySelector("[data-type]"),n=t.getAttribute("data-type");_[S].sliderElements[e].classList.add("tobi__slide--is-active"),T[n].onLoad(t)},H=function(e){_[S].currentIndex>0&&(R(_[S].currentIndex),V(--_[S].currentIndex),me("left"),W(_[S].currentIndex+1),U(_[S].currentIndex-1),e&&e.call(this))},B=function(e){_[S].currentIndex<_[S].elementsLength-1&&(R(_[S].currentIndex),V(++_[S].currentIndex),me("right"),W(_[S].currentIndex-1),U(_[S].currentIndex+1),e&&e.call(this))},R=function(e){if(void 0===_[S].sliderElements[e])return;const t=_[S].sliderElements[e].querySelector("[data-type]"),n=t.getAttribute("data-type");_[S].sliderElements[e].classList.remove("tobi__slide--is-active"),T[n].onLeave(t)},W=function(e){if(void 0===_[S].sliderElements[e])return;const t=_[S].sliderElements[e].querySelector("[data-type]"),n=t.getAttribute("data-type");T[n].onCleanup(t)},G=function(){S=null!==S?S:C,A=-_[S].currentIndex*window.innerWidth,_[S].slider.style.transform="translate3d("+A+"px, 0, 0)",x=A},J=function(){p.textContent=_[S].currentIndex+1+"/"+_[S].elementsLength},K=function(e){let t=null;a.nav?(l.disabled=!1,c.disabled=!1,"left"===e?l.focus():c.focus(),1===_[S].elementsLength?(l.disabled=!0,c.disabled=!0,a.close&&u.focus()):(0===_[S].currentIndex&&(l.disabled=!0,c.focus()),_[S].currentIndex===_[S].elementsLength-1&&(c.disabled=!0,l.focus()))):a.close&&u.focus(),t=d.querySelectorAll(".tobi > button:not(:disabled)"),y=t[0],v=1===t.length?t[0]:t[t.length-1]},F=function(){b={startX:0,endX:0,startY:0,endY:0}},$=function(){const e=b.endX-b.startX,t=b.endY-b.startY,n=Math.abs(e),r=Math.abs(t);e>0&&n>a.threshold&&_[S].currentIndex>0?H():e<0&&n>a.threshold&&_[S].currentIndex!==_[S].elementsLength-1?B():t<0&&r>a.threshold&&a.swipeClose?D():G()},Q=function(e){e.preventDefault(),S=q(this),z(_[S].gallery.indexOf(this))},Z=function(e){e.target===l?H():e.target===c?B():(e.target===u||e.target.classList.contains("tobi__slide")&&a.docClose)&&D(),e.stopPropagation()},ee=function(){return Array.prototype.slice.call(d.querySelectorAll(".tobi__close:not([disabled]), .tobi__prev:not([disabled]), .tobi__next:not([disabled]), .tobi__slide--is-active + "+n.join(", .tobi__slide--is-active "))).filter(function(e){return!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length)})},te=function(e){const t=ee(),n=t.indexOf(document.activeElement);9===e.keyCode||"Tab"===e.code?e.shiftKey&&0===n?(t[t.length-1].focus(),e.preventDefault()):e.shiftKey||n!==t.length-1||(t[0].focus(),e.preventDefault()):27===e.keyCode||"Escape"===e.code?(e.preventDefault(),D()):37===e.keyCode||"ArrowLeft"===e.code?(e.preventDefault(),H()):39!==e.keyCode&&"ArrowRight"!==e.code||(e.preventDefault(),B())},ne=function(e){xe(e.target)||(e.stopPropagation(),m=!0,b.startX=e.touches[0].pageX,b.startY=e.touches[0].pageY,_[S].slider.classList.add("tobi__slider--is-dragging"))},re=function(e){e.stopPropagation(),m&&(e.preventDefault(),b.endX=e.touches[0].pageX,b.endY=e.touches[0].pageY,le())},oe=function(e){e.stopPropagation(),m=!1,_[S].slider.classList.remove("tobi__slider--is-dragging"),b.endX&&(f=!1,h=!1,$()),F()},ie=function(e){xe(e.target)||(e.preventDefault(),e.stopPropagation(),m=!0,b.startX=e.pageX,b.startY=e.pageY,_[S].slider.classList.add("tobi__slider--is-dragging"))},ae=function(e){e.preventDefault(),m&&(b.endX=e.pageX,b.endY=e.pageY,le())},se=function(e){e.stopPropagation(),m=!1,_[S].slider.classList.remove("tobi__slider--is-dragging"),b.endX&&(f=!1,h=!1,$()),F()},de=function(e){m=!1},le=function(){Math.abs(b.startX-b.endX)>0&&!h&&a.swipeClose?(_[S].slider.style.transform="translate3d("+(x-Math.round(b.startX-b.endX))+"px, 0, 0)",f=!0,h=!1):Math.abs(b.startY-b.endY)>0&&!f&&(_[S].slider.style.transform="translate3d("+x+"px, -"+Math.round(b.startY-b.endY)+"px, 0)",f=!1,h=!0)},ce=function(){a.keyboard&&document.addEventListener("keydown",te),d.addEventListener("click",Z),a.draggable&&(Ae()&&(d.addEventListener("touchstart",ne),d.addEventListener("touchmove",re),d.addEventListener("touchend",oe)),d.addEventListener("mousedown",ie),d.addEventListener("mouseup",se),d.addEventListener("mousemove",ae),d.addEventListener("contextmenu",de))},ue=function(){a.keyboard&&document.removeEventListener("keydown",te),d.removeEventListener("click",Z),a.draggable&&(Ae()&&(d.removeEventListener("touchstart",ne),d.removeEventListener("touchmove",re),d.removeEventListener("touchend",oe)),d.removeEventListener("mousedown",ie),d.removeEventListener("mouseup",se),d.removeEventListener("mousemove",ae),d.removeEventListener("contextmenu",de))},pe=function(e,t){return e.getAttribute("data-type")===t},be=function(e){const t=e.querySelectorAll("src");t&&Array.prototype.forEach.call(t,function(e){e.setAttribute("src","")})},fe=function(){a.draggable&&_[S].elementsLength>1&&!_[S].slider.classList.contains("tobi__slider--is-draggable")&&_[S].slider.classList.add("tobi__slider--is-draggable"),!a.nav||1===_[S].elementsLength||"auto"===a.nav&&Ae()?(l.setAttribute("aria-hidden","true"),c.setAttribute("aria-hidden","true")):(l.setAttribute("aria-hidden","false"),c.setAttribute("aria-hidden","false")),a.counter&&1!==_[S].elementsLength?p.setAttribute("aria-hidden","false"):p.setAttribute("aria-hidden","true")},he=function(){for(let e in _)Object.prototype.hasOwnProperty.call(_,e)&&(_[e].slider.style.display=S===e?"block":"none")},me=function(e){he(),G(),J(),K(e)},ge=function(e){ve()&&D();const t=Object.entries(_);Array.prototype.forEach.call(t,function(e){const t=e[1].gallery;Array.prototype.forEach.call(t,function(e){X(e)})}),_={},C=S=null,s=0,e&&e.call(this)},ye=function(e){ge(),d.parentNode.removeChild(d),e&&e.call(this)},ve=function(){return"false"===d.getAttribute("aria-hidden")},Ae=function(){return"ontouchstart"in window},xe=function(e){return-1!==["TEXTAREA","OPTION","INPUT","SELECT"].indexOf(e.nodeName)||e===l||e===c||e===u||1===_[S].elementsLength},we=function(){return _[S].currentIndex},Ee=function(){return null!==S?S:C},Le=function(e){if(ve())throw new Error("Ups, I can't do this. Tobi is open.");if(e){if(e&&!Object.prototype.hasOwnProperty.call(_,e))throw new Error("Ups, I don't have a group called \""+e+'".');S=e}};return O(e),{open:z,prev:H,next:B,close:D,add:k,remove:X,reset:ge,destroy:ye,isOpen:ve,currentSlide:we,selectGroup:Le,currentGroup:Ee}};return e});