File size: 862 Bytes
c336648 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
let stepCursor = {txt: 0, img: 0};
function setupScroll(tab) {
const buttons = gradioApp().querySelectorAll(`#${tab}2img_gallery.gradio-gallery * button.thumbnail-small`);
if (buttons.length > 0) {
const gallery = gradioApp().querySelector(`#${tab}2img_gallery.gradio-gallery`);
gallery.onwheel = (event) => {
event.preventDefault();
const dir = Math.sign(event.deltaY);
const nextStepCursor = Math.min(Math.max(0, (stepCursor[tab] - dir)), buttons.length - 1);
if (stepCursor[tab] != nextStepCursor) {
stepCursor[tab] = nextStepCursor;
buttons[stepCursor[tab]].click();
}
}
}
}
onAfterUiUpdate(function() {
setupScroll("txt");
setupScroll("img");
updateOnBackgroundChange();
}); |