1 / X
const gdv_6b0508fcb0b7dcanvas = document.getElementById("gdv_6b0508fcb0b7dimageCanvas"); const gdv_6b0508fcb0b7dctx = gdv_6b0508fcb0b7dcanvas.getContext("2d");
const gdv_6b0508fcb0b7dthumbnailContainer = document.getElementById("gdv_6b0508fcb0b7dthumbnailContainer"); const gdv_6b0508fcb0b7dthumbnailContainerWrapper = document.getElementById("gdv_6b0508fcb0b7dthumbnailContainerWrapper"); const gdv_6b0508fcb0b7dzoomInButton = document.getElementById("gdv_6b0508fcb0b7dzoomIn"); const gdv_6b0508fcb0b7dzoomOutButton = document.getElementById("gdv_6b0508fcb0b7dzoomOut"); const gdv_6b0508fcb0b7dresetZoomButton = document.getElementById("gdv_6b0508fcb0b7dresetZoom");
const gdv_6b0508fcb0b7dbrightnessInput = document.getElementById("gdv_6b0508fcb0b7dbrightness"); const gdv_6b0508fcb0b7dcontrastInput = document.getElementById("gdv_6b0508fcb0b7dcontrast"); const gdv_6b0508fcb0b7dfullscreenButton = document.getElementById("gdv_6b0508fcb0b7dfullscreen");
const gdv_6b0508fcb0b7drotateRightButton = document.getElementById("gdv_6b0508fcb0b7drotateRight"); const gdv_6b0508fcb0b7drotateLeftButton = document.getElementById("gdv_6b0508fcb0b7drotateLeft");
const gdv_6b0508fcb0b7dprevSlideButton = document.getElementById("gdv_6b0508fcb0b7dprevSlide"); const gdv_6b0508fcb0b7dnextSlideButton = document.getElementById("gdv_6b0508fcb0b7dnextSlide"); const gdv_6b0508fcb0b7dslideNumberDisplay = document.getElementById("gdv_6b0508fcb0b7dslideNumber"); const gdv_6b0508fcb0b7dimageName = document.getElementById("gdv_6b0508fcb0b7dimageName");
let gdv_6b0508fcb0b7dcurrentSlideIndex = 0;
gdv_6b0508fcb0b7dbrightnessInput.addEventListener("input", gdv_6b0508fcb0b7ddrawImage); gdv_6b0508fcb0b7dcontrastInput.addEventListener("input", gdv_6b0508fcb0b7ddrawImage);
const gdv_6b0508fcb0b7dimageUrls = [{"url":"https:\/\/drive.google.com\/thumbnail?id=1rj822uUokR_C8p1qcZqFha58q9sfNRDg&sz=w3000","name":"EPOL et LFS_sur la loi du 25 aout sur les biens des personnes non re\u0301sidantes en France ou dans les colonies.jpg"}];
let gdv_6b0508fcb0b7dscale = 1; let gdv_6b0508fcb0b7doriginX = 0; let gdv_6b0508fcb0b7doriginY = 0; const gdv_6b0508fcb0b7dminScale = 0.1; const gdv_6b0508fcb0b7dmaxScale = 5; let gdv_6b0508fcb0b7dcurrentImage = new Image();
let gdv_6b0508fcb0b7drotationAngle = 0;
gdv_6b0508fcb0b7drotateRightButton.addEventListener("click", function() { gdv_6b0508fcb0b7drotationAngle = (gdv_6b0508fcb0b7drotationAngle + 90) % 360; gdv_6b0508fcb0b7ddrawImage(); });
gdv_6b0508fcb0b7drotateLeftButton.addEventListener("click", function() { gdv_6b0508fcb0b7drotationAngle = (gdv_6b0508fcb0b7drotationAngle - 90 + 360) % 360; gdv_6b0508fcb0b7ddrawImage(); });
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_6b0508fcb0b7dcurrentImage.src = gdv_6b0508fcb0b7dimageUrls[0]["url"]; gdv_6b0508fcb0b7dimageName.innerHTML = filtrerChaine(gdv_6b0508fcb0b7dimageUrls[0]["name"], "rien"); gdv_6b0508fcb0b7dcurrentImage.onload = function() {
gdv_6b0508fcb0b7dupdateSlideNumber(); gdv_6b0508fcb0b7dresizeCanvas(); gdv_6b0508fcb0b7ddrawImage(); document.getElementById("gdv_6b0508fcb0b7dcontrols").style.display = "block"; };
function gdv_6b0508fcb0b7dupdateSlideNumber() { gdv_6b0508fcb0b7dslideNumberDisplay.textContent = `${gdv_6b0508fcb0b7dcurrentSlideIndex + 1} / ${gdv_6b0508fcb0b7dimageUrls.length}`; }
gdv_6b0508fcb0b7dprevSlideButton.addEventListener("click", function() { if (gdv_6b0508fcb0b7dcurrentSlideIndex > 0) { gdv_6b0508fcb0b7dcurrentSlideIndex--; gdv_6b0508fcb0b7dloadImage(gdv_6b0508fcb0b7dcurrentSlideIndex); gdv_6b0508fcb0b7dupdateSlideNumber(); } });
gdv_6b0508fcb0b7dnextSlideButton.addEventListener("click", function() { if (gdv_6b0508fcb0b7dcurrentSlideIndex < gdv_6b0508fcb0b7dimageUrls.length - 1) { gdv_6b0508fcb0b7dcurrentSlideIndex++; gdv_6b0508fcb0b7dloadImage(gdv_6b0508fcb0b7dcurrentSlideIndex); gdv_6b0508fcb0b7dupdateSlideNumber(); } }); function gdv_6b0508fcb0b7dresizeCanvas() { // Ajuster la taille du canvas pour correspondre à celle du conteneur const container = document.getElementById("gdv_6b0508fcb0b7dcanvasContainer"); gdv_6b0508fcb0b7dcanvas.width = container.clientWidth; gdv_6b0508fcb0b7dcanvas.height = container.clientHeight - 30; gdv_6b0508fcb0b7dfitImageToCanvas(); // Redessiner le contenu du canvas ici gdv_6b0508fcb0b7ddrawImage(); } window.addEventListener("load", gdv_6b0508fcb0b7dresizeCanvas); window.addEventListener("resize", gdv_6b0508fcb0b7dresizeCanvas); function gdv_6b0508fcb0b7dfitImageToCanvas() { const canvasAspect = gdv_6b0508fcb0b7dcanvas.width / gdv_6b0508fcb0b7dcanvas.height; const imageAspect = gdv_6b0508fcb0b7dcurrentImage.width / gdv_6b0508fcb0b7dcurrentImage.height; if (imageAspect > canvasAspect) { gdv_6b0508fcb0b7dscale = gdv_6b0508fcb0b7dcanvas.width / gdv_6b0508fcb0b7dcurrentImage.width; } else { gdv_6b0508fcb0b7dscale = gdv_6b0508fcb0b7dcanvas.height / gdv_6b0508fcb0b7dcurrentImage.height; } gdv_6b0508fcb0b7doriginX = gdv_6b0508fcb0b7dcanvas.width / 2; gdv_6b0508fcb0b7doriginY = gdv_6b0508fcb0b7dcanvas.height / 2; }
function gdv_6b0508fcb0b7ddrawImage() { gdv_6b0508fcb0b7dctx.clearRect(0, 0, gdv_6b0508fcb0b7dcanvas.width, gdv_6b0508fcb0b7dcanvas.height); gdv_6b0508fcb0b7dctx.save(); gdv_6b0508fcb0b7dctx.translate(gdv_6b0508fcb0b7doriginX, gdv_6b0508fcb0b7doriginY); gdv_6b0508fcb0b7dctx.rotate((Math.PI / 180) * gdv_6b0508fcb0b7drotationAngle); gdv_6b0508fcb0b7dctx.scale(gdv_6b0508fcb0b7dscale, gdv_6b0508fcb0b7dscale);
// Appliquer la luminosité et le contraste gdv_6b0508fcb0b7dctx.filter = `brightness(${gdv_6b0508fcb0b7dbrightnessInput.value}) contrast(${gdv_6b0508fcb0b7dcontrastInput.value})`; gdv_6b0508fcb0b7dctx.drawImage(gdv_6b0508fcb0b7dcurrentImage, -gdv_6b0508fcb0b7dcurrentImage.width/2, -gdv_6b0508fcb0b7dcurrentImage.height/2); gdv_6b0508fcb0b7dctx.restore(); }
// Ajouter les miniatures des images gdv_6b0508fcb0b7dimageUrls.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_6b0508fcb0b7dloadImage(index); gdv_6b0508fcb0b7dcurrentSlideIndex = index; gdv_6b0508fcb0b7dupdateSlideNumber(); }; slide.appendChild(img); gdv_6b0508fcb0b7dthumbnailContainerWrapper.appendChild(slide); });
// Charger une image dans le canvas function gdv_6b0508fcb0b7dloadImage(index) { gdv_6b0508fcb0b7dcurrentImage.src = gdv_6b0508fcb0b7dimageUrls[index]["url"]; gdv_6b0508fcb0b7dimageName.innerHTML = filtrerChaine(gdv_6b0508fcb0b7dimageUrls[index]["name"], "rien"); gdv_6b0508fcb0b7dcurrentImage.onload = function() { gdv_6b0508fcb0b7dscale = 1; gdv_6b0508fcb0b7doriginX = 0; gdv_6b0508fcb0b7doriginY = 0; gdv_6b0508fcb0b7dfitImageToCanvas(); gdv_6b0508fcb0b7ddrawImage(); };
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_6b0508fcb0b7dswiper = new Swiper(".gdv_6b0508fcb0b7dswiper-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_6b0508fcb0b7dswiper.on("slideChange", function () { // gdv_6b0508fcb0b7dcurrentSlideIndex = gdv_6b0508fcb0b7dswiper.activeIndex; // gdv_6b0508fcb0b7dupdateSlideNumber(); //});
// Plein écran gdv_6b0508fcb0b7dfullscreenButton.addEventListener("click", function() { if (!document.fullscreenElement) { document.getElementById("gdv_6b0508fcb0b7dgd-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_6b0508fcb0b7dcanvas.addEventListener("wheel", function(event) { event.preventDefault(); const zoomFactor = 0.025; const mouseX = event.offsetX; const mouseY = event.offsetY;
let newScale = gdv_6b0508fcb0b7dscale; if (event.deltaY < 0) { newScale *= 1 + zoomFactor; } else { newScale /= 1 + zoomFactor; } newScale = Math.max(gdv_6b0508fcb0b7dminScale, Math.min(gdv_6b0508fcb0b7dmaxScale, newScale)); const scaleRatio = newScale / gdv_6b0508fcb0b7dscale; gdv_6b0508fcb0b7doriginX = mouseX - (mouseX - gdv_6b0508fcb0b7doriginX) * scaleRatio; gdv_6b0508fcb0b7doriginY = mouseY - (mouseY - gdv_6b0508fcb0b7doriginY) * scaleRatio; gdv_6b0508fcb0b7dscale = newScale; gdv_6b0508fcb0b7ddrawImage(); }); // Gestion du déplacement (pan) let gdv_6b0508fcb0b7disDragging = false; let gdv_6b0508fcb0b7dstartX, gdv_6b0508fcb0b7dstartY; gdv_6b0508fcb0b7dcanvas.addEventListener("mousedown", function(event) { gdv_6b0508fcb0b7disDragging = true; gdv_6b0508fcb0b7dstartX = event.offsetX - gdv_6b0508fcb0b7doriginX; gdv_6b0508fcb0b7dstartY = event.offsetY - gdv_6b0508fcb0b7doriginY; gdv_6b0508fcb0b7dcanvas.style.cursor = "grabbing"; }); gdv_6b0508fcb0b7dcanvas.addEventListener("mousemove", function(event) { if (gdv_6b0508fcb0b7disDragging) { gdv_6b0508fcb0b7doriginX = event.offsetX - gdv_6b0508fcb0b7dstartX; gdv_6b0508fcb0b7doriginY = event.offsetY - gdv_6b0508fcb0b7dstartY; gdv_6b0508fcb0b7ddrawImage(); } }); // Gestion des événements tactiles gdv_6b0508fcb0b7dcanvas.addEventListener("touchstart", function(event) { if (event.touches.length === 1) { gdv_6b0508fcb0b7disDragging = true; const touch = event.touches[0]; gdv_6b0508fcb0b7dstartX = touch.pageX - gdv_6b0508fcb0b7doriginX; gdv_6b0508fcb0b7dstartY = touch.pageY - gdv_6b0508fcb0b7doriginY; } }); gdv_6b0508fcb0b7dcanvas.addEventListener("touchmove", function(event) { event.preventDefault(); // Empêche le comportement par défaut du navigateur const touch = event.touches[0]; gdv_6b0508fcb0b7doriginX = touch.pageX - gdv_6b0508fcb0b7dstartX; gdv_6b0508fcb0b7doriginY = touch.pageY - gdv_6b0508fcb0b7dstartY; gdv_6b0508fcb0b7ddrawImage(); }); gdv_6b0508fcb0b7dcanvas.addEventListener("touchend", function() { gdv_6b0508fcb0b7disDragging = false; }); gdv_6b0508fcb0b7dcanvas.addEventListener("mouseup", function() { gdv_6b0508fcb0b7disDragging = false; gdv_6b0508fcb0b7dcanvas.style.cursor = "grab"; }); gdv_6b0508fcb0b7dcanvas.addEventListener("mouseleave", function() { gdv_6b0508fcb0b7disDragging = false; gdv_6b0508fcb0b7dcanvas.style.cursor = "grab"; }); gdv_6b0508fcb0b7dzoomInButton.addEventListener("click", function() { let newScale = gdv_6b0508fcb0b7dscale; const zoomFactor = 0.025; newScale *= 1 + zoomFactor; gdv_6b0508fcb0b7dscale = Math.max(gdv_6b0508fcb0b7dminScale, Math.min(gdv_6b0508fcb0b7dmaxScale, newScale)); gdv_6b0508fcb0b7ddrawImage(); }); gdv_6b0508fcb0b7dzoomOutButton.addEventListener("click", function() { let newScale = gdv_6b0508fcb0b7dscale; const zoomFactor = 0.025; newScale /= 1 + zoomFactor; gdv_6b0508fcb0b7dscale = Math.max(gdv_6b0508fcb0b7dminScale, Math.min(gdv_6b0508fcb0b7dmaxScale, newScale)); gdv_6b0508fcb0b7ddrawImage(); }); gdv_6b0508fcb0b7dresetZoomButton.addEventListener("click", function() { gdv_6b0508fcb0b7drotationAngle = 0; gdv_6b0508fcb0b7dfitImageToCanvas(); gdv_6b0508fcb0b7ddrawImage(); }); function gdv_6b0508fcb0b7dgetImageIdFromUrl(url) { const urlObj = new URL(url); return urlObj.searchParams.get("id"); } document.getElementById("gdv_6b0508fcb0b7ddownloadImage").addEventListener("click", function() { let url = gdv_6b0508fcb0b7dcurrentImage.src; const imageId = gdv_6b0508fcb0b7dgetImageIdFromUrl(url); const apiUrl = `${window.location.origin}/wp-json/gdv/v1/download-image?image_id=${imageId}`; fetch(apiUrl, {credentials: "same-origin", headers: {"X-WP-Nonce": "62bb307993"}}) .then(response => { if (!response.ok) { return response.json().then(e => { throw new Error(e.message || "Téléchargement impossible."); }); } return 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); alert(error.message); }); });
function gdv_6b0508fcb0b7dprintImageFromApi(imageId) { const apiUrl = `${window.location.origin}/wp-json/gdv/v1/download-image?image_id=${imageId}`;
fetch(apiUrl, {credentials: "same-origin", headers: {"X-WP-Nonce": "62bb307993"}}) .then(response => { if (!response.ok) { return response.json().then(e => { throw new Error(e.message || "Téléchargement impossible."); }); } return response.blob(); }) .then(blob => { const url = URL.createObjectURL(blob); const printWindow = window.open("", "_blank"); printWindow.document.write(`
const gdv_6b0508fcb0b7dprintButton = document.getElementById("gdv_6b0508fcb0b7dprintCanvas");
gdv_6b0508fcb0b7dprintButton.addEventListener("click", function() { let url = gdv_6b0508fcb0b7dcurrentImage.src; const imageId = gdv_6b0508fcb0b7dgetImageIdFromUrl(url); gdv_6b0508fcb0b7dprintImageFromApi(imageId); });
let gdv_6b0508fcb0b7dinitialDistance = 0; let gdv_6b0508fcb0b7dinitialScale = 1;
gdv_6b0508fcb0b7dcanvas.addEventListener("touchstart", function(event) { if (event.touches.length === 2) { event.preventDefault(); gdv_6b0508fcb0b7dinitialDistance = getDistance(event.touches[0], event.touches[1]); gdv_6b0508fcb0b7dinitialScale = gdv_6b0508fcb0b7dscale; } });
gdv_6b0508fcb0b7dcanvas.addEventListener("touchmove", function(event) { if (event.touches.length === 2) { event.preventDefault(); const currentDistance = getDistance(event.touches[0], event.touches[1]); const scaleChange = currentDistance / gdv_6b0508fcb0b7dinitialDistance; let newScale = gdv_6b0508fcb0b7dinitialScale * scaleChange;
newScale = Math.max(gdv_6b0508fcb0b7dminScale, Math.min(gdv_6b0508fcb0b7dmaxScale, 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_6b0508fcb0b7dscale; gdv_6b0508fcb0b7doriginX = centerX - (centerX - gdv_6b0508fcb0b7doriginX) * scaleRatio; gdv_6b0508fcb0b7doriginY = centerY - (centerY - gdv_6b0508fcb0b7doriginY) * scaleRatio;
gdv_6b0508fcb0b7dscale = newScale; gdv_6b0508fcb0b7ddrawImage(); // 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); }