accordions everywhere

This commit is contained in:
Vladimir Mandic
2023-09-22 20:34:25 -04:00
parent 4e7ad0e15a
commit 9b4c4e5b49
13 changed files with 260 additions and 191 deletions
+22
View File
@@ -0,0 +1,22 @@
function uiOpenSubmenus() {
const accordions = Array.from(gradioApp().querySelectorAll('.gradio-accordion'));
const states = {};
accordions.forEach((el) => {
const name = el.querySelector('.label-wrap > span:not(.icon)').innerText.trim();
const children = Array.from(el.childNodes);
const open = children.filter((c) => c.style?.display === 'block');
if (states[name] === undefined) states[name] = open.length > 0;
});
return states;
}
onUiLoaded(() => {
const btn = gradioApp().getElementById('ui_defaults_view');
console.log('HERE', btn);
if (!btn) return;
const intersectionObserver = new IntersectionObserver((entries) => {
if (entries[0].intersectionRatio <= 0) {}
if (entries[0].intersectionRatio > 0) btn.click();
});
intersectionObserver.observe(btn); // monitor visibility of tab
});