1 / X
const gdv_687086c35f70ccanvas = document.getElementById("gdv_687086c35f70cimageCanvas"); const gdv_687086c35f70cctx = gdv_687086c35f70ccanvas.getContext("2d");
const gdv_687086c35f70cthumbnailContainer = document.getElementById("gdv_687086c35f70cthumbnailContainer"); const gdv_687086c35f70cthumbnailContainerWrapper = document.getElementById("gdv_687086c35f70cthumbnailContainerWrapper"); const gdv_687086c35f70czoomInButton = document.getElementById("gdv_687086c35f70czoomIn"); const gdv_687086c35f70czoomOutButton = document.getElementById("gdv_687086c35f70czoomOut"); const gdv_687086c35f70cresetZoomButton = document.getElementById("gdv_687086c35f70cresetZoom");
const gdv_687086c35f70cbrightnessInput = document.getElementById("gdv_687086c35f70cbrightness"); const gdv_687086c35f70ccontrastInput = document.getElementById("gdv_687086c35f70ccontrast"); const gdv_687086c35f70cfullscreenButton = document.getElementById("gdv_687086c35f70cfullscreen");
const gdv_687086c35f70crotateRightButton = document.getElementById("gdv_687086c35f70crotateRight"); const gdv_687086c35f70crotateLeftButton = document.getElementById("gdv_687086c35f70crotateLeft");
const gdv_687086c35f70cprevSlideButton = document.getElementById("gdv_687086c35f70cprevSlide"); const gdv_687086c35f70cnextSlideButton = document.getElementById("gdv_687086c35f70cnextSlide"); const gdv_687086c35f70cslideNumberDisplay = document.getElementById("gdv_687086c35f70cslideNumber"); const gdv_687086c35f70cimageName = document.getElementById("gdv_687086c35f70cimageName");
let gdv_687086c35f70ccurrentSlideIndex = 0;
gdv_687086c35f70cbrightnessInput.addEventListener("input", gdv_687086c35f70cdrawImage); gdv_687086c35f70ccontrastInput.addEventListener("input", gdv_687086c35f70cdrawImage);
const gdv_687086c35f70cimageUrls = [{"url":"https:\/\/drive.google.com\/thumbnail?id=1r5oMLHMHzqXONXDNCU9rI65g4nUPi7JF&sz=w3000","name":"LFS_EPOL_Sur les biens mobiliers des e\u0301migre\u0301s.jpg"}];
let gdv_687086c35f70cscale = 1; let gdv_687086c35f70coriginX = 0; let gdv_687086c35f70coriginY = 0; const gdv_687086c35f70cminScale = 0.1; const gdv_687086c35f70cmaxScale = 5; let gdv_687086c35f70ccurrentImage = new Image();
let gdv_687086c35f70crotationAngle = 0;
gdv_687086c35f70crotateRightButton.addEventListener("click", function() { gdv_687086c35f70crotationAngle = (gdv_687086c35f70crotationAngle + 90) % 360; gdv_687086c35f70cdrawImage(); });
gdv_687086c35f70crotateLeftButton.addEventListener("click", function() { gdv_687086c35f70crotationAngle = (gdv_687086c35f70crotationAngle - 90 + 360) % 360; gdv_687086c35f70cdrawImage(); });
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_687086c35f70ccurrentImage.src = gdv_687086c35f70cimageUrls[0]["url"]; gdv_687086c35f70cimageName.innerHTML = filtrerChaine(gdv_687086c35f70cimageUrls[0]["name"], "rien"); gdv_687086c35f70ccurrentImage.onload = function() {
gdv_687086c35f70cupdateSlideNumber(); gdv_687086c35f70cresizeCanvas(); gdv_687086c35f70cdrawImage(); document.getElementById("gdv_687086c35f70ccontrols").style.display = "block"; };
function gdv_687086c35f70cupdateSlideNumber() { gdv_687086c35f70cslideNumberDisplay.textContent = `${gdv_687086c35f70ccurrentSlideIndex + 1} / ${gdv_687086c35f70cimageUrls.length}`; }
gdv_687086c35f70cprevSlideButton.addEventListener("click", function() { if (gdv_687086c35f70ccurrentSlideIndex > 0) { gdv_687086c35f70ccurrentSlideIndex--; gdv_687086c35f70cloadImage(gdv_687086c35f70ccurrentSlideIndex); gdv_687086c35f70cupdateSlideNumber(); } });
gdv_687086c35f70cnextSlideButton.addEventListener("click", function() { if (gdv_687086c35f70ccurrentSlideIndex < gdv_687086c35f70cimageUrls.length - 1) { gdv_687086c35f70ccurrentSlideIndex++; gdv_687086c35f70cloadImage(gdv_687086c35f70ccurrentSlideIndex); gdv_687086c35f70cupdateSlideNumber(); } }); function gdv_687086c35f70cresizeCanvas() { // Ajuster la taille du canvas pour correspondre à celle du conteneur const container = document.getElementById("gdv_687086c35f70ccanvasContainer"); gdv_687086c35f70ccanvas.width = container.clientWidth; gdv_687086c35f70ccanvas.height = container.clientHeight - 30; gdv_687086c35f70cfitImageToCanvas(); // Redessiner le contenu du canvas ici gdv_687086c35f70cdrawImage(); } window.addEventListener("load", gdv_687086c35f70cresizeCanvas); window.addEventListener("resize", gdv_687086c35f70cresizeCanvas); function gdv_687086c35f70cfitImageToCanvas() { const canvasAspect = gdv_687086c35f70ccanvas.width / gdv_687086c35f70ccanvas.height; const imageAspect = gdv_687086c35f70ccurrentImage.width / gdv_687086c35f70ccurrentImage.height; if (imageAspect > canvasAspect) { gdv_687086c35f70cscale = gdv_687086c35f70ccanvas.width / gdv_687086c35f70ccurrentImage.width; } else { gdv_687086c35f70cscale = gdv_687086c35f70ccanvas.height / gdv_687086c35f70ccurrentImage.height; } gdv_687086c35f70coriginX = gdv_687086c35f70ccanvas.width / 2; gdv_687086c35f70coriginY = gdv_687086c35f70ccanvas.height / 2; }
function gdv_687086c35f70cdrawImage() { gdv_687086c35f70cctx.clearRect(0, 0, gdv_687086c35f70ccanvas.width, gdv_687086c35f70ccanvas.height); gdv_687086c35f70cctx.save(); gdv_687086c35f70cctx.translate(gdv_687086c35f70coriginX, gdv_687086c35f70coriginY); gdv_687086c35f70cctx.rotate((Math.PI / 180) * gdv_687086c35f70crotationAngle); gdv_687086c35f70cctx.scale(gdv_687086c35f70cscale, gdv_687086c35f70cscale);
// Appliquer la luminosité et le contraste gdv_687086c35f70cctx.filter = `brightness(${gdv_687086c35f70cbrightnessInput.value}) contrast(${gdv_687086c35f70ccontrastInput.value})`; gdv_687086c35f70cctx.drawImage(gdv_687086c35f70ccurrentImage, -gdv_687086c35f70ccurrentImage.width/2, -gdv_687086c35f70ccurrentImage.height/2); gdv_687086c35f70cctx.restore(); }
// Ajouter les miniatures des images gdv_687086c35f70cimageUrls.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_687086c35f70cloadImage(index); gdv_687086c35f70ccurrentSlideIndex = index; gdv_687086c35f70cupdateSlideNumber(); }; slide.appendChild(img); gdv_687086c35f70cthumbnailContainerWrapper.appendChild(slide); });
// Charger une image dans le canvas function gdv_687086c35f70cloadImage(index) { gdv_687086c35f70ccurrentImage.src = gdv_687086c35f70cimageUrls[index]["url"]; gdv_687086c35f70cimageName.innerHTML = filtrerChaine(gdv_687086c35f70cimageUrls[index]["name"], "rien"); gdv_687086c35f70ccurrentImage.onload = function() { gdv_687086c35f70cscale = 1; gdv_687086c35f70coriginX = 0; gdv_687086c35f70coriginY = 0; gdv_687086c35f70cfitImageToCanvas(); gdv_687086c35f70cdrawImage(); };
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_687086c35f70cswiper = new Swiper(".gdv_687086c35f70cswiper-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_687086c35f70cswiper.on("slideChange", function () { // gdv_687086c35f70ccurrentSlideIndex = gdv_687086c35f70cswiper.activeIndex; // gdv_687086c35f70cupdateSlideNumber(); //});
// Plein écran gdv_687086c35f70cfullscreenButton.addEventListener("click", function() { if (!document.fullscreenElement) { document.getElementById("gdv_687086c35f70cgd-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_687086c35f70ccanvas.addEventListener("wheel", function(event) { event.preventDefault(); const zoomFactor = 0.025; const mouseX = event.offsetX; const mouseY = event.offsetY;
let newScale = gdv_687086c35f70cscale; if (event.deltaY < 0) { newScale *= 1 + zoomFactor; } else { newScale /= 1 + zoomFactor; } newScale = Math.max(gdv_687086c35f70cminScale, Math.min(gdv_687086c35f70cmaxScale, newScale)); const scaleRatio = newScale / gdv_687086c35f70cscale; gdv_687086c35f70coriginX = mouseX - (mouseX - gdv_687086c35f70coriginX) * scaleRatio; gdv_687086c35f70coriginY = mouseY - (mouseY - gdv_687086c35f70coriginY) * scaleRatio; gdv_687086c35f70cscale = newScale; gdv_687086c35f70cdrawImage(); }); // Gestion du déplacement (pan) let gdv_687086c35f70cisDragging = false; let gdv_687086c35f70cstartX, gdv_687086c35f70cstartY; gdv_687086c35f70ccanvas.addEventListener("mousedown", function(event) { gdv_687086c35f70cisDragging = true; gdv_687086c35f70cstartX = event.offsetX - gdv_687086c35f70coriginX; gdv_687086c35f70cstartY = event.offsetY - gdv_687086c35f70coriginY; gdv_687086c35f70ccanvas.style.cursor = "grabbing"; }); gdv_687086c35f70ccanvas.addEventListener("mousemove", function(event) { if (gdv_687086c35f70cisDragging) { gdv_687086c35f70coriginX = event.offsetX - gdv_687086c35f70cstartX; gdv_687086c35f70coriginY = event.offsetY - gdv_687086c35f70cstartY; gdv_687086c35f70cdrawImage(); } }); // Gestion des événements tactiles gdv_687086c35f70ccanvas.addEventListener("touchstart", function(event) { if (event.touches.length === 1) { gdv_687086c35f70cisDragging = true; const touch = event.touches[0]; gdv_687086c35f70cstartX = touch.pageX - gdv_687086c35f70coriginX; gdv_687086c35f70cstartY = touch.pageY - gdv_687086c35f70coriginY; } }); gdv_687086c35f70ccanvas.addEventListener("touchmove", function(event) { event.preventDefault(); // Empêche le comportement par défaut du navigateur const touch = event.touches[0]; gdv_687086c35f70coriginX = touch.pageX - gdv_687086c35f70cstartX; gdv_687086c35f70coriginY = touch.pageY - gdv_687086c35f70cstartY; gdv_687086c35f70cdrawImage(); }); gdv_687086c35f70ccanvas.addEventListener("touchend", function() { gdv_687086c35f70cisDragging = false; }); gdv_687086c35f70ccanvas.addEventListener("mouseup", function() { gdv_687086c35f70cisDragging = false; gdv_687086c35f70ccanvas.style.cursor = "grab"; }); gdv_687086c35f70ccanvas.addEventListener("mouseleave", function() { gdv_687086c35f70cisDragging = false; gdv_687086c35f70ccanvas.style.cursor = "grab"; }); gdv_687086c35f70czoomInButton.addEventListener("click", function() { let newScale = gdv_687086c35f70cscale; const zoomFactor = 0.025; newScale *= 1 + zoomFactor; gdv_687086c35f70cscale = Math.max(gdv_687086c35f70cminScale, Math.min(gdv_687086c35f70cmaxScale, newScale)); gdv_687086c35f70cdrawImage(); }); gdv_687086c35f70czoomOutButton.addEventListener("click", function() { let newScale = gdv_687086c35f70cscale; const zoomFactor = 0.025; newScale /= 1 + zoomFactor; gdv_687086c35f70cscale = Math.max(gdv_687086c35f70cminScale, Math.min(gdv_687086c35f70cmaxScale, newScale)); gdv_687086c35f70cdrawImage(); }); gdv_687086c35f70cresetZoomButton.addEventListener("click", function() { gdv_687086c35f70crotationAngle = 0; gdv_687086c35f70cfitImageToCanvas(); gdv_687086c35f70cdrawImage(); }); function gdv_687086c35f70cgetImageIdFromUrl(url) { const urlObj = new URL(url); return urlObj.searchParams.get("id"); } document.getElementById("gdv_687086c35f70cdownloadImage").addEventListener("click", function() { let url = gdv_687086c35f70ccurrentImage.src; const imageId = gdv_687086c35f70cgetImageIdFromUrl(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_687086c35f70cprintImageFromApi(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_687086c35f70cprintButton = document.getElementById("gdv_687086c35f70cprintCanvas");
gdv_687086c35f70cprintButton.addEventListener("click", function() { let url = gdv_687086c35f70ccurrentImage.src; const imageId = gdv_687086c35f70cgetImageIdFromUrl(url); gdv_687086c35f70cprintImageFromApi(imageId); });
let gdv_687086c35f70cinitialDistance = 0; let gdv_687086c35f70cinitialScale = 1;
gdv_687086c35f70ccanvas.addEventListener("touchstart", function(event) { if (event.touches.length === 2) { event.preventDefault(); gdv_687086c35f70cinitialDistance = getDistance(event.touches[0], event.touches[1]); gdv_687086c35f70cinitialScale = gdv_687086c35f70cscale; } });
gdv_687086c35f70ccanvas.addEventListener("touchmove", function(event) { if (event.touches.length === 2) { event.preventDefault(); const currentDistance = getDistance(event.touches[0], event.touches[1]); const scaleChange = currentDistance / gdv_687086c35f70cinitialDistance; let newScale = gdv_687086c35f70cinitialScale * scaleChange;
newScale = Math.max(gdv_687086c35f70cminScale, Math.min(gdv_687086c35f70cmaxScale, 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_687086c35f70cscale; gdv_687086c35f70coriginX = centerX - (centerX - gdv_687086c35f70coriginX) * scaleRatio; gdv_687086c35f70coriginY = centerY - (centerY - gdv_687086c35f70coriginY) * scaleRatio;
gdv_687086c35f70cscale = newScale; gdv_687086c35f70cdrawImage(); // 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); }