diff --git a/javascript/gallery.js b/javascript/gallery.js index 4159d8ad1..fb81bb58a 100644 --- a/javascript/gallery.js +++ b/javascript/gallery.js @@ -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);