tobii.min.js 18 KB

1
  1. !function(){if("function"!=typeof window.CustomEvent){var e=function(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n};e.prototype=window.Event.prototype,window.CustomEvent=e}function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e}).apply(this,arguments)}function n(e){var i=['a[href]:not([tabindex^="-"]):not([inert])','area[href]:not([tabindex^="-"]):not([inert])',"input:not([disabled]):not([inert])","select:not([disabled]):not([inert])","textarea:not([disabled]):not([inert])","button:not([disabled]):not([inert])",'iframe:not([tabindex^="-"]):not([inert])','audio:not([tabindex^="-"]):not([inert])','video:not([tabindex^="-"]):not([inert])','[contenteditable]:not([tabindex^="-"]):not([inert])','[tabindex]:not([tabindex^="-"]):not([inert])'],r=[],o={gallery:[],slider:null,sliderElements:[],elementsLength:0,currentIndex:0,x:0},a=[],d={},s=0,l=null,u=null,c=null,p=null,b=null,f={},m=!1,h=!1,v=!1,g=null,y=null,w=null,x=!1,E=!1,A=0,L={},_=null,C=null,I={image:{checkSupport:function(e){return!e.hasAttribute("data-type")&&e.href.match(/\.(png|jpe?g|tiff|tif|gif|bmp|webp|avif|svg|ico)(\?.*)?$/i)},init:function(e,t){var n=document.createElement("figure"),i=document.createElement("figcaption"),r=document.createElement("img"),o=e.querySelector("img"),a=document.createElement("div");n.style.opacity="0",o&&(r.alt=o.alt||""),r.setAttribute("src",""),r.setAttribute("data-src",e.href),n.appendChild(r),d.captions&&("function"==typeof d.captionText?i.textContent=d.captionText(e):"self"===d.captionsSelector&&e.getAttribute(d.captionAttribute)?i.textContent=e.getAttribute(d.captionAttribute):"img"===d.captionsSelector&&o&&o.getAttribute(d.captionAttribute)&&(i.textContent=o.getAttribute(d.captionAttribute)),i.textContent&&(i.id="tobii-figcaption-"+s,n.appendChild(i),r.setAttribute("aria-labelledby",i.id),++s)),t.appendChild(n),a.className="tobii__loader",a.setAttribute("role","progressbar"),a.setAttribute("aria-label",d.loadingIndicatorLabel),t.appendChild(a),t.setAttribute("data-type","image")},onPreload:function(e){I.image.onLoad(e)},onLoad:function(e){var t=e.querySelector("img");if(t.hasAttribute("data-src")){var n=e.querySelector("figure"),i=e.querySelector(".tobii__loader");t.onload=function(){e.removeChild(i),n.style.opacity="1"},t.setAttribute("src",t.getAttribute("data-src")),t.removeAttribute("data-src")}},onLeave:function(e){},onCleanup:function(e){}},html:{checkSupport:function(e){return oe(e,"html")},init:function(e,t){var n=e.hasAttribute("href")?e.getAttribute("href"):e.getAttribute("data-target"),i=document.querySelector(n);if(!i)throw new Error("Ups, I can't find the target "+n+".");t.appendChild(i),t.setAttribute("data-type","html")},onPreload:function(e){},onLoad:function(e){var t=e.querySelector("video");t&&(t.hasAttribute("data-time")&&t.readyState>0&&(t.currentTime=t.getAttribute("data-time")),d.autoplayVideo&&t.play())},onLeave:function(e){var t=e.querySelector("video");t&&(t.paused||t.pause(),t.readyState>0&&t.setAttribute("data-time",t.currentTime))},onCleanup:function(e){var t=e.querySelector("video");if(t&&t.readyState>0&&t.readyState<3&&t.duration!==t.currentTime){var n=t.cloneNode(!0);ae(t),t.load(),t.parentNode.removeChild(t),e.appendChild(n)}}},iframe:{checkSupport:function(e){return oe(e,"iframe")},init:function(e,t){var n=document.createElement("iframe"),i=e.hasAttribute("href")?e.getAttribute("href"):e.getAttribute("data-target");n.setAttribute("frameborder","0"),n.setAttribute("src",""),n.setAttribute("data-src",i),e.getAttribute("data-width")&&(n.style.maxWidth=e.getAttribute("data-width")+"px"),e.getAttribute("data-height")&&(n.style.maxHeight=e.getAttribute("data-height")+"px"),t.appendChild(n),t.setAttribute("data-type","iframe")},onPreload:function(e){},onLoad:function(e){var t=e.querySelector("iframe");t.setAttribute("src",t.getAttribute("data-src"))},onLeave:function(e){},onCleanup:function(e){}},youtube:{checkSupport:function(e){return oe(e,"youtube")},init:function(e,t){var n=document.createElement("div");t.appendChild(n),a[A]=new window.YT.Player(n,{host:"https://www.youtube-nocookie.com",height:e.getAttribute("data-height")||"360",width:e.getAttribute("data-width")||"640",videoId:e.getAttribute("data-id"),playerVars:{controls:e.getAttribute("data-controls")||1,rel:0,playsinline:1}}),t.setAttribute("data-player",A),t.setAttribute("data-type","youtube"),A++},onPreload:function(e){},onLoad:function(e){d.autoplayVideo&&a[e.getAttribute("data-player")].playVideo()},onLeave:function(e){1===a[e.getAttribute("data-player")].getPlayerState()&&a[e.getAttribute("data-player")].pauseVideo()},onCleanup:function(e){1===a[e.getAttribute("data-player")].getPlayerState()&&a[e.getAttribute("data-player")].pauseVideo()}}},S=function(e){if(null===document.querySelector('[data-type="youtube"]')||E)k(e);else{if(null===document.getElementById("iframe_api")){var t=document.createElement("script"),n=document.getElementsByTagName("script")[0];t.id="iframe_api",t.src="https://www.youtube.com/iframe_api",n.parentNode.insertBefore(t,n)}-1===r.indexOf(e)&&r.push(e),window.onYouTubePlayerAPIReady=function(){r.forEach(function(e){k(e)}),E=!0}}},T=function(e){return e.hasAttribute("data-group")?e.getAttribute("data-group"):"default"},k=function(e){if(_=T(e),Object.prototype.hasOwnProperty.call(L,_)||(L[_]=JSON.parse(JSON.stringify(o)),N()),-1!==L[_].gallery.indexOf(e))throw new Error("Ups, element already added.");if(L[_].gallery.push(e),L[_].elementsLength++,d.zoom&&e.querySelector("img")){var t=document.createElement("div");t.className="tobii-zoom__icon",t.innerHTML=d.zoomText,e.classList.add("tobii-zoom"),e.appendChild(t)}e.addEventListener("click",W),O(e),ue()&&_===C&&(de(),se())},P=function(e){var t=T(e);if(-1===L[t].gallery.indexOf(e))throw new Error("Ups, I can't find a slide for the element "+e+".");var n=L[t].gallery.indexOf(e),i=L[t].sliderElements[n];if(ue()&&t===C&&n===L[t].currentIndex){if(1===L[t].elementsLength)throw X(),new Error("Ups, I've closed. There are no slides more to show.");0===L[t].currentIndex?M():z()}if(L[t].elementsLength--,d.zoom&&e.querySelector(".tobii-zoom__icon")){var r=e.querySelector(".tobii-zoom__icon");r.parentNode.classList.remove("tobii-zoom"),r.parentNode.removeChild(r)}e.removeEventListener("click",W),i.parentNode.removeChild(i)},N=function(){L[_].slider=document.createElement("div"),L[_].slider.className="tobii__slider",L[_].slider.setAttribute("aria-hidden","true"),l.appendChild(L[_].slider)},O=function(e){for(var t in I)if(Object.prototype.hasOwnProperty.call(I,t)&&I[t].checkSupport(e)){var n=document.createElement("div"),i=document.createElement("div");n.className="tobii__slide",n.style.position="absolute",n.style.left=100*L[_].x+"%",n.setAttribute("aria-hidden","true"),I[t].init(e,i),n.appendChild(i),L[_].slider.appendChild(n),L[_].sliderElements.push(n),++L[_].x;break}},q=function(e){if(C=null!==C?C:_,ue())throw new Error("Ups, I'm aleady open.");if(!ue()&&(e||(e=0),-1===e||e>=L[C].elementsLength))throw new Error("Ups, I can't find slide "+e+".");d.hideScrollbar&&(document.documentElement.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open")),de(),d.close||(p.disabled=!1,p.setAttribute("aria-hidden","true")),g=document.activeElement;var t=window.location.href;window.history.pushState({tobii:"close"},"Image",t),L[C].currentIndex=e,B(),ie(),Y(L[C].currentIndex),L[C].slider.setAttribute("aria-hidden","false"),l.setAttribute("aria-hidden","false"),se(),U(L[C].currentIndex+1),U(L[C].currentIndex-1),setTimeout(function(){L[C].slider.classList.add("tobii__slider--animate")},1e3);var n=new window.CustomEvent("open");l.dispatchEvent(n)},X=function(){if(!ue())throw new Error("Ups, I'm already closed.");d.hideScrollbar&&(document.documentElement.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open")),re(),null!==window.history.state&&"close"===window.history.state.tobii&&window.history.back(),g.focus(),D(L[C].currentIndex),H(L[C].currentIndex),l.setAttribute("aria-hidden","true"),L[C].slider.setAttribute("aria-hidden","true"),L[C].currentIndex=0,L[C].slider.classList.remove("tobii__slider--animate")},U=function(e){if(void 0!==L[C].sliderElements[e]){var t=L[C].sliderElements[e].querySelector("[data-type]"),n=t.getAttribute("data-type");I[n].onPreload(t)}},Y=function(e){if(void 0!==L[C].sliderElements[e]){var t=L[C].sliderElements[e].querySelector("[data-type]"),n=t.getAttribute("data-type");L[C].sliderElements[e].classList.add("tobii__slide--is-active"),L[C].sliderElements[e].setAttribute("aria-hidden","false"),I[n].onLoad(t)}},z=function(){if(!ue())throw new Error("Ups, I'm closed.");L[C].currentIndex>0&&(D(L[C].currentIndex),Y(--L[C].currentIndex),se("left"),H(L[C].currentIndex+1),U(L[C].currentIndex-1));var e=new window.CustomEvent("previous");l.dispatchEvent(e)},M=function(){if(!ue())throw new Error("Ups, I'm closed.");L[C].currentIndex<L[C].elementsLength-1&&(D(L[C].currentIndex),Y(++L[C].currentIndex),se("right"),H(L[C].currentIndex-1),U(L[C].currentIndex+1));var e=new window.CustomEvent("next");l.dispatchEvent(e)},D=function(e){if(void 0!==L[C].sliderElements[e]){var t=L[C].sliderElements[e].querySelector("[data-type]"),n=t.getAttribute("data-type");L[C].sliderElements[e].classList.remove("tobii__slide--is-active"),L[C].sliderElements[e].setAttribute("aria-hidden","true"),I[n].onLeave(t)}},H=function(e){if(void 0!==L[C].sliderElements[e]){var t=L[C].sliderElements[e].querySelector("[data-type]"),n=t.getAttribute("data-type");I[n].onCleanup(t)}},j=function(){L[C=null!==C?C:_].slider.style.transform="translate3d("+(y=-L[C].currentIndex*l.offsetWidth)+"px, 0, 0)",w=y},B=function(){f={startX:0,endX:0,startY:0,endY:0}},V=function(){var e=f.endX-f.startX,t=f.endY-f.startY,n=Math.abs(e),i=Math.abs(t);e>0&&n>d.threshold&&L[C].currentIndex>0?z():e<0&&n>d.threshold&&L[C].currentIndex!==L[C].elementsLength-1?M():t<0&&i>d.threshold&&d.swipeClose?X():j()},R=function(){x||(x=!0,window.requestAnimationFrame(function(){j(),x=!1}))},W=function(e){e.preventDefault(),C=T(e.currentTarget),q(L[C].gallery.indexOf(e.currentTarget))},G=function(e){e.target===u?z():e.target===c?M():(e.target===p||!1===m&&!1===h&&e.target.classList.contains("tobii__slide")&&d.docClose)&&X(),e.stopPropagation()},J=function(e){var t=Array.prototype.slice.call(l.querySelectorAll(".tobii__btn:not([disabled]), .tobii__slide--is-active + "+i.join(", .tobii__slide--is-active "))).filter(function(e){return!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length)}),n=t.indexOf(document.activeElement);9===e.keyCode||"Tab"===e.code?e.shiftKey&&0===n?(t[t.length-1].focus(),e.preventDefault()):e.shiftKey||n!==t.length-1||(t[0].focus(),e.preventDefault()):27===e.keyCode||"Escape"===e.code?(e.preventDefault(),X()):37===e.keyCode||"ArrowLeft"===e.code?(e.preventDefault(),z()):39!==e.keyCode&&"ArrowRight"!==e.code||(e.preventDefault(),M())},K=function(e){pe(e.target)||(e.stopPropagation(),m=!1,h=!1,v=!0,f.startX=e.touches[0].pageX,f.startY=e.touches[0].pageY,L[C].slider.classList.add("tobii__slider--is-dragging"))},F=function(e){e.stopPropagation(),v&&(e.preventDefault(),f.endX=e.touches[0].pageX,f.endY=e.touches[0].pageY,ne())},$=function(e){e.stopPropagation(),v=!1,L[C].slider.classList.remove("tobii__slider--is-dragging"),f.endX&&V(),B()},Q=function(e){pe(e.target)||(e.preventDefault(),e.stopPropagation(),m=!1,h=!1,v=!0,f.startX=e.pageX,f.startY=e.pageY,L[C].slider.classList.add("tobii__slider--is-dragging"))},Z=function(e){e.preventDefault(),v&&(f.endX=e.pageX,f.endY=e.pageY,ne())},ee=function(e){e.stopPropagation(),v=!1,L[C].slider.classList.remove("tobii__slider--is-dragging"),f.endX&&V(),B()},te=function(){v=!1},ne=function(){Math.abs(f.startX-f.endX)>0&&!h&&L[C].elementsLength>1?(L[C].slider.style.transform="translate3d("+(w-Math.round(f.startX-f.endX))+"px, 0, 0)",m=!0,h=!1):Math.abs(f.startY-f.endY)>0&&!m&&d.swipeClose&&(L[C].slider.style.transform="translate3d("+w+"px, -"+Math.round(f.startY-f.endY)+"px, 0)",m=!1,h=!0)},ie=function(){d.keyboard&&window.addEventListener("keydown",J),window.addEventListener("resize",R),window.addEventListener("popstate",X),l.addEventListener("click",G),d.draggable&&(ce()&&(l.addEventListener("touchstart",K),l.addEventListener("touchmove",F),l.addEventListener("touchend",$)),l.addEventListener("mousedown",Q),l.addEventListener("mouseup",ee),l.addEventListener("mousemove",Z),l.addEventListener("contextmenu",te))},re=function(){d.keyboard&&window.removeEventListener("keydown",J),window.removeEventListener("resize",R),window.removeEventListener("popstate",X),l.removeEventListener("click",G),d.draggable&&(ce()&&(l.removeEventListener("touchstart",K),l.removeEventListener("touchmove",F),l.removeEventListener("touchend",$)),l.removeEventListener("mousedown",Q),l.removeEventListener("mouseup",ee),l.removeEventListener("mousemove",Z),l.removeEventListener("contextmenu",te))},oe=function(e,t){return e.getAttribute("data-type")===t},ae=function(e){var t=e.querySelectorAll("src");t&&t.forEach(function(e){e.setAttribute("src","")})},de=function(){(d.draggable&&d.swipeClose&&!L[C].slider.classList.contains("tobii__slider--is-draggable")||d.draggable&&L[C].elementsLength>1&&!L[C].slider.classList.contains("tobii__slider--is-draggable"))&&L[C].slider.classList.add("tobii__slider--is-draggable"),!d.nav||1===L[C].elementsLength||"auto"===d.nav&&ce()?(u.setAttribute("aria-hidden","true"),u.disabled=!0,c.setAttribute("aria-hidden","true"),c.disabled=!0):(u.setAttribute("aria-hidden","false"),u.disabled=!1,c.setAttribute("aria-hidden","false"),c.disabled=!1),b.setAttribute("aria-hidden",d.counter&&1!==L[C].elementsLength?"false":"true")},se=function(e){j(),b.textContent=L[C].currentIndex+1+"/"+L[C].elementsLength,function(e){(!0===d.nav||"auto"===d.nav)&&!ce()&&L[C].elementsLength>1?(u.setAttribute("aria-hidden","true"),u.disabled=!0,c.setAttribute("aria-hidden","true"),c.disabled=!0,1===L[C].elementsLength?d.close&&p.focus():0===L[C].currentIndex?(c.setAttribute("aria-hidden","false"),c.disabled=!1,c.focus()):L[C].currentIndex===L[C].elementsLength-1?(u.setAttribute("aria-hidden","false"),u.disabled=!1,u.focus()):(u.setAttribute("aria-hidden","false"),u.disabled=!1,c.setAttribute("aria-hidden","false"),c.disabled=!1,"left"===e?u.focus():c.focus())):d.close&&p.focus()}(e)},le=function(){ue()&&X(),Object.entries(L).forEach(function(e){e[1].gallery.forEach(function(e){P(e)})}),L={},_=C=null,s=0},ue=function(){return"false"===l.getAttribute("aria-hidden")},ce=function(){return"ontouchstart"in window},pe=function(e){return-1!==["TEXTAREA","OPTION","INPUT","SELECT"].indexOf(e.nodeName)||e===u||e===c||e===p};return function(e){d=function(e){return t({},{selector:".lightbox",captions:!0,captionsSelector:"img",captionAttribute:"alt",captionText:null,nav:"auto",navText:['<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path stroke="none" d="M0 0h24v24H0z"/><polyline points="15 6 9 12 15 18" /></svg>','<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path stroke="none" d="M0 0h24v24H0z"/><polyline points="9 6 15 12 9 18" /></svg>'],navLabel:["Previous image","Next image"],close:!0,closeText:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path stroke="none" d="M0 0h24v24H0z"/><line x1="18" y1="6" x2="6" y2="18" /><line x1="6" y1="6" x2="18" y2="18" /></svg>',closeLabel:"Close lightbox",loadingIndicatorLabel:"Image loading",counter:!0,download:!1,downloadText:"",downloadLabel:"Download image",keyboard:!0,zoom:!0,zoomText:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path stroke="none" d="M0 0h24v24H0z"/><polyline points="16 4 20 4 20 8" /><line x1="14" y1="10" x2="20" y2="4" /><polyline points="8 20 4 20 4 16" /><line x1="4" y1="20" x2="10" y2="14" /><polyline points="16 20 20 20 20 16" /><line x1="14" y1="14" x2="20" y2="20" /><polyline points="8 4 4 4 4 8" /><line x1="4" y1="4" x2="10" y2="10" /></svg>',docClose:!0,swipeClose:!0,hideScrollbar:!0,draggable:!0,threshold:100,rtl:!1,loop:!1,autoplayVideo:!1,modal:!1,theme:"tobii--theme-default"},e)}(e),l||((l=document.createElement("div")).setAttribute("role","dialog"),l.setAttribute("aria-hidden","true"),l.classList.add("tobii"),l.classList.add(d.theme),(u=document.createElement("button")).className="tobii__btn tobii__btn--previous",u.setAttribute("type","button"),u.setAttribute("aria-label",d.navLabel[0]),u.innerHTML=d.navText[0],l.appendChild(u),(c=document.createElement("button")).className="tobii__btn tobii__btn--next",c.setAttribute("type","button"),c.setAttribute("aria-label",d.navLabel[1]),c.innerHTML=d.navText[1],l.appendChild(c),(p=document.createElement("button")).className="tobii__btn tobii__btn--close",p.setAttribute("type","button"),p.setAttribute("aria-label",d.closeLabel),p.innerHTML=d.closeText,l.appendChild(p),(b=document.createElement("div")).className="tobii__counter",l.appendChild(b),document.body.appendChild(l));var n=document.querySelectorAll(d.selector);if(!n)throw new Error("Ups, I can't find the selector "+d.selector+" on this website.");n.forEach(function(e){S(e)})}(e),n.open=q,n.previous=z,n.next=M,n.close=X,n.add=S,n.remove=P,n.reset=le,n.destroy=function(){le(),l.parentNode.removeChild(l)},n.isOpen=ue,n.slidesIndex=function(){return L[C].currentIndex},n.select=function(e){var t=L[C].currentIndex;if(!ue())throw new Error("Ups, I'm closed.");if(ue()){if(!e&&0!==e)throw new Error("Ups, no slide specified.");if(e===L[C].currentIndex)throw new Error("Ups, slide "+e+" is already selected.");if(-1===e||e>=L[C].elementsLength)throw new Error("Ups, I can't find slide "+e+".")}L[C].currentIndex=e,D(t),Y(e),e<t&&(se("left"),H(t),U(e-1)),e>t&&(se("right"),H(t),U(e+1))},n.slidesCount=function(){return L[C].elementsLength},n.selectGroup=function(e){if(ue())throw new Error("Ups, I'm open.");if(!e)throw new Error("Ups, no group specified.");if(e&&!Object.prototype.hasOwnProperty.call(L,e))throw new Error("Ups, I don't have a group called \""+e+'".');C=e},n.currentGroup=function(){return null!==C?C:_},n.on=function(e,t){l.addEventListener(e,t)},n.off=function(e,t){l.removeEventListener(e,t)},n}typeof module<"u"?module.exports=n:self.Tobii=n}();