2023-08-10 02:20:46 -06:00
|
|
|
var observerAccordionOpen = new MutationObserver(function(mutations) {
|
|
|
|
mutations.forEach(function(mutationRecord) {
|
|
|
|
var elem = mutationRecord.target;
|
|
|
|
var open = elem.classList.contains('open');
|
|
|
|
|
|
|
|
var accordion = elem.parentNode;
|
|
|
|
accordion.classList.toggle('input-accordion-open', open);
|
|
|
|
|
|
|
|
var checkbox = gradioApp().querySelector('#' + accordion.id + "-checkbox input");
|
|
|
|
checkbox.checked = open;
|
|
|
|
updateInput(checkbox);
|
|
|
|
|
2023-08-10 03:58:00 -06:00
|
|
|
var extra = gradioApp().querySelector('#' + accordion.id + "-extra");
|
|
|
|
if (extra) {
|
2023-08-10 02:20:46 -06:00
|
|
|
extra.style.display = open ? "" : "none";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-08-10 03:58:00 -06:00
|
|
|
function inputAccordionChecked(id, checked) {
|
2023-08-10 02:20:46 -06:00
|
|
|
var label = gradioApp().querySelector('#' + id + " .label-wrap");
|
2023-08-10 03:58:00 -06:00
|
|
|
if (label.classList.contains('open') != checked) {
|
2023-08-10 02:20:46 -06:00
|
|
|
label.click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onUiLoaded(function() {
|
|
|
|
for (var accordion of gradioApp().querySelectorAll('.input-accordion')) {
|
|
|
|
var labelWrap = accordion.querySelector('.label-wrap');
|
|
|
|
observerAccordionOpen.observe(labelWrap, {attributes: true, attributeFilter: ['class']});
|
|
|
|
|
|
|
|
var extra = gradioApp().querySelector('#' + accordion.id + "-extra");
|
2023-08-10 03:58:00 -06:00
|
|
|
if (extra) {
|
|
|
|
labelWrap.insertBefore(extra, labelWrap.lastElementChild);
|
2023-08-10 02:20:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|