1 / X
const gdv_6870694571750canvas = document.getElementById("gdv_6870694571750imageCanvas"); const gdv_6870694571750ctx = gdv_6870694571750canvas.getContext("2d");
const gdv_6870694571750thumbnailContainer = document.getElementById("gdv_6870694571750thumbnailContainer"); const gdv_6870694571750thumbnailContainerWrapper = document.getElementById("gdv_6870694571750thumbnailContainerWrapper"); const gdv_6870694571750zoomInButton = document.getElementById("gdv_6870694571750zoomIn"); const gdv_6870694571750zoomOutButton = document.getElementById("gdv_6870694571750zoomOut"); const gdv_6870694571750resetZoomButton = document.getElementById("gdv_6870694571750resetZoom");
const gdv_6870694571750brightnessInput = document.getElementById("gdv_6870694571750brightness"); const gdv_6870694571750contrastInput = document.getElementById("gdv_6870694571750contrast"); const gdv_6870694571750fullscreenButton = document.getElementById("gdv_6870694571750fullscreen");
const gdv_6870694571750rotateRightButton = document.getElementById("gdv_6870694571750rotateRight"); const gdv_6870694571750rotateLeftButton = document.getElementById("gdv_6870694571750rotateLeft");
const gdv_6870694571750prevSlideButton = document.getElementById("gdv_6870694571750prevSlide"); const gdv_6870694571750nextSlideButton = document.getElementById("gdv_6870694571750nextSlide"); const gdv_6870694571750slideNumberDisplay = document.getElementById("gdv_6870694571750slideNumber"); const gdv_6870694571750imageName = document.getElementById("gdv_6870694571750imageName");
let gdv_6870694571750currentSlideIndex = 0;
gdv_6870694571750brightnessInput.addEventListener("input", gdv_6870694571750drawImage); gdv_6870694571750contrastInput.addEventListener("input", gdv_6870694571750drawImage);
const gdv_6870694571750imageUrls = [{"url":"https:\/\/drive.google.com\/thumbnail?id=1r5oMLHMHzqXONXDNCU9rI65g4nUPi7JF&sz=w3000","name":"LFS_EPOL_Sur les biens mobiliers des e\u0301migre\u0301s.jpg"}];
let gdv_6870694571750scale = 1; let gdv_6870694571750originX = 0; let gdv_6870694571750originY = 0; const gdv_6870694571750minScale = 0.1; const gdv_6870694571750maxScale = 5; let gdv_6870694571750currentImage = new Image();
let gdv_6870694571750rotationAngle = 0;
gdv_6870694571750rotateRightButton.addEventListener("click", function() { gdv_6870694571750rotationAngle = (gdv_6870694571750rotationAngle + 90) % 360; gdv_6870694571750drawImage(); });
gdv_6870694571750rotateLeftButton.addEventListener("click", function() { gdv_6870694571750rotationAngle = (gdv_6870694571750rotationAngle - 90 + 360) % 360; gdv_6870694571750drawImage(); });
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_6870694571750currentImage.src = gdv_6870694571750imageUrls[0]["url"]; gdv_6870694571750imageName.innerHTML = filtrerChaine(gdv_6870694571750imageUrls[0]["name"], "rien"); gdv_6870694571750currentImage.onload = function() {
gdv_6870694571750updateSlideNumber(); gdv_6870694571750resizeCanvas(); gdv_6870694571750drawImage(); document.getElementById("gdv_6870694571750controls").style.display = "block"; };
function gdv_6870694571750updateSlideNumber() { gdv_6870694571750slideNumberDisplay.textContent = `${gdv_6870694571750currentSlideIndex + 1} / ${gdv_6870694571750imageUrls.length}`; }
gdv_6870694571750prevSlideButton.addEventListener("click", function() { if (gdv_6870694571750currentSlideIndex > 0) { gdv_6870694571750currentSlideIndex--; gdv_6870694571750loadImage(gdv_6870694571750currentSlideIndex); gdv_6870694571750updateSlideNumber(); } });
gdv_6870694571750nextSlideButton.addEventListener("click", function() { if (gdv_6870694571750currentSlideIndex < gdv_6870694571750imageUrls.length - 1) { gdv_6870694571750currentSlideIndex++; gdv_6870694571750loadImage(gdv_6870694571750currentSlideIndex); gdv_6870694571750updateSlideNumber(); } }); function gdv_6870694571750resizeCanvas() { // Ajuster la taille du canvas pour correspondre à celle du conteneur const container = document.getElementById("gdv_6870694571750canvasContainer"); gdv_6870694571750canvas.width = container.clientWidth; gdv_6870694571750canvas.height = container.clientHeight - 30; gdv_6870694571750fitImageToCanvas(); // Redessiner le contenu du canvas ici gdv_6870694571750drawImage(); } window.addEventListener("load", gdv_6870694571750resizeCanvas); window.addEventListener("resize", gdv_6870694571750resizeCanvas); function gdv_6870694571750fitImageToCanvas() { const canvasAspect = gdv_6870694571750canvas.width / gdv_6870694571750canvas.height; const imageAspect = gdv_6870694571750currentImage.width / gdv_6870694571750currentImage.height; if (imageAspect > canvasAspect) { gdv_6870694571750scale = gdv_6870694571750canvas.width / gdv_6870694571750currentImage.width; } else { gdv_6870694571750scale = gdv_6870694571750canvas.height / gdv_6870694571750currentImage.height; } gdv_6870694571750originX = gdv_6870694571750canvas.width / 2; gdv_6870694571750originY = gdv_6870694571750canvas.height / 2; }
function gdv_6870694571750drawImage() { gdv_6870694571750ctx.clearRect(0, 0, gdv_6870694571750canvas.width, gdv_6870694571750canvas.height); gdv_6870694571750ctx.save(); gdv_6870694571750ctx.translate(gdv_6870694571750originX, gdv_6870694571750originY); gdv_6870694571750ctx.rotate((Math.PI / 180) * gdv_6870694571750rotationAngle); gdv_6870694571750ctx.scale(gdv_6870694571750scale, gdv_6870694571750scale);
// Appliquer la luminosité et le contraste gdv_6870694571750ctx.filter = `brightness(${gdv_6870694571750brightnessInput.value}) contrast(${gdv_6870694571750contrastInput.value})`; gdv_6870694571750ctx.drawImage(gdv_6870694571750currentImage, -gdv_6870694571750currentImage.width/2, -gdv_6870694571750currentImage.height/2); gdv_6870694571750ctx.restore(); }
// Ajouter les miniatures des images gdv_6870694571750imageUrls.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_6870694571750loadImage(index); gdv_6870694571750currentSlideIndex = index; gdv_6870694571750updateSlideNumber(); }; slide.appendChild(img); gdv_6870694571750thumbnailContainerWrapper.appendChild(slide); });
// Charger une image dans le canvas function gdv_6870694571750loadImage(index) { gdv_6870694571750currentImage.src = gdv_6870694571750imageUrls[index]["url"]; gdv_6870694571750imageName.innerHTML = filtrerChaine(gdv_6870694571750imageUrls[index]["name"], "rien"); gdv_6870694571750currentImage.onload = function() { gdv_6870694571750scale = 1; gdv_6870694571750originX = 0; gdv_6870694571750originY = 0; gdv_6870694571750fitImageToCanvas(); gdv_6870694571750drawImage(); };
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_6870694571750swiper = new Swiper(".gdv_6870694571750swiper-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_6870694571750swiper.on("slideChange", function () { // gdv_6870694571750currentSlideIndex = gdv_6870694571750swiper.activeIndex; // gdv_6870694571750updateSlideNumber(); //});
// Plein écran gdv_6870694571750fullscreenButton.addEventListener("click", function() { if (!document.fullscreenElement) { document.getElementById("gdv_6870694571750gd-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_6870694571750canvas.addEventListener("wheel", function(event) { event.preventDefault(); const zoomFactor = 0.025; const mouseX = event.offsetX; const mouseY = event.offsetY;
let newScale = gdv_6870694571750scale; if (event.deltaY < 0) { newScale *= 1 + zoomFactor; } else { newScale /= 1 + zoomFactor; } newScale = Math.max(gdv_6870694571750minScale, Math.min(gdv_6870694571750maxScale, newScale)); const scaleRatio = newScale / gdv_6870694571750scale; gdv_6870694571750originX = mouseX - (mouseX - gdv_6870694571750originX) * scaleRatio; gdv_6870694571750originY = mouseY - (mouseY - gdv_6870694571750originY) * scaleRatio; gdv_6870694571750scale = newScale; gdv_6870694571750drawImage(); }); // Gestion du déplacement (pan) let gdv_6870694571750isDragging = false; let gdv_6870694571750startX, gdv_6870694571750startY; gdv_6870694571750canvas.addEventListener("mousedown", function(event) { gdv_6870694571750isDragging = true; gdv_6870694571750startX = event.offsetX - gdv_6870694571750originX; gdv_6870694571750startY = event.offsetY - gdv_6870694571750originY; gdv_6870694571750canvas.style.cursor = "grabbing"; }); gdv_6870694571750canvas.addEventListener("mousemove", function(event) { if (gdv_6870694571750isDragging) { gdv_6870694571750originX = event.offsetX - gdv_6870694571750startX; gdv_6870694571750originY = event.offsetY - gdv_6870694571750startY; gdv_6870694571750drawImage(); } }); // Gestion des événements tactiles gdv_6870694571750canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 1) { gdv_6870694571750isDragging = true; const touch = event.touches[0]; gdv_6870694571750startX = touch.pageX - gdv_6870694571750originX; gdv_6870694571750startY = touch.pageY - gdv_6870694571750originY; } }); gdv_6870694571750canvas.addEventListener("touchmove", function(event) { event.preventDefault(); // Empêche le comportement par défaut du navigateur const touch = event.touches[0]; gdv_6870694571750originX = touch.pageX - gdv_6870694571750startX; gdv_6870694571750originY = touch.pageY - gdv_6870694571750startY; gdv_6870694571750drawImage(); }); gdv_6870694571750canvas.addEventListener("touchend", function() { gdv_6870694571750isDragging = false; }); gdv_6870694571750canvas.addEventListener("mouseup", function() { gdv_6870694571750isDragging = false; gdv_6870694571750canvas.style.cursor = "grab"; }); gdv_6870694571750canvas.addEventListener("mouseleave", function() { gdv_6870694571750isDragging = false; gdv_6870694571750canvas.style.cursor = "grab"; }); gdv_6870694571750zoomInButton.addEventListener("click", function() { let newScale = gdv_6870694571750scale; const zoomFactor = 0.025; newScale *= 1 + zoomFactor; gdv_6870694571750scale = Math.max(gdv_6870694571750minScale, Math.min(gdv_6870694571750maxScale, newScale)); gdv_6870694571750drawImage(); }); gdv_6870694571750zoomOutButton.addEventListener("click", function() { let newScale = gdv_6870694571750scale; const zoomFactor = 0.025; newScale /= 1 + zoomFactor; gdv_6870694571750scale = Math.max(gdv_6870694571750minScale, Math.min(gdv_6870694571750maxScale, newScale)); gdv_6870694571750drawImage(); }); gdv_6870694571750resetZoomButton.addEventListener("click", function() { gdv_6870694571750rotationAngle = 0; gdv_6870694571750fitImageToCanvas(); gdv_6870694571750drawImage(); }); function gdv_6870694571750getImageIdFromUrl(url) { const urlObj = new URL(url); return urlObj.searchParams.get("id"); } document.getElementById("gdv_6870694571750downloadImage").addEventListener("click", function() { let url = gdv_6870694571750currentImage.src; const imageId = gdv_6870694571750getImageIdFromUrl(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_6870694571750printImageFromApi(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_6870694571750printButton = document.getElementById("gdv_6870694571750printCanvas");
gdv_6870694571750printButton.addEventListener("click", function() { let url = gdv_6870694571750currentImage.src; const imageId = gdv_6870694571750getImageIdFromUrl(url); gdv_6870694571750printImageFromApi(imageId); });
let gdv_6870694571750initialDistance = 0; let gdv_6870694571750initialScale = 1;
gdv_6870694571750canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 2) { event.preventDefault(); gdv_6870694571750initialDistance = getDistance(event.touches[0], event.touches[1]); gdv_6870694571750initialScale = gdv_6870694571750scale; } });
gdv_6870694571750canvas.addEventListener("touchmove", function(event) { if (event.touches.length === 2) { event.preventDefault(); const currentDistance = getDistance(event.touches[0], event.touches[1]); const scaleChange = currentDistance / gdv_6870694571750initialDistance; let newScale = gdv_6870694571750initialScale * scaleChange;
newScale = Math.max(gdv_6870694571750minScale, Math.min(gdv_6870694571750maxScale, 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_6870694571750scale; gdv_6870694571750originX = centerX - (centerX - gdv_6870694571750originX) * scaleRatio; gdv_6870694571750originY = centerY - (centerY - gdv_6870694571750originY) * scaleRatio;
gdv_6870694571750scale = newScale; gdv_6870694571750drawImage(); // 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); }