@midzer/tobii
Advanced tools
Comparing version 2.0.7 to 2.1.0
@@ -1,1 +0,1 @@ | ||
!function(){if("function"!=typeof window.CustomEvent){const e=function(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};const r=document.createEvent("CustomEvent");return r.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),r};e.prototype=window.Event.prototype,window.CustomEvent=e}function e(t){const r=['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])'],i=[],n={gallery:[],slider:null,sliderElements:[],elementsLength:0,currentIndex:0,x:0},o=[];let a={},s=0,d=null,l=null,u=null,c=null,p=null,b={},m=!1,h=!1,g=!1,f=null,v=null,y=null,w=!1,x=!1,E=0,A={},L=null,_=null;const C={image:{checkSupport:e=>!e.hasAttribute("data-type")&&e.href.match(/\.(png|jpe?g|tiff|tif|gif|bmp|webp|avif|svg|ico)(\?.*)?$/i),init(e,t){const r=document.createElement("figure"),i=document.createElement("figcaption"),n=document.createElement("img"),o=e.querySelector("img"),d=document.createElement("div");r.style.opacity="0",o&&(n.alt=o.alt||""),n.setAttribute("src",""),n.setAttribute("data-src",e.href),r.appendChild(n),a.captions&&("function"==typeof a.captionText?i.textContent=a.captionText(e):"self"===a.captionsSelector&&e.getAttribute(a.captionAttribute)?i.textContent=e.getAttribute(a.captionAttribute):"img"===a.captionsSelector&&o&&o.getAttribute(a.captionAttribute)&&(i.textContent=o.getAttribute(a.captionAttribute)),i.textContent&&(i.id=`tobii-figcaption-${s}`,r.appendChild(i),n.setAttribute("aria-labelledby",i.id),++s)),t.appendChild(r),d.className="tobii__loader",d.setAttribute("role","progressbar"),d.setAttribute("aria-label",a.loadingIndicatorLabel),t.appendChild(d),t.setAttribute("data-type","image")},onPreload(e){C.image.onLoad(e)},onLoad(e){const t=e.querySelector("img");if(!t.hasAttribute("data-src"))return;const r=e.querySelector("figure"),i=e.querySelector(".tobii__loader");t.onload=()=>{e.removeChild(i),r.style.opacity="1"},t.setAttribute("src",t.getAttribute("data-src")),t.removeAttribute("data-src")},onLeave(e){},onCleanup(e){}},html:{checkSupport:e=>ne(e,"html"),init(e,t){const r=e.hasAttribute("href")?e.getAttribute("href"):e.getAttribute("data-target"),i=document.querySelector(r);if(!i)throw new Error(`Ups, I can't find the target ${r}.`);t.appendChild(i),t.setAttribute("data-type","html")},onPreload(e){},onLoad(e){const t=e.querySelector("video");t&&(t.hasAttribute("data-time")&&t.readyState>0&&(t.currentTime=t.getAttribute("data-time")),a.autoplayVideo&&t.play())},onLeave(e){const t=e.querySelector("video");t&&(t.paused||t.pause(),t.readyState>0&&t.setAttribute("data-time",t.currentTime))},onCleanup(e){const t=e.querySelector("video");if(t&&t.readyState>0&&t.readyState<3&&t.duration!==t.currentTime){const r=t.cloneNode(!0);oe(t),t.load(),t.parentNode.removeChild(t),e.appendChild(r)}}},iframe:{checkSupport:e=>ne(e,"iframe"),init(e,t){const r=document.createElement("iframe"),i=e.hasAttribute("href")?e.getAttribute("href"):e.getAttribute("data-target");r.setAttribute("frameborder","0"),r.setAttribute("src",""),r.setAttribute("data-src",i),e.getAttribute("data-width")&&(r.style.maxWidth=`${e.getAttribute("data-width")}px`),e.getAttribute("data-height")&&(r.style.maxHeight=`${e.getAttribute("data-height")}px`),t.appendChild(r),t.setAttribute("data-type","iframe")},onPreload(e){},onLoad(e){const t=e.querySelector("iframe");t.setAttribute("src",t.getAttribute("data-src"))},onLeave(e){},onCleanup(e){}},youtube:{checkSupport:e=>ne(e,"youtube"),init(e,t){const r=document.createElement("div");t.appendChild(r),o[E]=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",E),t.setAttribute("data-type","youtube"),E++},onPreload(e){},onLoad(e){a.autoplayVideo&&o[e.getAttribute("data-player")].playVideo()},onLeave(e){1===o[e.getAttribute("data-player")].getPlayerState()&&o[e.getAttribute("data-player")].pauseVideo()},onCleanup(e){1===o[e.getAttribute("data-player")].getPlayerState()&&o[e.getAttribute("data-player")].pauseVideo()}}},I=e=>{if(null===document.querySelector('[data-type="youtube"]')||x)T(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===i.indexOf(e)&&i.push(e),window.onYouTubePlayerAPIReady=()=>{i.forEach(e=>{T(e)}),x=!0}}},S=e=>e.hasAttribute("data-group")?e.getAttribute("data-group"):"default",T=e=>{if(L=S(e),Object.prototype.hasOwnProperty.call(A,L)||(A[L]=JSON.parse(JSON.stringify(n)),N()),-1!==A[L].gallery.indexOf(e))throw new Error("Ups, element already added.");if(A[L].gallery.push(e),A[L].elementsLength++,a.zoom&&e.querySelector("img")){const t=document.createElement("div");t.className="tobii-zoom__icon",t.innerHTML=a.zoomText,e.classList.add("tobii-zoom"),e.appendChild(t)}e.addEventListener("click",j),P(e),le()&&L===_&&(ae(),se())},k=e=>{const t=S(e);if(-1===A[t].gallery.indexOf(e))throw new Error(`Ups, I can't find a slide for the element ${e}.`);{const r=A[t].gallery.indexOf(e),i=A[t].sliderElements[r];if(le()&&t===_&&r===A[t].currentIndex){if(1===A[t].elementsLength)throw O(),new Error("Ups, I've closed. There are no slides more to show.");0===A[t].currentIndex?$():Y()}if(A[t].elementsLength--,a.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",j),i.parentNode.removeChild(i)}},N=()=>{A[L].slider=document.createElement("div"),A[L].slider.className="tobii__slider",A[L].slider.setAttribute("aria-hidden","true"),d.appendChild(A[L].slider)},P=e=>{for(const t in C)if(Object.prototype.hasOwnProperty.call(C,t)&&C[t].checkSupport(e)){const r=document.createElement("div"),i=document.createElement("div");r.className="tobii__slide",r.style.position="absolute",r.style.left=100*A[L].x+"%",r.setAttribute("aria-hidden","true"),C[t].init(e,i),r.appendChild(i),A[L].slider.appendChild(r),A[L].sliderElements.push(r),++A[L].x;break}},q=e=>{if(_=null!==_?_:L,le())throw new Error("Ups, I'm aleady open.");if(!le()&&(e||(e=0),-1===e||e>=A[_].elementsLength))throw new Error(`Ups, I can't find slide ${e}.`);a.hideScrollbar&&(document.documentElement.classList.add("tobii-is-open"),document.body.classList.add("tobii-is-open")),ae(),a.close||(c.disabled=!1,c.setAttribute("aria-hidden","true")),f=document.activeElement;const t=window.location.href;window.history.pushState({tobii:"close"},"Image",t),A[_].currentIndex=e,H(),re(),U(A[_].currentIndex),A[_].slider.setAttribute("aria-hidden","false"),d.setAttribute("aria-hidden","false"),se(),X(A[_].currentIndex+1),X(A[_].currentIndex-1),setTimeout(()=>{A[_].slider.classList.add("tobii__slider--animate")},1e3);const r=new window.CustomEvent("open");d.dispatchEvent(r)},O=()=>{if(!le())throw new Error("Ups, I'm already closed.");a.hideScrollbar&&(document.documentElement.classList.remove("tobii-is-open"),document.body.classList.remove("tobii-is-open")),ie(),null!==window.history.state&&"close"===window.history.state.tobii&&window.history.back(),f.focus(),z(A[_].currentIndex),M(A[_].currentIndex),d.setAttribute("aria-hidden","true"),A[_].slider.setAttribute("aria-hidden","true"),A[_].currentIndex=0,A[_].slider.classList.remove("tobii__slider--animate")},X=e=>{if(void 0===A[_].sliderElements[e])return;const t=A[_].sliderElements[e].querySelector("[data-type]"),r=t.getAttribute("data-type");C[r].onPreload(t)},U=e=>{if(void 0===A[_].sliderElements[e])return;const t=A[_].sliderElements[e].querySelector("[data-type]"),r=t.getAttribute("data-type");A[_].sliderElements[e].classList.add("tobii__slide--is-active"),A[_].sliderElements[e].setAttribute("aria-hidden","false"),C[r].onLoad(t)},Y=()=>{if(!le())throw new Error("Ups, I'm closed.");A[_].currentIndex>0&&(z(A[_].currentIndex),U(--A[_].currentIndex),se("left"),M(A[_].currentIndex+1),X(A[_].currentIndex-1));const e=new window.CustomEvent("previous");d.dispatchEvent(e)},$=()=>{if(!le())throw new Error("Ups, I'm closed.");A[_].currentIndex<A[_].elementsLength-1&&(z(A[_].currentIndex),U(++A[_].currentIndex),se("right"),M(A[_].currentIndex-1),X(A[_].currentIndex+1));const e=new window.CustomEvent("next");d.dispatchEvent(e)},z=e=>{if(void 0===A[_].sliderElements[e])return;const t=A[_].sliderElements[e].querySelector("[data-type]"),r=t.getAttribute("data-type");A[_].sliderElements[e].classList.remove("tobii__slide--is-active"),A[_].sliderElements[e].setAttribute("aria-hidden","true"),C[r].onLeave(t)},M=e=>{if(void 0===A[_].sliderElements[e])return;const t=A[_].sliderElements[e].querySelector("[data-type]"),r=t.getAttribute("data-type");C[r].onCleanup(t)},D=()=>{_=null!==_?_:L,v=-A[_].currentIndex*d.offsetWidth,A[_].slider.style.transform=`translate3d(${v}px, 0, 0)`,y=v},H=()=>{b={startX:0,endX:0,startY:0,endY:0}},B=()=>{const e=b.endX-b.startX,t=b.endY-b.startY,r=Math.abs(e),i=Math.abs(t);e>0&&r>a.threshold&&A[_].currentIndex>0?Y():e<0&&r>a.threshold&&A[_].currentIndex!==A[_].elementsLength-1?$():t<0&&i>a.threshold&&a.swipeClose?O():D()},V=()=>{w||(w=!0,window.requestAnimationFrame(()=>{D(),w=!1}))},j=e=>{e.preventDefault(),_=S(e.currentTarget),q(A[_].gallery.indexOf(e.currentTarget))},R=e=>{e.target===l?Y():e.target===u?$():(e.target===c||!1===m&&!1===h&&e.target.classList.contains("tobii__slide")&&a.docClose)&&O(),e.stopPropagation()},W=e=>{const t=Array.prototype.slice.call(d.querySelectorAll(`.tobii__btn:not([disabled]), .tobii__slide--is-active + ${r.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(),O()):37===e.keyCode||"ArrowLeft"===e.code?(e.preventDefault(),Y()):39!==e.keyCode&&"ArrowRight"!==e.code||(e.preventDefault(),$())},G=e=>{ce(e.target)||(e.stopPropagation(),m=!1,h=!1,g=!0,b.startX=e.touches[0].pageX,b.startY=e.touches[0].pageY,A[_].slider.classList.add("tobii__slider--is-dragging"))},J=e=>{e.stopPropagation(),g&&(e.preventDefault(),b.endX=e.touches[0].pageX,b.endY=e.touches[0].pageY,te())},K=e=>{e.stopPropagation(),g=!1,A[_].slider.classList.remove("tobii__slider--is-dragging"),b.endX&&B(),H()},F=e=>{ce(e.target)||(e.preventDefault(),e.stopPropagation(),m=!1,h=!1,g=!0,b.startX=e.pageX,b.startY=e.pageY,A[_].slider.classList.add("tobii__slider--is-dragging"))},Q=e=>{e.preventDefault(),g&&(b.endX=e.pageX,b.endY=e.pageY,te())},Z=e=>{e.stopPropagation(),g=!1,A[_].slider.classList.remove("tobii__slider--is-dragging"),b.endX&&B(),H()},ee=()=>{g=!1},te=()=>{Math.abs(b.startX-b.endX)>0&&!h&&A[_].elementsLength>1?(A[_].slider.style.transform=`translate3d(${y-Math.round(b.startX-b.endX)}px, 0, 0)`,m=!0,h=!1):Math.abs(b.startY-b.endY)>0&&!m&&a.swipeClose&&(A[_].slider.style.transform=`translate3d(${y}px, -${Math.round(b.startY-b.endY)}px, 0)`,m=!1,h=!0)},re=()=>{a.keyboard&&window.addEventListener("keydown",W),window.addEventListener("resize",V),window.addEventListener("popstate",O),d.addEventListener("click",R),a.draggable&&(ue()&&(d.addEventListener("touchstart",G),d.addEventListener("touchmove",J),d.addEventListener("touchend",K)),d.addEventListener("mousedown",F),d.addEventListener("mouseup",Z),d.addEventListener("mousemove",Q),d.addEventListener("contextmenu",ee))},ie=()=>{a.keyboard&&window.removeEventListener("keydown",W),window.removeEventListener("resize",V),window.removeEventListener("popstate",O),d.removeEventListener("click",R),a.draggable&&(ue()&&(d.removeEventListener("touchstart",G),d.removeEventListener("touchmove",J),d.removeEventListener("touchend",K)),d.removeEventListener("mousedown",F),d.removeEventListener("mouseup",Z),d.removeEventListener("mousemove",Q),d.removeEventListener("contextmenu",ee))},ne=(e,t)=>e.getAttribute("data-type")===t,oe=e=>{const t=e.querySelectorAll("src");t&&t.forEach(e=>{e.setAttribute("src","")})},ae=()=>{(a.draggable&&a.swipeClose&&!A[_].slider.classList.contains("tobii__slider--is-draggable")||a.draggable&&A[_].elementsLength>1&&!A[_].slider.classList.contains("tobii__slider--is-draggable"))&&A[_].slider.classList.add("tobii__slider--is-draggable"),!a.nav||1===A[_].elementsLength||"auto"===a.nav&&ue()?(l.setAttribute("aria-hidden","true"),l.disabled=!0,u.setAttribute("aria-hidden","true"),u.disabled=!0):(l.setAttribute("aria-hidden","false"),l.disabled=!1,u.setAttribute("aria-hidden","false"),u.disabled=!1),p.setAttribute("aria-hidden",a.counter&&1!==A[_].elementsLength?"false":"true")},se=e=>{D(),p.textContent=`${A[_].currentIndex+1}/${A[_].elementsLength}`,(e=>{(!0===a.nav||"auto"===a.nav)&&!ue()&&A[_].elementsLength>1?(l.setAttribute("aria-hidden","true"),l.disabled=!0,u.setAttribute("aria-hidden","true"),u.disabled=!0,1===A[_].elementsLength?a.close&&c.focus():0===A[_].currentIndex?(u.setAttribute("aria-hidden","false"),u.disabled=!1,u.focus()):A[_].currentIndex===A[_].elementsLength-1?(l.setAttribute("aria-hidden","false"),l.disabled=!1,l.focus()):(l.setAttribute("aria-hidden","false"),l.disabled=!1,u.setAttribute("aria-hidden","false"),u.disabled=!1,"left"===e?l.focus():u.focus())):a.close&&c.focus()})(e)},de=()=>{le()&&O(),Object.entries(A).forEach(e=>{e[1].gallery.forEach(e=>{k(e)})}),A={},L=_=null,s=0},le=()=>"false"===d.getAttribute("aria-hidden"),ue=()=>"ontouchstart"in window,ce=e=>-1!==["TEXTAREA","OPTION","INPUT","SELECT"].indexOf(e.nodeName)||e===l||e===u||e===c;return(e=>{a=(e=>({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),d||(d=document.createElement("div"),d.setAttribute("role","dialog"),d.setAttribute("aria-hidden","true"),d.classList.add("tobii"),d.classList.add(a.theme),l=document.createElement("button"),l.className="tobii__btn tobii__btn--previous",l.setAttribute("type","button"),l.setAttribute("aria-label",a.navLabel[0]),l.innerHTML=a.navText[0],d.appendChild(l),u=document.createElement("button"),u.className="tobii__btn tobii__btn--next",u.setAttribute("type","button"),u.setAttribute("aria-label",a.navLabel[1]),u.innerHTML=a.navText[1],d.appendChild(u),c=document.createElement("button"),c.className="tobii__btn tobii__btn--close",c.setAttribute("type","button"),c.setAttribute("aria-label",a.closeLabel),c.innerHTML=a.closeText,d.appendChild(c),p=document.createElement("div"),p.className="tobii__counter",d.appendChild(p),document.body.appendChild(d));const t=document.querySelectorAll(a.selector);if(!t)throw new Error(`Ups, I can't find the selector ${a.selector} on this website.`);t.forEach(e=>{I(e)})})(t),e.open=q,e.previous=Y,e.next=$,e.close=O,e.add=I,e.remove=k,e.reset=de,e.destroy=()=>{de(),d.parentNode.removeChild(d)},e.isOpen=le,e.slidesIndex=()=>A[_].currentIndex,e.select=e=>{const t=A[_].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===A[_].currentIndex)throw new Error(`Ups, slide ${e} is already selected.`);if(-1===e||e>=A[_].elementsLength)throw new Error(`Ups, I can't find slide ${e}.`)}A[_].currentIndex=e,z(t),U(e),e<t&&(se("left"),M(t),X(e-1)),e>t&&(se("right"),M(t),X(e+1))},e.slidesCount=()=>A[_].elementsLength,e.selectGroup=e=>{if(le())throw new Error("Ups, I'm open.");if(!e)throw new Error("Ups, no group specified.");if(e&&!Object.prototype.hasOwnProperty.call(A,e))throw new Error(`Ups, I don't have a group called "${e}".`);_=e},e.currentGroup=()=>null!==_?_:L,e.on=(e,t)=>{d.addEventListener(e,t)},e.off=(e,t)=>{d.removeEventListener(e,t)},e}typeof module<"u"?module.exports=e:self.Tobii=e}(); | ||
!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}(); |
{ | ||
"name": "@midzer/tobii", | ||
"version": "2.0.7", | ||
"version": "2.1.0", | ||
"description": "An accessible, open-source lightbox with no dependencies.", | ||
@@ -28,11 +28,17 @@ "main": "dist/tobii.js", | ||
}, | ||
"browserslist": [ | ||
"last 2 versions", | ||
"not <= 1%", | ||
"not IE 10" | ||
], | ||
"browserslist": { | ||
"browser": [ | ||
"last 2 versions", | ||
"not <= 1%", | ||
"IE >= 11" | ||
], | ||
"main": [ | ||
"last 2 versions", | ||
"not <= 1%" | ||
] | ||
}, | ||
"scripts": { | ||
"build": "npm run clean && npm run build:main && npm run build:browser", | ||
"build:main": "microbundle build --raw --no-sourcemap --name Tobii", | ||
"build:browser": "microbundle build --raw -f iife src/js/browser.js -o dist/tobii.min.js --no-sourcemap --name Tobii", | ||
"build:main": "BROWSERSLIST_ENV=main microbundle build --raw --no-sourcemap --name Tobii", | ||
"build:browser": "BROWSERSLIST_ENV=browser microbundle build --raw -f iife src/js/browser.js -o dist/tobii.min.js --no-sourcemap --name Tobii", | ||
"clean": "rimraf dist", | ||
@@ -47,2 +53,6 @@ "dev": "microbundle watch --raw --format cjs", | ||
}, | ||
"files": [ | ||
"src", | ||
"dist" | ||
], | ||
"keywords": [ | ||
@@ -49,0 +59,0 @@ "lightbox", |
# Tobii | ||
[![Version](https://img.shields.io/badge/Version-2.0.0-1a2a3a.svg)](https://github.com/midzer/tobii/releases) | ||
[![License](https://img.shields.io/badge/License-MIT-1a2a3a.svg)](https://github.com/midzer/tobii/blob/master/LICENSE.md) | ||
![Dependecies](https://img.shields.io/badge/Dependencies-none-1a2a3a.svg) | ||
![npm bundle size](https://img.shields.io/bundlephobia/minzip/tobii?color=1a2a3a) | ||
[![Amazon wishlist](https://img.shields.io/badge/Amazon_wishlist-0366d6.svg)](https://www.amazon.de/hz/wishlist/ls/29WXITO63O0BX) | ||
[![Version](https://badgen.net/npm/v/@midzer/tobii)](https://github.com/midzer/tobii/releases) | ||
[![License](https://badgen.net/npm/license/@midzer/tobii)](https://github.com/midzer/tobii/blob/master/LICENSE.md) | ||
![Dependencies](https://badgen.net/npm/dependents/@midzer/tobii) | ||
![npm bundle size](https://badgen.net/bundlephobia/minzip/@midzer/tobii) | ||
@@ -60,6 +59,12 @@ An accessible, open-source lightbox with no dependencies. | ||
CSS: `css/tobii.min.css` minified, or `css/tobii.css` un-minified | ||
CSS: `dist/tobii.min.css` | ||
JavaScript: `js/tobii.min.js` minified, or `js/tobii.js` un-minified | ||
JavaScript: | ||
* `dist/tobii.min.js`: IIFE build for maximum browser support, including IE 11 | ||
* `dist/tobii.modern.js`: Build specially designed to work in all modern browsers | ||
* `dist/tobii.module.js`: ESM build | ||
* `dist/tobii.umd.js`: UMD build | ||
* `dist/tobii.js`: CommonJS/Node build | ||
### Package managers | ||
@@ -69,3 +74,3 @@ | ||
`npm install tobii --save` | ||
`npm install @midzer/tobii --save` | ||
@@ -324,3 +329,3 @@ ## Usage | ||
- Firefox | ||
- Internet Explorer | ||
- Internet Explorer 11 | ||
- Edge | ||
@@ -327,0 +332,0 @@ - Safari |
Sorry, the diff of this file is not supported yet
1670
339
155157
15