diff --git a/dist/tobii.js b/dist/tobii.js index 3385e09..90a2bab 100644 --- a/dist/tobii.js +++ b/dist/tobii.js @@ -1 +1 @@ -class e{constructor(){this.figcaptionId=0,this.userSettings=null}init(e,t,i){this.userSettings=i;const r=document.createElement("figure"),n=document.createElement("figcaption"),a=document.createElement("img"),s=e.querySelector("img"),o=document.createElement("div");if(r.style.opacity="0",s&&(a.alt=s.alt||""),a.setAttribute("src",""),a.setAttribute("data-src",e.href),e.hasAttribute("data-srcset")&&a.setAttribute("data-srcset",e.getAttribute("data-srcset")),r.appendChild(a),this.userSettings.captions){let t;"function"==typeof this.userSettings.captionText?t=this.userSettings.captionText(e):"self"===this.userSettings.captionsSelector&&e.getAttribute(this.userSettings.captionAttribute)?t=e.getAttribute(this.userSettings.captionAttribute):"img"===this.userSettings.captionsSelector&&s&&s.getAttribute(this.userSettings.captionAttribute)&&(t=s.getAttribute(this.userSettings.captionAttribute)),this.userSettings.captionHTML?n.innerHTML=t:n.textContent=t,t&&(n.id=`tobii-figcaption-${this.figcaptionId}`,r.appendChild(n),a.setAttribute("aria-labelledby",n.id),++this.figcaptionId)}t.appendChild(r),o.className="tobii__loader",o.setAttribute("role","progressbar"),o.setAttribute("aria-label",this.userSettings.loadingIndicatorLabel),t.appendChild(o),t.setAttribute("data-type","image"),t.classList.add("tobii-image")}onPreload(e){this.onLoad(e)}onLoad(e){const t=e.querySelector("img");if(!t.hasAttribute("data-src"))return;const i=e.querySelector("figure"),r=e.querySelector(".tobii__loader");t.addEventListener("load",()=>{e.removeChild(r),i.style.opacity="1"}),t.addEventListener("error",()=>{e.removeChild(r),i.style.opacity="1"}),t.setAttribute("src",t.getAttribute("data-src")),t.removeAttribute("data-src"),t.hasAttribute("data-srcset")&&t.setAttribute("srcset",t.getAttribute("data-srcset"))}onLeave(e){}onCleanup(e){}onReset(){this.figcaptionId=0}}class t{constructor(){this.userSettings=null}init(e,t,i){this.userSettings=i;const r=e.hasAttribute("data-target")?e.getAttribute("data-target"):e.getAttribute("href");t.setAttribute("data-HREF",r),e.getAttribute("data-allow")&&t.setAttribute("data-allow",e.getAttribute("data-allow")),e.hasAttribute("data-width")&&t.setAttribute("data-width",`${e.getAttribute("data-width")}`),e.hasAttribute("data-height")&&t.setAttribute("data-height",`${e.getAttribute("data-height")}`),t.setAttribute("data-type","iframe"),t.classList.add("tobii-iframe")}onPreload(e){}onLoad(e){let t=e.querySelector("iframe");const i=document.createElement("div");if(i.className="tobii__loader",i.setAttribute("role","progressbar"),i.setAttribute("aria-label",this.userSettings.loadingIndicatorLabel),e.appendChild(i),null==t){t=document.createElement("iframe");const i=e.getAttribute("data-href");t.setAttribute("frameborder","0"),t.setAttribute("src",i),t.setAttribute("allowfullscreen",""),i.indexOf("youtube.com")>-1?t.setAttribute("allow","accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"):i.indexOf("vimeo.com")>-1?t.setAttribute("allow","autoplay; picture-in-picture"):e.hasAttribute("data-allow")&&t.setAttribute("allow",e.getAttribute("data-allow")),e.getAttribute("data-width")&&(t.style.maxWidth=`${e.getAttribute("data-width")}`),e.getAttribute("data-height")&&(t.style.maxHeight=`${e.getAttribute("data-height")}`),t.style.opacity="0",e.appendChild(t),t.addEventListener("load",()=>{t.style.opacity="1";const i=e.querySelector(".tobii__loader");i&&e.removeChild(i)}),t.addEventListener("error",()=>{t.style.opacity="1";const i=e.querySelector(".tobii__loader");i&&e.removeChild(i)})}else t.setAttribute("src",e.getAttribute("data-href"))}onLeave(e){}onCleanup(e){const t=e.querySelector("iframe");t.setAttribute("src",""),t.style.opacity="0"}onReset(){}}class i{constructor(){this.userSettings=null}init(e,t,i){this.userSettings=i;const r=e.hasAttribute("data-target")?e.getAttribute("data-target"):e.getAttribute("href"),n=document.querySelector(r).cloneNode(!0);if(!n)throw new Error(`Ups, I can't find the target ${r}.`);t.appendChild(n),t.setAttribute("data-type","html"),t.classList.add("tobii-html")}onPreload(e){}onLoad(e,t){const i=e.querySelector("video");i&&(i.hasAttribute("data-time")&&i.readyState>0&&(i.currentTime=i.getAttribute("data-time")),this.userSettings.autoplayVideo&&i.play());const r=e.querySelector("audio");r&&this.userSettings.autoplayAudio&&r.play(),e.classList.add("tobii-group-"+t)}onLeave(e){const t=e.querySelector("video");t&&(t.paused||t.pause(),t.readyState>0&&t.setAttribute("data-time",t.currentTime));const i=e.querySelector("audio");i&&(i.paused||i.pause())}onCleanup(e){const t=e.querySelector("video");if(t&&t.readyState>0&&t.readyState<3&&t.duration!==t.currentTime){const i=t.cloneNode(!0);this._removeSources(t),t.load(),t.parentNode.removeChild(t),e.appendChild(i)}}onReset(){}_removeSources(e){const t=e.querySelectorAll("src");t&&t.forEach(e=>{e.setAttribute("src","")})}}class r{constructor(){this.playerId=0,this.PLAYER=[],this.userSettings=null}init(e,t,i){this.userSettings=i;const r=document.createElement("div");t.appendChild(r),this.PLAYER[this.playerId]=new window.YT.Player(r,{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",this.playerId),t.setAttribute("data-type","youtube"),t.classList.add("tobii-youtube"),this.playerId++}onPreload(e){}onLoad(e){this.userSettings.autoplayVideo&&this.PLAYER[e.getAttribute("data-player")].playVideo()}onLeave(e){1===this.PLAYER[e.getAttribute("data-player")].getPlayerState()&&this.PLAYER[e.getAttribute("data-player")].pauseVideo()}onCleanup(e){1===this.PLAYER[e.getAttribute("data-player")].getPlayerState()&&this.PLAYER[e.getAttribute("data-player")].pauseVideo()}onReset(){}}module.exports=function n(a){const s={image:new e,html:new i,iframe:new t,youtube:new r},o=['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])'];let l={};const d=[],c={gallery:[],slider:null,sliderElements:[],elementsLength:0,currentIndex:0,x:0};let u=null,p=null,h=null,b=null,g=null,m=null,y=null,f=!1,w={},v=null,A=[],x=0;const E={element:null,originX:0,originY:0,translateX:0,translateY:0,scale:1},L={startX:0,startY:0,x:0,y:0,distance:0},_=e=>{if(null===document.querySelector('[data-type="youtube"]')||f)S(e);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===d.indexOf(e)&&d.push(e),window.onYouTubePlayerAPIReady=()=>{d.forEach(e=>{S(e)}),f=!0}}},I=e=>e.hasAttribute("data-group")?e.getAttribute("data-group"):"default",S=e=>{const t=I(e);if(Object.prototype.hasOwnProperty.call(w,t)||(w[t]=JSON.parse(JSON.stringify(c)),w[t].slider=document.createElement("div"),w[t].slider.className="tobii__slider",w[t].slider.setAttribute("aria-hidden","true"),u.appendChild(w[t].slider)),-1!==w[t].gallery.indexOf(e))throw new Error("Ups, element already added.");{if(w[t].gallery.push(e),w[t].elementsLength++,l.zoom&&e.querySelector("img")&&"false"!==e.getAttribute("data-zoom")||"true"===e.getAttribute("data-zoom")){const t=document.createElement("div");t.className="tobii-zoom__icon",t.innerHTML=l.zoomText,e.classList.add("tobii-zoom"),e.appendChild(t)}e.addEventListener("click",z);const i=Y(e),r=document.createElement("div"),n=document.createElement("div");r.className="tobii__slide",r.style.position="absolute",r.style.left=100*w[t].x+"%",r.setAttribute("aria-hidden","true"),i.init(e,n,l),r.appendChild(n),w[t].slider.appendChild(r),w[t].sliderElements.push(r),++w[t].x,le()&&t===v&&(ae(),se())}},C=e=>{const t=I(e);if(-1===w[t].gallery.indexOf(e))throw new Error(`Ups, I can't find a slide for the element ${e}.`);{const i=w[t].gallery.indexOf(e),r=w[t].sliderElements[i];if(le()&&t===v&&i===w[t].currentIndex){if(1===w[t].elementsLength)throw X(),new Error("Ups, I've closed. There are no slides more to show.");0===w[t].currentIndex?P():N(),ae(),se()}if(w[t].gallery.splice(w[t].gallery.indexOf(e)),w[t].sliderElements.splice(w[t].gallery.indexOf(e)),w[t].elementsLength--,--w[t].x,l.zoom&&e.querySelector(".tobii-zoom__icon")){const t=e.querySelector(".tobii-zoom__icon");t.parentNode.classList.remove("tobii-zoom"),t.parentNode.removeChild(t)}e.removeEventListener("click",z),r.parentNode.removeChild(r)}},Y=e=>{const t=e.getAttribute("data-type");return void 0!==s[t]?s[t]:(e.hasAttribute("data-type")&&console.log("Unknown lightbox element type: "+t),s.image)},T=(e=0)=>{if(le())throw new Error("Ups, I'm aleady open.");if(-1===e||e>=w[v].elementsLength)throw new Error(`Ups, I can't find slide ${e}.`);document.documentElement.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open-"+v),ae(),l.close||(b.disabled=!1,b.setAttribute("aria-hidden","true")),m=document.activeElement;const t=window.location.href;window.history.pushState({tobii:"close"},"Image",t),w[v].currentIndex=e,re(),M(w[v].currentIndex),w[v].slider.setAttribute("aria-hidden","false"),u.setAttribute("aria-hidden","false"),se(),q(w[v].currentIndex+1),q(w[v].currentIndex-1),w[v].slider.classList.add("tobii__slider--animate");const i=new window.CustomEvent("open",{detail:{group:v}});u.dispatchEvent(i)},X=()=>{if(!le())throw new Error("Ups, I'm already closed.");document.documentElement.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open-"+v),ne(),null!==window.history.state&&"close"===window.history.state.tobii&&window.history.back(),m.focus(),O(w[v].currentIndex),k(w[v].currentIndex),u.setAttribute("aria-hidden","true"),w[v].slider.setAttribute("aria-hidden","true"),w[v].currentIndex=0,w[v].slider.classList.remove("tobii__slider--animate");const e=new window.CustomEvent("close",{detail:{group:v}});u.dispatchEvent(e)},q=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]");Y(t).onPreload(t)},M=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]"),i=Y(t);w[v].sliderElements[e].classList.add("tobii__slide--is-active"),w[v].sliderElements[e].setAttribute("aria-hidden","false"),i.onLoad(t,v)},N=()=>{if(!le())throw new Error("Ups, I'm closed.");w[v].currentIndex>0&&(O(w[v].currentIndex),M(--w[v].currentIndex),se("left"),k(w[v].currentIndex+1),q(w[v].currentIndex-1));const e=new window.CustomEvent("previous",{detail:{group:v}});u.dispatchEvent(e)},P=()=>{if(!le())throw new Error("Ups, I'm closed.");w[v].currentIndex{if(le())throw new Error("Ups, I'm open.");if(!e)throw new Error("Ups, no group specified.");if(e&&!Object.prototype.hasOwnProperty.call(w,e))throw new Error(`Ups, I don't have a group called "${e}".`);v=e},O=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]"),i=Y(t);w[v].sliderElements[e].classList.remove("tobii__slide--is-active"),w[v].sliderElements[e].setAttribute("aria-hidden","true"),i.onLeave(t)},k=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]");Y(t).onCleanup(t),L.startX=0,L.startY=0,L.x=0,L.y=0,L.distance=0,x=0,ie()},R=()=>{y=-w[v].currentIndex*u.offsetWidth,w[v].slider.style.transform=`translate(${y}px, 0)`},U=()=>{R()},z=e=>{e.preventDefault(),v=I(e.currentTarget),T(w[v].gallery.indexOf(e.currentTarget))},H=e=>{e.target===p?N():e.target===h?P():(e.target===b||e.target.classList.contains("tobii__slide")&&l.docClose)&&X(),e.stopPropagation()},D=e=>{const t=Array.prototype.slice.call(u.querySelectorAll(`.tobii__btn:not([disabled]), .tobii__slide--is-active ${o.join(", .tobii__slide--is-active ")}`)).filter(e=>!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length)),i=t.indexOf(document.activeElement);9===e.keyCode||"Tab"===e.code?e.shiftKey&&0===i?(t[t.length-1].focus(),e.preventDefault()):e.shiftKey||i!==t.length-1||(t[0].focus(),e.preventDefault()):27===e.keyCode||"Escape"===e.code?(e.preventDefault(),X()):37===e.keyCode||"ArrowLeft"===e.code?(e.preventDefault(),N()):39!==e.keyCode&&"ArrowRight"!==e.code||(e.preventDefault(),P())},B=()=>{A=[],R(),w[v].slider.classList.remove("tobii__slider--is-"+(F()?"moving":"dragging"))},V=e=>{if(!ce(e.target)&&(e.preventDefault(),e.stopPropagation(),L.startX=L.x=e.clientX,L.startY=L.y=e.clientY,L.distance=0,A.push(e),2===A.length)){const{x:e,y:t}=te(A[0].clientX,A[0].clientY,A[1].clientX,A[1].clientY);L.startX=L.x=e,L.startY=L.y=t,L.distance=ee(A[0].clientX-A[1].clientX,A[0].clientY-A[1].clientY)/E.scale}},j=e=>{if(!A.length)return;w[v].slider.classList.add("tobii__slider--is-"+(F()?"moving":"dragging"));const t=A.findIndex(t=>t.pointerId===e.pointerId);if(A[t]=e,2===A.length){const{x:e,y:t}=te(A[0].clientX,A[0].clientY,A[1].clientX,A[1].clientY),i=ee(A[0].clientX-A[1].clientX,A[0].clientY-A[1].clientY)/L.distance;return Z(K(i,1,4),e,t,e-L.x,t-L.y),L.x=e,void(L.y=t)}if(F()&&Q(e.clientX-L.x,e.clientY-L.y),L.x=e.clientX,L.y=e.clientY,!F()){const e=L.startX-L.x,t=L.startY-L.y;if(ee(e,t)<10)return;Math.abs(e)>Math.abs(t)&&w[v].elementsLength>1?w[v].slider.style.transform=`translate(${y-Math.round(e)}px, 0)`:l.swipeClose&&(w[v].slider.style.transform=`translate(${y}px, -${Math.round(t)}px)`)}},W=e=>{if(!A.length)return;w[v].slider.classList.remove("tobii__slider--is-"+(F()?"moving":"dragging"));const t=A.findIndex(t=>t.pointerId===e.pointerId);A.splice(t,1);const i=e.clientX,r=e.clientY,n=L.startX-i,a=L.startY-r,s=Math.abs(n),o=Math.abs(a);if(s||o)F()||(n<0&&s>l.threshold&&w[v].currentIndex>0?N():n>0&&s>l.threshold&&w[v].currentIndex!==w[v].elementsLength-1?P():a>0&&o>l.threshold&&l.swipeClose?X():R());else{const t=(new Date).getTime(),n=t-x;n<500&&n>100?(e.preventDefault(),x=0,F()?ie():Z(2,i,r,0,0)):(x=t,de()&&window.setTimeout(()=>{const{left:t,top:n,bottom:a,right:s,width:o}=e.target.getBoundingClientRect();ra||!x||(i>t&&is-o/2&&P())},500))}},G=e=>{const t=Math.sign(e.deltaY)>0?-1:1;(F()||t)&&(e.preventDefault(),Z(K(E.scale+t/(10/E.scale),1,4),e.clientX,e.clientY,0,0))},J=(e,t)=>{const{element:i,scale:r,originX:n,originY:a}=E,s="x"===e,o=s?n:a,l=s?"offsetWidth":"offsetHeight",d=i.parentNode[l],c=i[l],u=i.getBoundingClientRect(),p=(o-c/2)*(r-1),h=Math.max(0,Math.round(s?u.width:u.height)-d),b=Math.round(h/2);return K(t,0-b+p,b+p)},K=(e,t,i)=>Math.max(Math.min(e,i),t),F=()=>1!==E.scale,Q=(e,t)=>{0!==e&&(E.translateX=J("x",E.translateX+e)),0!==t&&(E.translateY=J("y",E.translateY+t));const{element:i,originX:r,originY:n,translateX:a,translateY:s,scale:o}=E;i.style.transformOrigin=`${r}px ${n}px`,i.style.transform=`translate(${a}px, ${s}px) scale(${o})`},Z=(e,t,i,r,n)=>{E.element||(E.element=u.querySelector(".tobii__slide--is-active img"));const{left:a,top:s}=E.element.getBoundingClientRect(),o=(i-s)/E.scale;E.originX=(t-a)/E.scale,E.originY=o,E.scale=e,Q(r,n)},ee=(e,t)=>Math.hypot(e,t),te=(e,t,i,r)=>({x:(e+i)/2,y:(t+r)/2}),ie=()=>{E.scale=1,E.originX=0,E.originY=0,E.translateX=0,E.translateY=0,Q(0,0),E.element=null},re=()=>{l.keyboard&&window.addEventListener("keydown",D),window.addEventListener("resize",U),window.addEventListener("popstate",X),ue("click",H),l.draggable&&(ue("pointerdown",V),ue("pointermove",j),ue("pointerup",W),ue("pointercancel",B),ue("pointerout",B),ue("pointerleave",B),ue("contextmenu",B)),ue("wheel",G)},ne=()=>{l.keyboard&&window.removeEventListener("keydown",D),window.removeEventListener("resize",U),window.removeEventListener("popstate",X),pe("click",H),l.draggable&&(pe("pointerdown",V),pe("pointermove",j),pe("pointerup",W),pe("pointercancel",B),pe("pointerout",B),pe("pointerleave",B),pe("contextmenu",B)),pe("wheel",G)},ae=()=>{l.draggable&&!w[v].slider.classList.contains("tobii__slider--is-draggable")&&w[v].slider.classList.add("tobii__slider--is-draggable"),!l.nav||1===w[v].elementsLength||"auto"===l.nav&&de()?(p.setAttribute("aria-hidden","true"),p.disabled=!0,h.setAttribute("aria-hidden","true"),h.disabled=!0):(p.setAttribute("aria-hidden","false"),p.disabled=!1,h.setAttribute("aria-hidden","false"),h.disabled=!1),g.setAttribute("aria-hidden",l.counter&&1!==w[v].elementsLength?"false":"true")},se=(e=null)=>{R(),g.textContent=`${w[v].currentIndex+1}/${w[v].elementsLength}`,(e=>{(!0===l.nav||"auto"===l.nav)&&!de()&&w[v].elementsLength>1?(p.setAttribute("aria-hidden","true"),p.disabled=!0,h.setAttribute("aria-hidden","true"),h.disabled=!0,1===w[v].elementsLength?l.close&&b.focus():0===w[v].currentIndex?(h.setAttribute("aria-hidden","false"),h.disabled=!1,h.focus()):w[v].currentIndex===w[v].elementsLength-1?(p.setAttribute("aria-hidden","false"),p.disabled=!1,p.focus()):(p.setAttribute("aria-hidden","false"),p.disabled=!1,h.setAttribute("aria-hidden","false"),h.disabled=!1,"left"===e?p.focus():h.focus())):l.close&&b.focus()})(e)},oe=()=>{le()&&X(),Object.entries(w).forEach(e=>{e[1].gallery.forEach(e=>{C(e)})}),w={},v=null;for(const e in s)s[e].onReset()},le=()=>"false"===u.getAttribute("aria-hidden"),de=()=>"ontouchstart"in window,ce=e=>-1!==["TEXTAREA","OPTION","INPUT","SELECT"].indexOf(e.nodeName)||e===p||e===h||e===b,ue=(e,t)=>{u.addEventListener(e,t)},pe=(e,t)=>{u.removeEventListener(e,t)};return(e=>{if(document.querySelector("div.tobii"))return void console.log("Multiple lightbox instances not supported.");l=(e=>({selector:".lightbox",captions:!0,captionsSelector:"img",captionAttribute:"alt",captionText:null,captionHTML:!1,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,modal:!1,theme:"tobii--theme-default",...e}))(e),u||(u=document.createElement("div"),u.setAttribute("role","dialog"),u.setAttribute("aria-hidden","true"),u.classList.add("tobii"),u.classList.add(l.theme),p=document.createElement("button"),p.className="tobii__btn tobii__btn--previous",p.setAttribute("type","button"),p.setAttribute("aria-label",l.navLabel[0]),p.innerHTML=l.navText[0],u.appendChild(p),h=document.createElement("button"),h.className="tobii__btn tobii__btn--next",h.setAttribute("type","button"),h.setAttribute("aria-label",l.navLabel[1]),h.innerHTML=l.navText[1],u.appendChild(h),b=document.createElement("button"),b.className="tobii__btn tobii__btn--close",b.setAttribute("type","button"),b.setAttribute("aria-label",l.closeLabel),b.innerHTML=l.closeText,u.appendChild(b),g=document.createElement("div"),g.className="tobii__counter",u.appendChild(g),document.body.appendChild(u));const t=document.querySelectorAll(l.selector);if(!t)throw new Error(`Ups, I can't find the selector ${l.selector} on this website.`);const i=[];t.forEach(e=>{const t=e.hasAttribute("data-group")?e.getAttribute("data-group"):"default";let r=e.href;e.hasAttribute("data-target")&&(r=e.getAttribute("data-target")),r+="__"+t,void 0!==i[r]?e.addEventListener("click",e=>{$(t),T(),e.preventDefault()}):(i[r]=1,_(e))})})(a),n.open=T,n.previous=N,n.next=P,n.close=X,n.add=_,n.remove=C,n.reset=oe,n.destroy=()=>{oe(),u.parentNode.removeChild(u)},n.isOpen=le,n.slidesIndex=()=>w[v].currentIndex,n.select=e=>{const t=w[v].currentIndex;if(!le())throw new Error("Ups, I'm closed.");if(le()){if(!e&&0!==e)throw new Error("Ups, no slide specified.");if(e===w[v].currentIndex)throw new Error(`Ups, slide ${e} is already selected.`);if(-1===e||e>=w[v].elementsLength)throw new Error(`Ups, I can't find slide ${e}.`)}w[v].currentIndex=e,O(t),M(e),et&&(se("right"),k(t),q(e+1))},n.slidesCount=()=>w[v].elementsLength,n.selectGroup=$,n.currentGroup=()=>v,n.on=ue,n.off=pe,n}; +class e{constructor(){this.figcaptionId=0,this.userSettings=null}init(e,t,i){this.userSettings=i;const r=document.createElement("figure"),n=document.createElement("figcaption"),a=document.createElement("img"),s=e.querySelector("img"),o=document.createElement("div");if(r.style.opacity="0",s&&(a.alt=s.alt||""),a.setAttribute("src",""),a.setAttribute("data-src",e.href),e.hasAttribute("data-srcset")&&a.setAttribute("data-srcset",e.getAttribute("data-srcset")),r.appendChild(a),this.userSettings.captions){let t;"function"==typeof this.userSettings.captionText?t=this.userSettings.captionText(e):"self"===this.userSettings.captionsSelector&&e.getAttribute(this.userSettings.captionAttribute)?t=e.getAttribute(this.userSettings.captionAttribute):"img"===this.userSettings.captionsSelector&&s&&s.getAttribute(this.userSettings.captionAttribute)&&(t=s.getAttribute(this.userSettings.captionAttribute)),this.userSettings.captionHTML?n.innerHTML=t:n.textContent=t,t&&(n.id=`tobii-figcaption-${this.figcaptionId}`,r.appendChild(n),a.setAttribute("aria-labelledby",n.id),++this.figcaptionId)}t.appendChild(r),o.className="tobii__loader",o.setAttribute("role","progressbar"),o.setAttribute("aria-label",this.userSettings.loadingIndicatorLabel),t.appendChild(o),t.setAttribute("data-type","image"),t.classList.add("tobii-image")}onPreload(e){this.onLoad(e)}onLoad(e){const t=e.querySelector("img");if(!t.hasAttribute("data-src"))return;const i=e.querySelector("figure"),r=e.querySelector(".tobii__loader");t.addEventListener("load",()=>{e.removeChild(r),i.style.opacity="1"}),t.addEventListener("error",()=>{e.removeChild(r),i.style.opacity="1"}),t.setAttribute("src",t.getAttribute("data-src")),t.removeAttribute("data-src"),t.hasAttribute("data-srcset")&&t.setAttribute("srcset",t.getAttribute("data-srcset"))}onLeave(e){}onCleanup(e){}onReset(){this.figcaptionId=0}}class t{constructor(){this.userSettings=null}init(e,t,i){this.userSettings=i;const r=e.hasAttribute("data-target")?e.getAttribute("data-target"):e.getAttribute("href");t.setAttribute("data-HREF",r),e.getAttribute("data-allow")&&t.setAttribute("data-allow",e.getAttribute("data-allow")),e.hasAttribute("data-width")&&t.setAttribute("data-width",`${e.getAttribute("data-width")}`),e.hasAttribute("data-height")&&t.setAttribute("data-height",`${e.getAttribute("data-height")}`),t.setAttribute("data-type","iframe"),t.classList.add("tobii-iframe")}onPreload(e){}onLoad(e){let t=e.querySelector("iframe");const i=document.createElement("div");if(i.className="tobii__loader",i.setAttribute("role","progressbar"),i.setAttribute("aria-label",this.userSettings.loadingIndicatorLabel),e.appendChild(i),null==t){t=document.createElement("iframe");const i=e.getAttribute("data-href");t.setAttribute("frameborder","0"),t.setAttribute("src",i),t.setAttribute("allowfullscreen",""),i.indexOf("youtube.com")>-1?t.setAttribute("allow","accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"):i.indexOf("vimeo.com")>-1?t.setAttribute("allow","autoplay; picture-in-picture"):e.hasAttribute("data-allow")&&t.setAttribute("allow",e.getAttribute("data-allow")),e.getAttribute("data-width")&&(t.style.maxWidth=`${e.getAttribute("data-width")}`),e.getAttribute("data-height")&&(t.style.maxHeight=`${e.getAttribute("data-height")}`),t.style.opacity="0",e.appendChild(t),t.addEventListener("load",()=>{t.style.opacity="1";const i=e.querySelector(".tobii__loader");i&&e.removeChild(i)}),t.addEventListener("error",()=>{t.style.opacity="1";const i=e.querySelector(".tobii__loader");i&&e.removeChild(i)})}else t.setAttribute("src",e.getAttribute("data-href"))}onLeave(e){}onCleanup(e){const t=e.querySelector("iframe");t.setAttribute("src",""),t.style.opacity="0"}onReset(){}}class i{constructor(){this.userSettings=null}init(e,t,i){this.userSettings=i;const r=e.hasAttribute("data-target")?e.getAttribute("data-target"):e.getAttribute("href"),n=document.querySelector(r).cloneNode(!0);if(!n)throw new Error(`Ups, I can't find the target ${r}.`);t.appendChild(n),t.setAttribute("data-type","html"),t.classList.add("tobii-html")}onPreload(e){}onLoad(e,t){const i=e.querySelector("video");i&&(i.hasAttribute("data-time")&&i.readyState>0&&(i.currentTime=i.getAttribute("data-time")),this.userSettings.autoplayVideo&&i.play());const r=e.querySelector("audio");r&&this.userSettings.autoplayAudio&&r.play(),e.classList.add("tobii-group-"+t)}onLeave(e){const t=e.querySelector("video");t&&(t.paused||t.pause(),t.readyState>0&&t.setAttribute("data-time",t.currentTime));const i=e.querySelector("audio");i&&(i.paused||i.pause())}onCleanup(e){const t=e.querySelector("video");if(t&&t.readyState>0&&t.readyState<3&&t.duration!==t.currentTime){const i=t.cloneNode(!0);this._removeSources(t),t.load(),t.parentNode.removeChild(t),e.appendChild(i)}}onReset(){}_removeSources(e){const t=e.querySelectorAll("src");t&&t.forEach(e=>{e.setAttribute("src","")})}}class r{constructor(){this.playerId=0,this.PLAYER=[],this.userSettings=null}init(e,t,i){this.userSettings=i;const r=document.createElement("div");t.appendChild(r),this.PLAYER[this.playerId]=new window.YT.Player(r,{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",this.playerId),t.setAttribute("data-type","youtube"),t.classList.add("tobii-youtube"),this.playerId++}onPreload(e){}onLoad(e){this.userSettings.autoplayVideo&&this.PLAYER[e.getAttribute("data-player")].playVideo()}onLeave(e){1===this.PLAYER[e.getAttribute("data-player")].getPlayerState()&&this.PLAYER[e.getAttribute("data-player")].pauseVideo()}onCleanup(e){1===this.PLAYER[e.getAttribute("data-player")].getPlayerState()&&this.PLAYER[e.getAttribute("data-player")].pauseVideo()}onReset(){}}module.exports=function n(a){const s={image:new e,html:new i,iframe:new t,youtube:new r},o=['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])'];let l={};const d=[],c={gallery:[],slider:null,sliderElements:[],elementsLength:0,currentIndex:0,x:0};let u=null,p=null,h=null,b=null,g=null,m=null,y=null,f=!1,w={},v=null,A=[],x=0;const E={element:null,originX:0,originY:0,translateX:0,translateY:0,scale:1},L={startX:0,startY:0,x:0,y:0,distance:0},_=e=>{if(null===document.querySelector('[data-type="youtube"]')||f)S(e);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===d.indexOf(e)&&d.push(e),window.onYouTubePlayerAPIReady=()=>{d.forEach(e=>{S(e)}),f=!0}}},I=e=>e.hasAttribute("data-group")?e.getAttribute("data-group"):"default",S=e=>{const t=I(e);if(Object.prototype.hasOwnProperty.call(w,t)||(w[t]=JSON.parse(JSON.stringify(c)),w[t].slider=document.createElement("div"),w[t].slider.className="tobii__slider",w[t].slider.setAttribute("aria-hidden","true"),u.appendChild(w[t].slider)),-1!==w[t].gallery.indexOf(e))throw new Error("Ups, element already added.");{if(w[t].gallery.push(e),w[t].elementsLength++,l.zoom&&e.querySelector("img")&&"false"!==e.getAttribute("data-zoom")||"true"===e.getAttribute("data-zoom")){const t=document.createElement("div");t.className="tobii-zoom__icon",t.innerHTML=l.zoomText,e.classList.add("tobii-zoom"),e.appendChild(t)}e.addEventListener("click",z);const i=Y(e),r=document.createElement("div"),n=document.createElement("div");r.className="tobii__slide",r.style.position="absolute",r.style.left=100*w[t].x+"%",r.setAttribute("aria-hidden","true"),i.init(e,n,l),r.appendChild(n),w[t].slider.appendChild(r),w[t].sliderElements.push(r),++w[t].x,le()&&t===v&&(ae(),se())}},C=e=>{const t=I(e);if(-1===w[t].gallery.indexOf(e))throw new Error(`Ups, I can't find a slide for the element ${e}.`);{const i=w[t].gallery.indexOf(e),r=w[t].sliderElements[i];if(le()&&t===v&&i===w[t].currentIndex){if(1===w[t].elementsLength)throw X(),new Error("Ups, I've closed. There are no slides more to show.");0===w[t].currentIndex?P():N(),ae(),se()}if(w[t].gallery.splice(w[t].gallery.indexOf(e)),w[t].sliderElements.splice(w[t].gallery.indexOf(e)),w[t].elementsLength--,--w[t].x,l.zoom&&e.querySelector(".tobii-zoom__icon")){const t=e.querySelector(".tobii-zoom__icon");t.parentNode.classList.remove("tobii-zoom"),t.parentNode.removeChild(t)}e.removeEventListener("click",z),r.parentNode.removeChild(r)}},Y=e=>{const t=e.getAttribute("data-type");return void 0!==s[t]?s[t]:(e.hasAttribute("data-type")&&console.log("Unknown lightbox element type: "+t),s.image)},T=(e=0)=>{if(le())throw new Error("Ups, I'm aleady open.");if(-1===e||e>=w[v].elementsLength)throw new Error(`Ups, I can't find slide ${e}.`);document.documentElement.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open-"+v),ae(),l.close||(b.disabled=!1,b.setAttribute("aria-hidden","true")),m=document.activeElement;const t=window.location.href;window.history.pushState({tobii:"close"},"Image",t),w[v].currentIndex=e,re(),M(w[v].currentIndex),w[v].slider.setAttribute("aria-hidden","false"),u.setAttribute("aria-hidden","false"),se(),q(w[v].currentIndex+1),q(w[v].currentIndex-1),w[v].slider.classList.add("tobii__slider--animate");const i=new window.CustomEvent("open",{detail:{group:v}});u.dispatchEvent(i)},X=()=>{if(!le())throw new Error("Ups, I'm already closed.");document.documentElement.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open-"+v),ne(),null!==window.history.state&&"close"===window.history.state.tobii&&window.history.back(),m.focus(),O(w[v].currentIndex),k(w[v].currentIndex),u.setAttribute("aria-hidden","true"),w[v].slider.setAttribute("aria-hidden","true"),w[v].currentIndex=0,w[v].slider.classList.remove("tobii__slider--animate");const e=new window.CustomEvent("close",{detail:{group:v}});u.dispatchEvent(e)},q=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]");Y(t).onPreload(t)},M=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]"),i=Y(t);w[v].sliderElements[e].classList.add("tobii__slide--is-active"),w[v].sliderElements[e].setAttribute("aria-hidden","false"),i.onLoad(t,v)},N=()=>{if(!le())throw new Error("Ups, I'm closed.");w[v].currentIndex>0&&(O(w[v].currentIndex),M(--w[v].currentIndex),se("left"),k(w[v].currentIndex+1),q(w[v].currentIndex-1));const e=new window.CustomEvent("previous",{detail:{group:v}});u.dispatchEvent(e)},P=()=>{if(!le())throw new Error("Ups, I'm closed.");w[v].currentIndex{if(le())throw new Error("Ups, I'm open.");if(!e)throw new Error("Ups, no group specified.");if(e&&!Object.prototype.hasOwnProperty.call(w,e))throw new Error(`Ups, I don't have a group called "${e}".`);v=e},O=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]"),i=Y(t);w[v].sliderElements[e].classList.remove("tobii__slide--is-active"),w[v].sliderElements[e].setAttribute("aria-hidden","true"),i.onLeave(t)},k=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]");Y(t).onCleanup(t),L.startX=0,L.startY=0,L.x=0,L.y=0,L.distance=0,x=0,F()&&ie(),E.element=null},R=()=>{y=-w[v].currentIndex*u.offsetWidth,w[v].slider.style.transform=`translate(${y}px, 0)`},U=()=>{R()},z=e=>{e.preventDefault(),v=I(e.currentTarget),T(w[v].gallery.indexOf(e.currentTarget))},H=e=>{e.target===p?N():e.target===h?P():(e.target===b||e.target.classList.contains("tobii__slide")&&l.docClose)&&X(),e.stopPropagation()},D=e=>{const t=Array.prototype.slice.call(u.querySelectorAll(`.tobii__btn:not([disabled]), .tobii__slide--is-active ${o.join(", .tobii__slide--is-active ")}`)).filter(e=>!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length)),i=t.indexOf(document.activeElement);9===e.keyCode||"Tab"===e.code?e.shiftKey&&0===i?(t[t.length-1].focus(),e.preventDefault()):e.shiftKey||i!==t.length-1||(t[0].focus(),e.preventDefault()):27===e.keyCode||"Escape"===e.code?(e.preventDefault(),X()):37===e.keyCode||"ArrowLeft"===e.code?(e.preventDefault(),N()):39!==e.keyCode&&"ArrowRight"!==e.code||(e.preventDefault(),P())},B=()=>{A=[],R(),w[v].slider.classList.remove("tobii__slider--is-"+(F()?"moving":"dragging"))},V=e=>{if(!ce(e.target)&&(e.preventDefault(),e.stopPropagation(),L.startX=L.x=e.clientX,L.startY=L.y=e.clientY,L.distance=0,A.push(e),2===A.length)){const{x:e,y:t}=te(A[0].clientX,A[0].clientY,A[1].clientX,A[1].clientY);L.startX=L.x=e,L.startY=L.y=t,L.distance=ee(A[0].clientX-A[1].clientX,A[0].clientY-A[1].clientY)/E.scale}},j=e=>{if(!A.length)return;w[v].slider.classList.add("tobii__slider--is-"+(F()?"moving":"dragging"));const t=A.findIndex(t=>t.pointerId===e.pointerId);if(A[t]=e,2===A.length){const{x:e,y:t}=te(A[0].clientX,A[0].clientY,A[1].clientX,A[1].clientY),i=ee(A[0].clientX-A[1].clientX,A[0].clientY-A[1].clientY)/L.distance;return Z(K(i,1,4),e,t,e-L.x,t-L.y),L.x=e,void(L.y=t)}if(F()&&Q(e.clientX-L.x,e.clientY-L.y),L.x=e.clientX,L.y=e.clientY,!F()){const e=L.startX-L.x,t=L.startY-L.y;if(ee(e,t)<10)return;Math.abs(e)>Math.abs(t)&&w[v].elementsLength>1?w[v].slider.style.transform=`translate(${y-Math.round(e)}px, 0)`:l.swipeClose&&(w[v].slider.style.transform=`translate(${y}px, -${Math.round(t)}px)`)}},W=e=>{if(!A.length)return;w[v].slider.classList.remove("tobii__slider--is-"+(F()?"moving":"dragging"));const t=A.findIndex(t=>t.pointerId===e.pointerId);A.splice(t,1);const i=e.clientX,r=e.clientY,n=L.startX-i,a=L.startY-r,s=Math.abs(n),o=Math.abs(a);if(s||o)F()||(n<0&&s>l.threshold&&w[v].currentIndex>0?N():n>0&&s>l.threshold&&w[v].currentIndex!==w[v].elementsLength-1?P():a>0&&o>l.threshold&&l.swipeClose?X():R());else{const t=(new Date).getTime(),n=t-x;n<500&&n>100?(e.preventDefault(),x=0,F()?ie():Z(2,i,r,0,0)):(x=t,de()&&window.setTimeout(()=>{const{left:t,top:n,bottom:a,right:s,width:o}=e.target.getBoundingClientRect();ra||!x||(i>t&&is-o/2&&P())},500))}},G=e=>{const t=Math.sign(e.deltaY)>0?-1:1;(F()||t)&&(e.preventDefault(),Z(K(E.scale+t/(10/E.scale),1,4),e.clientX,e.clientY,0,0))},J=(e,t)=>{const{element:i,scale:r,originX:n,originY:a}=E,s="x"===e,o=s?n:a,l=s?"offsetWidth":"offsetHeight",d=i.parentNode[l],c=i[l],u=i.getBoundingClientRect(),p=(o-c/2)*(r-1),h=Math.max(0,Math.round(s?u.width:u.height)-d),b=Math.round(h/2);return K(t,0-b+p,b+p)},K=(e,t,i)=>Math.max(Math.min(e,i),t),F=()=>1!==E.scale,Q=(e,t)=>{0!==e&&(E.translateX=J("x",E.translateX+e)),0!==t&&(E.translateY=J("y",E.translateY+t));const{element:i,originX:r,originY:n,translateX:a,translateY:s,scale:o}=E;i.style.transformOrigin=`${r}px ${n}px`,i.style.transform=`translate(${a}px, ${s}px) scale(${o})`},Z=(e,t,i,r,n)=>{E.element||(E.element=u.querySelector(".tobii__slide--is-active img"));const{left:a,top:s}=E.element.getBoundingClientRect(),o=(i-s)/E.scale;E.originX=(t-a)/E.scale,E.originY=o,E.scale=e,Q(r,n)},ee=(e,t)=>Math.hypot(e,t),te=(e,t,i,r)=>({x:(e+i)/2,y:(t+r)/2}),ie=()=>{E.scale=1,E.originX=0,E.originY=0,E.translateX=0,E.translateY=0,Q(0,0)},re=()=>{l.keyboard&&window.addEventListener("keydown",D),window.addEventListener("resize",U),window.addEventListener("popstate",X),ue("click",H),l.draggable&&(ue("pointerdown",V),ue("pointermove",j),ue("pointerup",W),ue("pointercancel",B),ue("pointerout",B),ue("pointerleave",B),ue("contextmenu",B)),ue("wheel",G)},ne=()=>{l.keyboard&&window.removeEventListener("keydown",D),window.removeEventListener("resize",U),window.removeEventListener("popstate",X),pe("click",H),l.draggable&&(pe("pointerdown",V),pe("pointermove",j),pe("pointerup",W),pe("pointercancel",B),pe("pointerout",B),pe("pointerleave",B),pe("contextmenu",B)),pe("wheel",G)},ae=()=>{l.draggable&&!w[v].slider.classList.contains("tobii__slider--is-draggable")&&w[v].slider.classList.add("tobii__slider--is-draggable"),!l.nav||1===w[v].elementsLength||"auto"===l.nav&&de()?(p.setAttribute("aria-hidden","true"),p.disabled=!0,h.setAttribute("aria-hidden","true"),h.disabled=!0):(p.setAttribute("aria-hidden","false"),p.disabled=!1,h.setAttribute("aria-hidden","false"),h.disabled=!1),g.setAttribute("aria-hidden",l.counter&&1!==w[v].elementsLength?"false":"true")},se=(e=null)=>{R(),g.textContent=`${w[v].currentIndex+1}/${w[v].elementsLength}`,(e=>{(!0===l.nav||"auto"===l.nav)&&!de()&&w[v].elementsLength>1?(p.setAttribute("aria-hidden","true"),p.disabled=!0,h.setAttribute("aria-hidden","true"),h.disabled=!0,1===w[v].elementsLength?l.close&&b.focus():0===w[v].currentIndex?(h.setAttribute("aria-hidden","false"),h.disabled=!1,h.focus()):w[v].currentIndex===w[v].elementsLength-1?(p.setAttribute("aria-hidden","false"),p.disabled=!1,p.focus()):(p.setAttribute("aria-hidden","false"),p.disabled=!1,h.setAttribute("aria-hidden","false"),h.disabled=!1,"left"===e?p.focus():h.focus())):l.close&&b.focus()})(e)},oe=()=>{le()&&X(),Object.entries(w).forEach(e=>{e[1].gallery.forEach(e=>{C(e)})}),w={},v=null;for(const e in s)s[e].onReset()},le=()=>"false"===u.getAttribute("aria-hidden"),de=()=>"ontouchstart"in window,ce=e=>-1!==["TEXTAREA","OPTION","INPUT","SELECT"].indexOf(e.nodeName)||e===p||e===h||e===b,ue=(e,t)=>{u.addEventListener(e,t)},pe=(e,t)=>{u.removeEventListener(e,t)};return(e=>{if(document.querySelector("div.tobii"))return void console.log("Multiple lightbox instances not supported.");l=(e=>({selector:".lightbox",captions:!0,captionsSelector:"img",captionAttribute:"alt",captionText:null,captionHTML:!1,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,modal:!1,theme:"tobii--theme-default",...e}))(e),u||(u=document.createElement("div"),u.setAttribute("role","dialog"),u.setAttribute("aria-hidden","true"),u.classList.add("tobii"),u.classList.add(l.theme),p=document.createElement("button"),p.className="tobii__btn tobii__btn--previous",p.setAttribute("type","button"),p.setAttribute("aria-label",l.navLabel[0]),p.innerHTML=l.navText[0],u.appendChild(p),h=document.createElement("button"),h.className="tobii__btn tobii__btn--next",h.setAttribute("type","button"),h.setAttribute("aria-label",l.navLabel[1]),h.innerHTML=l.navText[1],u.appendChild(h),b=document.createElement("button"),b.className="tobii__btn tobii__btn--close",b.setAttribute("type","button"),b.setAttribute("aria-label",l.closeLabel),b.innerHTML=l.closeText,u.appendChild(b),g=document.createElement("div"),g.className="tobii__counter",u.appendChild(g),document.body.appendChild(u));const t=document.querySelectorAll(l.selector);if(!t)throw new Error(`Ups, I can't find the selector ${l.selector} on this website.`);const i=[];t.forEach(e=>{const t=e.hasAttribute("data-group")?e.getAttribute("data-group"):"default";let r=e.href;e.hasAttribute("data-target")&&(r=e.getAttribute("data-target")),r+="__"+t,void 0!==i[r]?e.addEventListener("click",e=>{$(t),T(),e.preventDefault()}):(i[r]=1,_(e))})})(a),n.open=T,n.previous=N,n.next=P,n.close=X,n.add=_,n.remove=C,n.reset=oe,n.destroy=()=>{oe(),u.parentNode.removeChild(u)},n.isOpen=le,n.slidesIndex=()=>w[v].currentIndex,n.select=e=>{const t=w[v].currentIndex;if(!le())throw new Error("Ups, I'm closed.");if(le()){if(!e&&0!==e)throw new Error("Ups, no slide specified.");if(e===w[v].currentIndex)throw new Error(`Ups, slide ${e} is already selected.`);if(-1===e||e>=w[v].elementsLength)throw new Error(`Ups, I can't find slide ${e}.`)}w[v].currentIndex=e,O(t),M(e),et&&(se("right"),k(t),q(e+1))},n.slidesCount=()=>w[v].elementsLength,n.selectGroup=$,n.currentGroup=()=>v,n.on=ue,n.off=pe,n}; diff --git a/dist/tobii.min.js b/dist/tobii.min.js index 3b4432e..10a3a82 100644 --- a/dist/tobii.min.js +++ b/dist/tobii.min.js @@ -1 +1 @@ -!function(){if("function"!=typeof window.CustomEvent){var t=function(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),i};t.prototype=window.Event.prototype,window.CustomEvent=t}function e(){return e=Object.assign?Object.assign.bind():function(t){for(var e=1;e-1?e.setAttribute("allow","accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"):n.indexOf("vimeo.com")>-1?e.setAttribute("allow","autoplay; picture-in-picture"):t.hasAttribute("data-allow")&&e.setAttribute("allow",t.getAttribute("data-allow")),t.getAttribute("data-width")&&(e.style.maxWidth=""+t.getAttribute("data-width")),t.getAttribute("data-height")&&(e.style.maxHeight=""+t.getAttribute("data-height")),e.style.opacity="0",t.appendChild(e),e.addEventListener("load",function(){e.style.opacity="1";var i=t.querySelector(".tobii__loader");i&&t.removeChild(i)}),e.addEventListener("error",function(){e.style.opacity="1";var i=t.querySelector(".tobii__loader");i&&t.removeChild(i)})}else e.setAttribute("src",t.getAttribute("data-href"))},e.onLeave=function(t){},e.onCleanup=function(t){var e=t.querySelector("iframe");e.setAttribute("src",""),e.style.opacity="0"},e.onReset=function(){},t}(),r=/*#__PURE__*/function(){function t(){this.userSettings=null}var e=t.prototype;return e.init=function(t,e,i){this.userSettings=i;var n=t.hasAttribute("data-target")?t.getAttribute("data-target"):t.getAttribute("href"),r=document.querySelector(n).cloneNode(!0);if(!r)throw new Error("Ups, I can't find the target "+n+".");e.appendChild(r),e.setAttribute("data-type","html"),e.classList.add("tobii-html")},e.onPreload=function(t){},e.onLoad=function(t,e){var i=t.querySelector("video");i&&(i.hasAttribute("data-time")&&i.readyState>0&&(i.currentTime=i.getAttribute("data-time")),this.userSettings.autoplayVideo&&i.play());var n=t.querySelector("audio");n&&this.userSettings.autoplayAudio&&n.play(),t.classList.add("tobii-group-"+e)},e.onLeave=function(t){var e=t.querySelector("video");e&&(e.paused||e.pause(),e.readyState>0&&e.setAttribute("data-time",e.currentTime));var i=t.querySelector("audio");i&&(i.paused||i.pause())},e.onCleanup=function(t){var e=t.querySelector("video");if(e&&e.readyState>0&&e.readyState<3&&e.duration!==e.currentTime){var i=e.cloneNode(!0);this._removeSources(e),e.load(),e.parentNode.removeChild(e),t.appendChild(i)}},e.onReset=function(){},e._removeSources=function(t){var e=t.querySelectorAll("src");e&&e.forEach(function(t){t.setAttribute("src","")})},t}(),a=/*#__PURE__*/function(){function t(){this.playerId=0,this.PLAYER=[],this.userSettings=null}var e=t.prototype;return e.init=function(t,e,i){this.userSettings=i;var n=document.createElement("div");e.appendChild(n),this.PLAYER[this.playerId]=new window.YT.Player(n,{host:"https://www.youtube-nocookie.com",height:t.getAttribute("data-height")||"360",width:t.getAttribute("data-width")||"640",videoId:t.getAttribute("data-id"),playerVars:{controls:t.getAttribute("data-controls")||1,rel:0,playsinline:1}}),e.setAttribute("data-player",this.playerId),e.setAttribute("data-type","youtube"),e.classList.add("tobii-youtube"),this.playerId++},e.onPreload=function(t){},e.onLoad=function(t){this.userSettings.autoplayVideo&&this.PLAYER[t.getAttribute("data-player")].playVideo()},e.onLeave=function(t){1===this.PLAYER[t.getAttribute("data-player")].getPlayerState()&&this.PLAYER[t.getAttribute("data-player")].pauseVideo()},e.onCleanup=function(t){1===this.PLAYER[t.getAttribute("data-player")].getPlayerState()&&this.PLAYER[t.getAttribute("data-player")].pauseVideo()},e.onReset=function(){},t}();function o(t){var s={image:new i,html:new r,iframe:new n,youtube:new a},l=['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])'],d={},u=[],c={gallery:[],slider:null,sliderElements:[],elementsLength:0,currentIndex:0,x:0},p=null,f=null,b=null,h=null,g=null,m=null,v=null,y=!1,w={},A=null,x=[],E=0,L={element:null,originX:0,originY:0,translateX:0,translateY:0,scale:1},_={startX:0,startY:0,x:0,y:0,distance:0},I=function(t){if(null===document.querySelector('[data-type="youtube"]')||y)C(t);else{if(null===document.getElementById("iframe_api")){var e=document.createElement("script"),i=document.getElementsByTagName("script")[0];e.id="iframe_api",e.src="https://www.youtube.com/iframe_api",i.parentNode.insertBefore(e,i)}-1===u.indexOf(t)&&u.push(t),window.onYouTubePlayerAPIReady=function(){u.forEach(function(t){C(t)}),y=!0}}},S=function(t){return t.hasAttribute("data-group")?t.getAttribute("data-group"):"default"},C=function(t){var e=S(t);if(Object.prototype.hasOwnProperty.call(w,e)||(w[e]=JSON.parse(JSON.stringify(c)),w[e].slider=document.createElement("div"),w[e].slider.className="tobii__slider",w[e].slider.setAttribute("aria-hidden","true"),p.appendChild(w[e].slider)),-1!==w[e].gallery.indexOf(t))throw new Error("Ups, element already added.");if(w[e].gallery.push(t),w[e].elementsLength++,d.zoom&&t.querySelector("img")&&"false"!==t.getAttribute("data-zoom")||"true"===t.getAttribute("data-zoom")){var i=document.createElement("div");i.className="tobii-zoom__icon",i.innerHTML=d.zoomText,t.classList.add("tobii-zoom"),t.appendChild(i)}t.addEventListener("click",D);var n=T(t),r=document.createElement("div"),a=document.createElement("div");r.className="tobii__slide",r.style.position="absolute",r.style.left=100*w[e].x+"%",r.setAttribute("aria-hidden","true"),n.init(t,a,d),r.appendChild(a),w[e].slider.appendChild(r),w[e].sliderElements.push(r),++w[e].x,dt()&&e===A&&(ot(),st())},Y=function(t){var e=S(t);if(-1===w[e].gallery.indexOf(t))throw new Error("Ups, I can't find a slide for the element "+t+".");var i=w[e].gallery.indexOf(t),n=w[e].sliderElements[i];if(dt()&&e===A&&i===w[e].currentIndex){if(1===w[e].elementsLength)throw N(),new Error("Ups, I've closed. There are no slides more to show.");0===w[e].currentIndex?P():O(),ot(),st()}if(w[e].gallery.splice(w[e].gallery.indexOf(t)),w[e].sliderElements.splice(w[e].gallery.indexOf(t)),w[e].elementsLength--,--w[e].x,d.zoom&&t.querySelector(".tobii-zoom__icon")){var r=t.querySelector(".tobii-zoom__icon");r.parentNode.classList.remove("tobii-zoom"),r.parentNode.removeChild(r)}t.removeEventListener("click",D),n.parentNode.removeChild(n)},T=function(t){var e=t.getAttribute("data-type");return void 0!==s[e]?s[e]:(t.hasAttribute("data-type")&&console.log("Unknown lightbox element type: "+e),s.image)},X=function(t){if(void 0===t&&(t=0),dt())throw new Error("Ups, I'm aleady open.");if(-1===t||t>=w[A].elementsLength)throw new Error("Ups, I can't find slide "+t+".");document.documentElement.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open-"+A),ot(),d.close||(h.disabled=!1,h.setAttribute("aria-hidden","true")),m=document.activeElement;var e=window.location.href;window.history.pushState({tobii:"close"},"Image",e),w[A].currentIndex=t,rt(),M(w[A].currentIndex),w[A].slider.setAttribute("aria-hidden","false"),p.setAttribute("aria-hidden","false"),st(),q(w[A].currentIndex+1),q(w[A].currentIndex-1),w[A].slider.classList.add("tobii__slider--animate");var i=new window.CustomEvent("open",{detail:{group:A}});p.dispatchEvent(i)},N=function(){if(!dt())throw new Error("Ups, I'm already closed.");document.documentElement.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open-"+A),at(),null!==window.history.state&&"close"===window.history.state.tobii&&window.history.back(),m.focus(),R(w[A].currentIndex),U(w[A].currentIndex),p.setAttribute("aria-hidden","true"),w[A].slider.setAttribute("aria-hidden","true"),w[A].currentIndex=0,w[A].slider.classList.remove("tobii__slider--animate");var t=new window.CustomEvent("close",{detail:{group:A}});p.dispatchEvent(t)},q=function(t){if(void 0!==w[A].sliderElements[t]){var e=w[A].sliderElements[t].querySelector("[data-type]");T(e).onPreload(e)}},M=function(t){if(void 0!==w[A].sliderElements[t]){var e=w[A].sliderElements[t].querySelector("[data-type]"),i=T(e);w[A].sliderElements[t].classList.add("tobii__slide--is-active"),w[A].sliderElements[t].setAttribute("aria-hidden","false"),i.onLoad(e,A)}},O=function(){if(!dt())throw new Error("Ups, I'm closed.");w[A].currentIndex>0&&(R(w[A].currentIndex),M(--w[A].currentIndex),st("left"),U(w[A].currentIndex+1),q(w[A].currentIndex-1));var t=new window.CustomEvent("previous",{detail:{group:A}});p.dispatchEvent(t)},P=function(){if(!dt())throw new Error("Ups, I'm closed.");w[A].currentIndexMath.abs(s)&&w[A].elementsLength>1?w[A].slider.style.transform="translate("+(v-Math.round(o))+"px, 0)":d.swipeClose&&(w[A].slider.style.transform="translate("+v+"px, -"+Math.round(s)+"px)")}}},J=function(t){if(x.length){w[A].slider.classList.remove("tobii__slider--is-"+(Z()?"moving":"dragging"));var e=x.findIndex(function(e){return e.pointerId===t.pointerId});x.splice(e,1);var i=t.clientX,n=t.clientY,r=_.startX-i,a=_.startY-n,o=Math.abs(r),s=Math.abs(a);if(o||s)Z()||(r<0&&o>d.threshold&&w[A].currentIndex>0?O():r>0&&o>d.threshold&&w[A].currentIndex!==w[A].elementsLength-1?P():a>0&&s>d.threshold&&d.swipeClose?N():z());else{var l=(new Date).getTime(),u=l-E;u<500&&u>100?(t.preventDefault(),E=0,Z()?nt():tt(2,i,n,0,0)):(E=l,ut()&&window.setTimeout(function(){var e=t.target.getBoundingClientRect(),r=e.left,a=e.right,o=e.width;ne.bottom||!E||(i>r&&ia-o/2&&P())},500))}}},K=function(t){var e=Math.sign(t.deltaY)>0?-1:1;(Z()||e)&&(t.preventDefault(),tt(Q(L.scale+e/(10/L.scale),1,4),t.clientX,t.clientY,0,0))},F=function(t,e){var i=L.element,n=L.scale,r="x"===t,a=r?L.originX:L.originY,o=r?"offsetWidth":"offsetHeight",s=i.parentNode[o],l=i[o],d=i.getBoundingClientRect(),u=(a-l/2)*(n-1),c=Math.max(0,Math.round(r?d.width:d.height)-s),p=Math.round(c/2);return Q(e,0-p+u,p+u)},Q=function(t,e,i){return Math.max(Math.min(t,i),e)},Z=function(){return 1!==L.scale},$=function(t,e){0!==t&&(L.translateX=F("x",L.translateX+t)),0!==e&&(L.translateY=F("y",L.translateY+e));var i=L.element,n=L.translateX,r=L.translateY,a=L.scale;i.style.transformOrigin=L.originX+"px "+L.originY+"px",i.style.transform="translate("+n+"px, "+r+"px) scale("+a+")"},tt=function(t,e,i,n,r){L.element||(L.element=p.querySelector(".tobii__slide--is-active img"));var a=L.element.getBoundingClientRect(),o=(i-a.top)/L.scale;L.originX=(e-a.left)/L.scale,L.originY=o,L.scale=t,$(n,r)},et=function(t,e){return Math.hypot(t,e)},it=function(t,e,i,n){return{x:(t+i)/2,y:(e+n)/2}},nt=function(){L.scale=1,L.originX=0,L.originY=0,L.translateX=0,L.translateY=0,$(0,0),L.element=null},rt=function(){d.keyboard&&window.addEventListener("keydown",V),window.addEventListener("resize",H),window.addEventListener("popstate",N),pt("click",B),d.draggable&&(pt("pointerdown",W),pt("pointermove",G),pt("pointerup",J),pt("pointercancel",j),pt("pointerout",j),pt("pointerleave",j),pt("contextmenu",j)),pt("wheel",K)},at=function(){d.keyboard&&window.removeEventListener("keydown",V),window.removeEventListener("resize",H),window.removeEventListener("popstate",N),ft("click",B),d.draggable&&(ft("pointerdown",W),ft("pointermove",G),ft("pointerup",J),ft("pointercancel",j),ft("pointerout",j),ft("pointerleave",j),ft("contextmenu",j)),ft("wheel",K)},ot=function(){d.draggable&&!w[A].slider.classList.contains("tobii__slider--is-draggable")&&w[A].slider.classList.add("tobii__slider--is-draggable"),!d.nav||1===w[A].elementsLength||"auto"===d.nav&&ut()?(f.setAttribute("aria-hidden","true"),f.disabled=!0,b.setAttribute("aria-hidden","true"),b.disabled=!0):(f.setAttribute("aria-hidden","false"),f.disabled=!1,b.setAttribute("aria-hidden","false"),b.disabled=!1),g.setAttribute("aria-hidden",d.counter&&1!==w[A].elementsLength?"false":"true")},st=function(t){void 0===t&&(t=null),z(),g.textContent=w[A].currentIndex+1+"/"+w[A].elementsLength,function(t){(!0===d.nav||"auto"===d.nav)&&!ut()&&w[A].elementsLength>1?(f.setAttribute("aria-hidden","true"),f.disabled=!0,b.setAttribute("aria-hidden","true"),b.disabled=!0,1===w[A].elementsLength?d.close&&h.focus():0===w[A].currentIndex?(b.setAttribute("aria-hidden","false"),b.disabled=!1,b.focus()):w[A].currentIndex===w[A].elementsLength-1?(f.setAttribute("aria-hidden","false"),f.disabled=!1,f.focus()):(f.setAttribute("aria-hidden","false"),f.disabled=!1,b.setAttribute("aria-hidden","false"),b.disabled=!1,"left"===t?f.focus():b.focus())):d.close&&h.focus()}(t)},lt=function(){dt()&&N();var t=Object.entries(w);for(var e in t.forEach(function(t){t[1].gallery.forEach(function(t){Y(t)})}),w={},A=null,s)s[e].onReset()},dt=function(){return"false"===p.getAttribute("aria-hidden")},ut=function(){return"ontouchstart"in window},ct=function(t){return-1!==["TEXTAREA","OPTION","INPUT","SELECT"].indexOf(t.nodeName)||t===f||t===b||t===h},pt=function(t,e){p.addEventListener(t,e)},ft=function(t,e){p.removeEventListener(t,e)};return function(t){if(document.querySelector("div.tobii"))console.log("Multiple lightbox instances not supported.");else{d=function(t){return e({},{selector:".lightbox",captions:!0,captionsSelector:"img",captionAttribute:"alt",captionText:null,captionHTML:!1,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,modal:!1,theme:"tobii--theme-default"},t)}(t),p||((p=document.createElement("div")).setAttribute("role","dialog"),p.setAttribute("aria-hidden","true"),p.classList.add("tobii"),p.classList.add(d.theme),(f=document.createElement("button")).className="tobii__btn tobii__btn--previous",f.setAttribute("type","button"),f.setAttribute("aria-label",d.navLabel[0]),f.innerHTML=d.navText[0],p.appendChild(f),(b=document.createElement("button")).className="tobii__btn tobii__btn--next",b.setAttribute("type","button"),b.setAttribute("aria-label",d.navLabel[1]),b.innerHTML=d.navText[1],p.appendChild(b),(h=document.createElement("button")).className="tobii__btn tobii__btn--close",h.setAttribute("type","button"),h.setAttribute("aria-label",d.closeLabel),h.innerHTML=d.closeText,p.appendChild(h),(g=document.createElement("div")).className="tobii__counter",p.appendChild(g),document.body.appendChild(p));var i=document.querySelectorAll(d.selector);if(!i)throw new Error("Ups, I can't find the selector "+d.selector+" on this website.");var n=[];i.forEach(function(t){var e=t.hasAttribute("data-group")?t.getAttribute("data-group"):"default",i=t.href;t.hasAttribute("data-target")&&(i=t.getAttribute("data-target")),void 0!==n[i+="__"+e]?t.addEventListener("click",function(t){k(e),X(),t.preventDefault()}):(n[i]=1,I(t))})}}(t),o.open=X,o.previous=O,o.next=P,o.close=N,o.add=I,o.remove=Y,o.reset=lt,o.destroy=function(){lt(),p.parentNode.removeChild(p)},o.isOpen=dt,o.slidesIndex=function(){return w[A].currentIndex},o.select=function(t){var e=w[A].currentIndex;if(!dt())throw new Error("Ups, I'm closed.");if(dt()){if(!t&&0!==t)throw new Error("Ups, no slide specified.");if(t===w[A].currentIndex)throw new Error("Ups, slide "+t+" is already selected.");if(-1===t||t>=w[A].elementsLength)throw new Error("Ups, I can't find slide "+t+".")}w[A].currentIndex=t,R(e),M(t),te&&(st("right"),U(e),q(t+1))},o.slidesCount=function(){return w[A].elementsLength},o.selectGroup=k,o.currentGroup=function(){return A},o.on=pt,o.off=ft,o}typeof module<"u"?module.exports=o:self.Tobii=o}(); +!function(){if("function"!=typeof window.CustomEvent){var t=function(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),i};t.prototype=window.Event.prototype,window.CustomEvent=t}function e(){return e=Object.assign?Object.assign.bind():function(t){for(var e=1;e-1?e.setAttribute("allow","accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"):n.indexOf("vimeo.com")>-1?e.setAttribute("allow","autoplay; picture-in-picture"):t.hasAttribute("data-allow")&&e.setAttribute("allow",t.getAttribute("data-allow")),t.getAttribute("data-width")&&(e.style.maxWidth=""+t.getAttribute("data-width")),t.getAttribute("data-height")&&(e.style.maxHeight=""+t.getAttribute("data-height")),e.style.opacity="0",t.appendChild(e),e.addEventListener("load",function(){e.style.opacity="1";var i=t.querySelector(".tobii__loader");i&&t.removeChild(i)}),e.addEventListener("error",function(){e.style.opacity="1";var i=t.querySelector(".tobii__loader");i&&t.removeChild(i)})}else e.setAttribute("src",t.getAttribute("data-href"))},e.onLeave=function(t){},e.onCleanup=function(t){var e=t.querySelector("iframe");e.setAttribute("src",""),e.style.opacity="0"},e.onReset=function(){},t}(),r=/*#__PURE__*/function(){function t(){this.userSettings=null}var e=t.prototype;return e.init=function(t,e,i){this.userSettings=i;var n=t.hasAttribute("data-target")?t.getAttribute("data-target"):t.getAttribute("href"),r=document.querySelector(n).cloneNode(!0);if(!r)throw new Error("Ups, I can't find the target "+n+".");e.appendChild(r),e.setAttribute("data-type","html"),e.classList.add("tobii-html")},e.onPreload=function(t){},e.onLoad=function(t,e){var i=t.querySelector("video");i&&(i.hasAttribute("data-time")&&i.readyState>0&&(i.currentTime=i.getAttribute("data-time")),this.userSettings.autoplayVideo&&i.play());var n=t.querySelector("audio");n&&this.userSettings.autoplayAudio&&n.play(),t.classList.add("tobii-group-"+e)},e.onLeave=function(t){var e=t.querySelector("video");e&&(e.paused||e.pause(),e.readyState>0&&e.setAttribute("data-time",e.currentTime));var i=t.querySelector("audio");i&&(i.paused||i.pause())},e.onCleanup=function(t){var e=t.querySelector("video");if(e&&e.readyState>0&&e.readyState<3&&e.duration!==e.currentTime){var i=e.cloneNode(!0);this._removeSources(e),e.load(),e.parentNode.removeChild(e),t.appendChild(i)}},e.onReset=function(){},e._removeSources=function(t){var e=t.querySelectorAll("src");e&&e.forEach(function(t){t.setAttribute("src","")})},t}(),a=/*#__PURE__*/function(){function t(){this.playerId=0,this.PLAYER=[],this.userSettings=null}var e=t.prototype;return e.init=function(t,e,i){this.userSettings=i;var n=document.createElement("div");e.appendChild(n),this.PLAYER[this.playerId]=new window.YT.Player(n,{host:"https://www.youtube-nocookie.com",height:t.getAttribute("data-height")||"360",width:t.getAttribute("data-width")||"640",videoId:t.getAttribute("data-id"),playerVars:{controls:t.getAttribute("data-controls")||1,rel:0,playsinline:1}}),e.setAttribute("data-player",this.playerId),e.setAttribute("data-type","youtube"),e.classList.add("tobii-youtube"),this.playerId++},e.onPreload=function(t){},e.onLoad=function(t){this.userSettings.autoplayVideo&&this.PLAYER[t.getAttribute("data-player")].playVideo()},e.onLeave=function(t){1===this.PLAYER[t.getAttribute("data-player")].getPlayerState()&&this.PLAYER[t.getAttribute("data-player")].pauseVideo()},e.onCleanup=function(t){1===this.PLAYER[t.getAttribute("data-player")].getPlayerState()&&this.PLAYER[t.getAttribute("data-player")].pauseVideo()},e.onReset=function(){},t}();function o(t){var s={image:new i,html:new r,iframe:new n,youtube:new a},l=['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])'],d={},u=[],c={gallery:[],slider:null,sliderElements:[],elementsLength:0,currentIndex:0,x:0},p=null,f=null,b=null,h=null,g=null,m=null,v=null,y=!1,w={},A=null,x=[],E=0,L={element:null,originX:0,originY:0,translateX:0,translateY:0,scale:1},_={startX:0,startY:0,x:0,y:0,distance:0},I=function(t){if(null===document.querySelector('[data-type="youtube"]')||y)C(t);else{if(null===document.getElementById("iframe_api")){var e=document.createElement("script"),i=document.getElementsByTagName("script")[0];e.id="iframe_api",e.src="https://www.youtube.com/iframe_api",i.parentNode.insertBefore(e,i)}-1===u.indexOf(t)&&u.push(t),window.onYouTubePlayerAPIReady=function(){u.forEach(function(t){C(t)}),y=!0}}},S=function(t){return t.hasAttribute("data-group")?t.getAttribute("data-group"):"default"},C=function(t){var e=S(t);if(Object.prototype.hasOwnProperty.call(w,e)||(w[e]=JSON.parse(JSON.stringify(c)),w[e].slider=document.createElement("div"),w[e].slider.className="tobii__slider",w[e].slider.setAttribute("aria-hidden","true"),p.appendChild(w[e].slider)),-1!==w[e].gallery.indexOf(t))throw new Error("Ups, element already added.");if(w[e].gallery.push(t),w[e].elementsLength++,d.zoom&&t.querySelector("img")&&"false"!==t.getAttribute("data-zoom")||"true"===t.getAttribute("data-zoom")){var i=document.createElement("div");i.className="tobii-zoom__icon",i.innerHTML=d.zoomText,t.classList.add("tobii-zoom"),t.appendChild(i)}t.addEventListener("click",D);var n=T(t),r=document.createElement("div"),a=document.createElement("div");r.className="tobii__slide",r.style.position="absolute",r.style.left=100*w[e].x+"%",r.setAttribute("aria-hidden","true"),n.init(t,a,d),r.appendChild(a),w[e].slider.appendChild(r),w[e].sliderElements.push(r),++w[e].x,dt()&&e===A&&(ot(),st())},Y=function(t){var e=S(t);if(-1===w[e].gallery.indexOf(t))throw new Error("Ups, I can't find a slide for the element "+t+".");var i=w[e].gallery.indexOf(t),n=w[e].sliderElements[i];if(dt()&&e===A&&i===w[e].currentIndex){if(1===w[e].elementsLength)throw N(),new Error("Ups, I've closed. There are no slides more to show.");0===w[e].currentIndex?P():O(),ot(),st()}if(w[e].gallery.splice(w[e].gallery.indexOf(t)),w[e].sliderElements.splice(w[e].gallery.indexOf(t)),w[e].elementsLength--,--w[e].x,d.zoom&&t.querySelector(".tobii-zoom__icon")){var r=t.querySelector(".tobii-zoom__icon");r.parentNode.classList.remove("tobii-zoom"),r.parentNode.removeChild(r)}t.removeEventListener("click",D),n.parentNode.removeChild(n)},T=function(t){var e=t.getAttribute("data-type");return void 0!==s[e]?s[e]:(t.hasAttribute("data-type")&&console.log("Unknown lightbox element type: "+e),s.image)},X=function(t){if(void 0===t&&(t=0),dt())throw new Error("Ups, I'm aleady open.");if(-1===t||t>=w[A].elementsLength)throw new Error("Ups, I can't find slide "+t+".");document.documentElement.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open-"+A),ot(),d.close||(h.disabled=!1,h.setAttribute("aria-hidden","true")),m=document.activeElement;var e=window.location.href;window.history.pushState({tobii:"close"},"Image",e),w[A].currentIndex=t,rt(),M(w[A].currentIndex),w[A].slider.setAttribute("aria-hidden","false"),p.setAttribute("aria-hidden","false"),st(),q(w[A].currentIndex+1),q(w[A].currentIndex-1),w[A].slider.classList.add("tobii__slider--animate");var i=new window.CustomEvent("open",{detail:{group:A}});p.dispatchEvent(i)},N=function(){if(!dt())throw new Error("Ups, I'm already closed.");document.documentElement.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open-"+A),at(),null!==window.history.state&&"close"===window.history.state.tobii&&window.history.back(),m.focus(),R(w[A].currentIndex),U(w[A].currentIndex),p.setAttribute("aria-hidden","true"),w[A].slider.setAttribute("aria-hidden","true"),w[A].currentIndex=0,w[A].slider.classList.remove("tobii__slider--animate");var t=new window.CustomEvent("close",{detail:{group:A}});p.dispatchEvent(t)},q=function(t){if(void 0!==w[A].sliderElements[t]){var e=w[A].sliderElements[t].querySelector("[data-type]");T(e).onPreload(e)}},M=function(t){if(void 0!==w[A].sliderElements[t]){var e=w[A].sliderElements[t].querySelector("[data-type]"),i=T(e);w[A].sliderElements[t].classList.add("tobii__slide--is-active"),w[A].sliderElements[t].setAttribute("aria-hidden","false"),i.onLoad(e,A)}},O=function(){if(!dt())throw new Error("Ups, I'm closed.");w[A].currentIndex>0&&(R(w[A].currentIndex),M(--w[A].currentIndex),st("left"),U(w[A].currentIndex+1),q(w[A].currentIndex-1));var t=new window.CustomEvent("previous",{detail:{group:A}});p.dispatchEvent(t)},P=function(){if(!dt())throw new Error("Ups, I'm closed.");w[A].currentIndexMath.abs(s)&&w[A].elementsLength>1?w[A].slider.style.transform="translate("+(v-Math.round(o))+"px, 0)":d.swipeClose&&(w[A].slider.style.transform="translate("+v+"px, -"+Math.round(s)+"px)")}}},J=function(t){if(x.length){w[A].slider.classList.remove("tobii__slider--is-"+(Z()?"moving":"dragging"));var e=x.findIndex(function(e){return e.pointerId===t.pointerId});x.splice(e,1);var i=t.clientX,n=t.clientY,r=_.startX-i,a=_.startY-n,o=Math.abs(r),s=Math.abs(a);if(o||s)Z()||(r<0&&o>d.threshold&&w[A].currentIndex>0?O():r>0&&o>d.threshold&&w[A].currentIndex!==w[A].elementsLength-1?P():a>0&&s>d.threshold&&d.swipeClose?N():z());else{var l=(new Date).getTime(),u=l-E;u<500&&u>100?(t.preventDefault(),E=0,Z()?nt():tt(2,i,n,0,0)):(E=l,ut()&&window.setTimeout(function(){var e=t.target.getBoundingClientRect(),r=e.left,a=e.right,o=e.width;ne.bottom||!E||(i>r&&ia-o/2&&P())},500))}}},K=function(t){var e=Math.sign(t.deltaY)>0?-1:1;(Z()||e)&&(t.preventDefault(),tt(Q(L.scale+e/(10/L.scale),1,4),t.clientX,t.clientY,0,0))},F=function(t,e){var i=L.element,n=L.scale,r="x"===t,a=r?L.originX:L.originY,o=r?"offsetWidth":"offsetHeight",s=i.parentNode[o],l=i[o],d=i.getBoundingClientRect(),u=(a-l/2)*(n-1),c=Math.max(0,Math.round(r?d.width:d.height)-s),p=Math.round(c/2);return Q(e,0-p+u,p+u)},Q=function(t,e,i){return Math.max(Math.min(t,i),e)},Z=function(){return 1!==L.scale},$=function(t,e){0!==t&&(L.translateX=F("x",L.translateX+t)),0!==e&&(L.translateY=F("y",L.translateY+e));var i=L.element,n=L.translateX,r=L.translateY,a=L.scale;i.style.transformOrigin=L.originX+"px "+L.originY+"px",i.style.transform="translate("+n+"px, "+r+"px) scale("+a+")"},tt=function(t,e,i,n,r){L.element||(L.element=p.querySelector(".tobii__slide--is-active img"));var a=L.element.getBoundingClientRect(),o=(i-a.top)/L.scale;L.originX=(e-a.left)/L.scale,L.originY=o,L.scale=t,$(n,r)},et=function(t,e){return Math.hypot(t,e)},it=function(t,e,i,n){return{x:(t+i)/2,y:(e+n)/2}},nt=function(){L.scale=1,L.originX=0,L.originY=0,L.translateX=0,L.translateY=0,$(0,0)},rt=function(){d.keyboard&&window.addEventListener("keydown",V),window.addEventListener("resize",H),window.addEventListener("popstate",N),pt("click",B),d.draggable&&(pt("pointerdown",W),pt("pointermove",G),pt("pointerup",J),pt("pointercancel",j),pt("pointerout",j),pt("pointerleave",j),pt("contextmenu",j)),pt("wheel",K)},at=function(){d.keyboard&&window.removeEventListener("keydown",V),window.removeEventListener("resize",H),window.removeEventListener("popstate",N),ft("click",B),d.draggable&&(ft("pointerdown",W),ft("pointermove",G),ft("pointerup",J),ft("pointercancel",j),ft("pointerout",j),ft("pointerleave",j),ft("contextmenu",j)),ft("wheel",K)},ot=function(){d.draggable&&!w[A].slider.classList.contains("tobii__slider--is-draggable")&&w[A].slider.classList.add("tobii__slider--is-draggable"),!d.nav||1===w[A].elementsLength||"auto"===d.nav&&ut()?(f.setAttribute("aria-hidden","true"),f.disabled=!0,b.setAttribute("aria-hidden","true"),b.disabled=!0):(f.setAttribute("aria-hidden","false"),f.disabled=!1,b.setAttribute("aria-hidden","false"),b.disabled=!1),g.setAttribute("aria-hidden",d.counter&&1!==w[A].elementsLength?"false":"true")},st=function(t){void 0===t&&(t=null),z(),g.textContent=w[A].currentIndex+1+"/"+w[A].elementsLength,function(t){(!0===d.nav||"auto"===d.nav)&&!ut()&&w[A].elementsLength>1?(f.setAttribute("aria-hidden","true"),f.disabled=!0,b.setAttribute("aria-hidden","true"),b.disabled=!0,1===w[A].elementsLength?d.close&&h.focus():0===w[A].currentIndex?(b.setAttribute("aria-hidden","false"),b.disabled=!1,b.focus()):w[A].currentIndex===w[A].elementsLength-1?(f.setAttribute("aria-hidden","false"),f.disabled=!1,f.focus()):(f.setAttribute("aria-hidden","false"),f.disabled=!1,b.setAttribute("aria-hidden","false"),b.disabled=!1,"left"===t?f.focus():b.focus())):d.close&&h.focus()}(t)},lt=function(){dt()&&N();var t=Object.entries(w);for(var e in t.forEach(function(t){t[1].gallery.forEach(function(t){Y(t)})}),w={},A=null,s)s[e].onReset()},dt=function(){return"false"===p.getAttribute("aria-hidden")},ut=function(){return"ontouchstart"in window},ct=function(t){return-1!==["TEXTAREA","OPTION","INPUT","SELECT"].indexOf(t.nodeName)||t===f||t===b||t===h},pt=function(t,e){p.addEventListener(t,e)},ft=function(t,e){p.removeEventListener(t,e)};return function(t){if(document.querySelector("div.tobii"))console.log("Multiple lightbox instances not supported.");else{d=function(t){return e({},{selector:".lightbox",captions:!0,captionsSelector:"img",captionAttribute:"alt",captionText:null,captionHTML:!1,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,modal:!1,theme:"tobii--theme-default"},t)}(t),p||((p=document.createElement("div")).setAttribute("role","dialog"),p.setAttribute("aria-hidden","true"),p.classList.add("tobii"),p.classList.add(d.theme),(f=document.createElement("button")).className="tobii__btn tobii__btn--previous",f.setAttribute("type","button"),f.setAttribute("aria-label",d.navLabel[0]),f.innerHTML=d.navText[0],p.appendChild(f),(b=document.createElement("button")).className="tobii__btn tobii__btn--next",b.setAttribute("type","button"),b.setAttribute("aria-label",d.navLabel[1]),b.innerHTML=d.navText[1],p.appendChild(b),(h=document.createElement("button")).className="tobii__btn tobii__btn--close",h.setAttribute("type","button"),h.setAttribute("aria-label",d.closeLabel),h.innerHTML=d.closeText,p.appendChild(h),(g=document.createElement("div")).className="tobii__counter",p.appendChild(g),document.body.appendChild(p));var i=document.querySelectorAll(d.selector);if(!i)throw new Error("Ups, I can't find the selector "+d.selector+" on this website.");var n=[];i.forEach(function(t){var e=t.hasAttribute("data-group")?t.getAttribute("data-group"):"default",i=t.href;t.hasAttribute("data-target")&&(i=t.getAttribute("data-target")),void 0!==n[i+="__"+e]?t.addEventListener("click",function(t){k(e),X(),t.preventDefault()}):(n[i]=1,I(t))})}}(t),o.open=X,o.previous=O,o.next=P,o.close=N,o.add=I,o.remove=Y,o.reset=lt,o.destroy=function(){lt(),p.parentNode.removeChild(p)},o.isOpen=dt,o.slidesIndex=function(){return w[A].currentIndex},o.select=function(t){var e=w[A].currentIndex;if(!dt())throw new Error("Ups, I'm closed.");if(dt()){if(!t&&0!==t)throw new Error("Ups, no slide specified.");if(t===w[A].currentIndex)throw new Error("Ups, slide "+t+" is already selected.");if(-1===t||t>=w[A].elementsLength)throw new Error("Ups, I can't find slide "+t+".")}w[A].currentIndex=t,R(e),M(t),te&&(st("right"),U(e),q(t+1))},o.slidesCount=function(){return w[A].elementsLength},o.selectGroup=k,o.currentGroup=function(){return A},o.on=pt,o.off=ft,o}typeof module<"u"?module.exports=o:self.Tobii=o}(); diff --git a/dist/tobii.modern.js b/dist/tobii.modern.js index 0f8b39e..66bb5ff 100644 --- a/dist/tobii.modern.js +++ b/dist/tobii.modern.js @@ -1 +1 @@ -function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t{e.removeChild(r),i.style.opacity="1"}),t.addEventListener("error",()=>{e.removeChild(r),i.style.opacity="1"}),t.setAttribute("src",t.getAttribute("data-src")),t.removeAttribute("data-src"),t.hasAttribute("data-srcset")&&t.setAttribute("srcset",t.getAttribute("data-srcset"))}onLeave(e){}onCleanup(e){}onReset(){this.figcaptionId=0}}class i{constructor(){this.userSettings=null}init(e,t,i){this.userSettings=i;const r=e.hasAttribute("data-target")?e.getAttribute("data-target"):e.getAttribute("href");t.setAttribute("data-HREF",r),e.getAttribute("data-allow")&&t.setAttribute("data-allow",e.getAttribute("data-allow")),e.hasAttribute("data-width")&&t.setAttribute("data-width",`${e.getAttribute("data-width")}`),e.hasAttribute("data-height")&&t.setAttribute("data-height",`${e.getAttribute("data-height")}`),t.setAttribute("data-type","iframe"),t.classList.add("tobii-iframe")}onPreload(e){}onLoad(e){let t=e.querySelector("iframe");const i=document.createElement("div");if(i.className="tobii__loader",i.setAttribute("role","progressbar"),i.setAttribute("aria-label",this.userSettings.loadingIndicatorLabel),e.appendChild(i),null==t){t=document.createElement("iframe");const i=e.getAttribute("data-href");t.setAttribute("frameborder","0"),t.setAttribute("src",i),t.setAttribute("allowfullscreen",""),i.indexOf("youtube.com")>-1?t.setAttribute("allow","accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"):i.indexOf("vimeo.com")>-1?t.setAttribute("allow","autoplay; picture-in-picture"):e.hasAttribute("data-allow")&&t.setAttribute("allow",e.getAttribute("data-allow")),e.getAttribute("data-width")&&(t.style.maxWidth=`${e.getAttribute("data-width")}`),e.getAttribute("data-height")&&(t.style.maxHeight=`${e.getAttribute("data-height")}`),t.style.opacity="0",e.appendChild(t),t.addEventListener("load",()=>{t.style.opacity="1";const i=e.querySelector(".tobii__loader");i&&e.removeChild(i)}),t.addEventListener("error",()=>{t.style.opacity="1";const i=e.querySelector(".tobii__loader");i&&e.removeChild(i)})}else t.setAttribute("src",e.getAttribute("data-href"))}onLeave(e){}onCleanup(e){const t=e.querySelector("iframe");t.setAttribute("src",""),t.style.opacity="0"}onReset(){}}class r{constructor(){this.userSettings=null}init(e,t,i){this.userSettings=i;const r=e.hasAttribute("data-target")?e.getAttribute("data-target"):e.getAttribute("href"),n=document.querySelector(r).cloneNode(!0);if(!n)throw new Error(`Ups, I can't find the target ${r}.`);t.appendChild(n),t.setAttribute("data-type","html"),t.classList.add("tobii-html")}onPreload(e){}onLoad(e,t){const i=e.querySelector("video");i&&(i.hasAttribute("data-time")&&i.readyState>0&&(i.currentTime=i.getAttribute("data-time")),this.userSettings.autoplayVideo&&i.play());const r=e.querySelector("audio");r&&this.userSettings.autoplayAudio&&r.play(),e.classList.add("tobii-group-"+t)}onLeave(e){const t=e.querySelector("video");t&&(t.paused||t.pause(),t.readyState>0&&t.setAttribute("data-time",t.currentTime));const i=e.querySelector("audio");i&&(i.paused||i.pause())}onCleanup(e){const t=e.querySelector("video");if(t&&t.readyState>0&&t.readyState<3&&t.duration!==t.currentTime){const i=t.cloneNode(!0);this._removeSources(t),t.load(),t.parentNode.removeChild(t),e.appendChild(i)}}onReset(){}_removeSources(e){const t=e.querySelectorAll("src");t&&t.forEach(e=>{e.setAttribute("src","")})}}class n{constructor(){this.playerId=0,this.PLAYER=[],this.userSettings=null}init(e,t,i){this.userSettings=i;const r=document.createElement("div");t.appendChild(r),this.PLAYER[this.playerId]=new window.YT.Player(r,{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",this.playerId),t.setAttribute("data-type","youtube"),t.classList.add("tobii-youtube"),this.playerId++}onPreload(e){}onLoad(e){this.userSettings.autoplayVideo&&this.PLAYER[e.getAttribute("data-player")].playVideo()}onLeave(e){1===this.PLAYER[e.getAttribute("data-player")].getPlayerState()&&this.PLAYER[e.getAttribute("data-player")].pauseVideo()}onCleanup(e){1===this.PLAYER[e.getAttribute("data-player")].getPlayerState()&&this.PLAYER[e.getAttribute("data-player")].pauseVideo()}onReset(){}}function a(s){const o={image:new t,html:new r,iframe:new i,youtube:new n},l=['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])'];let d={};const c=[],u={gallery:[],slider:null,sliderElements:[],elementsLength:0,currentIndex:0,x:0};let p=null,h=null,b=null,g=null,m=null,y=null,f=null,w=!1,v={},A=null,x=[],E=0;const L={element:null,originX:0,originY:0,translateX:0,translateY:0,scale:1},_={startX:0,startY:0,x:0,y:0,distance:0},I=e=>{if(null===document.querySelector('[data-type="youtube"]')||w)C(e);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===c.indexOf(e)&&c.push(e),window.onYouTubePlayerAPIReady=()=>{c.forEach(e=>{C(e)}),w=!0}}},S=e=>e.hasAttribute("data-group")?e.getAttribute("data-group"):"default",C=e=>{const t=S(e);if(Object.prototype.hasOwnProperty.call(v,t)||(v[t]=JSON.parse(JSON.stringify(u)),v[t].slider=document.createElement("div"),v[t].slider.className="tobii__slider",v[t].slider.setAttribute("aria-hidden","true"),p.appendChild(v[t].slider)),-1!==v[t].gallery.indexOf(e))throw new Error("Ups, element already added.");{if(v[t].gallery.push(e),v[t].elementsLength++,d.zoom&&e.querySelector("img")&&"false"!==e.getAttribute("data-zoom")||"true"===e.getAttribute("data-zoom")){const t=document.createElement("div");t.className="tobii-zoom__icon",t.innerHTML=d.zoomText,e.classList.add("tobii-zoom"),e.appendChild(t)}e.addEventListener("click",H);const i=T(e),r=document.createElement("div"),n=document.createElement("div");r.className="tobii__slide",r.style.position="absolute",r.style.left=100*v[t].x+"%",r.setAttribute("aria-hidden","true"),i.init(e,n,d),r.appendChild(n),v[t].slider.appendChild(r),v[t].sliderElements.push(r),++v[t].x,de()&&t===A&&(se(),oe())}},Y=e=>{const t=S(e);if(-1===v[t].gallery.indexOf(e))throw new Error(`Ups, I can't find a slide for the element ${e}.`);{const i=v[t].gallery.indexOf(e),r=v[t].sliderElements[i];if(de()&&t===A&&i===v[t].currentIndex){if(1===v[t].elementsLength)throw q(),new Error("Ups, I've closed. There are no slides more to show.");0===v[t].currentIndex?P():O(),se(),oe()}if(v[t].gallery.splice(v[t].gallery.indexOf(e)),v[t].sliderElements.splice(v[t].gallery.indexOf(e)),v[t].elementsLength--,--v[t].x,d.zoom&&e.querySelector(".tobii-zoom__icon")){const t=e.querySelector(".tobii-zoom__icon");t.parentNode.classList.remove("tobii-zoom"),t.parentNode.removeChild(t)}e.removeEventListener("click",H),r.parentNode.removeChild(r)}},T=e=>{const t=e.getAttribute("data-type");return void 0!==o[t]?o[t]:(e.hasAttribute("data-type")&&console.log("Unknown lightbox element type: "+t),o.image)},X=(e=0)=>{if(de())throw new Error("Ups, I'm aleady open.");if(-1===e||e>=v[A].elementsLength)throw new Error(`Ups, I can't find slide ${e}.`);document.documentElement.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open-"+A),se(),d.close||(g.disabled=!1,g.setAttribute("aria-hidden","true")),y=document.activeElement;const t=window.location.href;window.history.pushState({tobii:"close"},"Image",t),v[A].currentIndex=e,ne(),N(v[A].currentIndex),v[A].slider.setAttribute("aria-hidden","false"),p.setAttribute("aria-hidden","false"),oe(),M(v[A].currentIndex+1),M(v[A].currentIndex-1),v[A].slider.classList.add("tobii__slider--animate");const i=new window.CustomEvent("open",{detail:{group:A}});p.dispatchEvent(i)},q=()=>{if(!de())throw new Error("Ups, I'm already closed.");document.documentElement.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open-"+A),ae(),null!==window.history.state&&"close"===window.history.state.tobii&&window.history.back(),y.focus(),k(v[A].currentIndex),R(v[A].currentIndex),p.setAttribute("aria-hidden","true"),v[A].slider.setAttribute("aria-hidden","true"),v[A].currentIndex=0,v[A].slider.classList.remove("tobii__slider--animate");const e=new window.CustomEvent("close",{detail:{group:A}});p.dispatchEvent(e)},M=e=>{if(void 0===v[A].sliderElements[e])return;const t=v[A].sliderElements[e].querySelector("[data-type]");T(t).onPreload(t)},N=e=>{if(void 0===v[A].sliderElements[e])return;const t=v[A].sliderElements[e].querySelector("[data-type]"),i=T(t);v[A].sliderElements[e].classList.add("tobii__slide--is-active"),v[A].sliderElements[e].setAttribute("aria-hidden","false"),i.onLoad(t,A)},O=()=>{if(!de())throw new Error("Ups, I'm closed.");v[A].currentIndex>0&&(k(v[A].currentIndex),N(--v[A].currentIndex),oe("left"),R(v[A].currentIndex+1),M(v[A].currentIndex-1));const e=new window.CustomEvent("previous",{detail:{group:A}});p.dispatchEvent(e)},P=()=>{if(!de())throw new Error("Ups, I'm closed.");v[A].currentIndex{if(de())throw new Error("Ups, I'm open.");if(!e)throw new Error("Ups, no group specified.");if(e&&!Object.prototype.hasOwnProperty.call(v,e))throw new Error(`Ups, I don't have a group called "${e}".`);A=e},k=e=>{if(void 0===v[A].sliderElements[e])return;const t=v[A].sliderElements[e].querySelector("[data-type]"),i=T(t);v[A].sliderElements[e].classList.remove("tobii__slide--is-active"),v[A].sliderElements[e].setAttribute("aria-hidden","true"),i.onLeave(t)},R=e=>{if(void 0===v[A].sliderElements[e])return;const t=v[A].sliderElements[e].querySelector("[data-type]");T(t).onCleanup(t),_.startX=0,_.startY=0,_.x=0,_.y=0,_.distance=0,E=0,re()},U=()=>{f=-v[A].currentIndex*p.offsetWidth,v[A].slider.style.transform=`translate(${f}px, 0)`},z=()=>{U()},H=e=>{e.preventDefault(),A=S(e.currentTarget),X(v[A].gallery.indexOf(e.currentTarget))},D=e=>{e.target===h?O():e.target===b?P():(e.target===g||e.target.classList.contains("tobii__slide")&&d.docClose)&&q(),e.stopPropagation()},B=e=>{const t=Array.prototype.slice.call(p.querySelectorAll(`.tobii__btn:not([disabled]), .tobii__slide--is-active ${l.join(", .tobii__slide--is-active ")}`)).filter(e=>!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length)),i=t.indexOf(document.activeElement);9===e.keyCode||"Tab"===e.code?e.shiftKey&&0===i?(t[t.length-1].focus(),e.preventDefault()):e.shiftKey||i!==t.length-1||(t[0].focus(),e.preventDefault()):27===e.keyCode||"Escape"===e.code?(e.preventDefault(),q()):37===e.keyCode||"ArrowLeft"===e.code?(e.preventDefault(),O()):39!==e.keyCode&&"ArrowRight"!==e.code||(e.preventDefault(),P())},V=()=>{x=[],U(),v[A].slider.classList.remove("tobii__slider--is-"+(Q()?"moving":"dragging"))},j=e=>{if(!ue(e.target)&&(e.preventDefault(),e.stopPropagation(),_.startX=_.x=e.clientX,_.startY=_.y=e.clientY,_.distance=0,x.push(e),2===x.length)){const{x:e,y:t}=ie(x[0].clientX,x[0].clientY,x[1].clientX,x[1].clientY);_.startX=_.x=e,_.startY=_.y=t,_.distance=te(x[0].clientX-x[1].clientX,x[0].clientY-x[1].clientY)/L.scale}},W=e=>{if(!x.length)return;v[A].slider.classList.add("tobii__slider--is-"+(Q()?"moving":"dragging"));const t=x.findIndex(t=>t.pointerId===e.pointerId);if(x[t]=e,2===x.length){const{x:e,y:t}=ie(x[0].clientX,x[0].clientY,x[1].clientX,x[1].clientY),i=te(x[0].clientX-x[1].clientX,x[0].clientY-x[1].clientY)/_.distance;return ee(F(i,1,4),e,t,e-_.x,t-_.y),_.x=e,void(_.y=t)}if(Q()&&Z(e.clientX-_.x,e.clientY-_.y),_.x=e.clientX,_.y=e.clientY,!Q()){const e=_.startX-_.x,t=_.startY-_.y;if(te(e,t)<10)return;Math.abs(e)>Math.abs(t)&&v[A].elementsLength>1?v[A].slider.style.transform=`translate(${f-Math.round(e)}px, 0)`:d.swipeClose&&(v[A].slider.style.transform=`translate(${f}px, -${Math.round(t)}px)`)}},G=e=>{if(!x.length)return;v[A].slider.classList.remove("tobii__slider--is-"+(Q()?"moving":"dragging"));const t=x.findIndex(t=>t.pointerId===e.pointerId);x.splice(t,1);const i=e.clientX,r=e.clientY,n=_.startX-i,a=_.startY-r,s=Math.abs(n),o=Math.abs(a);if(s||o)Q()||(n<0&&s>d.threshold&&v[A].currentIndex>0?O():n>0&&s>d.threshold&&v[A].currentIndex!==v[A].elementsLength-1?P():a>0&&o>d.threshold&&d.swipeClose?q():U());else{const t=(new Date).getTime(),n=t-E;n<500&&n>100?(e.preventDefault(),E=0,Q()?re():ee(2,i,r,0,0)):(E=t,ce()&&window.setTimeout(()=>{const{left:t,top:n,bottom:a,right:s,width:o}=e.target.getBoundingClientRect();ra||!E||(i>t&&is-o/2&&P())},500))}},J=e=>{const t=Math.sign(e.deltaY)>0?-1:1;(Q()||t)&&(e.preventDefault(),ee(F(L.scale+t/(10/L.scale),1,4),e.clientX,e.clientY,0,0))},K=(e,t)=>{const{element:i,scale:r,originX:n,originY:a}=L,s="x"===e,o=s?n:a,l=s?"offsetWidth":"offsetHeight",d=i.parentNode[l],c=i[l],u=i.getBoundingClientRect(),p=(o-c/2)*(r-1),h=Math.max(0,Math.round(s?u.width:u.height)-d),b=Math.round(h/2);return F(t,0-b+p,b+p)},F=(e,t,i)=>Math.max(Math.min(e,i),t),Q=()=>1!==L.scale,Z=(e,t)=>{0!==e&&(L.translateX=K("x",L.translateX+e)),0!==t&&(L.translateY=K("y",L.translateY+t));const{element:i,originX:r,originY:n,translateX:a,translateY:s,scale:o}=L;i.style.transformOrigin=`${r}px ${n}px`,i.style.transform=`translate(${a}px, ${s}px) scale(${o})`},ee=(e,t,i,r,n)=>{L.element||(L.element=p.querySelector(".tobii__slide--is-active img"));const{left:a,top:s}=L.element.getBoundingClientRect(),o=(i-s)/L.scale;L.originX=(t-a)/L.scale,L.originY=o,L.scale=e,Z(r,n)},te=(e,t)=>Math.hypot(e,t),ie=(e,t,i,r)=>({x:(e+i)/2,y:(t+r)/2}),re=()=>{L.scale=1,L.originX=0,L.originY=0,L.translateX=0,L.translateY=0,Z(0,0),L.element=null},ne=()=>{d.keyboard&&window.addEventListener("keydown",B),window.addEventListener("resize",z),window.addEventListener("popstate",q),pe("click",D),d.draggable&&(pe("pointerdown",j),pe("pointermove",W),pe("pointerup",G),pe("pointercancel",V),pe("pointerout",V),pe("pointerleave",V),pe("contextmenu",V)),pe("wheel",J)},ae=()=>{d.keyboard&&window.removeEventListener("keydown",B),window.removeEventListener("resize",z),window.removeEventListener("popstate",q),he("click",D),d.draggable&&(he("pointerdown",j),he("pointermove",W),he("pointerup",G),he("pointercancel",V),he("pointerout",V),he("pointerleave",V),he("contextmenu",V)),he("wheel",J)},se=()=>{d.draggable&&!v[A].slider.classList.contains("tobii__slider--is-draggable")&&v[A].slider.classList.add("tobii__slider--is-draggable"),!d.nav||1===v[A].elementsLength||"auto"===d.nav&&ce()?(h.setAttribute("aria-hidden","true"),h.disabled=!0,b.setAttribute("aria-hidden","true"),b.disabled=!0):(h.setAttribute("aria-hidden","false"),h.disabled=!1,b.setAttribute("aria-hidden","false"),b.disabled=!1),m.setAttribute("aria-hidden",d.counter&&1!==v[A].elementsLength?"false":"true")},oe=(e=null)=>{U(),m.textContent=`${v[A].currentIndex+1}/${v[A].elementsLength}`,(e=>{(!0===d.nav||"auto"===d.nav)&&!ce()&&v[A].elementsLength>1?(h.setAttribute("aria-hidden","true"),h.disabled=!0,b.setAttribute("aria-hidden","true"),b.disabled=!0,1===v[A].elementsLength?d.close&&g.focus():0===v[A].currentIndex?(b.setAttribute("aria-hidden","false"),b.disabled=!1,b.focus()):v[A].currentIndex===v[A].elementsLength-1?(h.setAttribute("aria-hidden","false"),h.disabled=!1,h.focus()):(h.setAttribute("aria-hidden","false"),h.disabled=!1,b.setAttribute("aria-hidden","false"),b.disabled=!1,"left"===e?h.focus():b.focus())):d.close&&g.focus()})(e)},le=()=>{de()&&q(),Object.entries(v).forEach(e=>{e[1].gallery.forEach(e=>{Y(e)})}),v={},A=null;for(const e in o)o[e].onReset()},de=()=>"false"===p.getAttribute("aria-hidden"),ce=()=>"ontouchstart"in window,ue=e=>-1!==["TEXTAREA","OPTION","INPUT","SELECT"].indexOf(e.nodeName)||e===h||e===b||e===g,pe=(e,t)=>{p.addEventListener(e,t)},he=(e,t)=>{p.removeEventListener(e,t)};return(t=>{if(document.querySelector("div.tobii"))return void console.log("Multiple lightbox instances not supported.");d=(t=>e({},{selector:".lightbox",captions:!0,captionsSelector:"img",captionAttribute:"alt",captionText:null,captionHTML:!1,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,modal:!1,theme:"tobii--theme-default"},t))(t),p||(p=document.createElement("div"),p.setAttribute("role","dialog"),p.setAttribute("aria-hidden","true"),p.classList.add("tobii"),p.classList.add(d.theme),h=document.createElement("button"),h.className="tobii__btn tobii__btn--previous",h.setAttribute("type","button"),h.setAttribute("aria-label",d.navLabel[0]),h.innerHTML=d.navText[0],p.appendChild(h),b=document.createElement("button"),b.className="tobii__btn tobii__btn--next",b.setAttribute("type","button"),b.setAttribute("aria-label",d.navLabel[1]),b.innerHTML=d.navText[1],p.appendChild(b),g=document.createElement("button"),g.className="tobii__btn tobii__btn--close",g.setAttribute("type","button"),g.setAttribute("aria-label",d.closeLabel),g.innerHTML=d.closeText,p.appendChild(g),m=document.createElement("div"),m.className="tobii__counter",p.appendChild(m),document.body.appendChild(p));const i=document.querySelectorAll(d.selector);if(!i)throw new Error(`Ups, I can't find the selector ${d.selector} on this website.`);const r=[];i.forEach(e=>{const t=e.hasAttribute("data-group")?e.getAttribute("data-group"):"default";let i=e.href;e.hasAttribute("data-target")&&(i=e.getAttribute("data-target")),i+="__"+t,void 0!==r[i]?e.addEventListener("click",e=>{$(t),X(),e.preventDefault()}):(r[i]=1,I(e))})})(s),a.open=X,a.previous=O,a.next=P,a.close=q,a.add=I,a.remove=Y,a.reset=le,a.destroy=()=>{le(),p.parentNode.removeChild(p)},a.isOpen=de,a.slidesIndex=()=>v[A].currentIndex,a.select=e=>{const t=v[A].currentIndex;if(!de())throw new Error("Ups, I'm closed.");if(de()){if(!e&&0!==e)throw new Error("Ups, no slide specified.");if(e===v[A].currentIndex)throw new Error(`Ups, slide ${e} is already selected.`);if(-1===e||e>=v[A].elementsLength)throw new Error(`Ups, I can't find slide ${e}.`)}v[A].currentIndex=e,k(t),N(e),et&&(oe("right"),R(t),M(e+1))},a.slidesCount=()=>v[A].elementsLength,a.selectGroup=$,a.currentGroup=()=>A,a.on=pe,a.off=he,a}export{a as default}; +function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t{e.removeChild(r),i.style.opacity="1"}),t.addEventListener("error",()=>{e.removeChild(r),i.style.opacity="1"}),t.setAttribute("src",t.getAttribute("data-src")),t.removeAttribute("data-src"),t.hasAttribute("data-srcset")&&t.setAttribute("srcset",t.getAttribute("data-srcset"))}onLeave(e){}onCleanup(e){}onReset(){this.figcaptionId=0}}class i{constructor(){this.userSettings=null}init(e,t,i){this.userSettings=i;const r=e.hasAttribute("data-target")?e.getAttribute("data-target"):e.getAttribute("href");t.setAttribute("data-HREF",r),e.getAttribute("data-allow")&&t.setAttribute("data-allow",e.getAttribute("data-allow")),e.hasAttribute("data-width")&&t.setAttribute("data-width",`${e.getAttribute("data-width")}`),e.hasAttribute("data-height")&&t.setAttribute("data-height",`${e.getAttribute("data-height")}`),t.setAttribute("data-type","iframe"),t.classList.add("tobii-iframe")}onPreload(e){}onLoad(e){let t=e.querySelector("iframe");const i=document.createElement("div");if(i.className="tobii__loader",i.setAttribute("role","progressbar"),i.setAttribute("aria-label",this.userSettings.loadingIndicatorLabel),e.appendChild(i),null==t){t=document.createElement("iframe");const i=e.getAttribute("data-href");t.setAttribute("frameborder","0"),t.setAttribute("src",i),t.setAttribute("allowfullscreen",""),i.indexOf("youtube.com")>-1?t.setAttribute("allow","accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"):i.indexOf("vimeo.com")>-1?t.setAttribute("allow","autoplay; picture-in-picture"):e.hasAttribute("data-allow")&&t.setAttribute("allow",e.getAttribute("data-allow")),e.getAttribute("data-width")&&(t.style.maxWidth=`${e.getAttribute("data-width")}`),e.getAttribute("data-height")&&(t.style.maxHeight=`${e.getAttribute("data-height")}`),t.style.opacity="0",e.appendChild(t),t.addEventListener("load",()=>{t.style.opacity="1";const i=e.querySelector(".tobii__loader");i&&e.removeChild(i)}),t.addEventListener("error",()=>{t.style.opacity="1";const i=e.querySelector(".tobii__loader");i&&e.removeChild(i)})}else t.setAttribute("src",e.getAttribute("data-href"))}onLeave(e){}onCleanup(e){const t=e.querySelector("iframe");t.setAttribute("src",""),t.style.opacity="0"}onReset(){}}class r{constructor(){this.userSettings=null}init(e,t,i){this.userSettings=i;const r=e.hasAttribute("data-target")?e.getAttribute("data-target"):e.getAttribute("href"),n=document.querySelector(r).cloneNode(!0);if(!n)throw new Error(`Ups, I can't find the target ${r}.`);t.appendChild(n),t.setAttribute("data-type","html"),t.classList.add("tobii-html")}onPreload(e){}onLoad(e,t){const i=e.querySelector("video");i&&(i.hasAttribute("data-time")&&i.readyState>0&&(i.currentTime=i.getAttribute("data-time")),this.userSettings.autoplayVideo&&i.play());const r=e.querySelector("audio");r&&this.userSettings.autoplayAudio&&r.play(),e.classList.add("tobii-group-"+t)}onLeave(e){const t=e.querySelector("video");t&&(t.paused||t.pause(),t.readyState>0&&t.setAttribute("data-time",t.currentTime));const i=e.querySelector("audio");i&&(i.paused||i.pause())}onCleanup(e){const t=e.querySelector("video");if(t&&t.readyState>0&&t.readyState<3&&t.duration!==t.currentTime){const i=t.cloneNode(!0);this._removeSources(t),t.load(),t.parentNode.removeChild(t),e.appendChild(i)}}onReset(){}_removeSources(e){const t=e.querySelectorAll("src");t&&t.forEach(e=>{e.setAttribute("src","")})}}class n{constructor(){this.playerId=0,this.PLAYER=[],this.userSettings=null}init(e,t,i){this.userSettings=i;const r=document.createElement("div");t.appendChild(r),this.PLAYER[this.playerId]=new window.YT.Player(r,{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",this.playerId),t.setAttribute("data-type","youtube"),t.classList.add("tobii-youtube"),this.playerId++}onPreload(e){}onLoad(e){this.userSettings.autoplayVideo&&this.PLAYER[e.getAttribute("data-player")].playVideo()}onLeave(e){1===this.PLAYER[e.getAttribute("data-player")].getPlayerState()&&this.PLAYER[e.getAttribute("data-player")].pauseVideo()}onCleanup(e){1===this.PLAYER[e.getAttribute("data-player")].getPlayerState()&&this.PLAYER[e.getAttribute("data-player")].pauseVideo()}onReset(){}}function a(s){const o={image:new t,html:new r,iframe:new i,youtube:new n},l=['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])'];let d={};const c=[],u={gallery:[],slider:null,sliderElements:[],elementsLength:0,currentIndex:0,x:0};let p=null,h=null,b=null,g=null,m=null,y=null,f=null,w=!1,v={},A=null,x=[],E=0;const L={element:null,originX:0,originY:0,translateX:0,translateY:0,scale:1},_={startX:0,startY:0,x:0,y:0,distance:0},I=e=>{if(null===document.querySelector('[data-type="youtube"]')||w)C(e);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===c.indexOf(e)&&c.push(e),window.onYouTubePlayerAPIReady=()=>{c.forEach(e=>{C(e)}),w=!0}}},S=e=>e.hasAttribute("data-group")?e.getAttribute("data-group"):"default",C=e=>{const t=S(e);if(Object.prototype.hasOwnProperty.call(v,t)||(v[t]=JSON.parse(JSON.stringify(u)),v[t].slider=document.createElement("div"),v[t].slider.className="tobii__slider",v[t].slider.setAttribute("aria-hidden","true"),p.appendChild(v[t].slider)),-1!==v[t].gallery.indexOf(e))throw new Error("Ups, element already added.");{if(v[t].gallery.push(e),v[t].elementsLength++,d.zoom&&e.querySelector("img")&&"false"!==e.getAttribute("data-zoom")||"true"===e.getAttribute("data-zoom")){const t=document.createElement("div");t.className="tobii-zoom__icon",t.innerHTML=d.zoomText,e.classList.add("tobii-zoom"),e.appendChild(t)}e.addEventListener("click",H);const i=T(e),r=document.createElement("div"),n=document.createElement("div");r.className="tobii__slide",r.style.position="absolute",r.style.left=100*v[t].x+"%",r.setAttribute("aria-hidden","true"),i.init(e,n,d),r.appendChild(n),v[t].slider.appendChild(r),v[t].sliderElements.push(r),++v[t].x,de()&&t===A&&(se(),oe())}},Y=e=>{const t=S(e);if(-1===v[t].gallery.indexOf(e))throw new Error(`Ups, I can't find a slide for the element ${e}.`);{const i=v[t].gallery.indexOf(e),r=v[t].sliderElements[i];if(de()&&t===A&&i===v[t].currentIndex){if(1===v[t].elementsLength)throw q(),new Error("Ups, I've closed. There are no slides more to show.");0===v[t].currentIndex?P():O(),se(),oe()}if(v[t].gallery.splice(v[t].gallery.indexOf(e)),v[t].sliderElements.splice(v[t].gallery.indexOf(e)),v[t].elementsLength--,--v[t].x,d.zoom&&e.querySelector(".tobii-zoom__icon")){const t=e.querySelector(".tobii-zoom__icon");t.parentNode.classList.remove("tobii-zoom"),t.parentNode.removeChild(t)}e.removeEventListener("click",H),r.parentNode.removeChild(r)}},T=e=>{const t=e.getAttribute("data-type");return void 0!==o[t]?o[t]:(e.hasAttribute("data-type")&&console.log("Unknown lightbox element type: "+t),o.image)},X=(e=0)=>{if(de())throw new Error("Ups, I'm aleady open.");if(-1===e||e>=v[A].elementsLength)throw new Error(`Ups, I can't find slide ${e}.`);document.documentElement.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open-"+A),se(),d.close||(g.disabled=!1,g.setAttribute("aria-hidden","true")),y=document.activeElement;const t=window.location.href;window.history.pushState({tobii:"close"},"Image",t),v[A].currentIndex=e,ne(),N(v[A].currentIndex),v[A].slider.setAttribute("aria-hidden","false"),p.setAttribute("aria-hidden","false"),oe(),M(v[A].currentIndex+1),M(v[A].currentIndex-1),v[A].slider.classList.add("tobii__slider--animate");const i=new window.CustomEvent("open",{detail:{group:A}});p.dispatchEvent(i)},q=()=>{if(!de())throw new Error("Ups, I'm already closed.");document.documentElement.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open-"+A),ae(),null!==window.history.state&&"close"===window.history.state.tobii&&window.history.back(),y.focus(),k(v[A].currentIndex),R(v[A].currentIndex),p.setAttribute("aria-hidden","true"),v[A].slider.setAttribute("aria-hidden","true"),v[A].currentIndex=0,v[A].slider.classList.remove("tobii__slider--animate");const e=new window.CustomEvent("close",{detail:{group:A}});p.dispatchEvent(e)},M=e=>{if(void 0===v[A].sliderElements[e])return;const t=v[A].sliderElements[e].querySelector("[data-type]");T(t).onPreload(t)},N=e=>{if(void 0===v[A].sliderElements[e])return;const t=v[A].sliderElements[e].querySelector("[data-type]"),i=T(t);v[A].sliderElements[e].classList.add("tobii__slide--is-active"),v[A].sliderElements[e].setAttribute("aria-hidden","false"),i.onLoad(t,A)},O=()=>{if(!de())throw new Error("Ups, I'm closed.");v[A].currentIndex>0&&(k(v[A].currentIndex),N(--v[A].currentIndex),oe("left"),R(v[A].currentIndex+1),M(v[A].currentIndex-1));const e=new window.CustomEvent("previous",{detail:{group:A}});p.dispatchEvent(e)},P=()=>{if(!de())throw new Error("Ups, I'm closed.");v[A].currentIndex{if(de())throw new Error("Ups, I'm open.");if(!e)throw new Error("Ups, no group specified.");if(e&&!Object.prototype.hasOwnProperty.call(v,e))throw new Error(`Ups, I don't have a group called "${e}".`);A=e},k=e=>{if(void 0===v[A].sliderElements[e])return;const t=v[A].sliderElements[e].querySelector("[data-type]"),i=T(t);v[A].sliderElements[e].classList.remove("tobii__slide--is-active"),v[A].sliderElements[e].setAttribute("aria-hidden","true"),i.onLeave(t)},R=e=>{if(void 0===v[A].sliderElements[e])return;const t=v[A].sliderElements[e].querySelector("[data-type]");T(t).onCleanup(t),_.startX=0,_.startY=0,_.x=0,_.y=0,_.distance=0,E=0,Q()&&re(),L.element=null},U=()=>{f=-v[A].currentIndex*p.offsetWidth,v[A].slider.style.transform=`translate(${f}px, 0)`},z=()=>{U()},H=e=>{e.preventDefault(),A=S(e.currentTarget),X(v[A].gallery.indexOf(e.currentTarget))},D=e=>{e.target===h?O():e.target===b?P():(e.target===g||e.target.classList.contains("tobii__slide")&&d.docClose)&&q(),e.stopPropagation()},B=e=>{const t=Array.prototype.slice.call(p.querySelectorAll(`.tobii__btn:not([disabled]), .tobii__slide--is-active ${l.join(", .tobii__slide--is-active ")}`)).filter(e=>!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length)),i=t.indexOf(document.activeElement);9===e.keyCode||"Tab"===e.code?e.shiftKey&&0===i?(t[t.length-1].focus(),e.preventDefault()):e.shiftKey||i!==t.length-1||(t[0].focus(),e.preventDefault()):27===e.keyCode||"Escape"===e.code?(e.preventDefault(),q()):37===e.keyCode||"ArrowLeft"===e.code?(e.preventDefault(),O()):39!==e.keyCode&&"ArrowRight"!==e.code||(e.preventDefault(),P())},V=()=>{x=[],U(),v[A].slider.classList.remove("tobii__slider--is-"+(Q()?"moving":"dragging"))},j=e=>{if(!ue(e.target)&&(e.preventDefault(),e.stopPropagation(),_.startX=_.x=e.clientX,_.startY=_.y=e.clientY,_.distance=0,x.push(e),2===x.length)){const{x:e,y:t}=ie(x[0].clientX,x[0].clientY,x[1].clientX,x[1].clientY);_.startX=_.x=e,_.startY=_.y=t,_.distance=te(x[0].clientX-x[1].clientX,x[0].clientY-x[1].clientY)/L.scale}},W=e=>{if(!x.length)return;v[A].slider.classList.add("tobii__slider--is-"+(Q()?"moving":"dragging"));const t=x.findIndex(t=>t.pointerId===e.pointerId);if(x[t]=e,2===x.length){const{x:e,y:t}=ie(x[0].clientX,x[0].clientY,x[1].clientX,x[1].clientY),i=te(x[0].clientX-x[1].clientX,x[0].clientY-x[1].clientY)/_.distance;return ee(F(i,1,4),e,t,e-_.x,t-_.y),_.x=e,void(_.y=t)}if(Q()&&Z(e.clientX-_.x,e.clientY-_.y),_.x=e.clientX,_.y=e.clientY,!Q()){const e=_.startX-_.x,t=_.startY-_.y;if(te(e,t)<10)return;Math.abs(e)>Math.abs(t)&&v[A].elementsLength>1?v[A].slider.style.transform=`translate(${f-Math.round(e)}px, 0)`:d.swipeClose&&(v[A].slider.style.transform=`translate(${f}px, -${Math.round(t)}px)`)}},G=e=>{if(!x.length)return;v[A].slider.classList.remove("tobii__slider--is-"+(Q()?"moving":"dragging"));const t=x.findIndex(t=>t.pointerId===e.pointerId);x.splice(t,1);const i=e.clientX,r=e.clientY,n=_.startX-i,a=_.startY-r,s=Math.abs(n),o=Math.abs(a);if(s||o)Q()||(n<0&&s>d.threshold&&v[A].currentIndex>0?O():n>0&&s>d.threshold&&v[A].currentIndex!==v[A].elementsLength-1?P():a>0&&o>d.threshold&&d.swipeClose?q():U());else{const t=(new Date).getTime(),n=t-E;n<500&&n>100?(e.preventDefault(),E=0,Q()?re():ee(2,i,r,0,0)):(E=t,ce()&&window.setTimeout(()=>{const{left:t,top:n,bottom:a,right:s,width:o}=e.target.getBoundingClientRect();ra||!E||(i>t&&is-o/2&&P())},500))}},J=e=>{const t=Math.sign(e.deltaY)>0?-1:1;(Q()||t)&&(e.preventDefault(),ee(F(L.scale+t/(10/L.scale),1,4),e.clientX,e.clientY,0,0))},K=(e,t)=>{const{element:i,scale:r,originX:n,originY:a}=L,s="x"===e,o=s?n:a,l=s?"offsetWidth":"offsetHeight",d=i.parentNode[l],c=i[l],u=i.getBoundingClientRect(),p=(o-c/2)*(r-1),h=Math.max(0,Math.round(s?u.width:u.height)-d),b=Math.round(h/2);return F(t,0-b+p,b+p)},F=(e,t,i)=>Math.max(Math.min(e,i),t),Q=()=>1!==L.scale,Z=(e,t)=>{0!==e&&(L.translateX=K("x",L.translateX+e)),0!==t&&(L.translateY=K("y",L.translateY+t));const{element:i,originX:r,originY:n,translateX:a,translateY:s,scale:o}=L;i.style.transformOrigin=`${r}px ${n}px`,i.style.transform=`translate(${a}px, ${s}px) scale(${o})`},ee=(e,t,i,r,n)=>{L.element||(L.element=p.querySelector(".tobii__slide--is-active img"));const{left:a,top:s}=L.element.getBoundingClientRect(),o=(i-s)/L.scale;L.originX=(t-a)/L.scale,L.originY=o,L.scale=e,Z(r,n)},te=(e,t)=>Math.hypot(e,t),ie=(e,t,i,r)=>({x:(e+i)/2,y:(t+r)/2}),re=()=>{L.scale=1,L.originX=0,L.originY=0,L.translateX=0,L.translateY=0,Z(0,0)},ne=()=>{d.keyboard&&window.addEventListener("keydown",B),window.addEventListener("resize",z),window.addEventListener("popstate",q),pe("click",D),d.draggable&&(pe("pointerdown",j),pe("pointermove",W),pe("pointerup",G),pe("pointercancel",V),pe("pointerout",V),pe("pointerleave",V),pe("contextmenu",V)),pe("wheel",J)},ae=()=>{d.keyboard&&window.removeEventListener("keydown",B),window.removeEventListener("resize",z),window.removeEventListener("popstate",q),he("click",D),d.draggable&&(he("pointerdown",j),he("pointermove",W),he("pointerup",G),he("pointercancel",V),he("pointerout",V),he("pointerleave",V),he("contextmenu",V)),he("wheel",J)},se=()=>{d.draggable&&!v[A].slider.classList.contains("tobii__slider--is-draggable")&&v[A].slider.classList.add("tobii__slider--is-draggable"),!d.nav||1===v[A].elementsLength||"auto"===d.nav&&ce()?(h.setAttribute("aria-hidden","true"),h.disabled=!0,b.setAttribute("aria-hidden","true"),b.disabled=!0):(h.setAttribute("aria-hidden","false"),h.disabled=!1,b.setAttribute("aria-hidden","false"),b.disabled=!1),m.setAttribute("aria-hidden",d.counter&&1!==v[A].elementsLength?"false":"true")},oe=(e=null)=>{U(),m.textContent=`${v[A].currentIndex+1}/${v[A].elementsLength}`,(e=>{(!0===d.nav||"auto"===d.nav)&&!ce()&&v[A].elementsLength>1?(h.setAttribute("aria-hidden","true"),h.disabled=!0,b.setAttribute("aria-hidden","true"),b.disabled=!0,1===v[A].elementsLength?d.close&&g.focus():0===v[A].currentIndex?(b.setAttribute("aria-hidden","false"),b.disabled=!1,b.focus()):v[A].currentIndex===v[A].elementsLength-1?(h.setAttribute("aria-hidden","false"),h.disabled=!1,h.focus()):(h.setAttribute("aria-hidden","false"),h.disabled=!1,b.setAttribute("aria-hidden","false"),b.disabled=!1,"left"===e?h.focus():b.focus())):d.close&&g.focus()})(e)},le=()=>{de()&&q(),Object.entries(v).forEach(e=>{e[1].gallery.forEach(e=>{Y(e)})}),v={},A=null;for(const e in o)o[e].onReset()},de=()=>"false"===p.getAttribute("aria-hidden"),ce=()=>"ontouchstart"in window,ue=e=>-1!==["TEXTAREA","OPTION","INPUT","SELECT"].indexOf(e.nodeName)||e===h||e===b||e===g,pe=(e,t)=>{p.addEventListener(e,t)},he=(e,t)=>{p.removeEventListener(e,t)};return(t=>{if(document.querySelector("div.tobii"))return void console.log("Multiple lightbox instances not supported.");d=(t=>e({},{selector:".lightbox",captions:!0,captionsSelector:"img",captionAttribute:"alt",captionText:null,captionHTML:!1,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,modal:!1,theme:"tobii--theme-default"},t))(t),p||(p=document.createElement("div"),p.setAttribute("role","dialog"),p.setAttribute("aria-hidden","true"),p.classList.add("tobii"),p.classList.add(d.theme),h=document.createElement("button"),h.className="tobii__btn tobii__btn--previous",h.setAttribute("type","button"),h.setAttribute("aria-label",d.navLabel[0]),h.innerHTML=d.navText[0],p.appendChild(h),b=document.createElement("button"),b.className="tobii__btn tobii__btn--next",b.setAttribute("type","button"),b.setAttribute("aria-label",d.navLabel[1]),b.innerHTML=d.navText[1],p.appendChild(b),g=document.createElement("button"),g.className="tobii__btn tobii__btn--close",g.setAttribute("type","button"),g.setAttribute("aria-label",d.closeLabel),g.innerHTML=d.closeText,p.appendChild(g),m=document.createElement("div"),m.className="tobii__counter",p.appendChild(m),document.body.appendChild(p));const i=document.querySelectorAll(d.selector);if(!i)throw new Error(`Ups, I can't find the selector ${d.selector} on this website.`);const r=[];i.forEach(e=>{const t=e.hasAttribute("data-group")?e.getAttribute("data-group"):"default";let i=e.href;e.hasAttribute("data-target")&&(i=e.getAttribute("data-target")),i+="__"+t,void 0!==r[i]?e.addEventListener("click",e=>{$(t),X(),e.preventDefault()}):(r[i]=1,I(e))})})(s),a.open=X,a.previous=O,a.next=P,a.close=q,a.add=I,a.remove=Y,a.reset=le,a.destroy=()=>{le(),p.parentNode.removeChild(p)},a.isOpen=de,a.slidesIndex=()=>v[A].currentIndex,a.select=e=>{const t=v[A].currentIndex;if(!de())throw new Error("Ups, I'm closed.");if(de()){if(!e&&0!==e)throw new Error("Ups, no slide specified.");if(e===v[A].currentIndex)throw new Error(`Ups, slide ${e} is already selected.`);if(-1===e||e>=v[A].elementsLength)throw new Error(`Ups, I can't find slide ${e}.`)}v[A].currentIndex=e,k(t),N(e),et&&(oe("right"),R(t),M(e+1))},a.slidesCount=()=>v[A].elementsLength,a.selectGroup=$,a.currentGroup=()=>A,a.on=pe,a.off=he,a}export{a as default}; diff --git a/dist/tobii.module.js b/dist/tobii.module.js index 58c1420..04c9e25 100644 --- a/dist/tobii.module.js +++ b/dist/tobii.module.js @@ -1 +1 @@ -class e{constructor(){this.figcaptionId=0,this.userSettings=null}init(e,t,i){this.userSettings=i;const r=document.createElement("figure"),n=document.createElement("figcaption"),a=document.createElement("img"),s=e.querySelector("img"),o=document.createElement("div");if(r.style.opacity="0",s&&(a.alt=s.alt||""),a.setAttribute("src",""),a.setAttribute("data-src",e.href),e.hasAttribute("data-srcset")&&a.setAttribute("data-srcset",e.getAttribute("data-srcset")),r.appendChild(a),this.userSettings.captions){let t;"function"==typeof this.userSettings.captionText?t=this.userSettings.captionText(e):"self"===this.userSettings.captionsSelector&&e.getAttribute(this.userSettings.captionAttribute)?t=e.getAttribute(this.userSettings.captionAttribute):"img"===this.userSettings.captionsSelector&&s&&s.getAttribute(this.userSettings.captionAttribute)&&(t=s.getAttribute(this.userSettings.captionAttribute)),this.userSettings.captionHTML?n.innerHTML=t:n.textContent=t,t&&(n.id=`tobii-figcaption-${this.figcaptionId}`,r.appendChild(n),a.setAttribute("aria-labelledby",n.id),++this.figcaptionId)}t.appendChild(r),o.className="tobii__loader",o.setAttribute("role","progressbar"),o.setAttribute("aria-label",this.userSettings.loadingIndicatorLabel),t.appendChild(o),t.setAttribute("data-type","image"),t.classList.add("tobii-image")}onPreload(e){this.onLoad(e)}onLoad(e){const t=e.querySelector("img");if(!t.hasAttribute("data-src"))return;const i=e.querySelector("figure"),r=e.querySelector(".tobii__loader");t.addEventListener("load",()=>{e.removeChild(r),i.style.opacity="1"}),t.addEventListener("error",()=>{e.removeChild(r),i.style.opacity="1"}),t.setAttribute("src",t.getAttribute("data-src")),t.removeAttribute("data-src"),t.hasAttribute("data-srcset")&&t.setAttribute("srcset",t.getAttribute("data-srcset"))}onLeave(e){}onCleanup(e){}onReset(){this.figcaptionId=0}}class t{constructor(){this.userSettings=null}init(e,t,i){this.userSettings=i;const r=e.hasAttribute("data-target")?e.getAttribute("data-target"):e.getAttribute("href");t.setAttribute("data-HREF",r),e.getAttribute("data-allow")&&t.setAttribute("data-allow",e.getAttribute("data-allow")),e.hasAttribute("data-width")&&t.setAttribute("data-width",`${e.getAttribute("data-width")}`),e.hasAttribute("data-height")&&t.setAttribute("data-height",`${e.getAttribute("data-height")}`),t.setAttribute("data-type","iframe"),t.classList.add("tobii-iframe")}onPreload(e){}onLoad(e){let t=e.querySelector("iframe");const i=document.createElement("div");if(i.className="tobii__loader",i.setAttribute("role","progressbar"),i.setAttribute("aria-label",this.userSettings.loadingIndicatorLabel),e.appendChild(i),null==t){t=document.createElement("iframe");const i=e.getAttribute("data-href");t.setAttribute("frameborder","0"),t.setAttribute("src",i),t.setAttribute("allowfullscreen",""),i.indexOf("youtube.com")>-1?t.setAttribute("allow","accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"):i.indexOf("vimeo.com")>-1?t.setAttribute("allow","autoplay; picture-in-picture"):e.hasAttribute("data-allow")&&t.setAttribute("allow",e.getAttribute("data-allow")),e.getAttribute("data-width")&&(t.style.maxWidth=`${e.getAttribute("data-width")}`),e.getAttribute("data-height")&&(t.style.maxHeight=`${e.getAttribute("data-height")}`),t.style.opacity="0",e.appendChild(t),t.addEventListener("load",()=>{t.style.opacity="1";const i=e.querySelector(".tobii__loader");i&&e.removeChild(i)}),t.addEventListener("error",()=>{t.style.opacity="1";const i=e.querySelector(".tobii__loader");i&&e.removeChild(i)})}else t.setAttribute("src",e.getAttribute("data-href"))}onLeave(e){}onCleanup(e){const t=e.querySelector("iframe");t.setAttribute("src",""),t.style.opacity="0"}onReset(){}}class i{constructor(){this.userSettings=null}init(e,t,i){this.userSettings=i;const r=e.hasAttribute("data-target")?e.getAttribute("data-target"):e.getAttribute("href"),n=document.querySelector(r).cloneNode(!0);if(!n)throw new Error(`Ups, I can't find the target ${r}.`);t.appendChild(n),t.setAttribute("data-type","html"),t.classList.add("tobii-html")}onPreload(e){}onLoad(e,t){const i=e.querySelector("video");i&&(i.hasAttribute("data-time")&&i.readyState>0&&(i.currentTime=i.getAttribute("data-time")),this.userSettings.autoplayVideo&&i.play());const r=e.querySelector("audio");r&&this.userSettings.autoplayAudio&&r.play(),e.classList.add("tobii-group-"+t)}onLeave(e){const t=e.querySelector("video");t&&(t.paused||t.pause(),t.readyState>0&&t.setAttribute("data-time",t.currentTime));const i=e.querySelector("audio");i&&(i.paused||i.pause())}onCleanup(e){const t=e.querySelector("video");if(t&&t.readyState>0&&t.readyState<3&&t.duration!==t.currentTime){const i=t.cloneNode(!0);this._removeSources(t),t.load(),t.parentNode.removeChild(t),e.appendChild(i)}}onReset(){}_removeSources(e){const t=e.querySelectorAll("src");t&&t.forEach(e=>{e.setAttribute("src","")})}}class r{constructor(){this.playerId=0,this.PLAYER=[],this.userSettings=null}init(e,t,i){this.userSettings=i;const r=document.createElement("div");t.appendChild(r),this.PLAYER[this.playerId]=new window.YT.Player(r,{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",this.playerId),t.setAttribute("data-type","youtube"),t.classList.add("tobii-youtube"),this.playerId++}onPreload(e){}onLoad(e){this.userSettings.autoplayVideo&&this.PLAYER[e.getAttribute("data-player")].playVideo()}onLeave(e){1===this.PLAYER[e.getAttribute("data-player")].getPlayerState()&&this.PLAYER[e.getAttribute("data-player")].pauseVideo()}onCleanup(e){1===this.PLAYER[e.getAttribute("data-player")].getPlayerState()&&this.PLAYER[e.getAttribute("data-player")].pauseVideo()}onReset(){}}function n(a){const s={image:new e,html:new i,iframe:new t,youtube:new r},o=['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])'];let l={};const d=[],c={gallery:[],slider:null,sliderElements:[],elementsLength:0,currentIndex:0,x:0};let u=null,p=null,h=null,b=null,g=null,m=null,y=null,f=!1,w={},v=null,A=[],x=0;const E={element:null,originX:0,originY:0,translateX:0,translateY:0,scale:1},L={startX:0,startY:0,x:0,y:0,distance:0},_=e=>{if(null===document.querySelector('[data-type="youtube"]')||f)S(e);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===d.indexOf(e)&&d.push(e),window.onYouTubePlayerAPIReady=()=>{d.forEach(e=>{S(e)}),f=!0}}},I=e=>e.hasAttribute("data-group")?e.getAttribute("data-group"):"default",S=e=>{const t=I(e);if(Object.prototype.hasOwnProperty.call(w,t)||(w[t]=JSON.parse(JSON.stringify(c)),w[t].slider=document.createElement("div"),w[t].slider.className="tobii__slider",w[t].slider.setAttribute("aria-hidden","true"),u.appendChild(w[t].slider)),-1!==w[t].gallery.indexOf(e))throw new Error("Ups, element already added.");{if(w[t].gallery.push(e),w[t].elementsLength++,l.zoom&&e.querySelector("img")&&"false"!==e.getAttribute("data-zoom")||"true"===e.getAttribute("data-zoom")){const t=document.createElement("div");t.className="tobii-zoom__icon",t.innerHTML=l.zoomText,e.classList.add("tobii-zoom"),e.appendChild(t)}e.addEventListener("click",z);const i=Y(e),r=document.createElement("div"),n=document.createElement("div");r.className="tobii__slide",r.style.position="absolute",r.style.left=100*w[t].x+"%",r.setAttribute("aria-hidden","true"),i.init(e,n,l),r.appendChild(n),w[t].slider.appendChild(r),w[t].sliderElements.push(r),++w[t].x,le()&&t===v&&(ae(),se())}},C=e=>{const t=I(e);if(-1===w[t].gallery.indexOf(e))throw new Error(`Ups, I can't find a slide for the element ${e}.`);{const i=w[t].gallery.indexOf(e),r=w[t].sliderElements[i];if(le()&&t===v&&i===w[t].currentIndex){if(1===w[t].elementsLength)throw X(),new Error("Ups, I've closed. There are no slides more to show.");0===w[t].currentIndex?P():N(),ae(),se()}if(w[t].gallery.splice(w[t].gallery.indexOf(e)),w[t].sliderElements.splice(w[t].gallery.indexOf(e)),w[t].elementsLength--,--w[t].x,l.zoom&&e.querySelector(".tobii-zoom__icon")){const t=e.querySelector(".tobii-zoom__icon");t.parentNode.classList.remove("tobii-zoom"),t.parentNode.removeChild(t)}e.removeEventListener("click",z),r.parentNode.removeChild(r)}},Y=e=>{const t=e.getAttribute("data-type");return void 0!==s[t]?s[t]:(e.hasAttribute("data-type")&&console.log("Unknown lightbox element type: "+t),s.image)},T=(e=0)=>{if(le())throw new Error("Ups, I'm aleady open.");if(-1===e||e>=w[v].elementsLength)throw new Error(`Ups, I can't find slide ${e}.`);document.documentElement.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open-"+v),ae(),l.close||(b.disabled=!1,b.setAttribute("aria-hidden","true")),m=document.activeElement;const t=window.location.href;window.history.pushState({tobii:"close"},"Image",t),w[v].currentIndex=e,re(),M(w[v].currentIndex),w[v].slider.setAttribute("aria-hidden","false"),u.setAttribute("aria-hidden","false"),se(),q(w[v].currentIndex+1),q(w[v].currentIndex-1),w[v].slider.classList.add("tobii__slider--animate");const i=new window.CustomEvent("open",{detail:{group:v}});u.dispatchEvent(i)},X=()=>{if(!le())throw new Error("Ups, I'm already closed.");document.documentElement.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open-"+v),ne(),null!==window.history.state&&"close"===window.history.state.tobii&&window.history.back(),m.focus(),O(w[v].currentIndex),k(w[v].currentIndex),u.setAttribute("aria-hidden","true"),w[v].slider.setAttribute("aria-hidden","true"),w[v].currentIndex=0,w[v].slider.classList.remove("tobii__slider--animate");const e=new window.CustomEvent("close",{detail:{group:v}});u.dispatchEvent(e)},q=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]");Y(t).onPreload(t)},M=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]"),i=Y(t);w[v].sliderElements[e].classList.add("tobii__slide--is-active"),w[v].sliderElements[e].setAttribute("aria-hidden","false"),i.onLoad(t,v)},N=()=>{if(!le())throw new Error("Ups, I'm closed.");w[v].currentIndex>0&&(O(w[v].currentIndex),M(--w[v].currentIndex),se("left"),k(w[v].currentIndex+1),q(w[v].currentIndex-1));const e=new window.CustomEvent("previous",{detail:{group:v}});u.dispatchEvent(e)},P=()=>{if(!le())throw new Error("Ups, I'm closed.");w[v].currentIndex{if(le())throw new Error("Ups, I'm open.");if(!e)throw new Error("Ups, no group specified.");if(e&&!Object.prototype.hasOwnProperty.call(w,e))throw new Error(`Ups, I don't have a group called "${e}".`);v=e},O=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]"),i=Y(t);w[v].sliderElements[e].classList.remove("tobii__slide--is-active"),w[v].sliderElements[e].setAttribute("aria-hidden","true"),i.onLeave(t)},k=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]");Y(t).onCleanup(t),L.startX=0,L.startY=0,L.x=0,L.y=0,L.distance=0,x=0,ie()},R=()=>{y=-w[v].currentIndex*u.offsetWidth,w[v].slider.style.transform=`translate(${y}px, 0)`},U=()=>{R()},z=e=>{e.preventDefault(),v=I(e.currentTarget),T(w[v].gallery.indexOf(e.currentTarget))},H=e=>{e.target===p?N():e.target===h?P():(e.target===b||e.target.classList.contains("tobii__slide")&&l.docClose)&&X(),e.stopPropagation()},D=e=>{const t=Array.prototype.slice.call(u.querySelectorAll(`.tobii__btn:not([disabled]), .tobii__slide--is-active ${o.join(", .tobii__slide--is-active ")}`)).filter(e=>!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length)),i=t.indexOf(document.activeElement);9===e.keyCode||"Tab"===e.code?e.shiftKey&&0===i?(t[t.length-1].focus(),e.preventDefault()):e.shiftKey||i!==t.length-1||(t[0].focus(),e.preventDefault()):27===e.keyCode||"Escape"===e.code?(e.preventDefault(),X()):37===e.keyCode||"ArrowLeft"===e.code?(e.preventDefault(),N()):39!==e.keyCode&&"ArrowRight"!==e.code||(e.preventDefault(),P())},B=()=>{A=[],R(),w[v].slider.classList.remove("tobii__slider--is-"+(F()?"moving":"dragging"))},V=e=>{if(!ce(e.target)&&(e.preventDefault(),e.stopPropagation(),L.startX=L.x=e.clientX,L.startY=L.y=e.clientY,L.distance=0,A.push(e),2===A.length)){const{x:e,y:t}=te(A[0].clientX,A[0].clientY,A[1].clientX,A[1].clientY);L.startX=L.x=e,L.startY=L.y=t,L.distance=ee(A[0].clientX-A[1].clientX,A[0].clientY-A[1].clientY)/E.scale}},j=e=>{if(!A.length)return;w[v].slider.classList.add("tobii__slider--is-"+(F()?"moving":"dragging"));const t=A.findIndex(t=>t.pointerId===e.pointerId);if(A[t]=e,2===A.length){const{x:e,y:t}=te(A[0].clientX,A[0].clientY,A[1].clientX,A[1].clientY),i=ee(A[0].clientX-A[1].clientX,A[0].clientY-A[1].clientY)/L.distance;return Z(K(i,1,4),e,t,e-L.x,t-L.y),L.x=e,void(L.y=t)}if(F()&&Q(e.clientX-L.x,e.clientY-L.y),L.x=e.clientX,L.y=e.clientY,!F()){const e=L.startX-L.x,t=L.startY-L.y;if(ee(e,t)<10)return;Math.abs(e)>Math.abs(t)&&w[v].elementsLength>1?w[v].slider.style.transform=`translate(${y-Math.round(e)}px, 0)`:l.swipeClose&&(w[v].slider.style.transform=`translate(${y}px, -${Math.round(t)}px)`)}},W=e=>{if(!A.length)return;w[v].slider.classList.remove("tobii__slider--is-"+(F()?"moving":"dragging"));const t=A.findIndex(t=>t.pointerId===e.pointerId);A.splice(t,1);const i=e.clientX,r=e.clientY,n=L.startX-i,a=L.startY-r,s=Math.abs(n),o=Math.abs(a);if(s||o)F()||(n<0&&s>l.threshold&&w[v].currentIndex>0?N():n>0&&s>l.threshold&&w[v].currentIndex!==w[v].elementsLength-1?P():a>0&&o>l.threshold&&l.swipeClose?X():R());else{const t=(new Date).getTime(),n=t-x;n<500&&n>100?(e.preventDefault(),x=0,F()?ie():Z(2,i,r,0,0)):(x=t,de()&&window.setTimeout(()=>{const{left:t,top:n,bottom:a,right:s,width:o}=e.target.getBoundingClientRect();ra||!x||(i>t&&is-o/2&&P())},500))}},G=e=>{const t=Math.sign(e.deltaY)>0?-1:1;(F()||t)&&(e.preventDefault(),Z(K(E.scale+t/(10/E.scale),1,4),e.clientX,e.clientY,0,0))},J=(e,t)=>{const{element:i,scale:r,originX:n,originY:a}=E,s="x"===e,o=s?n:a,l=s?"offsetWidth":"offsetHeight",d=i.parentNode[l],c=i[l],u=i.getBoundingClientRect(),p=(o-c/2)*(r-1),h=Math.max(0,Math.round(s?u.width:u.height)-d),b=Math.round(h/2);return K(t,0-b+p,b+p)},K=(e,t,i)=>Math.max(Math.min(e,i),t),F=()=>1!==E.scale,Q=(e,t)=>{0!==e&&(E.translateX=J("x",E.translateX+e)),0!==t&&(E.translateY=J("y",E.translateY+t));const{element:i,originX:r,originY:n,translateX:a,translateY:s,scale:o}=E;i.style.transformOrigin=`${r}px ${n}px`,i.style.transform=`translate(${a}px, ${s}px) scale(${o})`},Z=(e,t,i,r,n)=>{E.element||(E.element=u.querySelector(".tobii__slide--is-active img"));const{left:a,top:s}=E.element.getBoundingClientRect(),o=(i-s)/E.scale;E.originX=(t-a)/E.scale,E.originY=o,E.scale=e,Q(r,n)},ee=(e,t)=>Math.hypot(e,t),te=(e,t,i,r)=>({x:(e+i)/2,y:(t+r)/2}),ie=()=>{E.scale=1,E.originX=0,E.originY=0,E.translateX=0,E.translateY=0,Q(0,0),E.element=null},re=()=>{l.keyboard&&window.addEventListener("keydown",D),window.addEventListener("resize",U),window.addEventListener("popstate",X),ue("click",H),l.draggable&&(ue("pointerdown",V),ue("pointermove",j),ue("pointerup",W),ue("pointercancel",B),ue("pointerout",B),ue("pointerleave",B),ue("contextmenu",B)),ue("wheel",G)},ne=()=>{l.keyboard&&window.removeEventListener("keydown",D),window.removeEventListener("resize",U),window.removeEventListener("popstate",X),pe("click",H),l.draggable&&(pe("pointerdown",V),pe("pointermove",j),pe("pointerup",W),pe("pointercancel",B),pe("pointerout",B),pe("pointerleave",B),pe("contextmenu",B)),pe("wheel",G)},ae=()=>{l.draggable&&!w[v].slider.classList.contains("tobii__slider--is-draggable")&&w[v].slider.classList.add("tobii__slider--is-draggable"),!l.nav||1===w[v].elementsLength||"auto"===l.nav&&de()?(p.setAttribute("aria-hidden","true"),p.disabled=!0,h.setAttribute("aria-hidden","true"),h.disabled=!0):(p.setAttribute("aria-hidden","false"),p.disabled=!1,h.setAttribute("aria-hidden","false"),h.disabled=!1),g.setAttribute("aria-hidden",l.counter&&1!==w[v].elementsLength?"false":"true")},se=(e=null)=>{R(),g.textContent=`${w[v].currentIndex+1}/${w[v].elementsLength}`,(e=>{(!0===l.nav||"auto"===l.nav)&&!de()&&w[v].elementsLength>1?(p.setAttribute("aria-hidden","true"),p.disabled=!0,h.setAttribute("aria-hidden","true"),h.disabled=!0,1===w[v].elementsLength?l.close&&b.focus():0===w[v].currentIndex?(h.setAttribute("aria-hidden","false"),h.disabled=!1,h.focus()):w[v].currentIndex===w[v].elementsLength-1?(p.setAttribute("aria-hidden","false"),p.disabled=!1,p.focus()):(p.setAttribute("aria-hidden","false"),p.disabled=!1,h.setAttribute("aria-hidden","false"),h.disabled=!1,"left"===e?p.focus():h.focus())):l.close&&b.focus()})(e)},oe=()=>{le()&&X(),Object.entries(w).forEach(e=>{e[1].gallery.forEach(e=>{C(e)})}),w={},v=null;for(const e in s)s[e].onReset()},le=()=>"false"===u.getAttribute("aria-hidden"),de=()=>"ontouchstart"in window,ce=e=>-1!==["TEXTAREA","OPTION","INPUT","SELECT"].indexOf(e.nodeName)||e===p||e===h||e===b,ue=(e,t)=>{u.addEventListener(e,t)},pe=(e,t)=>{u.removeEventListener(e,t)};return(e=>{if(document.querySelector("div.tobii"))return void console.log("Multiple lightbox instances not supported.");l=(e=>({selector:".lightbox",captions:!0,captionsSelector:"img",captionAttribute:"alt",captionText:null,captionHTML:!1,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,modal:!1,theme:"tobii--theme-default",...e}))(e),u||(u=document.createElement("div"),u.setAttribute("role","dialog"),u.setAttribute("aria-hidden","true"),u.classList.add("tobii"),u.classList.add(l.theme),p=document.createElement("button"),p.className="tobii__btn tobii__btn--previous",p.setAttribute("type","button"),p.setAttribute("aria-label",l.navLabel[0]),p.innerHTML=l.navText[0],u.appendChild(p),h=document.createElement("button"),h.className="tobii__btn tobii__btn--next",h.setAttribute("type","button"),h.setAttribute("aria-label",l.navLabel[1]),h.innerHTML=l.navText[1],u.appendChild(h),b=document.createElement("button"),b.className="tobii__btn tobii__btn--close",b.setAttribute("type","button"),b.setAttribute("aria-label",l.closeLabel),b.innerHTML=l.closeText,u.appendChild(b),g=document.createElement("div"),g.className="tobii__counter",u.appendChild(g),document.body.appendChild(u));const t=document.querySelectorAll(l.selector);if(!t)throw new Error(`Ups, I can't find the selector ${l.selector} on this website.`);const i=[];t.forEach(e=>{const t=e.hasAttribute("data-group")?e.getAttribute("data-group"):"default";let r=e.href;e.hasAttribute("data-target")&&(r=e.getAttribute("data-target")),r+="__"+t,void 0!==i[r]?e.addEventListener("click",e=>{$(t),T(),e.preventDefault()}):(i[r]=1,_(e))})})(a),n.open=T,n.previous=N,n.next=P,n.close=X,n.add=_,n.remove=C,n.reset=oe,n.destroy=()=>{oe(),u.parentNode.removeChild(u)},n.isOpen=le,n.slidesIndex=()=>w[v].currentIndex,n.select=e=>{const t=w[v].currentIndex;if(!le())throw new Error("Ups, I'm closed.");if(le()){if(!e&&0!==e)throw new Error("Ups, no slide specified.");if(e===w[v].currentIndex)throw new Error(`Ups, slide ${e} is already selected.`);if(-1===e||e>=w[v].elementsLength)throw new Error(`Ups, I can't find slide ${e}.`)}w[v].currentIndex=e,O(t),M(e),et&&(se("right"),k(t),q(e+1))},n.slidesCount=()=>w[v].elementsLength,n.selectGroup=$,n.currentGroup=()=>v,n.on=ue,n.off=pe,n}export{n as default}; +class e{constructor(){this.figcaptionId=0,this.userSettings=null}init(e,t,i){this.userSettings=i;const r=document.createElement("figure"),n=document.createElement("figcaption"),a=document.createElement("img"),s=e.querySelector("img"),o=document.createElement("div");if(r.style.opacity="0",s&&(a.alt=s.alt||""),a.setAttribute("src",""),a.setAttribute("data-src",e.href),e.hasAttribute("data-srcset")&&a.setAttribute("data-srcset",e.getAttribute("data-srcset")),r.appendChild(a),this.userSettings.captions){let t;"function"==typeof this.userSettings.captionText?t=this.userSettings.captionText(e):"self"===this.userSettings.captionsSelector&&e.getAttribute(this.userSettings.captionAttribute)?t=e.getAttribute(this.userSettings.captionAttribute):"img"===this.userSettings.captionsSelector&&s&&s.getAttribute(this.userSettings.captionAttribute)&&(t=s.getAttribute(this.userSettings.captionAttribute)),this.userSettings.captionHTML?n.innerHTML=t:n.textContent=t,t&&(n.id=`tobii-figcaption-${this.figcaptionId}`,r.appendChild(n),a.setAttribute("aria-labelledby",n.id),++this.figcaptionId)}t.appendChild(r),o.className="tobii__loader",o.setAttribute("role","progressbar"),o.setAttribute("aria-label",this.userSettings.loadingIndicatorLabel),t.appendChild(o),t.setAttribute("data-type","image"),t.classList.add("tobii-image")}onPreload(e){this.onLoad(e)}onLoad(e){const t=e.querySelector("img");if(!t.hasAttribute("data-src"))return;const i=e.querySelector("figure"),r=e.querySelector(".tobii__loader");t.addEventListener("load",()=>{e.removeChild(r),i.style.opacity="1"}),t.addEventListener("error",()=>{e.removeChild(r),i.style.opacity="1"}),t.setAttribute("src",t.getAttribute("data-src")),t.removeAttribute("data-src"),t.hasAttribute("data-srcset")&&t.setAttribute("srcset",t.getAttribute("data-srcset"))}onLeave(e){}onCleanup(e){}onReset(){this.figcaptionId=0}}class t{constructor(){this.userSettings=null}init(e,t,i){this.userSettings=i;const r=e.hasAttribute("data-target")?e.getAttribute("data-target"):e.getAttribute("href");t.setAttribute("data-HREF",r),e.getAttribute("data-allow")&&t.setAttribute("data-allow",e.getAttribute("data-allow")),e.hasAttribute("data-width")&&t.setAttribute("data-width",`${e.getAttribute("data-width")}`),e.hasAttribute("data-height")&&t.setAttribute("data-height",`${e.getAttribute("data-height")}`),t.setAttribute("data-type","iframe"),t.classList.add("tobii-iframe")}onPreload(e){}onLoad(e){let t=e.querySelector("iframe");const i=document.createElement("div");if(i.className="tobii__loader",i.setAttribute("role","progressbar"),i.setAttribute("aria-label",this.userSettings.loadingIndicatorLabel),e.appendChild(i),null==t){t=document.createElement("iframe");const i=e.getAttribute("data-href");t.setAttribute("frameborder","0"),t.setAttribute("src",i),t.setAttribute("allowfullscreen",""),i.indexOf("youtube.com")>-1?t.setAttribute("allow","accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"):i.indexOf("vimeo.com")>-1?t.setAttribute("allow","autoplay; picture-in-picture"):e.hasAttribute("data-allow")&&t.setAttribute("allow",e.getAttribute("data-allow")),e.getAttribute("data-width")&&(t.style.maxWidth=`${e.getAttribute("data-width")}`),e.getAttribute("data-height")&&(t.style.maxHeight=`${e.getAttribute("data-height")}`),t.style.opacity="0",e.appendChild(t),t.addEventListener("load",()=>{t.style.opacity="1";const i=e.querySelector(".tobii__loader");i&&e.removeChild(i)}),t.addEventListener("error",()=>{t.style.opacity="1";const i=e.querySelector(".tobii__loader");i&&e.removeChild(i)})}else t.setAttribute("src",e.getAttribute("data-href"))}onLeave(e){}onCleanup(e){const t=e.querySelector("iframe");t.setAttribute("src",""),t.style.opacity="0"}onReset(){}}class i{constructor(){this.userSettings=null}init(e,t,i){this.userSettings=i;const r=e.hasAttribute("data-target")?e.getAttribute("data-target"):e.getAttribute("href"),n=document.querySelector(r).cloneNode(!0);if(!n)throw new Error(`Ups, I can't find the target ${r}.`);t.appendChild(n),t.setAttribute("data-type","html"),t.classList.add("tobii-html")}onPreload(e){}onLoad(e,t){const i=e.querySelector("video");i&&(i.hasAttribute("data-time")&&i.readyState>0&&(i.currentTime=i.getAttribute("data-time")),this.userSettings.autoplayVideo&&i.play());const r=e.querySelector("audio");r&&this.userSettings.autoplayAudio&&r.play(),e.classList.add("tobii-group-"+t)}onLeave(e){const t=e.querySelector("video");t&&(t.paused||t.pause(),t.readyState>0&&t.setAttribute("data-time",t.currentTime));const i=e.querySelector("audio");i&&(i.paused||i.pause())}onCleanup(e){const t=e.querySelector("video");if(t&&t.readyState>0&&t.readyState<3&&t.duration!==t.currentTime){const i=t.cloneNode(!0);this._removeSources(t),t.load(),t.parentNode.removeChild(t),e.appendChild(i)}}onReset(){}_removeSources(e){const t=e.querySelectorAll("src");t&&t.forEach(e=>{e.setAttribute("src","")})}}class r{constructor(){this.playerId=0,this.PLAYER=[],this.userSettings=null}init(e,t,i){this.userSettings=i;const r=document.createElement("div");t.appendChild(r),this.PLAYER[this.playerId]=new window.YT.Player(r,{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",this.playerId),t.setAttribute("data-type","youtube"),t.classList.add("tobii-youtube"),this.playerId++}onPreload(e){}onLoad(e){this.userSettings.autoplayVideo&&this.PLAYER[e.getAttribute("data-player")].playVideo()}onLeave(e){1===this.PLAYER[e.getAttribute("data-player")].getPlayerState()&&this.PLAYER[e.getAttribute("data-player")].pauseVideo()}onCleanup(e){1===this.PLAYER[e.getAttribute("data-player")].getPlayerState()&&this.PLAYER[e.getAttribute("data-player")].pauseVideo()}onReset(){}}function n(a){const s={image:new e,html:new i,iframe:new t,youtube:new r},o=['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])'];let l={};const d=[],c={gallery:[],slider:null,sliderElements:[],elementsLength:0,currentIndex:0,x:0};let u=null,p=null,h=null,b=null,g=null,m=null,y=null,f=!1,w={},v=null,A=[],x=0;const E={element:null,originX:0,originY:0,translateX:0,translateY:0,scale:1},L={startX:0,startY:0,x:0,y:0,distance:0},_=e=>{if(null===document.querySelector('[data-type="youtube"]')||f)S(e);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===d.indexOf(e)&&d.push(e),window.onYouTubePlayerAPIReady=()=>{d.forEach(e=>{S(e)}),f=!0}}},I=e=>e.hasAttribute("data-group")?e.getAttribute("data-group"):"default",S=e=>{const t=I(e);if(Object.prototype.hasOwnProperty.call(w,t)||(w[t]=JSON.parse(JSON.stringify(c)),w[t].slider=document.createElement("div"),w[t].slider.className="tobii__slider",w[t].slider.setAttribute("aria-hidden","true"),u.appendChild(w[t].slider)),-1!==w[t].gallery.indexOf(e))throw new Error("Ups, element already added.");{if(w[t].gallery.push(e),w[t].elementsLength++,l.zoom&&e.querySelector("img")&&"false"!==e.getAttribute("data-zoom")||"true"===e.getAttribute("data-zoom")){const t=document.createElement("div");t.className="tobii-zoom__icon",t.innerHTML=l.zoomText,e.classList.add("tobii-zoom"),e.appendChild(t)}e.addEventListener("click",z);const i=Y(e),r=document.createElement("div"),n=document.createElement("div");r.className="tobii__slide",r.style.position="absolute",r.style.left=100*w[t].x+"%",r.setAttribute("aria-hidden","true"),i.init(e,n,l),r.appendChild(n),w[t].slider.appendChild(r),w[t].sliderElements.push(r),++w[t].x,le()&&t===v&&(ae(),se())}},C=e=>{const t=I(e);if(-1===w[t].gallery.indexOf(e))throw new Error(`Ups, I can't find a slide for the element ${e}.`);{const i=w[t].gallery.indexOf(e),r=w[t].sliderElements[i];if(le()&&t===v&&i===w[t].currentIndex){if(1===w[t].elementsLength)throw X(),new Error("Ups, I've closed. There are no slides more to show.");0===w[t].currentIndex?P():N(),ae(),se()}if(w[t].gallery.splice(w[t].gallery.indexOf(e)),w[t].sliderElements.splice(w[t].gallery.indexOf(e)),w[t].elementsLength--,--w[t].x,l.zoom&&e.querySelector(".tobii-zoom__icon")){const t=e.querySelector(".tobii-zoom__icon");t.parentNode.classList.remove("tobii-zoom"),t.parentNode.removeChild(t)}e.removeEventListener("click",z),r.parentNode.removeChild(r)}},Y=e=>{const t=e.getAttribute("data-type");return void 0!==s[t]?s[t]:(e.hasAttribute("data-type")&&console.log("Unknown lightbox element type: "+t),s.image)},T=(e=0)=>{if(le())throw new Error("Ups, I'm aleady open.");if(-1===e||e>=w[v].elementsLength)throw new Error(`Ups, I can't find slide ${e}.`);document.documentElement.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open-"+v),ae(),l.close||(b.disabled=!1,b.setAttribute("aria-hidden","true")),m=document.activeElement;const t=window.location.href;window.history.pushState({tobii:"close"},"Image",t),w[v].currentIndex=e,re(),M(w[v].currentIndex),w[v].slider.setAttribute("aria-hidden","false"),u.setAttribute("aria-hidden","false"),se(),q(w[v].currentIndex+1),q(w[v].currentIndex-1),w[v].slider.classList.add("tobii__slider--animate");const i=new window.CustomEvent("open",{detail:{group:v}});u.dispatchEvent(i)},X=()=>{if(!le())throw new Error("Ups, I'm already closed.");document.documentElement.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open-"+v),ne(),null!==window.history.state&&"close"===window.history.state.tobii&&window.history.back(),m.focus(),O(w[v].currentIndex),k(w[v].currentIndex),u.setAttribute("aria-hidden","true"),w[v].slider.setAttribute("aria-hidden","true"),w[v].currentIndex=0,w[v].slider.classList.remove("tobii__slider--animate");const e=new window.CustomEvent("close",{detail:{group:v}});u.dispatchEvent(e)},q=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]");Y(t).onPreload(t)},M=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]"),i=Y(t);w[v].sliderElements[e].classList.add("tobii__slide--is-active"),w[v].sliderElements[e].setAttribute("aria-hidden","false"),i.onLoad(t,v)},N=()=>{if(!le())throw new Error("Ups, I'm closed.");w[v].currentIndex>0&&(O(w[v].currentIndex),M(--w[v].currentIndex),se("left"),k(w[v].currentIndex+1),q(w[v].currentIndex-1));const e=new window.CustomEvent("previous",{detail:{group:v}});u.dispatchEvent(e)},P=()=>{if(!le())throw new Error("Ups, I'm closed.");w[v].currentIndex{if(le())throw new Error("Ups, I'm open.");if(!e)throw new Error("Ups, no group specified.");if(e&&!Object.prototype.hasOwnProperty.call(w,e))throw new Error(`Ups, I don't have a group called "${e}".`);v=e},O=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]"),i=Y(t);w[v].sliderElements[e].classList.remove("tobii__slide--is-active"),w[v].sliderElements[e].setAttribute("aria-hidden","true"),i.onLeave(t)},k=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]");Y(t).onCleanup(t),L.startX=0,L.startY=0,L.x=0,L.y=0,L.distance=0,x=0,F()&&ie(),E.element=null},R=()=>{y=-w[v].currentIndex*u.offsetWidth,w[v].slider.style.transform=`translate(${y}px, 0)`},U=()=>{R()},z=e=>{e.preventDefault(),v=I(e.currentTarget),T(w[v].gallery.indexOf(e.currentTarget))},H=e=>{e.target===p?N():e.target===h?P():(e.target===b||e.target.classList.contains("tobii__slide")&&l.docClose)&&X(),e.stopPropagation()},D=e=>{const t=Array.prototype.slice.call(u.querySelectorAll(`.tobii__btn:not([disabled]), .tobii__slide--is-active ${o.join(", .tobii__slide--is-active ")}`)).filter(e=>!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length)),i=t.indexOf(document.activeElement);9===e.keyCode||"Tab"===e.code?e.shiftKey&&0===i?(t[t.length-1].focus(),e.preventDefault()):e.shiftKey||i!==t.length-1||(t[0].focus(),e.preventDefault()):27===e.keyCode||"Escape"===e.code?(e.preventDefault(),X()):37===e.keyCode||"ArrowLeft"===e.code?(e.preventDefault(),N()):39!==e.keyCode&&"ArrowRight"!==e.code||(e.preventDefault(),P())},B=()=>{A=[],R(),w[v].slider.classList.remove("tobii__slider--is-"+(F()?"moving":"dragging"))},V=e=>{if(!ce(e.target)&&(e.preventDefault(),e.stopPropagation(),L.startX=L.x=e.clientX,L.startY=L.y=e.clientY,L.distance=0,A.push(e),2===A.length)){const{x:e,y:t}=te(A[0].clientX,A[0].clientY,A[1].clientX,A[1].clientY);L.startX=L.x=e,L.startY=L.y=t,L.distance=ee(A[0].clientX-A[1].clientX,A[0].clientY-A[1].clientY)/E.scale}},j=e=>{if(!A.length)return;w[v].slider.classList.add("tobii__slider--is-"+(F()?"moving":"dragging"));const t=A.findIndex(t=>t.pointerId===e.pointerId);if(A[t]=e,2===A.length){const{x:e,y:t}=te(A[0].clientX,A[0].clientY,A[1].clientX,A[1].clientY),i=ee(A[0].clientX-A[1].clientX,A[0].clientY-A[1].clientY)/L.distance;return Z(K(i,1,4),e,t,e-L.x,t-L.y),L.x=e,void(L.y=t)}if(F()&&Q(e.clientX-L.x,e.clientY-L.y),L.x=e.clientX,L.y=e.clientY,!F()){const e=L.startX-L.x,t=L.startY-L.y;if(ee(e,t)<10)return;Math.abs(e)>Math.abs(t)&&w[v].elementsLength>1?w[v].slider.style.transform=`translate(${y-Math.round(e)}px, 0)`:l.swipeClose&&(w[v].slider.style.transform=`translate(${y}px, -${Math.round(t)}px)`)}},W=e=>{if(!A.length)return;w[v].slider.classList.remove("tobii__slider--is-"+(F()?"moving":"dragging"));const t=A.findIndex(t=>t.pointerId===e.pointerId);A.splice(t,1);const i=e.clientX,r=e.clientY,n=L.startX-i,a=L.startY-r,s=Math.abs(n),o=Math.abs(a);if(s||o)F()||(n<0&&s>l.threshold&&w[v].currentIndex>0?N():n>0&&s>l.threshold&&w[v].currentIndex!==w[v].elementsLength-1?P():a>0&&o>l.threshold&&l.swipeClose?X():R());else{const t=(new Date).getTime(),n=t-x;n<500&&n>100?(e.preventDefault(),x=0,F()?ie():Z(2,i,r,0,0)):(x=t,de()&&window.setTimeout(()=>{const{left:t,top:n,bottom:a,right:s,width:o}=e.target.getBoundingClientRect();ra||!x||(i>t&&is-o/2&&P())},500))}},G=e=>{const t=Math.sign(e.deltaY)>0?-1:1;(F()||t)&&(e.preventDefault(),Z(K(E.scale+t/(10/E.scale),1,4),e.clientX,e.clientY,0,0))},J=(e,t)=>{const{element:i,scale:r,originX:n,originY:a}=E,s="x"===e,o=s?n:a,l=s?"offsetWidth":"offsetHeight",d=i.parentNode[l],c=i[l],u=i.getBoundingClientRect(),p=(o-c/2)*(r-1),h=Math.max(0,Math.round(s?u.width:u.height)-d),b=Math.round(h/2);return K(t,0-b+p,b+p)},K=(e,t,i)=>Math.max(Math.min(e,i),t),F=()=>1!==E.scale,Q=(e,t)=>{0!==e&&(E.translateX=J("x",E.translateX+e)),0!==t&&(E.translateY=J("y",E.translateY+t));const{element:i,originX:r,originY:n,translateX:a,translateY:s,scale:o}=E;i.style.transformOrigin=`${r}px ${n}px`,i.style.transform=`translate(${a}px, ${s}px) scale(${o})`},Z=(e,t,i,r,n)=>{E.element||(E.element=u.querySelector(".tobii__slide--is-active img"));const{left:a,top:s}=E.element.getBoundingClientRect(),o=(i-s)/E.scale;E.originX=(t-a)/E.scale,E.originY=o,E.scale=e,Q(r,n)},ee=(e,t)=>Math.hypot(e,t),te=(e,t,i,r)=>({x:(e+i)/2,y:(t+r)/2}),ie=()=>{E.scale=1,E.originX=0,E.originY=0,E.translateX=0,E.translateY=0,Q(0,0)},re=()=>{l.keyboard&&window.addEventListener("keydown",D),window.addEventListener("resize",U),window.addEventListener("popstate",X),ue("click",H),l.draggable&&(ue("pointerdown",V),ue("pointermove",j),ue("pointerup",W),ue("pointercancel",B),ue("pointerout",B),ue("pointerleave",B),ue("contextmenu",B)),ue("wheel",G)},ne=()=>{l.keyboard&&window.removeEventListener("keydown",D),window.removeEventListener("resize",U),window.removeEventListener("popstate",X),pe("click",H),l.draggable&&(pe("pointerdown",V),pe("pointermove",j),pe("pointerup",W),pe("pointercancel",B),pe("pointerout",B),pe("pointerleave",B),pe("contextmenu",B)),pe("wheel",G)},ae=()=>{l.draggable&&!w[v].slider.classList.contains("tobii__slider--is-draggable")&&w[v].slider.classList.add("tobii__slider--is-draggable"),!l.nav||1===w[v].elementsLength||"auto"===l.nav&&de()?(p.setAttribute("aria-hidden","true"),p.disabled=!0,h.setAttribute("aria-hidden","true"),h.disabled=!0):(p.setAttribute("aria-hidden","false"),p.disabled=!1,h.setAttribute("aria-hidden","false"),h.disabled=!1),g.setAttribute("aria-hidden",l.counter&&1!==w[v].elementsLength?"false":"true")},se=(e=null)=>{R(),g.textContent=`${w[v].currentIndex+1}/${w[v].elementsLength}`,(e=>{(!0===l.nav||"auto"===l.nav)&&!de()&&w[v].elementsLength>1?(p.setAttribute("aria-hidden","true"),p.disabled=!0,h.setAttribute("aria-hidden","true"),h.disabled=!0,1===w[v].elementsLength?l.close&&b.focus():0===w[v].currentIndex?(h.setAttribute("aria-hidden","false"),h.disabled=!1,h.focus()):w[v].currentIndex===w[v].elementsLength-1?(p.setAttribute("aria-hidden","false"),p.disabled=!1,p.focus()):(p.setAttribute("aria-hidden","false"),p.disabled=!1,h.setAttribute("aria-hidden","false"),h.disabled=!1,"left"===e?p.focus():h.focus())):l.close&&b.focus()})(e)},oe=()=>{le()&&X(),Object.entries(w).forEach(e=>{e[1].gallery.forEach(e=>{C(e)})}),w={},v=null;for(const e in s)s[e].onReset()},le=()=>"false"===u.getAttribute("aria-hidden"),de=()=>"ontouchstart"in window,ce=e=>-1!==["TEXTAREA","OPTION","INPUT","SELECT"].indexOf(e.nodeName)||e===p||e===h||e===b,ue=(e,t)=>{u.addEventListener(e,t)},pe=(e,t)=>{u.removeEventListener(e,t)};return(e=>{if(document.querySelector("div.tobii"))return void console.log("Multiple lightbox instances not supported.");l=(e=>({selector:".lightbox",captions:!0,captionsSelector:"img",captionAttribute:"alt",captionText:null,captionHTML:!1,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,modal:!1,theme:"tobii--theme-default",...e}))(e),u||(u=document.createElement("div"),u.setAttribute("role","dialog"),u.setAttribute("aria-hidden","true"),u.classList.add("tobii"),u.classList.add(l.theme),p=document.createElement("button"),p.className="tobii__btn tobii__btn--previous",p.setAttribute("type","button"),p.setAttribute("aria-label",l.navLabel[0]),p.innerHTML=l.navText[0],u.appendChild(p),h=document.createElement("button"),h.className="tobii__btn tobii__btn--next",h.setAttribute("type","button"),h.setAttribute("aria-label",l.navLabel[1]),h.innerHTML=l.navText[1],u.appendChild(h),b=document.createElement("button"),b.className="tobii__btn tobii__btn--close",b.setAttribute("type","button"),b.setAttribute("aria-label",l.closeLabel),b.innerHTML=l.closeText,u.appendChild(b),g=document.createElement("div"),g.className="tobii__counter",u.appendChild(g),document.body.appendChild(u));const t=document.querySelectorAll(l.selector);if(!t)throw new Error(`Ups, I can't find the selector ${l.selector} on this website.`);const i=[];t.forEach(e=>{const t=e.hasAttribute("data-group")?e.getAttribute("data-group"):"default";let r=e.href;e.hasAttribute("data-target")&&(r=e.getAttribute("data-target")),r+="__"+t,void 0!==i[r]?e.addEventListener("click",e=>{$(t),T(),e.preventDefault()}):(i[r]=1,_(e))})})(a),n.open=T,n.previous=N,n.next=P,n.close=X,n.add=_,n.remove=C,n.reset=oe,n.destroy=()=>{oe(),u.parentNode.removeChild(u)},n.isOpen=le,n.slidesIndex=()=>w[v].currentIndex,n.select=e=>{const t=w[v].currentIndex;if(!le())throw new Error("Ups, I'm closed.");if(le()){if(!e&&0!==e)throw new Error("Ups, no slide specified.");if(e===w[v].currentIndex)throw new Error(`Ups, slide ${e} is already selected.`);if(-1===e||e>=w[v].elementsLength)throw new Error(`Ups, I can't find slide ${e}.`)}w[v].currentIndex=e,O(t),M(e),et&&(se("right"),k(t),q(e+1))},n.slidesCount=()=>w[v].elementsLength,n.selectGroup=$,n.currentGroup=()=>v,n.on=ue,n.off=pe,n}export{n as default}; diff --git a/dist/tobii.umd.js b/dist/tobii.umd.js index 42abc51..018bf2a 100644 --- a/dist/tobii.umd.js +++ b/dist/tobii.umd.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e||self).Tobii=t()}(this,function(){class e{constructor(){this.figcaptionId=0,this.userSettings=null}init(e,t,i){this.userSettings=i;const r=document.createElement("figure"),n=document.createElement("figcaption"),a=document.createElement("img"),s=e.querySelector("img"),o=document.createElement("div");if(r.style.opacity="0",s&&(a.alt=s.alt||""),a.setAttribute("src",""),a.setAttribute("data-src",e.href),e.hasAttribute("data-srcset")&&a.setAttribute("data-srcset",e.getAttribute("data-srcset")),r.appendChild(a),this.userSettings.captions){let t;"function"==typeof this.userSettings.captionText?t=this.userSettings.captionText(e):"self"===this.userSettings.captionsSelector&&e.getAttribute(this.userSettings.captionAttribute)?t=e.getAttribute(this.userSettings.captionAttribute):"img"===this.userSettings.captionsSelector&&s&&s.getAttribute(this.userSettings.captionAttribute)&&(t=s.getAttribute(this.userSettings.captionAttribute)),this.userSettings.captionHTML?n.innerHTML=t:n.textContent=t,t&&(n.id=`tobii-figcaption-${this.figcaptionId}`,r.appendChild(n),a.setAttribute("aria-labelledby",n.id),++this.figcaptionId)}t.appendChild(r),o.className="tobii__loader",o.setAttribute("role","progressbar"),o.setAttribute("aria-label",this.userSettings.loadingIndicatorLabel),t.appendChild(o),t.setAttribute("data-type","image"),t.classList.add("tobii-image")}onPreload(e){this.onLoad(e)}onLoad(e){const t=e.querySelector("img");if(!t.hasAttribute("data-src"))return;const i=e.querySelector("figure"),r=e.querySelector(".tobii__loader");t.addEventListener("load",()=>{e.removeChild(r),i.style.opacity="1"}),t.addEventListener("error",()=>{e.removeChild(r),i.style.opacity="1"}),t.setAttribute("src",t.getAttribute("data-src")),t.removeAttribute("data-src"),t.hasAttribute("data-srcset")&&t.setAttribute("srcset",t.getAttribute("data-srcset"))}onLeave(e){}onCleanup(e){}onReset(){this.figcaptionId=0}}class t{constructor(){this.userSettings=null}init(e,t,i){this.userSettings=i;const r=e.hasAttribute("data-target")?e.getAttribute("data-target"):e.getAttribute("href");t.setAttribute("data-HREF",r),e.getAttribute("data-allow")&&t.setAttribute("data-allow",e.getAttribute("data-allow")),e.hasAttribute("data-width")&&t.setAttribute("data-width",`${e.getAttribute("data-width")}`),e.hasAttribute("data-height")&&t.setAttribute("data-height",`${e.getAttribute("data-height")}`),t.setAttribute("data-type","iframe"),t.classList.add("tobii-iframe")}onPreload(e){}onLoad(e){let t=e.querySelector("iframe");const i=document.createElement("div");if(i.className="tobii__loader",i.setAttribute("role","progressbar"),i.setAttribute("aria-label",this.userSettings.loadingIndicatorLabel),e.appendChild(i),null==t){t=document.createElement("iframe");const i=e.getAttribute("data-href");t.setAttribute("frameborder","0"),t.setAttribute("src",i),t.setAttribute("allowfullscreen",""),i.indexOf("youtube.com")>-1?t.setAttribute("allow","accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"):i.indexOf("vimeo.com")>-1?t.setAttribute("allow","autoplay; picture-in-picture"):e.hasAttribute("data-allow")&&t.setAttribute("allow",e.getAttribute("data-allow")),e.getAttribute("data-width")&&(t.style.maxWidth=`${e.getAttribute("data-width")}`),e.getAttribute("data-height")&&(t.style.maxHeight=`${e.getAttribute("data-height")}`),t.style.opacity="0",e.appendChild(t),t.addEventListener("load",()=>{t.style.opacity="1";const i=e.querySelector(".tobii__loader");i&&e.removeChild(i)}),t.addEventListener("error",()=>{t.style.opacity="1";const i=e.querySelector(".tobii__loader");i&&e.removeChild(i)})}else t.setAttribute("src",e.getAttribute("data-href"))}onLeave(e){}onCleanup(e){const t=e.querySelector("iframe");t.setAttribute("src",""),t.style.opacity="0"}onReset(){}}class i{constructor(){this.userSettings=null}init(e,t,i){this.userSettings=i;const r=e.hasAttribute("data-target")?e.getAttribute("data-target"):e.getAttribute("href"),n=document.querySelector(r).cloneNode(!0);if(!n)throw new Error(`Ups, I can't find the target ${r}.`);t.appendChild(n),t.setAttribute("data-type","html"),t.classList.add("tobii-html")}onPreload(e){}onLoad(e,t){const i=e.querySelector("video");i&&(i.hasAttribute("data-time")&&i.readyState>0&&(i.currentTime=i.getAttribute("data-time")),this.userSettings.autoplayVideo&&i.play());const r=e.querySelector("audio");r&&this.userSettings.autoplayAudio&&r.play(),e.classList.add("tobii-group-"+t)}onLeave(e){const t=e.querySelector("video");t&&(t.paused||t.pause(),t.readyState>0&&t.setAttribute("data-time",t.currentTime));const i=e.querySelector("audio");i&&(i.paused||i.pause())}onCleanup(e){const t=e.querySelector("video");if(t&&t.readyState>0&&t.readyState<3&&t.duration!==t.currentTime){const i=t.cloneNode(!0);this._removeSources(t),t.load(),t.parentNode.removeChild(t),e.appendChild(i)}}onReset(){}_removeSources(e){const t=e.querySelectorAll("src");t&&t.forEach(e=>{e.setAttribute("src","")})}}class r{constructor(){this.playerId=0,this.PLAYER=[],this.userSettings=null}init(e,t,i){this.userSettings=i;const r=document.createElement("div");t.appendChild(r),this.PLAYER[this.playerId]=new window.YT.Player(r,{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",this.playerId),t.setAttribute("data-type","youtube"),t.classList.add("tobii-youtube"),this.playerId++}onPreload(e){}onLoad(e){this.userSettings.autoplayVideo&&this.PLAYER[e.getAttribute("data-player")].playVideo()}onLeave(e){1===this.PLAYER[e.getAttribute("data-player")].getPlayerState()&&this.PLAYER[e.getAttribute("data-player")].pauseVideo()}onCleanup(e){1===this.PLAYER[e.getAttribute("data-player")].getPlayerState()&&this.PLAYER[e.getAttribute("data-player")].pauseVideo()}onReset(){}}return function n(a){const s={image:new e,html:new i,iframe:new t,youtube:new r},o=['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])'];let l={};const d=[],c={gallery:[],slider:null,sliderElements:[],elementsLength:0,currentIndex:0,x:0};let u=null,p=null,h=null,b=null,g=null,m=null,y=null,f=!1,w={},v=null,A=[],x=0;const E={element:null,originX:0,originY:0,translateX:0,translateY:0,scale:1},L={startX:0,startY:0,x:0,y:0,distance:0},_=e=>{if(null===document.querySelector('[data-type="youtube"]')||f)S(e);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===d.indexOf(e)&&d.push(e),window.onYouTubePlayerAPIReady=()=>{d.forEach(e=>{S(e)}),f=!0}}},I=e=>e.hasAttribute("data-group")?e.getAttribute("data-group"):"default",S=e=>{const t=I(e);if(Object.prototype.hasOwnProperty.call(w,t)||(w[t]=JSON.parse(JSON.stringify(c)),w[t].slider=document.createElement("div"),w[t].slider.className="tobii__slider",w[t].slider.setAttribute("aria-hidden","true"),u.appendChild(w[t].slider)),-1!==w[t].gallery.indexOf(e))throw new Error("Ups, element already added.");{if(w[t].gallery.push(e),w[t].elementsLength++,l.zoom&&e.querySelector("img")&&"false"!==e.getAttribute("data-zoom")||"true"===e.getAttribute("data-zoom")){const t=document.createElement("div");t.className="tobii-zoom__icon",t.innerHTML=l.zoomText,e.classList.add("tobii-zoom"),e.appendChild(t)}e.addEventListener("click",z);const i=Y(e),r=document.createElement("div"),n=document.createElement("div");r.className="tobii__slide",r.style.position="absolute",r.style.left=100*w[t].x+"%",r.setAttribute("aria-hidden","true"),i.init(e,n,l),r.appendChild(n),w[t].slider.appendChild(r),w[t].sliderElements.push(r),++w[t].x,le()&&t===v&&(ae(),se())}},C=e=>{const t=I(e);if(-1===w[t].gallery.indexOf(e))throw new Error(`Ups, I can't find a slide for the element ${e}.`);{const i=w[t].gallery.indexOf(e),r=w[t].sliderElements[i];if(le()&&t===v&&i===w[t].currentIndex){if(1===w[t].elementsLength)throw X(),new Error("Ups, I've closed. There are no slides more to show.");0===w[t].currentIndex?P():N(),ae(),se()}if(w[t].gallery.splice(w[t].gallery.indexOf(e)),w[t].sliderElements.splice(w[t].gallery.indexOf(e)),w[t].elementsLength--,--w[t].x,l.zoom&&e.querySelector(".tobii-zoom__icon")){const t=e.querySelector(".tobii-zoom__icon");t.parentNode.classList.remove("tobii-zoom"),t.parentNode.removeChild(t)}e.removeEventListener("click",z),r.parentNode.removeChild(r)}},Y=e=>{const t=e.getAttribute("data-type");return void 0!==s[t]?s[t]:(e.hasAttribute("data-type")&&console.log("Unknown lightbox element type: "+t),s.image)},T=(e=0)=>{if(le())throw new Error("Ups, I'm aleady open.");if(-1===e||e>=w[v].elementsLength)throw new Error(`Ups, I can't find slide ${e}.`);document.documentElement.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open-"+v),ae(),l.close||(b.disabled=!1,b.setAttribute("aria-hidden","true")),m=document.activeElement;const t=window.location.href;window.history.pushState({tobii:"close"},"Image",t),w[v].currentIndex=e,re(),M(w[v].currentIndex),w[v].slider.setAttribute("aria-hidden","false"),u.setAttribute("aria-hidden","false"),se(),q(w[v].currentIndex+1),q(w[v].currentIndex-1),w[v].slider.classList.add("tobii__slider--animate");const i=new window.CustomEvent("open",{detail:{group:v}});u.dispatchEvent(i)},X=()=>{if(!le())throw new Error("Ups, I'm already closed.");document.documentElement.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open-"+v),ne(),null!==window.history.state&&"close"===window.history.state.tobii&&window.history.back(),m.focus(),O(w[v].currentIndex),k(w[v].currentIndex),u.setAttribute("aria-hidden","true"),w[v].slider.setAttribute("aria-hidden","true"),w[v].currentIndex=0,w[v].slider.classList.remove("tobii__slider--animate");const e=new window.CustomEvent("close",{detail:{group:v}});u.dispatchEvent(e)},q=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]");Y(t).onPreload(t)},M=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]"),i=Y(t);w[v].sliderElements[e].classList.add("tobii__slide--is-active"),w[v].sliderElements[e].setAttribute("aria-hidden","false"),i.onLoad(t,v)},N=()=>{if(!le())throw new Error("Ups, I'm closed.");w[v].currentIndex>0&&(O(w[v].currentIndex),M(--w[v].currentIndex),se("left"),k(w[v].currentIndex+1),q(w[v].currentIndex-1));const e=new window.CustomEvent("previous",{detail:{group:v}});u.dispatchEvent(e)},P=()=>{if(!le())throw new Error("Ups, I'm closed.");w[v].currentIndex{if(le())throw new Error("Ups, I'm open.");if(!e)throw new Error("Ups, no group specified.");if(e&&!Object.prototype.hasOwnProperty.call(w,e))throw new Error(`Ups, I don't have a group called "${e}".`);v=e},O=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]"),i=Y(t);w[v].sliderElements[e].classList.remove("tobii__slide--is-active"),w[v].sliderElements[e].setAttribute("aria-hidden","true"),i.onLeave(t)},k=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]");Y(t).onCleanup(t),L.startX=0,L.startY=0,L.x=0,L.y=0,L.distance=0,x=0,ie()},R=()=>{y=-w[v].currentIndex*u.offsetWidth,w[v].slider.style.transform=`translate(${y}px, 0)`},U=()=>{R()},z=e=>{e.preventDefault(),v=I(e.currentTarget),T(w[v].gallery.indexOf(e.currentTarget))},H=e=>{e.target===p?N():e.target===h?P():(e.target===b||e.target.classList.contains("tobii__slide")&&l.docClose)&&X(),e.stopPropagation()},D=e=>{const t=Array.prototype.slice.call(u.querySelectorAll(`.tobii__btn:not([disabled]), .tobii__slide--is-active ${o.join(", .tobii__slide--is-active ")}`)).filter(e=>!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length)),i=t.indexOf(document.activeElement);9===e.keyCode||"Tab"===e.code?e.shiftKey&&0===i?(t[t.length-1].focus(),e.preventDefault()):e.shiftKey||i!==t.length-1||(t[0].focus(),e.preventDefault()):27===e.keyCode||"Escape"===e.code?(e.preventDefault(),X()):37===e.keyCode||"ArrowLeft"===e.code?(e.preventDefault(),N()):39!==e.keyCode&&"ArrowRight"!==e.code||(e.preventDefault(),P())},B=()=>{A=[],R(),w[v].slider.classList.remove("tobii__slider--is-"+(F()?"moving":"dragging"))},V=e=>{if(!ce(e.target)&&(e.preventDefault(),e.stopPropagation(),L.startX=L.x=e.clientX,L.startY=L.y=e.clientY,L.distance=0,A.push(e),2===A.length)){const{x:e,y:t}=te(A[0].clientX,A[0].clientY,A[1].clientX,A[1].clientY);L.startX=L.x=e,L.startY=L.y=t,L.distance=ee(A[0].clientX-A[1].clientX,A[0].clientY-A[1].clientY)/E.scale}},j=e=>{if(!A.length)return;w[v].slider.classList.add("tobii__slider--is-"+(F()?"moving":"dragging"));const t=A.findIndex(t=>t.pointerId===e.pointerId);if(A[t]=e,2===A.length){const{x:e,y:t}=te(A[0].clientX,A[0].clientY,A[1].clientX,A[1].clientY),i=ee(A[0].clientX-A[1].clientX,A[0].clientY-A[1].clientY)/L.distance;return Z(K(i,1,4),e,t,e-L.x,t-L.y),L.x=e,void(L.y=t)}if(F()&&Q(e.clientX-L.x,e.clientY-L.y),L.x=e.clientX,L.y=e.clientY,!F()){const e=L.startX-L.x,t=L.startY-L.y;if(ee(e,t)<10)return;Math.abs(e)>Math.abs(t)&&w[v].elementsLength>1?w[v].slider.style.transform=`translate(${y-Math.round(e)}px, 0)`:l.swipeClose&&(w[v].slider.style.transform=`translate(${y}px, -${Math.round(t)}px)`)}},W=e=>{if(!A.length)return;w[v].slider.classList.remove("tobii__slider--is-"+(F()?"moving":"dragging"));const t=A.findIndex(t=>t.pointerId===e.pointerId);A.splice(t,1);const i=e.clientX,r=e.clientY,n=L.startX-i,a=L.startY-r,s=Math.abs(n),o=Math.abs(a);if(s||o)F()||(n<0&&s>l.threshold&&w[v].currentIndex>0?N():n>0&&s>l.threshold&&w[v].currentIndex!==w[v].elementsLength-1?P():a>0&&o>l.threshold&&l.swipeClose?X():R());else{const t=(new Date).getTime(),n=t-x;n<500&&n>100?(e.preventDefault(),x=0,F()?ie():Z(2,i,r,0,0)):(x=t,de()&&window.setTimeout(()=>{const{left:t,top:n,bottom:a,right:s,width:o}=e.target.getBoundingClientRect();ra||!x||(i>t&&is-o/2&&P())},500))}},G=e=>{const t=Math.sign(e.deltaY)>0?-1:1;(F()||t)&&(e.preventDefault(),Z(K(E.scale+t/(10/E.scale),1,4),e.clientX,e.clientY,0,0))},J=(e,t)=>{const{element:i,scale:r,originX:n,originY:a}=E,s="x"===e,o=s?n:a,l=s?"offsetWidth":"offsetHeight",d=i.parentNode[l],c=i[l],u=i.getBoundingClientRect(),p=(o-c/2)*(r-1),h=Math.max(0,Math.round(s?u.width:u.height)-d),b=Math.round(h/2);return K(t,0-b+p,b+p)},K=(e,t,i)=>Math.max(Math.min(e,i),t),F=()=>1!==E.scale,Q=(e,t)=>{0!==e&&(E.translateX=J("x",E.translateX+e)),0!==t&&(E.translateY=J("y",E.translateY+t));const{element:i,originX:r,originY:n,translateX:a,translateY:s,scale:o}=E;i.style.transformOrigin=`${r}px ${n}px`,i.style.transform=`translate(${a}px, ${s}px) scale(${o})`},Z=(e,t,i,r,n)=>{E.element||(E.element=u.querySelector(".tobii__slide--is-active img"));const{left:a,top:s}=E.element.getBoundingClientRect(),o=(i-s)/E.scale;E.originX=(t-a)/E.scale,E.originY=o,E.scale=e,Q(r,n)},ee=(e,t)=>Math.hypot(e,t),te=(e,t,i,r)=>({x:(e+i)/2,y:(t+r)/2}),ie=()=>{E.scale=1,E.originX=0,E.originY=0,E.translateX=0,E.translateY=0,Q(0,0),E.element=null},re=()=>{l.keyboard&&window.addEventListener("keydown",D),window.addEventListener("resize",U),window.addEventListener("popstate",X),ue("click",H),l.draggable&&(ue("pointerdown",V),ue("pointermove",j),ue("pointerup",W),ue("pointercancel",B),ue("pointerout",B),ue("pointerleave",B),ue("contextmenu",B)),ue("wheel",G)},ne=()=>{l.keyboard&&window.removeEventListener("keydown",D),window.removeEventListener("resize",U),window.removeEventListener("popstate",X),pe("click",H),l.draggable&&(pe("pointerdown",V),pe("pointermove",j),pe("pointerup",W),pe("pointercancel",B),pe("pointerout",B),pe("pointerleave",B),pe("contextmenu",B)),pe("wheel",G)},ae=()=>{l.draggable&&!w[v].slider.classList.contains("tobii__slider--is-draggable")&&w[v].slider.classList.add("tobii__slider--is-draggable"),!l.nav||1===w[v].elementsLength||"auto"===l.nav&&de()?(p.setAttribute("aria-hidden","true"),p.disabled=!0,h.setAttribute("aria-hidden","true"),h.disabled=!0):(p.setAttribute("aria-hidden","false"),p.disabled=!1,h.setAttribute("aria-hidden","false"),h.disabled=!1),g.setAttribute("aria-hidden",l.counter&&1!==w[v].elementsLength?"false":"true")},se=(e=null)=>{R(),g.textContent=`${w[v].currentIndex+1}/${w[v].elementsLength}`,(e=>{(!0===l.nav||"auto"===l.nav)&&!de()&&w[v].elementsLength>1?(p.setAttribute("aria-hidden","true"),p.disabled=!0,h.setAttribute("aria-hidden","true"),h.disabled=!0,1===w[v].elementsLength?l.close&&b.focus():0===w[v].currentIndex?(h.setAttribute("aria-hidden","false"),h.disabled=!1,h.focus()):w[v].currentIndex===w[v].elementsLength-1?(p.setAttribute("aria-hidden","false"),p.disabled=!1,p.focus()):(p.setAttribute("aria-hidden","false"),p.disabled=!1,h.setAttribute("aria-hidden","false"),h.disabled=!1,"left"===e?p.focus():h.focus())):l.close&&b.focus()})(e)},oe=()=>{le()&&X(),Object.entries(w).forEach(e=>{e[1].gallery.forEach(e=>{C(e)})}),w={},v=null;for(const e in s)s[e].onReset()},le=()=>"false"===u.getAttribute("aria-hidden"),de=()=>"ontouchstart"in window,ce=e=>-1!==["TEXTAREA","OPTION","INPUT","SELECT"].indexOf(e.nodeName)||e===p||e===h||e===b,ue=(e,t)=>{u.addEventListener(e,t)},pe=(e,t)=>{u.removeEventListener(e,t)};return(e=>{if(document.querySelector("div.tobii"))return void console.log("Multiple lightbox instances not supported.");l=(e=>({selector:".lightbox",captions:!0,captionsSelector:"img",captionAttribute:"alt",captionText:null,captionHTML:!1,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,modal:!1,theme:"tobii--theme-default",...e}))(e),u||(u=document.createElement("div"),u.setAttribute("role","dialog"),u.setAttribute("aria-hidden","true"),u.classList.add("tobii"),u.classList.add(l.theme),p=document.createElement("button"),p.className="tobii__btn tobii__btn--previous",p.setAttribute("type","button"),p.setAttribute("aria-label",l.navLabel[0]),p.innerHTML=l.navText[0],u.appendChild(p),h=document.createElement("button"),h.className="tobii__btn tobii__btn--next",h.setAttribute("type","button"),h.setAttribute("aria-label",l.navLabel[1]),h.innerHTML=l.navText[1],u.appendChild(h),b=document.createElement("button"),b.className="tobii__btn tobii__btn--close",b.setAttribute("type","button"),b.setAttribute("aria-label",l.closeLabel),b.innerHTML=l.closeText,u.appendChild(b),g=document.createElement("div"),g.className="tobii__counter",u.appendChild(g),document.body.appendChild(u));const t=document.querySelectorAll(l.selector);if(!t)throw new Error(`Ups, I can't find the selector ${l.selector} on this website.`);const i=[];t.forEach(e=>{const t=e.hasAttribute("data-group")?e.getAttribute("data-group"):"default";let r=e.href;e.hasAttribute("data-target")&&(r=e.getAttribute("data-target")),r+="__"+t,void 0!==i[r]?e.addEventListener("click",e=>{$(t),T(),e.preventDefault()}):(i[r]=1,_(e))})})(a),n.open=T,n.previous=N,n.next=P,n.close=X,n.add=_,n.remove=C,n.reset=oe,n.destroy=()=>{oe(),u.parentNode.removeChild(u)},n.isOpen=le,n.slidesIndex=()=>w[v].currentIndex,n.select=e=>{const t=w[v].currentIndex;if(!le())throw new Error("Ups, I'm closed.");if(le()){if(!e&&0!==e)throw new Error("Ups, no slide specified.");if(e===w[v].currentIndex)throw new Error(`Ups, slide ${e} is already selected.`);if(-1===e||e>=w[v].elementsLength)throw new Error(`Ups, I can't find slide ${e}.`)}w[v].currentIndex=e,O(t),M(e),et&&(se("right"),k(t),q(e+1))},n.slidesCount=()=>w[v].elementsLength,n.selectGroup=$,n.currentGroup=()=>v,n.on=ue,n.off=pe,n}}); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e||self).Tobii=t()}(this,function(){class e{constructor(){this.figcaptionId=0,this.userSettings=null}init(e,t,i){this.userSettings=i;const r=document.createElement("figure"),n=document.createElement("figcaption"),a=document.createElement("img"),s=e.querySelector("img"),o=document.createElement("div");if(r.style.opacity="0",s&&(a.alt=s.alt||""),a.setAttribute("src",""),a.setAttribute("data-src",e.href),e.hasAttribute("data-srcset")&&a.setAttribute("data-srcset",e.getAttribute("data-srcset")),r.appendChild(a),this.userSettings.captions){let t;"function"==typeof this.userSettings.captionText?t=this.userSettings.captionText(e):"self"===this.userSettings.captionsSelector&&e.getAttribute(this.userSettings.captionAttribute)?t=e.getAttribute(this.userSettings.captionAttribute):"img"===this.userSettings.captionsSelector&&s&&s.getAttribute(this.userSettings.captionAttribute)&&(t=s.getAttribute(this.userSettings.captionAttribute)),this.userSettings.captionHTML?n.innerHTML=t:n.textContent=t,t&&(n.id=`tobii-figcaption-${this.figcaptionId}`,r.appendChild(n),a.setAttribute("aria-labelledby",n.id),++this.figcaptionId)}t.appendChild(r),o.className="tobii__loader",o.setAttribute("role","progressbar"),o.setAttribute("aria-label",this.userSettings.loadingIndicatorLabel),t.appendChild(o),t.setAttribute("data-type","image"),t.classList.add("tobii-image")}onPreload(e){this.onLoad(e)}onLoad(e){const t=e.querySelector("img");if(!t.hasAttribute("data-src"))return;const i=e.querySelector("figure"),r=e.querySelector(".tobii__loader");t.addEventListener("load",()=>{e.removeChild(r),i.style.opacity="1"}),t.addEventListener("error",()=>{e.removeChild(r),i.style.opacity="1"}),t.setAttribute("src",t.getAttribute("data-src")),t.removeAttribute("data-src"),t.hasAttribute("data-srcset")&&t.setAttribute("srcset",t.getAttribute("data-srcset"))}onLeave(e){}onCleanup(e){}onReset(){this.figcaptionId=0}}class t{constructor(){this.userSettings=null}init(e,t,i){this.userSettings=i;const r=e.hasAttribute("data-target")?e.getAttribute("data-target"):e.getAttribute("href");t.setAttribute("data-HREF",r),e.getAttribute("data-allow")&&t.setAttribute("data-allow",e.getAttribute("data-allow")),e.hasAttribute("data-width")&&t.setAttribute("data-width",`${e.getAttribute("data-width")}`),e.hasAttribute("data-height")&&t.setAttribute("data-height",`${e.getAttribute("data-height")}`),t.setAttribute("data-type","iframe"),t.classList.add("tobii-iframe")}onPreload(e){}onLoad(e){let t=e.querySelector("iframe");const i=document.createElement("div");if(i.className="tobii__loader",i.setAttribute("role","progressbar"),i.setAttribute("aria-label",this.userSettings.loadingIndicatorLabel),e.appendChild(i),null==t){t=document.createElement("iframe");const i=e.getAttribute("data-href");t.setAttribute("frameborder","0"),t.setAttribute("src",i),t.setAttribute("allowfullscreen",""),i.indexOf("youtube.com")>-1?t.setAttribute("allow","accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"):i.indexOf("vimeo.com")>-1?t.setAttribute("allow","autoplay; picture-in-picture"):e.hasAttribute("data-allow")&&t.setAttribute("allow",e.getAttribute("data-allow")),e.getAttribute("data-width")&&(t.style.maxWidth=`${e.getAttribute("data-width")}`),e.getAttribute("data-height")&&(t.style.maxHeight=`${e.getAttribute("data-height")}`),t.style.opacity="0",e.appendChild(t),t.addEventListener("load",()=>{t.style.opacity="1";const i=e.querySelector(".tobii__loader");i&&e.removeChild(i)}),t.addEventListener("error",()=>{t.style.opacity="1";const i=e.querySelector(".tobii__loader");i&&e.removeChild(i)})}else t.setAttribute("src",e.getAttribute("data-href"))}onLeave(e){}onCleanup(e){const t=e.querySelector("iframe");t.setAttribute("src",""),t.style.opacity="0"}onReset(){}}class i{constructor(){this.userSettings=null}init(e,t,i){this.userSettings=i;const r=e.hasAttribute("data-target")?e.getAttribute("data-target"):e.getAttribute("href"),n=document.querySelector(r).cloneNode(!0);if(!n)throw new Error(`Ups, I can't find the target ${r}.`);t.appendChild(n),t.setAttribute("data-type","html"),t.classList.add("tobii-html")}onPreload(e){}onLoad(e,t){const i=e.querySelector("video");i&&(i.hasAttribute("data-time")&&i.readyState>0&&(i.currentTime=i.getAttribute("data-time")),this.userSettings.autoplayVideo&&i.play());const r=e.querySelector("audio");r&&this.userSettings.autoplayAudio&&r.play(),e.classList.add("tobii-group-"+t)}onLeave(e){const t=e.querySelector("video");t&&(t.paused||t.pause(),t.readyState>0&&t.setAttribute("data-time",t.currentTime));const i=e.querySelector("audio");i&&(i.paused||i.pause())}onCleanup(e){const t=e.querySelector("video");if(t&&t.readyState>0&&t.readyState<3&&t.duration!==t.currentTime){const i=t.cloneNode(!0);this._removeSources(t),t.load(),t.parentNode.removeChild(t),e.appendChild(i)}}onReset(){}_removeSources(e){const t=e.querySelectorAll("src");t&&t.forEach(e=>{e.setAttribute("src","")})}}class r{constructor(){this.playerId=0,this.PLAYER=[],this.userSettings=null}init(e,t,i){this.userSettings=i;const r=document.createElement("div");t.appendChild(r),this.PLAYER[this.playerId]=new window.YT.Player(r,{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",this.playerId),t.setAttribute("data-type","youtube"),t.classList.add("tobii-youtube"),this.playerId++}onPreload(e){}onLoad(e){this.userSettings.autoplayVideo&&this.PLAYER[e.getAttribute("data-player")].playVideo()}onLeave(e){1===this.PLAYER[e.getAttribute("data-player")].getPlayerState()&&this.PLAYER[e.getAttribute("data-player")].pauseVideo()}onCleanup(e){1===this.PLAYER[e.getAttribute("data-player")].getPlayerState()&&this.PLAYER[e.getAttribute("data-player")].pauseVideo()}onReset(){}}return function n(a){const s={image:new e,html:new i,iframe:new t,youtube:new r},o=['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])'];let l={};const d=[],c={gallery:[],slider:null,sliderElements:[],elementsLength:0,currentIndex:0,x:0};let u=null,p=null,h=null,b=null,g=null,m=null,y=null,f=!1,w={},v=null,A=[],x=0;const E={element:null,originX:0,originY:0,translateX:0,translateY:0,scale:1},L={startX:0,startY:0,x:0,y:0,distance:0},_=e=>{if(null===document.querySelector('[data-type="youtube"]')||f)S(e);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===d.indexOf(e)&&d.push(e),window.onYouTubePlayerAPIReady=()=>{d.forEach(e=>{S(e)}),f=!0}}},I=e=>e.hasAttribute("data-group")?e.getAttribute("data-group"):"default",S=e=>{const t=I(e);if(Object.prototype.hasOwnProperty.call(w,t)||(w[t]=JSON.parse(JSON.stringify(c)),w[t].slider=document.createElement("div"),w[t].slider.className="tobii__slider",w[t].slider.setAttribute("aria-hidden","true"),u.appendChild(w[t].slider)),-1!==w[t].gallery.indexOf(e))throw new Error("Ups, element already added.");{if(w[t].gallery.push(e),w[t].elementsLength++,l.zoom&&e.querySelector("img")&&"false"!==e.getAttribute("data-zoom")||"true"===e.getAttribute("data-zoom")){const t=document.createElement("div");t.className="tobii-zoom__icon",t.innerHTML=l.zoomText,e.classList.add("tobii-zoom"),e.appendChild(t)}e.addEventListener("click",z);const i=Y(e),r=document.createElement("div"),n=document.createElement("div");r.className="tobii__slide",r.style.position="absolute",r.style.left=100*w[t].x+"%",r.setAttribute("aria-hidden","true"),i.init(e,n,l),r.appendChild(n),w[t].slider.appendChild(r),w[t].sliderElements.push(r),++w[t].x,le()&&t===v&&(ae(),se())}},C=e=>{const t=I(e);if(-1===w[t].gallery.indexOf(e))throw new Error(`Ups, I can't find a slide for the element ${e}.`);{const i=w[t].gallery.indexOf(e),r=w[t].sliderElements[i];if(le()&&t===v&&i===w[t].currentIndex){if(1===w[t].elementsLength)throw X(),new Error("Ups, I've closed. There are no slides more to show.");0===w[t].currentIndex?P():N(),ae(),se()}if(w[t].gallery.splice(w[t].gallery.indexOf(e)),w[t].sliderElements.splice(w[t].gallery.indexOf(e)),w[t].elementsLength--,--w[t].x,l.zoom&&e.querySelector(".tobii-zoom__icon")){const t=e.querySelector(".tobii-zoom__icon");t.parentNode.classList.remove("tobii-zoom"),t.parentNode.removeChild(t)}e.removeEventListener("click",z),r.parentNode.removeChild(r)}},Y=e=>{const t=e.getAttribute("data-type");return void 0!==s[t]?s[t]:(e.hasAttribute("data-type")&&console.log("Unknown lightbox element type: "+t),s.image)},T=(e=0)=>{if(le())throw new Error("Ups, I'm aleady open.");if(-1===e||e>=w[v].elementsLength)throw new Error(`Ups, I can't find slide ${e}.`);document.documentElement.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open-"+v),ae(),l.close||(b.disabled=!1,b.setAttribute("aria-hidden","true")),m=document.activeElement;const t=window.location.href;window.history.pushState({tobii:"close"},"Image",t),w[v].currentIndex=e,re(),M(w[v].currentIndex),w[v].slider.setAttribute("aria-hidden","false"),u.setAttribute("aria-hidden","false"),se(),q(w[v].currentIndex+1),q(w[v].currentIndex-1),w[v].slider.classList.add("tobii__slider--animate");const i=new window.CustomEvent("open",{detail:{group:v}});u.dispatchEvent(i)},X=()=>{if(!le())throw new Error("Ups, I'm already closed.");document.documentElement.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open-"+v),ne(),null!==window.history.state&&"close"===window.history.state.tobii&&window.history.back(),m.focus(),O(w[v].currentIndex),k(w[v].currentIndex),u.setAttribute("aria-hidden","true"),w[v].slider.setAttribute("aria-hidden","true"),w[v].currentIndex=0,w[v].slider.classList.remove("tobii__slider--animate");const e=new window.CustomEvent("close",{detail:{group:v}});u.dispatchEvent(e)},q=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]");Y(t).onPreload(t)},M=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]"),i=Y(t);w[v].sliderElements[e].classList.add("tobii__slide--is-active"),w[v].sliderElements[e].setAttribute("aria-hidden","false"),i.onLoad(t,v)},N=()=>{if(!le())throw new Error("Ups, I'm closed.");w[v].currentIndex>0&&(O(w[v].currentIndex),M(--w[v].currentIndex),se("left"),k(w[v].currentIndex+1),q(w[v].currentIndex-1));const e=new window.CustomEvent("previous",{detail:{group:v}});u.dispatchEvent(e)},P=()=>{if(!le())throw new Error("Ups, I'm closed.");w[v].currentIndex{if(le())throw new Error("Ups, I'm open.");if(!e)throw new Error("Ups, no group specified.");if(e&&!Object.prototype.hasOwnProperty.call(w,e))throw new Error(`Ups, I don't have a group called "${e}".`);v=e},O=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]"),i=Y(t);w[v].sliderElements[e].classList.remove("tobii__slide--is-active"),w[v].sliderElements[e].setAttribute("aria-hidden","true"),i.onLeave(t)},k=e=>{if(void 0===w[v].sliderElements[e])return;const t=w[v].sliderElements[e].querySelector("[data-type]");Y(t).onCleanup(t),L.startX=0,L.startY=0,L.x=0,L.y=0,L.distance=0,x=0,F()&&ie(),E.element=null},R=()=>{y=-w[v].currentIndex*u.offsetWidth,w[v].slider.style.transform=`translate(${y}px, 0)`},U=()=>{R()},z=e=>{e.preventDefault(),v=I(e.currentTarget),T(w[v].gallery.indexOf(e.currentTarget))},H=e=>{e.target===p?N():e.target===h?P():(e.target===b||e.target.classList.contains("tobii__slide")&&l.docClose)&&X(),e.stopPropagation()},D=e=>{const t=Array.prototype.slice.call(u.querySelectorAll(`.tobii__btn:not([disabled]), .tobii__slide--is-active ${o.join(", .tobii__slide--is-active ")}`)).filter(e=>!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length)),i=t.indexOf(document.activeElement);9===e.keyCode||"Tab"===e.code?e.shiftKey&&0===i?(t[t.length-1].focus(),e.preventDefault()):e.shiftKey||i!==t.length-1||(t[0].focus(),e.preventDefault()):27===e.keyCode||"Escape"===e.code?(e.preventDefault(),X()):37===e.keyCode||"ArrowLeft"===e.code?(e.preventDefault(),N()):39!==e.keyCode&&"ArrowRight"!==e.code||(e.preventDefault(),P())},B=()=>{A=[],R(),w[v].slider.classList.remove("tobii__slider--is-"+(F()?"moving":"dragging"))},V=e=>{if(!ce(e.target)&&(e.preventDefault(),e.stopPropagation(),L.startX=L.x=e.clientX,L.startY=L.y=e.clientY,L.distance=0,A.push(e),2===A.length)){const{x:e,y:t}=te(A[0].clientX,A[0].clientY,A[1].clientX,A[1].clientY);L.startX=L.x=e,L.startY=L.y=t,L.distance=ee(A[0].clientX-A[1].clientX,A[0].clientY-A[1].clientY)/E.scale}},j=e=>{if(!A.length)return;w[v].slider.classList.add("tobii__slider--is-"+(F()?"moving":"dragging"));const t=A.findIndex(t=>t.pointerId===e.pointerId);if(A[t]=e,2===A.length){const{x:e,y:t}=te(A[0].clientX,A[0].clientY,A[1].clientX,A[1].clientY),i=ee(A[0].clientX-A[1].clientX,A[0].clientY-A[1].clientY)/L.distance;return Z(K(i,1,4),e,t,e-L.x,t-L.y),L.x=e,void(L.y=t)}if(F()&&Q(e.clientX-L.x,e.clientY-L.y),L.x=e.clientX,L.y=e.clientY,!F()){const e=L.startX-L.x,t=L.startY-L.y;if(ee(e,t)<10)return;Math.abs(e)>Math.abs(t)&&w[v].elementsLength>1?w[v].slider.style.transform=`translate(${y-Math.round(e)}px, 0)`:l.swipeClose&&(w[v].slider.style.transform=`translate(${y}px, -${Math.round(t)}px)`)}},W=e=>{if(!A.length)return;w[v].slider.classList.remove("tobii__slider--is-"+(F()?"moving":"dragging"));const t=A.findIndex(t=>t.pointerId===e.pointerId);A.splice(t,1);const i=e.clientX,r=e.clientY,n=L.startX-i,a=L.startY-r,s=Math.abs(n),o=Math.abs(a);if(s||o)F()||(n<0&&s>l.threshold&&w[v].currentIndex>0?N():n>0&&s>l.threshold&&w[v].currentIndex!==w[v].elementsLength-1?P():a>0&&o>l.threshold&&l.swipeClose?X():R());else{const t=(new Date).getTime(),n=t-x;n<500&&n>100?(e.preventDefault(),x=0,F()?ie():Z(2,i,r,0,0)):(x=t,de()&&window.setTimeout(()=>{const{left:t,top:n,bottom:a,right:s,width:o}=e.target.getBoundingClientRect();ra||!x||(i>t&&is-o/2&&P())},500))}},G=e=>{const t=Math.sign(e.deltaY)>0?-1:1;(F()||t)&&(e.preventDefault(),Z(K(E.scale+t/(10/E.scale),1,4),e.clientX,e.clientY,0,0))},J=(e,t)=>{const{element:i,scale:r,originX:n,originY:a}=E,s="x"===e,o=s?n:a,l=s?"offsetWidth":"offsetHeight",d=i.parentNode[l],c=i[l],u=i.getBoundingClientRect(),p=(o-c/2)*(r-1),h=Math.max(0,Math.round(s?u.width:u.height)-d),b=Math.round(h/2);return K(t,0-b+p,b+p)},K=(e,t,i)=>Math.max(Math.min(e,i),t),F=()=>1!==E.scale,Q=(e,t)=>{0!==e&&(E.translateX=J("x",E.translateX+e)),0!==t&&(E.translateY=J("y",E.translateY+t));const{element:i,originX:r,originY:n,translateX:a,translateY:s,scale:o}=E;i.style.transformOrigin=`${r}px ${n}px`,i.style.transform=`translate(${a}px, ${s}px) scale(${o})`},Z=(e,t,i,r,n)=>{E.element||(E.element=u.querySelector(".tobii__slide--is-active img"));const{left:a,top:s}=E.element.getBoundingClientRect(),o=(i-s)/E.scale;E.originX=(t-a)/E.scale,E.originY=o,E.scale=e,Q(r,n)},ee=(e,t)=>Math.hypot(e,t),te=(e,t,i,r)=>({x:(e+i)/2,y:(t+r)/2}),ie=()=>{E.scale=1,E.originX=0,E.originY=0,E.translateX=0,E.translateY=0,Q(0,0)},re=()=>{l.keyboard&&window.addEventListener("keydown",D),window.addEventListener("resize",U),window.addEventListener("popstate",X),ue("click",H),l.draggable&&(ue("pointerdown",V),ue("pointermove",j),ue("pointerup",W),ue("pointercancel",B),ue("pointerout",B),ue("pointerleave",B),ue("contextmenu",B)),ue("wheel",G)},ne=()=>{l.keyboard&&window.removeEventListener("keydown",D),window.removeEventListener("resize",U),window.removeEventListener("popstate",X),pe("click",H),l.draggable&&(pe("pointerdown",V),pe("pointermove",j),pe("pointerup",W),pe("pointercancel",B),pe("pointerout",B),pe("pointerleave",B),pe("contextmenu",B)),pe("wheel",G)},ae=()=>{l.draggable&&!w[v].slider.classList.contains("tobii__slider--is-draggable")&&w[v].slider.classList.add("tobii__slider--is-draggable"),!l.nav||1===w[v].elementsLength||"auto"===l.nav&&de()?(p.setAttribute("aria-hidden","true"),p.disabled=!0,h.setAttribute("aria-hidden","true"),h.disabled=!0):(p.setAttribute("aria-hidden","false"),p.disabled=!1,h.setAttribute("aria-hidden","false"),h.disabled=!1),g.setAttribute("aria-hidden",l.counter&&1!==w[v].elementsLength?"false":"true")},se=(e=null)=>{R(),g.textContent=`${w[v].currentIndex+1}/${w[v].elementsLength}`,(e=>{(!0===l.nav||"auto"===l.nav)&&!de()&&w[v].elementsLength>1?(p.setAttribute("aria-hidden","true"),p.disabled=!0,h.setAttribute("aria-hidden","true"),h.disabled=!0,1===w[v].elementsLength?l.close&&b.focus():0===w[v].currentIndex?(h.setAttribute("aria-hidden","false"),h.disabled=!1,h.focus()):w[v].currentIndex===w[v].elementsLength-1?(p.setAttribute("aria-hidden","false"),p.disabled=!1,p.focus()):(p.setAttribute("aria-hidden","false"),p.disabled=!1,h.setAttribute("aria-hidden","false"),h.disabled=!1,"left"===e?p.focus():h.focus())):l.close&&b.focus()})(e)},oe=()=>{le()&&X(),Object.entries(w).forEach(e=>{e[1].gallery.forEach(e=>{C(e)})}),w={},v=null;for(const e in s)s[e].onReset()},le=()=>"false"===u.getAttribute("aria-hidden"),de=()=>"ontouchstart"in window,ce=e=>-1!==["TEXTAREA","OPTION","INPUT","SELECT"].indexOf(e.nodeName)||e===p||e===h||e===b,ue=(e,t)=>{u.addEventListener(e,t)},pe=(e,t)=>{u.removeEventListener(e,t)};return(e=>{if(document.querySelector("div.tobii"))return void console.log("Multiple lightbox instances not supported.");l=(e=>({selector:".lightbox",captions:!0,captionsSelector:"img",captionAttribute:"alt",captionText:null,captionHTML:!1,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,modal:!1,theme:"tobii--theme-default",...e}))(e),u||(u=document.createElement("div"),u.setAttribute("role","dialog"),u.setAttribute("aria-hidden","true"),u.classList.add("tobii"),u.classList.add(l.theme),p=document.createElement("button"),p.className="tobii__btn tobii__btn--previous",p.setAttribute("type","button"),p.setAttribute("aria-label",l.navLabel[0]),p.innerHTML=l.navText[0],u.appendChild(p),h=document.createElement("button"),h.className="tobii__btn tobii__btn--next",h.setAttribute("type","button"),h.setAttribute("aria-label",l.navLabel[1]),h.innerHTML=l.navText[1],u.appendChild(h),b=document.createElement("button"),b.className="tobii__btn tobii__btn--close",b.setAttribute("type","button"),b.setAttribute("aria-label",l.closeLabel),b.innerHTML=l.closeText,u.appendChild(b),g=document.createElement("div"),g.className="tobii__counter",u.appendChild(g),document.body.appendChild(u));const t=document.querySelectorAll(l.selector);if(!t)throw new Error(`Ups, I can't find the selector ${l.selector} on this website.`);const i=[];t.forEach(e=>{const t=e.hasAttribute("data-group")?e.getAttribute("data-group"):"default";let r=e.href;e.hasAttribute("data-target")&&(r=e.getAttribute("data-target")),r+="__"+t,void 0!==i[r]?e.addEventListener("click",e=>{$(t),T(),e.preventDefault()}):(i[r]=1,_(e))})})(a),n.open=T,n.previous=N,n.next=P,n.close=X,n.add=_,n.remove=C,n.reset=oe,n.destroy=()=>{oe(),u.parentNode.removeChild(u)},n.isOpen=le,n.slidesIndex=()=>w[v].currentIndex,n.select=e=>{const t=w[v].currentIndex;if(!le())throw new Error("Ups, I'm closed.");if(le()){if(!e&&0!==e)throw new Error("Ups, no slide specified.");if(e===w[v].currentIndex)throw new Error(`Ups, slide ${e} is already selected.`);if(-1===e||e>=w[v].elementsLength)throw new Error(`Ups, I can't find slide ${e}.`)}w[v].currentIndex=e,O(t),M(e),et&&(se("right"),k(t),q(e+1))},n.slidesCount=()=>w[v].elementsLength,n.selectGroup=$,n.currentGroup=()=>v,n.on=ue,n.off=pe,n}});