eslint
This commit is contained in:
parent
046c7b053a
commit
16ab174290
|
@ -4,20 +4,22 @@ function inputAccordionChecked(id, checked) {
|
||||||
accordion.onVisibleCheckboxChange();
|
accordion.onVisibleCheckboxChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupAccordion(accordion){
|
function setupAccordion(accordion) {
|
||||||
var labelWrap = accordion.querySelector('.label-wrap');
|
var labelWrap = accordion.querySelector('.label-wrap');
|
||||||
var gradioCheckbox = gradioApp().querySelector('#' + accordion.id + "-checkbox input");
|
var gradioCheckbox = gradioApp().querySelector('#' + accordion.id + "-checkbox input");
|
||||||
var extra = gradioApp().querySelector('#' + accordion.id + "-extra");
|
var extra = gradioApp().querySelector('#' + accordion.id + "-extra");
|
||||||
var span = labelWrap.querySelector('span');
|
var span = labelWrap.querySelector('span');
|
||||||
var linked = true;
|
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) {
|
var observerAccordionOpen = new MutationObserver(function(mutations) {
|
||||||
mutations.forEach(function(mutationRecord) {
|
mutations.forEach(function(mutationRecord) {
|
||||||
accordion.classList.toggle('input-accordion-open', isOpen());
|
accordion.classList.toggle('input-accordion-open', isOpen());
|
||||||
|
|
||||||
if(linked){
|
if (linked) {
|
||||||
accordion.visibleCheckbox.checked = isOpen();
|
accordion.visibleCheckbox.checked = isOpen();
|
||||||
accordion.onVisibleCheckboxChange();
|
accordion.onVisibleCheckboxChange();
|
||||||
}
|
}
|
||||||
|
@ -29,22 +31,22 @@ function setupAccordion(accordion){
|
||||||
labelWrap.insertBefore(extra, labelWrap.lastElementChild);
|
labelWrap.insertBefore(extra, labelWrap.lastElementChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
accordion.onChecked = function(checked){
|
accordion.onChecked = function(checked) {
|
||||||
if (isOpen() != checked) {
|
if (isOpen() != checked) {
|
||||||
labelWrap.click();
|
labelWrap.click();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
var visibleCheckbox = document.createElement('INPUT');
|
var visibleCheckbox = document.createElement('INPUT');
|
||||||
visibleCheckbox.type = 'checkbox';
|
visibleCheckbox.type = 'checkbox';
|
||||||
visibleCheckbox.checked = isOpen();
|
visibleCheckbox.checked = isOpen();
|
||||||
visibleCheckbox.id = accordion.id + "-visible-checkbox";
|
visibleCheckbox.id = accordion.id + "-visible-checkbox";
|
||||||
visibleCheckbox.className = gradioCheckbox.className + " input-accordion-checkbox";
|
visibleCheckbox.className = gradioCheckbox.className + " input-accordion-checkbox";
|
||||||
span.insertBefore(visibleCheckbox, span.firstChild);
|
span.insertBefore(visibleCheckbox, span.firstChild);
|
||||||
|
|
||||||
accordion.visibleCheckbox = visibleCheckbox;
|
accordion.visibleCheckbox = visibleCheckbox;
|
||||||
accordion.onVisibleCheckboxChange = function(){
|
accordion.onVisibleCheckboxChange = function() {
|
||||||
if(linked && isOpen() != visibleCheckbox.checked) {
|
if (linked && isOpen() != visibleCheckbox.checked) {
|
||||||
labelWrap.click();
|
labelWrap.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +54,7 @@ function setupAccordion(accordion){
|
||||||
updateInput(gradioCheckbox);
|
updateInput(gradioCheckbox);
|
||||||
};
|
};
|
||||||
|
|
||||||
visibleCheckbox.addEventListener('click', function(event){
|
visibleCheckbox.addEventListener('click', function(event) {
|
||||||
linked = false;
|
linked = false;
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue