mirror of
https://github.com/karl0ss/ai_image_frame_server.git
synced 2025-07-05 14:06:07 +01:00
keyboard support in the lightbox
This commit is contained in:
parent
0b7e0ca59d
commit
33404c7a37
@ -31,28 +31,20 @@ def gallery():
|
|||||||
def get_favourites_route():
|
def get_favourites_route():
|
||||||
return jsonify(get_favourites())
|
return jsonify(get_favourites())
|
||||||
|
|
||||||
@bp.route("/favourites/add", methods=["POST"])
|
@bp.route("/favourites/toggle", methods=["POST"])
|
||||||
def add_favourite():
|
def toggle_favourite():
|
||||||
data = request.get_json()
|
|
||||||
filename = data.get("filename")
|
|
||||||
if not filename:
|
|
||||||
return jsonify({"status": "error", "message": "Filename missing"}), 400
|
|
||||||
|
|
||||||
favourites = get_favourites()
|
|
||||||
if filename not in favourites:
|
|
||||||
favourites.append(filename)
|
|
||||||
save_favourites(favourites)
|
|
||||||
return jsonify({"status": "success"})
|
|
||||||
|
|
||||||
@bp.route("/favourites/remove", methods=["POST"])
|
|
||||||
def remove_favourite():
|
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
filename = data.get("filename")
|
filename = data.get("filename")
|
||||||
if not filename:
|
if not filename:
|
||||||
return jsonify({"status": "error", "message": "Filename missing"}), 400
|
return jsonify({"status": "error", "message": "Filename missing"}), 400
|
||||||
|
|
||||||
favourites = get_favourites()
|
favourites = get_favourites()
|
||||||
|
is_favourited = False
|
||||||
if filename in favourites:
|
if filename in favourites:
|
||||||
favourites.remove(filename)
|
favourites.remove(filename)
|
||||||
save_favourites(favourites)
|
else:
|
||||||
return jsonify({"status": "success"})
|
favourites.append(filename)
|
||||||
|
is_favourited = True
|
||||||
|
|
||||||
|
save_favourites(favourites)
|
||||||
|
return jsonify({"status": "success", "favourited": is_favourited})
|
||||||
|
@ -204,7 +204,7 @@
|
|||||||
<div class="gallery" id="gallery"></div>
|
<div class="gallery" id="gallery"></div>
|
||||||
|
|
||||||
<!-- Lightbox -->
|
<!-- Lightbox -->
|
||||||
<div class="lightbox" id="lightbox">
|
<div class="lightbox" id="lightbox" tabindex="-1" onkeyup="handleLightboxKeys(event)">
|
||||||
<span class="close" onclick="closeLightbox()">×</span>
|
<span class="close" onclick="closeLightbox()">×</span>
|
||||||
<span class="favourite-heart" id="favourite-heart" onclick="toggleFavourite()">♡</span>
|
<span class="favourite-heart" id="favourite-heart" onclick="toggleFavourite()">♡</span>
|
||||||
<span class="arrow left" onclick="prevImage()">❮</span>
|
<span class="arrow left" onclick="prevImage()">❮</span>
|
||||||
@ -297,7 +297,9 @@
|
|||||||
const images = getGalleryImages();
|
const images = getGalleryImages();
|
||||||
currentIndex = images.indexOf(imgEl);
|
currentIndex = images.indexOf(imgEl);
|
||||||
showImageAndLoadDetails(currentIndex);
|
showImageAndLoadDetails(currentIndex);
|
||||||
document.getElementById("lightbox").style.display = "flex";
|
const lightbox = document.getElementById("lightbox");
|
||||||
|
lightbox.style.display = "flex";
|
||||||
|
lightbox.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateFavouriteHeart(isFavourited) {
|
function updateFavouriteHeart(isFavourited) {
|
||||||
@ -310,10 +312,8 @@
|
|||||||
const images = getGalleryImages();
|
const images = getGalleryImages();
|
||||||
const imgEl = images[currentIndex];
|
const imgEl = images[currentIndex];
|
||||||
const filename = imgEl.dataset.filename;
|
const filename = imgEl.dataset.filename;
|
||||||
let isFavourited = imgEl.dataset.favourited === 'true';
|
|
||||||
|
|
||||||
const url = isFavourited ? '/favourites/remove' : '/favourites/add';
|
fetch('/favourites/toggle', {
|
||||||
fetch(url, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ filename: filename })
|
body: JSON.stringify({ filename: filename })
|
||||||
@ -321,17 +321,22 @@
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.status === 'success') {
|
if (data.status === 'success') {
|
||||||
isFavourited = !isFavourited;
|
const isFavourited = data.favourited;
|
||||||
imgEl.dataset.favourited = isFavourited;
|
imgEl.dataset.favourited = isFavourited;
|
||||||
updateFavouriteHeart(isFavourited);
|
updateFavouriteHeart(isFavourited);
|
||||||
// Update the main image list
|
|
||||||
const originalImage = allImages.find(img => img.filename === filename);
|
const originalImage = allImages.find(img => img.filename === filename);
|
||||||
if (originalImage) {
|
if (originalImage) {
|
||||||
originalImage.favourited = isFavourited;
|
originalImage.favourited = isFavourited;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
if (showingFavourites) {
|
||||||
}
|
filteredImages = allImages.filter(img => img.favourited);
|
||||||
|
renderGallery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function showImageAndLoadDetails(index) {
|
function showImageAndLoadDetails(index) {
|
||||||
const images = getGalleryImages();
|
const images = getGalleryImages();
|
||||||
@ -404,6 +409,18 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleLightboxKeys(e) {
|
||||||
|
if (e.key === 'f') {
|
||||||
|
toggleFavourite();
|
||||||
|
} else if (e.key === 'Escape') {
|
||||||
|
closeLightbox();
|
||||||
|
} else if (e.key === 'ArrowLeft') {
|
||||||
|
prevImage();
|
||||||
|
} else if (e.key === 'ArrowRight') {
|
||||||
|
nextImage();
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user