mirror of https://github.com/vladmandic/automatic
parent
e6f4c76638
commit
7664d7ea88
|
|
@ -29,6 +29,12 @@ function getVisibleGalleryFiles() {
|
|||
return Array.from(el.files.children).filter((node) => node.name && node.offsetParent);
|
||||
}
|
||||
|
||||
function updateGallerySelectionClasses(files = gallerySelection.files, index = gallerySelection.index) {
|
||||
files.forEach((file, i) => {
|
||||
file.classList.toggle('gallery-file-selected', i === index);
|
||||
});
|
||||
}
|
||||
|
||||
function refreshGallerySelection() {
|
||||
updateGallerySelectionClasses(gallerySelection.files, -1);
|
||||
const files = getVisibleGalleryFiles();
|
||||
|
|
@ -37,6 +43,12 @@ function refreshGallerySelection() {
|
|||
updateGallerySelectionClasses(files, index);
|
||||
}
|
||||
|
||||
function resetGallerySelection() {
|
||||
updateGallerySelectionClasses(gallerySelection.files, -1);
|
||||
gallerySelection = { files: [], index: -1 };
|
||||
currentImage = null;
|
||||
}
|
||||
|
||||
function applyGallerySelection(index, { send = true } = {}) {
|
||||
if (!gallerySelection.files.length) refreshGallerySelection();
|
||||
const files = gallerySelection.files;
|
||||
|
|
@ -62,22 +74,10 @@ function setGallerySelectionByElement(element, options) {
|
|||
if (index >= 0) applyGallerySelection(index, options);
|
||||
}
|
||||
|
||||
function resetGallerySelection() {
|
||||
updateGallerySelectionClasses(gallerySelection.files, -1);
|
||||
gallerySelection = { files: [], index: -1 };
|
||||
currentImage = null;
|
||||
}
|
||||
|
||||
function buildGalleryFileUrl(path) {
|
||||
return new URL(`/file=${encodeURI(path)}`, window.location.origin).toString();
|
||||
}
|
||||
|
||||
function updateGallerySelectionClasses(files = gallerySelection.files, index = gallerySelection.index) {
|
||||
files.forEach((file, i) => {
|
||||
file.classList.toggle('gallery-file-selected', i === index);
|
||||
});
|
||||
}
|
||||
|
||||
window.getGallerySelection = () => ({ index: gallerySelection.index, files: gallerySelection.files });
|
||||
window.setGallerySelection = (index, options) => applyGallerySelection(index, options);
|
||||
window.getGallerySelectedUrl = () => (currentImage ? buildGalleryFileUrl(currentImage) : null);
|
||||
|
|
|
|||
Loading…
Reference in New Issue