UNPKG

1.84 kBJavaScriptView Raw
1!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).htwoo=t.htwoo||{},t.htwoo.table={}))}(this,(function(t){"use strict";const e=t=>{const e=t.target.closest("tr"),s=t.target.closest("table"),l=e.dataset.sectionheader;let o=null;o="all"===l?"tr[data-section]":"tr[data-section="+l+"]";const i=s.querySelectorAll(o);for(let t=0;t<i.length;t++){const s=i[t];s.classList.contains("is-hidden")?(s.classList.remove("is-hidden"),s.classList.add("is-visible"),s.setAttribute("aria-hidden","false"),e.setAttribute("aria-expanded","true")):(s.classList.add("is-hidden"),s.classList.remove("is-visible"),s.setAttribute("aria-hidden","true"),e.setAttribute("aria-expanded","false"))}if("all"===l){let t=document.querySelectorAll("tbody tr.collapsable");if("true"===e.getAttribute("aria-expanded"))for(let e=0;e<t.length;e++){const s=t[e];s.setAttribute("aria-hidden","false"),s.setAttribute("aria-expanded","true")}else for(let e=0;e<t.length;e++){const s=t[e];s.setAttribute("aria-hidden","true"),s.setAttribute("aria-expanded","false")}}},s="left",l="right",o="top",i="bottom",a=(t,e,a)=>{const r=t.querySelectorAll(e);for(let t=0;t<r.length;t++){const e=r[t];a===s&&(e.style[a]=e.offsetLeft+"px"),a===l&&(e.style[a]=e.offsetRight+"px"),a===o&&(e.style[a]=e.offsetTop+"px"),a===i&&(e.style[a]=e.offsetBottom+"px")}};t.initTables=()=>{document.querySelectorAll(".hoo-table.is-collapsable").forEach((t=>{t.querySelectorAll(".collapsable").forEach((t=>{t.addEventListener("click",e)}))})),(()=>{const t=document.querySelectorAll("table.sticky");for(let e=0;e<t.length;e++){const l=t[e];a(l,"tr td.is-sticky.left",s),a(l,"tr th.is-sticky.left",s)}})()},Object.defineProperty(t,"__esModule",{value:!0})}));