1 / X
const gdv_69f349af44fbccanvas = document.getElementById("gdv_69f349af44fbcimageCanvas"); const gdv_69f349af44fbcctx = gdv_69f349af44fbccanvas.getContext("2d");
const gdv_69f349af44fbcthumbnailContainer = document.getElementById("gdv_69f349af44fbcthumbnailContainer"); const gdv_69f349af44fbcthumbnailContainerWrapper = document.getElementById("gdv_69f349af44fbcthumbnailContainerWrapper"); const gdv_69f349af44fbczoomInButton = document.getElementById("gdv_69f349af44fbczoomIn"); const gdv_69f349af44fbczoomOutButton = document.getElementById("gdv_69f349af44fbczoomOut"); const gdv_69f349af44fbcresetZoomButton = document.getElementById("gdv_69f349af44fbcresetZoom");
const gdv_69f349af44fbcbrightnessInput = document.getElementById("gdv_69f349af44fbcbrightness"); const gdv_69f349af44fbccontrastInput = document.getElementById("gdv_69f349af44fbccontrast"); const gdv_69f349af44fbcfullscreenButton = document.getElementById("gdv_69f349af44fbcfullscreen");
const gdv_69f349af44fbcrotateRightButton = document.getElementById("gdv_69f349af44fbcrotateRight"); const gdv_69f349af44fbcrotateLeftButton = document.getElementById("gdv_69f349af44fbcrotateLeft");
const gdv_69f349af44fbcprevSlideButton = document.getElementById("gdv_69f349af44fbcprevSlide"); const gdv_69f349af44fbcnextSlideButton = document.getElementById("gdv_69f349af44fbcnextSlide"); const gdv_69f349af44fbcslideNumberDisplay = document.getElementById("gdv_69f349af44fbcslideNumber"); const gdv_69f349af44fbcimageName = document.getElementById("gdv_69f349af44fbcimageName");
let gdv_69f349af44fbccurrentSlideIndex = 0;
gdv_69f349af44fbcbrightnessInput.addEventListener("input", gdv_69f349af44fbcdrawImage); gdv_69f349af44fbccontrastInput.addEventListener("input", gdv_69f349af44fbcdrawImage);
const gdv_69f349af44fbcimageUrls = [{"url":"https:\/\/drive.google.com\/thumbnail?id=1mQ3Q28_MXD-1EnUj-xwvqEUeQQcmSvAV&sz=w3000","name":"1 ComCIV_SUR LA POSTE.jpg"},{"url":"https:\/\/drive.google.com\/thumbnail?id=1E4fYOzrmFPT63gxyUdnuVMTb4qTyqMz9&sz=w3000","name":"2 ComCIV_SUR LA POSTE.jpg"},{"url":"https:\/\/drive.google.com\/thumbnail?id=1-n3s8Fn2Qs3mZXcRuvMuWXeB5EQH3lq2&sz=w3000","name":"3 ComCIV_SUR LA POSTE.jpg"},{"url":"https:\/\/drive.google.com\/thumbnail?id=1p4gUjR4yS--aX6y7CBf_AHjBtA7L-fUh&sz=w3000","name":"4 ComCIV_SUR LA POSTE.jpg"}];
let gdv_69f349af44fbcscale = 1; let gdv_69f349af44fbcoriginX = 0; let gdv_69f349af44fbcoriginY = 0; const gdv_69f349af44fbcminScale = 0.1; const gdv_69f349af44fbcmaxScale = 5; let gdv_69f349af44fbccurrentImage = new Image();
let gdv_69f349af44fbcrotationAngle = 0;
gdv_69f349af44fbcrotateRightButton.addEventListener("click", function() { gdv_69f349af44fbcrotationAngle = (gdv_69f349af44fbcrotationAngle + 90) % 360; gdv_69f349af44fbcdrawImage(); });
gdv_69f349af44fbcrotateLeftButton.addEventListener("click", function() { gdv_69f349af44fbcrotationAngle = (gdv_69f349af44fbcrotationAngle - 90 + 360) % 360; gdv_69f349af44fbcdrawImage(); });
function filtrerChaine(texte, cacher) { if (!texte) return "";
switch (cacher) { case "chiffre": return texte.replace(/\d/g, "");
case "tout": return "";
case "vide": default: return texte; } }
// Charger la première image par défaut gdv_69f349af44fbccurrentImage.src = gdv_69f349af44fbcimageUrls[0]["url"]; gdv_69f349af44fbcimageName.innerHTML = filtrerChaine(gdv_69f349af44fbcimageUrls[0]["name"], "rien"); gdv_69f349af44fbccurrentImage.onload = function() {
gdv_69f349af44fbcupdateSlideNumber(); gdv_69f349af44fbcresizeCanvas(); gdv_69f349af44fbcdrawImage(); document.getElementById("gdv_69f349af44fbccontrols").style.display = "block"; };
function gdv_69f349af44fbcupdateSlideNumber() { gdv_69f349af44fbcslideNumberDisplay.textContent = `${gdv_69f349af44fbccurrentSlideIndex + 1} / ${gdv_69f349af44fbcimageUrls.length}`; }
gdv_69f349af44fbcprevSlideButton.addEventListener("click", function() { if (gdv_69f349af44fbccurrentSlideIndex > 0) { gdv_69f349af44fbccurrentSlideIndex--; gdv_69f349af44fbcloadImage(gdv_69f349af44fbccurrentSlideIndex); gdv_69f349af44fbcupdateSlideNumber(); } });
gdv_69f349af44fbcnextSlideButton.addEventListener("click", function() { if (gdv_69f349af44fbccurrentSlideIndex < gdv_69f349af44fbcimageUrls.length - 1) { gdv_69f349af44fbccurrentSlideIndex++; gdv_69f349af44fbcloadImage(gdv_69f349af44fbccurrentSlideIndex); gdv_69f349af44fbcupdateSlideNumber(); } }); function gdv_69f349af44fbcresizeCanvas() { // Ajuster la taille du canvas pour correspondre à celle du conteneur const container = document.getElementById("gdv_69f349af44fbccanvasContainer"); gdv_69f349af44fbccanvas.width = container.clientWidth; gdv_69f349af44fbccanvas.height = container.clientHeight - 30; gdv_69f349af44fbcfitImageToCanvas(); // Redessiner le contenu du canvas ici gdv_69f349af44fbcdrawImage(); } window.addEventListener("load", gdv_69f349af44fbcresizeCanvas); window.addEventListener("resize", gdv_69f349af44fbcresizeCanvas); function gdv_69f349af44fbcfitImageToCanvas() { const canvasAspect = gdv_69f349af44fbccanvas.width / gdv_69f349af44fbccanvas.height; const imageAspect = gdv_69f349af44fbccurrentImage.width / gdv_69f349af44fbccurrentImage.height; if (imageAspect > canvasAspect) { gdv_69f349af44fbcscale = gdv_69f349af44fbccanvas.width / gdv_69f349af44fbccurrentImage.width; } else { gdv_69f349af44fbcscale = gdv_69f349af44fbccanvas.height / gdv_69f349af44fbccurrentImage.height; } gdv_69f349af44fbcoriginX = gdv_69f349af44fbccanvas.width / 2; gdv_69f349af44fbcoriginY = gdv_69f349af44fbccanvas.height / 2; }
function gdv_69f349af44fbcdrawImage() { gdv_69f349af44fbcctx.clearRect(0, 0, gdv_69f349af44fbccanvas.width, gdv_69f349af44fbccanvas.height); gdv_69f349af44fbcctx.save(); gdv_69f349af44fbcctx.translate(gdv_69f349af44fbcoriginX, gdv_69f349af44fbcoriginY); gdv_69f349af44fbcctx.rotate((Math.PI / 180) * gdv_69f349af44fbcrotationAngle); gdv_69f349af44fbcctx.scale(gdv_69f349af44fbcscale, gdv_69f349af44fbcscale);
// Appliquer la luminosité et le contraste gdv_69f349af44fbcctx.filter = `brightness(${gdv_69f349af44fbcbrightnessInput.value}) contrast(${gdv_69f349af44fbccontrastInput.value})`; gdv_69f349af44fbcctx.drawImage(gdv_69f349af44fbccurrentImage, -gdv_69f349af44fbccurrentImage.width/2, -gdv_69f349af44fbccurrentImage.height/2); gdv_69f349af44fbcctx.restore(); }
// Ajouter les miniatures des images gdv_69f349af44fbcimageUrls.forEach((obj, index) => { const slide = document.createElement("div"); slide.classList.add("swiper-slide"); const img = new Image(); img.loading = "lazy"; img.src = obj["url"]; img.onclick = function() { gdv_69f349af44fbcloadImage(index); gdv_69f349af44fbccurrentSlideIndex = index; gdv_69f349af44fbcupdateSlideNumber(); }; slide.appendChild(img); gdv_69f349af44fbcthumbnailContainerWrapper.appendChild(slide); });
// Charger une image dans le canvas function gdv_69f349af44fbcloadImage(index) { gdv_69f349af44fbccurrentImage.src = gdv_69f349af44fbcimageUrls[index]["url"]; gdv_69f349af44fbcimageName.innerHTML = filtrerChaine(gdv_69f349af44fbcimageUrls[index]["name"], "rien"); gdv_69f349af44fbccurrentImage.onload = function() { gdv_69f349af44fbcscale = 1; gdv_69f349af44fbcoriginX = 0; gdv_69f349af44fbcoriginY = 0; gdv_69f349af44fbcfitImageToCanvas(); gdv_69f349af44fbcdrawImage(); };
const thumbnails = document.querySelectorAll(".swiper-slide"); thumbnails.forEach((thumb, i) => { if (i === index) { thumb.classList.add("active-thumbnail"); } else { thumb.classList.remove("active-thumbnail"); } }); }
// Initialiser Swiper var gdv_69f349af44fbcswiper = new Swiper(".gdv_69f349af44fbcswiper-container", { direction: "horizontal", slidesPerView: 8, spaceBetween: 5, breakpoints: { 576: { slidesPerView: 8, spaceBetween: 5 }, 768: { slidesPerView: 9, spaceBetween: 5 }, 992: { slidesPerView: 11, spaceBetween: 5 }, 1200: { slidesPerView: 13, spaceBetween: 5 } }, mousewheel: true, });
document.querySelector(".swiper-slide").classList.add("active-thumbnail");
//gdv_69f349af44fbcswiper.on("slideChange", function () { // gdv_69f349af44fbccurrentSlideIndex = gdv_69f349af44fbcswiper.activeIndex; // gdv_69f349af44fbcupdateSlideNumber(); //});
// Plein écran gdv_69f349af44fbcfullscreenButton.addEventListener("click", function() { if (!document.fullscreenElement) { document.getElementById("gdv_69f349af44fbcgd-image-gallery").requestFullscreen().catch(err => { alert(`Erreur lors de la tentative de mise en plein écran: ${err.message}`); }); } else { document.exitFullscreen(); } });
// Impression du canvas
/*printButton.addEventListener("click", function() {
const dataUrl = canvas.toDataURL();
const windowContent = ``;
const printWindow = window.open("", "", "width=800,height=800");
printWindow.document.write(windowContent);
printWindow.document.close();
});
*/
// Gestion du zoom gdv_69f349af44fbccanvas.addEventListener("wheel", function(event) { event.preventDefault(); const zoomFactor = 0.025; const mouseX = event.offsetX; const mouseY = event.offsetY;
let newScale = gdv_69f349af44fbcscale; if (event.deltaY < 0) { newScale *= 1 + zoomFactor; } else { newScale /= 1 + zoomFactor; } newScale = Math.max(gdv_69f349af44fbcminScale, Math.min(gdv_69f349af44fbcmaxScale, newScale)); const scaleRatio = newScale / gdv_69f349af44fbcscale; gdv_69f349af44fbcoriginX = mouseX - (mouseX - gdv_69f349af44fbcoriginX) * scaleRatio; gdv_69f349af44fbcoriginY = mouseY - (mouseY - gdv_69f349af44fbcoriginY) * scaleRatio; gdv_69f349af44fbcscale = newScale; gdv_69f349af44fbcdrawImage(); }); // Gestion du déplacement (pan) let gdv_69f349af44fbcisDragging = false; let gdv_69f349af44fbcstartX, gdv_69f349af44fbcstartY; gdv_69f349af44fbccanvas.addEventListener("mousedown", function(event) { gdv_69f349af44fbcisDragging = true; gdv_69f349af44fbcstartX = event.offsetX - gdv_69f349af44fbcoriginX; gdv_69f349af44fbcstartY = event.offsetY - gdv_69f349af44fbcoriginY; gdv_69f349af44fbccanvas.style.cursor = "grabbing"; }); gdv_69f349af44fbccanvas.addEventListener("mousemove", function(event) { if (gdv_69f349af44fbcisDragging) { gdv_69f349af44fbcoriginX = event.offsetX - gdv_69f349af44fbcstartX; gdv_69f349af44fbcoriginY = event.offsetY - gdv_69f349af44fbcstartY; gdv_69f349af44fbcdrawImage(); } }); // Gestion des événements tactiles gdv_69f349af44fbccanvas.addEventListener("touchstart", function(event) { if (event.touches.length === 1) { gdv_69f349af44fbcisDragging = true; const touch = event.touches[0]; gdv_69f349af44fbcstartX = touch.pageX - gdv_69f349af44fbcoriginX; gdv_69f349af44fbcstartY = touch.pageY - gdv_69f349af44fbcoriginY; } }); gdv_69f349af44fbccanvas.addEventListener("touchmove", function(event) { event.preventDefault(); // Empêche le comportement par défaut du navigateur const touch = event.touches[0]; gdv_69f349af44fbcoriginX = touch.pageX - gdv_69f349af44fbcstartX; gdv_69f349af44fbcoriginY = touch.pageY - gdv_69f349af44fbcstartY; gdv_69f349af44fbcdrawImage(); }); gdv_69f349af44fbccanvas.addEventListener("touchend", function() { gdv_69f349af44fbcisDragging = false; }); gdv_69f349af44fbccanvas.addEventListener("mouseup", function() { gdv_69f349af44fbcisDragging = false; gdv_69f349af44fbccanvas.style.cursor = "grab"; }); gdv_69f349af44fbccanvas.addEventListener("mouseleave", function() { gdv_69f349af44fbcisDragging = false; gdv_69f349af44fbccanvas.style.cursor = "grab"; }); gdv_69f349af44fbczoomInButton.addEventListener("click", function() { let newScale = gdv_69f349af44fbcscale; const zoomFactor = 0.025; newScale *= 1 + zoomFactor; gdv_69f349af44fbcscale = Math.max(gdv_69f349af44fbcminScale, Math.min(gdv_69f349af44fbcmaxScale, newScale)); gdv_69f349af44fbcdrawImage(); }); gdv_69f349af44fbczoomOutButton.addEventListener("click", function() { let newScale = gdv_69f349af44fbcscale; const zoomFactor = 0.025; newScale /= 1 + zoomFactor; gdv_69f349af44fbcscale = Math.max(gdv_69f349af44fbcminScale, Math.min(gdv_69f349af44fbcmaxScale, newScale)); gdv_69f349af44fbcdrawImage(); }); gdv_69f349af44fbcresetZoomButton.addEventListener("click", function() { gdv_69f349af44fbcrotationAngle = 0; gdv_69f349af44fbcfitImageToCanvas(); gdv_69f349af44fbcdrawImage(); }); function gdv_69f349af44fbcgetImageIdFromUrl(url) { const urlObj = new URL(url); return urlObj.searchParams.get("id"); } document.getElementById("gdv_69f349af44fbcdownloadImage").addEventListener("click", function() { let url = gdv_69f349af44fbccurrentImage.src; const imageId = gdv_69f349af44fbcgetImageIdFromUrl(url); const apiUrl = `${window.location.origin}/wp-json/gdv/v1/download-image?image_id=${imageId}`; fetch(apiUrl) .then(response => response.blob()) .then(blob => { const url = window.URL.createObjectURL(blob); const a = document.createElement("a"); a.style.display = "none"; a.href = url; a.download = `${imageId}.jpg`; document.body.appendChild(a); a.click(); window.URL.revokeObjectURL(url); }) .catch(error => console.error("Error downloading image:", error)); });
function gdv_69f349af44fbcprintImageFromApi(imageId) { const apiUrl = `${window.location.origin}/wp-json/gdv/v1/download-image?image_id=${imageId}`;
fetch(apiUrl) .then(response => response.blob()) .then(blob => { const url = URL.createObjectURL(blob); const printWindow = window.open("", "_blank"); printWindow.document.write(`
const gdv_69f349af44fbcprintButton = document.getElementById("gdv_69f349af44fbcprintCanvas");
gdv_69f349af44fbcprintButton.addEventListener("click", function() { let url = gdv_69f349af44fbccurrentImage.src; const imageId = gdv_69f349af44fbcgetImageIdFromUrl(url); gdv_69f349af44fbcprintImageFromApi(imageId); });
let gdv_69f349af44fbcinitialDistance = 0; let gdv_69f349af44fbcinitialScale = 1;
gdv_69f349af44fbccanvas.addEventListener("touchstart", function(event) { if (event.touches.length === 2) { event.preventDefault(); gdv_69f349af44fbcinitialDistance = getDistance(event.touches[0], event.touches[1]); gdv_69f349af44fbcinitialScale = gdv_69f349af44fbcscale; } });
gdv_69f349af44fbccanvas.addEventListener("touchmove", function(event) { if (event.touches.length === 2) { event.preventDefault(); const currentDistance = getDistance(event.touches[0], event.touches[1]); const scaleChange = currentDistance / gdv_69f349af44fbcinitialDistance; let newScale = gdv_69f349af44fbcinitialScale * scaleChange;
newScale = Math.max(gdv_69f349af44fbcminScale, Math.min(gdv_69f349af44fbcmaxScale, newScale));
const centerX = (event.touches[0].pageX + event.touches[1].pageX) / 2; const centerY = (event.touches[0].pageY + event.touches[1].pageY) / 2;
const scaleRatio = newScale / gdv_69f349af44fbcscale; gdv_69f349af44fbcoriginX = centerX - (centerX - gdv_69f349af44fbcoriginX) * scaleRatio; gdv_69f349af44fbcoriginY = centerY - (centerY - gdv_69f349af44fbcoriginY) * scaleRatio;
gdv_69f349af44fbcscale = newScale; gdv_69f349af44fbcdrawImage(); // Remplacez par votre fonction de dessin } });
function getDistance(touch1, touch2) { const dx = touch2.pageX - touch1.pageX; const dy = touch2.pageY - touch1.pageY; return Math.sqrt(dx * dx + dy * dy); }