UNPKG

@n8d/htwoo-core

Version:

hTWOo is a Fluent Design Framework purely in HTML and CSS

2 lines (1 loc) • 1.7 kB
"use strict";var t;!function(t){t.LEFT="left",t.RIGHT="right",t.TOP="top",t.BOTTOM="bottom"}(t||(t={}));const e=t=>{const e=t.target,s=e.closest("tr");if(!s)return;const l=e.closest("table");if(!l)return;const r=s.dataset.sectionheader;if(!r)return;let i;i="all"===r?"tr[data-section]":`tr[data-section=${r}]`;const a=l.querySelectorAll(i);for(let t=0;t<a.length;t++){const e=a[t];e.classList.contains("is-hidden")?(e.classList.remove("is-hidden"),e.classList.add("is-visible"),e.setAttribute("aria-hidden","false"),s.setAttribute("aria-expanded","true")):(e.classList.add("is-hidden"),e.classList.remove("is-visible"),e.setAttribute("aria-hidden","true"),s.setAttribute("aria-expanded","false"))}if("all"===r){const t=document.querySelectorAll("tbody tr.collapsable");if("true"===s.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")}}};t.LEFT,t.RIGHT,t.TOP,t.BOTTOM;const s=(e,s,l)=>{const r=e.querySelectorAll(s);for(let e=0;e<r.length;e++){const s=r[e];l===t.LEFT&&(s.style[l]=s.offsetLeft+"px"),l===t.RIGHT&&(s.style[l]=s.offsetRight+"px"),l===t.TOP&&(s.style[l]=s.offsetTop+"px"),l===t.BOTTOM&&(s.style[l]=s.offsetBottom+"px")}};exports.initTables=()=>{document.querySelectorAll(".hoo-table.is-collapsable").forEach((t=>{t.querySelectorAll(".collapsable").forEach((t=>{t.addEventListener("click",e)}))})),(()=>{const e=document.querySelectorAll("table.sticky");for(let l=0;l<e.length;l++){const r=e[l];s(r,"tr td.is-sticky.left",t.LEFT),s(r,"tr th.is-sticky.left",t.LEFT)}})()};