1 / X
const gdv_698e70f45faf9canvas = document.getElementById("gdv_698e70f45faf9imageCanvas"); const gdv_698e70f45faf9ctx = gdv_698e70f45faf9canvas.getContext("2d");
const gdv_698e70f45faf9thumbnailContainer = document.getElementById("gdv_698e70f45faf9thumbnailContainer"); const gdv_698e70f45faf9thumbnailContainerWrapper = document.getElementById("gdv_698e70f45faf9thumbnailContainerWrapper"); const gdv_698e70f45faf9zoomInButton = document.getElementById("gdv_698e70f45faf9zoomIn"); const gdv_698e70f45faf9zoomOutButton = document.getElementById("gdv_698e70f45faf9zoomOut"); const gdv_698e70f45faf9resetZoomButton = document.getElementById("gdv_698e70f45faf9resetZoom");
const gdv_698e70f45faf9brightnessInput = document.getElementById("gdv_698e70f45faf9brightness"); const gdv_698e70f45faf9contrastInput = document.getElementById("gdv_698e70f45faf9contrast"); const gdv_698e70f45faf9fullscreenButton = document.getElementById("gdv_698e70f45faf9fullscreen");
const gdv_698e70f45faf9rotateRightButton = document.getElementById("gdv_698e70f45faf9rotateRight"); const gdv_698e70f45faf9rotateLeftButton = document.getElementById("gdv_698e70f45faf9rotateLeft");
const gdv_698e70f45faf9prevSlideButton = document.getElementById("gdv_698e70f45faf9prevSlide"); const gdv_698e70f45faf9nextSlideButton = document.getElementById("gdv_698e70f45faf9nextSlide"); const gdv_698e70f45faf9slideNumberDisplay = document.getElementById("gdv_698e70f45faf9slideNumber"); const gdv_698e70f45faf9imageName = document.getElementById("gdv_698e70f45faf9imageName");
let gdv_698e70f45faf9currentSlideIndex = 0;
gdv_698e70f45faf9brightnessInput.addEventListener("input", gdv_698e70f45faf9drawImage); gdv_698e70f45faf9contrastInput.addEventListener("input", gdv_698e70f45faf9drawImage);
const gdv_698e70f45faf9imageUrls = [{"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_698e70f45faf9scale = 1; let gdv_698e70f45faf9originX = 0; let gdv_698e70f45faf9originY = 0; const gdv_698e70f45faf9minScale = 0.1; const gdv_698e70f45faf9maxScale = 5; let gdv_698e70f45faf9currentImage = new Image();
let gdv_698e70f45faf9rotationAngle = 0;
gdv_698e70f45faf9rotateRightButton.addEventListener("click", function() { gdv_698e70f45faf9rotationAngle = (gdv_698e70f45faf9rotationAngle + 90) % 360; gdv_698e70f45faf9drawImage(); });
gdv_698e70f45faf9rotateLeftButton.addEventListener("click", function() { gdv_698e70f45faf9rotationAngle = (gdv_698e70f45faf9rotationAngle - 90 + 360) % 360; gdv_698e70f45faf9drawImage(); });
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_698e70f45faf9currentImage.src = gdv_698e70f45faf9imageUrls[0]["url"]; gdv_698e70f45faf9imageName.innerHTML = filtrerChaine(gdv_698e70f45faf9imageUrls[0]["name"], "rien"); gdv_698e70f45faf9currentImage.onload = function() {
gdv_698e70f45faf9updateSlideNumber(); gdv_698e70f45faf9resizeCanvas(); gdv_698e70f45faf9drawImage(); document.getElementById("gdv_698e70f45faf9controls").style.display = "block"; };
function gdv_698e70f45faf9updateSlideNumber() { gdv_698e70f45faf9slideNumberDisplay.textContent = `${gdv_698e70f45faf9currentSlideIndex + 1} / ${gdv_698e70f45faf9imageUrls.length}`; }
gdv_698e70f45faf9prevSlideButton.addEventListener("click", function() { if (gdv_698e70f45faf9currentSlideIndex > 0) { gdv_698e70f45faf9currentSlideIndex--; gdv_698e70f45faf9loadImage(gdv_698e70f45faf9currentSlideIndex); gdv_698e70f45faf9updateSlideNumber(); } });
gdv_698e70f45faf9nextSlideButton.addEventListener("click", function() { if (gdv_698e70f45faf9currentSlideIndex < gdv_698e70f45faf9imageUrls.length - 1) { gdv_698e70f45faf9currentSlideIndex++; gdv_698e70f45faf9loadImage(gdv_698e70f45faf9currentSlideIndex); gdv_698e70f45faf9updateSlideNumber(); } }); function gdv_698e70f45faf9resizeCanvas() { // Ajuster la taille du canvas pour correspondre à celle du conteneur const container = document.getElementById("gdv_698e70f45faf9canvasContainer"); gdv_698e70f45faf9canvas.width = container.clientWidth; gdv_698e70f45faf9canvas.height = container.clientHeight - 30; gdv_698e70f45faf9fitImageToCanvas(); // Redessiner le contenu du canvas ici gdv_698e70f45faf9drawImage(); } window.addEventListener("load", gdv_698e70f45faf9resizeCanvas); window.addEventListener("resize", gdv_698e70f45faf9resizeCanvas); function gdv_698e70f45faf9fitImageToCanvas() { const canvasAspect = gdv_698e70f45faf9canvas.width / gdv_698e70f45faf9canvas.height; const imageAspect = gdv_698e70f45faf9currentImage.width / gdv_698e70f45faf9currentImage.height; if (imageAspect > canvasAspect) { gdv_698e70f45faf9scale = gdv_698e70f45faf9canvas.width / gdv_698e70f45faf9currentImage.width; } else { gdv_698e70f45faf9scale = gdv_698e70f45faf9canvas.height / gdv_698e70f45faf9currentImage.height; } gdv_698e70f45faf9originX = gdv_698e70f45faf9canvas.width / 2; gdv_698e70f45faf9originY = gdv_698e70f45faf9canvas.height / 2; }
function gdv_698e70f45faf9drawImage() { gdv_698e70f45faf9ctx.clearRect(0, 0, gdv_698e70f45faf9canvas.width, gdv_698e70f45faf9canvas.height); gdv_698e70f45faf9ctx.save(); gdv_698e70f45faf9ctx.translate(gdv_698e70f45faf9originX, gdv_698e70f45faf9originY); gdv_698e70f45faf9ctx.rotate((Math.PI / 180) * gdv_698e70f45faf9rotationAngle); gdv_698e70f45faf9ctx.scale(gdv_698e70f45faf9scale, gdv_698e70f45faf9scale);
// Appliquer la luminosité et le contraste gdv_698e70f45faf9ctx.filter = `brightness(${gdv_698e70f45faf9brightnessInput.value}) contrast(${gdv_698e70f45faf9contrastInput.value})`; gdv_698e70f45faf9ctx.drawImage(gdv_698e70f45faf9currentImage, -gdv_698e70f45faf9currentImage.width/2, -gdv_698e70f45faf9currentImage.height/2); gdv_698e70f45faf9ctx.restore(); }
// Ajouter les miniatures des images gdv_698e70f45faf9imageUrls.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_698e70f45faf9loadImage(index); gdv_698e70f45faf9currentSlideIndex = index; gdv_698e70f45faf9updateSlideNumber(); }; slide.appendChild(img); gdv_698e70f45faf9thumbnailContainerWrapper.appendChild(slide); });
// Charger une image dans le canvas function gdv_698e70f45faf9loadImage(index) { gdv_698e70f45faf9currentImage.src = gdv_698e70f45faf9imageUrls[index]["url"]; gdv_698e70f45faf9imageName.innerHTML = filtrerChaine(gdv_698e70f45faf9imageUrls[index]["name"], "rien"); gdv_698e70f45faf9currentImage.onload = function() { gdv_698e70f45faf9scale = 1; gdv_698e70f45faf9originX = 0; gdv_698e70f45faf9originY = 0; gdv_698e70f45faf9fitImageToCanvas(); gdv_698e70f45faf9drawImage(); };
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_698e70f45faf9swiper = new Swiper(".gdv_698e70f45faf9swiper-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_698e70f45faf9swiper.on("slideChange", function () { // gdv_698e70f45faf9currentSlideIndex = gdv_698e70f45faf9swiper.activeIndex; // gdv_698e70f45faf9updateSlideNumber(); //});
// Plein écran gdv_698e70f45faf9fullscreenButton.addEventListener("click", function() { if (!document.fullscreenElement) { document.getElementById("gdv_698e70f45faf9gd-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_698e70f45faf9canvas.addEventListener("wheel", function(event) { event.preventDefault(); const zoomFactor = 0.025; const mouseX = event.offsetX; const mouseY = event.offsetY;
let newScale = gdv_698e70f45faf9scale; if (event.deltaY < 0) { newScale *= 1 + zoomFactor; } else { newScale /= 1 + zoomFactor; } newScale = Math.max(gdv_698e70f45faf9minScale, Math.min(gdv_698e70f45faf9maxScale, newScale)); const scaleRatio = newScale / gdv_698e70f45faf9scale; gdv_698e70f45faf9originX = mouseX - (mouseX - gdv_698e70f45faf9originX) * scaleRatio; gdv_698e70f45faf9originY = mouseY - (mouseY - gdv_698e70f45faf9originY) * scaleRatio; gdv_698e70f45faf9scale = newScale; gdv_698e70f45faf9drawImage(); }); // Gestion du déplacement (pan) let gdv_698e70f45faf9isDragging = false; let gdv_698e70f45faf9startX, gdv_698e70f45faf9startY; gdv_698e70f45faf9canvas.addEventListener("mousedown", function(event) { gdv_698e70f45faf9isDragging = true; gdv_698e70f45faf9startX = event.offsetX - gdv_698e70f45faf9originX; gdv_698e70f45faf9startY = event.offsetY - gdv_698e70f45faf9originY; gdv_698e70f45faf9canvas.style.cursor = "grabbing"; }); gdv_698e70f45faf9canvas.addEventListener("mousemove", function(event) { if (gdv_698e70f45faf9isDragging) { gdv_698e70f45faf9originX = event.offsetX - gdv_698e70f45faf9startX; gdv_698e70f45faf9originY = event.offsetY - gdv_698e70f45faf9startY; gdv_698e70f45faf9drawImage(); } }); // Gestion des événements tactiles gdv_698e70f45faf9canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 1) { gdv_698e70f45faf9isDragging = true; const touch = event.touches[0]; gdv_698e70f45faf9startX = touch.pageX - gdv_698e70f45faf9originX; gdv_698e70f45faf9startY = touch.pageY - gdv_698e70f45faf9originY; } }); gdv_698e70f45faf9canvas.addEventListener("touchmove", function(event) { event.preventDefault(); // Empêche le comportement par défaut du navigateur const touch = event.touches[0]; gdv_698e70f45faf9originX = touch.pageX - gdv_698e70f45faf9startX; gdv_698e70f45faf9originY = touch.pageY - gdv_698e70f45faf9startY; gdv_698e70f45faf9drawImage(); }); gdv_698e70f45faf9canvas.addEventListener("touchend", function() { gdv_698e70f45faf9isDragging = false; }); gdv_698e70f45faf9canvas.addEventListener("mouseup", function() { gdv_698e70f45faf9isDragging = false; gdv_698e70f45faf9canvas.style.cursor = "grab"; }); gdv_698e70f45faf9canvas.addEventListener("mouseleave", function() { gdv_698e70f45faf9isDragging = false; gdv_698e70f45faf9canvas.style.cursor = "grab"; }); gdv_698e70f45faf9zoomInButton.addEventListener("click", function() { let newScale = gdv_698e70f45faf9scale; const zoomFactor = 0.025; newScale *= 1 + zoomFactor; gdv_698e70f45faf9scale = Math.max(gdv_698e70f45faf9minScale, Math.min(gdv_698e70f45faf9maxScale, newScale)); gdv_698e70f45faf9drawImage(); }); gdv_698e70f45faf9zoomOutButton.addEventListener("click", function() { let newScale = gdv_698e70f45faf9scale; const zoomFactor = 0.025; newScale /= 1 + zoomFactor; gdv_698e70f45faf9scale = Math.max(gdv_698e70f45faf9minScale, Math.min(gdv_698e70f45faf9maxScale, newScale)); gdv_698e70f45faf9drawImage(); }); gdv_698e70f45faf9resetZoomButton.addEventListener("click", function() { gdv_698e70f45faf9rotationAngle = 0; gdv_698e70f45faf9fitImageToCanvas(); gdv_698e70f45faf9drawImage(); }); function gdv_698e70f45faf9getImageIdFromUrl(url) { const urlObj = new URL(url); return urlObj.searchParams.get("id"); } document.getElementById("gdv_698e70f45faf9downloadImage").addEventListener("click", function() { let url = gdv_698e70f45faf9currentImage.src; const imageId = gdv_698e70f45faf9getImageIdFromUrl(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_698e70f45faf9printImageFromApi(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_698e70f45faf9printButton = document.getElementById("gdv_698e70f45faf9printCanvas");
gdv_698e70f45faf9printButton.addEventListener("click", function() { let url = gdv_698e70f45faf9currentImage.src; const imageId = gdv_698e70f45faf9getImageIdFromUrl(url); gdv_698e70f45faf9printImageFromApi(imageId); });
let gdv_698e70f45faf9initialDistance = 0; let gdv_698e70f45faf9initialScale = 1;
gdv_698e70f45faf9canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 2) { event.preventDefault(); gdv_698e70f45faf9initialDistance = getDistance(event.touches[0], event.touches[1]); gdv_698e70f45faf9initialScale = gdv_698e70f45faf9scale; } });
gdv_698e70f45faf9canvas.addEventListener("touchmove", function(event) { if (event.touches.length === 2) { event.preventDefault(); const currentDistance = getDistance(event.touches[0], event.touches[1]); const scaleChange = currentDistance / gdv_698e70f45faf9initialDistance; let newScale = gdv_698e70f45faf9initialScale * scaleChange;
newScale = Math.max(gdv_698e70f45faf9minScale, Math.min(gdv_698e70f45faf9maxScale, 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_698e70f45faf9scale; gdv_698e70f45faf9originX = centerX - (centerX - gdv_698e70f45faf9originX) * scaleRatio; gdv_698e70f45faf9originY = centerY - (centerY - gdv_698e70f45faf9originY) * scaleRatio;
gdv_698e70f45faf9scale = newScale; gdv_698e70f45faf9drawImage(); // 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); }