This commit is contained in:
AUTOMATIC1111 2023-11-05 09:20:05 +03:00
parent 046c7b053a
commit 16ab174290
1 changed files with 11 additions and 9 deletions

View File

@ -4,20 +4,22 @@ function inputAccordionChecked(id, checked) {
accordion.onVisibleCheckboxChange();
}
function setupAccordion(accordion){
function setupAccordion(accordion) {
var labelWrap = accordion.querySelector('.label-wrap');
var gradioCheckbox = gradioApp().querySelector('#' + accordion.id + "-checkbox input");
var extra = gradioApp().querySelector('#' + accordion.id + "-extra");
var span = labelWrap.querySelector('span');
var linked = true;
var isOpen = function(){ return labelWrap.classList.contains('open'); }
var isOpen = function() {
return labelWrap.classList.contains('open');
};
var observerAccordionOpen = new MutationObserver(function(mutations) {
mutations.forEach(function(mutationRecord) {
accordion.classList.toggle('input-accordion-open', isOpen());
if(linked){
if (linked) {
accordion.visibleCheckbox.checked = isOpen();
accordion.onVisibleCheckboxChange();
}
@ -29,11 +31,11 @@ function setupAccordion(accordion){
labelWrap.insertBefore(extra, labelWrap.lastElementChild);
}
accordion.onChecked = function(checked){
accordion.onChecked = function(checked) {
if (isOpen() != checked) {
labelWrap.click();
}
}
};
var visibleCheckbox = document.createElement('INPUT');
visibleCheckbox.type = 'checkbox';
@ -43,8 +45,8 @@ function setupAccordion(accordion){
span.insertBefore(visibleCheckbox, span.firstChild);
accordion.visibleCheckbox = visibleCheckbox;
accordion.onVisibleCheckboxChange = function(){
if(linked && isOpen() != visibleCheckbox.checked) {
accordion.onVisibleCheckboxChange = function() {
if (linked && isOpen() != visibleCheckbox.checked) {
labelWrap.click();
}
@ -52,7 +54,7 @@ function setupAccordion(accordion){
updateInput(gradioCheckbox);
};
visibleCheckbox.addEventListener('click', function(event){
visibleCheckbox.addEventListener('click', function(event) {
linked = false;
event.stopPropagation();
});