fix(controls): fix ReferenceError hdBtn and preserve query params in cache busting url

This commit is contained in:
kdeterme 2026-08-17 11:14:05 +02:00
parent 06b70a3129
commit 68d3e042dc

View file

@ -2094,6 +2094,18 @@ function updateRemarkCarouselActiveSlide(idx) {
}
}
function addTimestampToUrl(url) {
if (!url) return url;
try {
const u = new URL(url, window.location.origin);
u.searchParams.set('t', Date.now().toString());
return u.pathname + u.search + u.hash;
} catch (e) {
const sep = url.includes('?') ? '&' : '?';
return url.replace(/([&?]t=\d+)/, '') + sep + 't=' + Date.now();
}
}
async function rotateRemarkImage(imageId, triggerBtn) {
if (!imageId) return;
@ -2117,26 +2129,20 @@ async function rotateRemarkImage(imageId, triggerBtn) {
});
const data = await response.json();
if (data.success) {
const timestamp = Date.now();
// Rafraîchir l'image active dans le carrousel si ouvert
const activeCarouselImg = document.querySelector('#remark-carousel-inner .carousel-item.active img');
if (activeCarouselImg) {
const cleanUrl = activeCarouselImg.src.split('?')[0];
activeCarouselImg.src = `${cleanUrl}?t=${timestamp}`;
activeCarouselImg.src = addTimestampToUrl(activeCarouselImg.src);
}
// Rafraîchir toutes les vignettes et attributs data correspondants sur la page
document.querySelectorAll(`img[data-image-id="${imageId}"]`).forEach(img => {
const cleanThumb = img.src.split('?')[0];
img.src = `${cleanThumb}?t=${timestamp}`;
img.src = addTimestampToUrl(img.src);
if (img.dataset.fullUrl) {
const cleanFull = img.dataset.fullUrl.split('?')[0];
img.dataset.fullUrl = `${cleanFull}?t=${timestamp}`;
img.dataset.fullUrl = addTimestampToUrl(img.dataset.fullUrl);
}
if (img.dataset.thumbUrl) {
const cleanThumbData = img.dataset.thumbUrl.split('?')[0];
img.dataset.thumbUrl = `${cleanThumbData}?t=${timestamp}`;
img.dataset.thumbUrl = addTimestampToUrl(img.dataset.thumbUrl);
}
});
@ -2144,8 +2150,9 @@ async function rotateRemarkImage(imageId, triggerBtn) {
if (currentRemarkCarouselPhotos && currentRemarkCarouselPhotos[currentRemarkCarouselIndex]) {
const curr = currentRemarkCarouselPhotos[currentRemarkCarouselIndex];
if (curr.imageId == imageId) {
curr.fullUrl = curr.fullUrl.split('?')[0] + `?t=${timestamp}`;
curr.thumbUrl = curr.thumbUrl.split('?')[0] + `?t=${timestamp}`;
curr.fullUrl = addTimestampToUrl(curr.fullUrl);
curr.thumbUrl = addTimestampToUrl(curr.thumbUrl);
const hdBtn = document.getElementById('remark-carousel-hd-btn');
if (hdBtn) hdBtn.href = curr.fullUrl;
}
}