Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add ImageViewer Navigation Index label #15731

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions javascript/imageviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ function showModal(event) {
gradioApp().getElementById("modal_save").style.display = "none";
}
event.stopPropagation();

setTimeout(() => {
updateModalNavigationIndex(selected_gallery_index(), all_gallery_buttons().length);
}, 10);
}

/**
* @param idx {number}
* @param length {number}
*/
function updateModalNavigationIndex(idx, length) {
const modalTitle = gradioApp().getElementById("lightboxModal").querySelector('.modalTitle');
modalTitle.textContent = `${idx + 1}/${length}`;
}

function negmod(n, m) {
Expand Down Expand Up @@ -51,24 +64,19 @@ function modalImageSwitch(offset) {
var galleryButtons = all_gallery_buttons();

if (galleryButtons.length > 1) {
var currentButton = selected_gallery_button();

var result = -1;
galleryButtons.forEach(function(v, i) {
if (v == currentButton) {
result = i;
}
});
var result = selected_gallery_index();

if (result != -1) {
var nextButton = galleryButtons[negmod((result + offset), galleryButtons.length)];
let idx = negmod((result + offset), galleryButtons.length);
var nextButton = galleryButtons[idx];
nextButton.click();
const modalImage = gradioApp().getElementById("modalImage");
const modal = gradioApp().getElementById("lightboxModal");
modalImage.src = nextButton.children[0].src;
if (modalImage.style.display === 'none') {
modal.style.setProperty('background-image', `url(${modalImage.src})`);
}
updateModalNavigationIndex(idx, galleryButtons.length);
setTimeout(function() {
modal.focus();
}, 10);
Expand Down Expand Up @@ -216,6 +224,10 @@ document.addEventListener("DOMContentLoaded", function() {
modalSave.title = "Save Image(s)";
modalControls.appendChild(modalSave);

const modalTitle = document.createElement("span");
modalTitle.className = "modalTitle";
modalControls.appendChild(modalTitle);

const modalClose = document.createElement('span');
modalClose.className = 'modalClose cursor';
modalClose.innerHTML = '×';
Expand Down
13 changes: 13 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ table.popup-table .link{
user-select: none;
-webkit-user-select: none;
flex-direction: column;
font-family: var(--font);
}

.modalControls {
Expand Down Expand Up @@ -706,6 +707,18 @@ table.popup-table .link{
text-decoration: none;
}

.modalControls .modalTitle {
display: block;
margin-left: auto;
width: 100% !important;
white-space: nowrap;
text-align: center;
}

.modalControls .modalTitle:hover {
color: white;
}

#lightboxModal > img {
display: block;
margin: auto;
Expand Down