-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpanelset.min.dca42702d7daf6fd31dc352efd2bcf0e4ac8c05ccaa58d9293f6177462de5d5f.js
More file actions
1 lines (1 loc) · 4.92 KB
/
Copy pathpanelset.min.dca42702d7daf6fd31dc352efd2bcf0e4ac8c05ccaa58d9293f6177462de5d5f.js
File metadata and controls
1 lines (1 loc) · 4.92 KB
1
(()=>{(function(){const e=function(e){const t=()=>{document.removeEventListener("DOMContentLoaded",t),window.removeEventListener("load",t),e()};document.readyState!=="loading"?setTimeout(e):(document.addEventListener("DOMContentLoaded",t),window.addEventListener("load",t))};e(function(){[...document.querySelectorAll(".panel-name")].map(e=>e.textContent.trim());const t={},r=e=>(e=encodeURIComponent(e.toLowerCase().replace(/[\s]/g,"-")),Object.keys(t).includes(e)?e+=++t[e]:t[e]=1,e),c=e=>{let n="Panel";if(!e.parentElement)return;if((e.tagName==="SECTION"||e.classList.contains("section"))&&/^H[1-6]/.test(e.children[0].tagName))return n=e.children[0].textContent,e.classList.remove("panel-name"),e.removeChild(e.children[0]),n;const t=e.querySelector(".panel-name");return t?t.tagName==="SPAN"&&t.parentNode.tagName==="P"&&t.textContent===t.parentNode.textContent?(n=t.textContent,e.removeChild(t.parentNode),n):(n=t.textContent,t.parentNode.removeChild(t),n):n},o=e=>{const t=c(e);return t?{name:t,content:e.children,id:r(t)}:null},i=e=>{const t=new URLSearchParams(window.location.search);return t.get(e)},a=(e,t)=>{const n=document.createElement("div");n.className="panelset",n.id="panelset"+(t>0?t:"");const s=i(n.id),o=document.createElement("ul");return o.className="panel-tabs",o.setAttribute("role","tablist"),e.map((e,t)=>{const o=document.createElement("li");o.className="panel-tab",o.setAttribute("role","tab");const a=s?s===e.id:t===0;a&&(o.classList.add("panel-tab-active"),o.setAttribute("aria-selected",!0)),o.tabIndex=0,o.id=n.id+"_"+e.id;const i=document.createElement("a");return i.href="?"+n.id+"="+e.id+"#"+o.id,i.setAttribute("onclick","return false;"),i.tabIndex=-1,i.innerHTML=e.name,i.setAttribute("aria-controls",e.id),o.appendChild(i),o}).forEach(e=>o.appendChild(e)),n.appendChild(o),e.map((e,t)=>{const n=document.createElement("section");n.className="panel",n.setAttribute("role","tabpanel");const o=s?s===e.id:t===0;return n.classList.toggle("panel-active",o),n.id=e.id,n.setAttribute("aria-labelledby",e.id),Array.from(e.content).forEach(e=>n.appendChild(e)),n}).forEach(e=>n.appendChild(e)),n};function s(e,t,n=new URLSearchParams(window.location.search)){return t?n.set(e,t):n.delete(e),n}const n=e=>{if(typeof e=="undefined")return;e=e.toString()?"?"+e.toString():"";const{pathname:n,hash:s}=window.location,t=n+e+s;window.history.replaceState(t,"",t)},e=e=>{if(e.nodeName.toUpperCase()==="A"&&(e=e.parentElement),!e.classList.contains("panel-tab"))return;if(e.classList.contains("panel-tab-active"))return;const o=e.parentNode.querySelectorAll(".panel-tab"),i=e.parentNode.parentNode.querySelectorAll(".panel"),t=e.children[0].getAttribute("aria-controls"),a=e.parentNode.parentNode.id;Array.from(o).forEach(e=>{e.classList.remove("panel-tab-active"),e.removeAttribute("aria-selected")}),Array.from(i).forEach(e=>{const n=e.id===t;e.classList.toggle("panel-active",n),n?(e.removeAttribute("tabIndex"),e.removeAttribute("aria-hidden")):(e.setAttribute("tabIndex",-1),e.setAttribute("aria-hidden",!0))}),e.classList.add("panel-tab-active"),e.setAttribute("aria-selected",!0),window.dispatchEvent(new Event("resize"));const r=s(a,t);n(r)},l=(t,n)=>{let s=Array.from(t.querySelectorAll(".panel"));if(!s.length&&t.matches('.section[class*="level"]')){const e=[...t.classList].filter(e=>e.match(/^level/))[0].replace("level","");Array.from(t.children).forEach(function(e){if(e.matches('div.section[class*="level"]'))return;t.parentElement.insertBefore(e,t)});const n=+e+1;s=Array.from(t.querySelectorAll(`.section.level${n}`))}if(!s.length)return;const c=s.map(o).filter(e=>e!==null),i=a(c,n);t.parentNode.insertBefore(i,t),t.parentNode.removeChild(t);const r=i.querySelector(".panel-tabs");return["click","touchend"].forEach(t=>{r.addEventListener(t,function(t){e(t.target),t.stopPropagation()})}),r.addEventListener("touchmove",function(e){e.preventDefault()}),i.querySelector(".panel-tabs").addEventListener("keydown",t=>{const n=t.currentTarget.querySelector(".panel-tab-active");t.code==="Space"||t.code==="Enter"?(e(t.target),t.stopPropagation()):t.code==="ArrowLeft"&&n.previousSibling?(e(n.previousSibling),n.previousSibling.focus(),t.stopPropagation()):t.code==="ArrowRight"&&n.nextSibling&&(e(n.nextSibling),n.nextSibling.focus(),t.stopPropagation())}),s};if(Array.from(document.querySelectorAll(".panelset")).map(l),typeof slideshow!="undefined"){const e=()=>{const e=document.querySelectorAll(".remark-visible .panel-tab-active");return e.length?e.map(e=>({panel:e,panelId:e.children[0].getAttribute("aria-controls"),panelSetId:e.parentNode.parentNode.id})):null};slideshow.on("hideSlide",e=>{document.activeElement.blur();const t=[...document.querySelectorAll(".remark-visible .panelset")].reduce(function(e,t){return s(t.id,null,e)},new URLSearchParams(window.location.search));n(t)}),slideshow.on("afterShowSlide",t=>{const o=e();if(o){o[0].panel.focus();const e=o.reduce(function(e,{panelId:t,panelSetId:n}){return s(n,t,e)},new URLSearchParams(window.location.search));n(e)}})}})})()})()