1 / X
const gdv_68711d548bcf5canvas = document.getElementById("gdv_68711d548bcf5imageCanvas"); const gdv_68711d548bcf5ctx = gdv_68711d548bcf5canvas.getContext("2d");
const gdv_68711d548bcf5thumbnailContainer = document.getElementById("gdv_68711d548bcf5thumbnailContainer"); const gdv_68711d548bcf5thumbnailContainerWrapper = document.getElementById("gdv_68711d548bcf5thumbnailContainerWrapper"); const gdv_68711d548bcf5zoomInButton = document.getElementById("gdv_68711d548bcf5zoomIn"); const gdv_68711d548bcf5zoomOutButton = document.getElementById("gdv_68711d548bcf5zoomOut"); const gdv_68711d548bcf5resetZoomButton = document.getElementById("gdv_68711d548bcf5resetZoom");
const gdv_68711d548bcf5brightnessInput = document.getElementById("gdv_68711d548bcf5brightness"); const gdv_68711d548bcf5contrastInput = document.getElementById("gdv_68711d548bcf5contrast"); const gdv_68711d548bcf5fullscreenButton = document.getElementById("gdv_68711d548bcf5fullscreen");
const gdv_68711d548bcf5rotateRightButton = document.getElementById("gdv_68711d548bcf5rotateRight"); const gdv_68711d548bcf5rotateLeftButton = document.getElementById("gdv_68711d548bcf5rotateLeft");
const gdv_68711d548bcf5prevSlideButton = document.getElementById("gdv_68711d548bcf5prevSlide"); const gdv_68711d548bcf5nextSlideButton = document.getElementById("gdv_68711d548bcf5nextSlide"); const gdv_68711d548bcf5slideNumberDisplay = document.getElementById("gdv_68711d548bcf5slideNumber"); const gdv_68711d548bcf5imageName = document.getElementById("gdv_68711d548bcf5imageName");
let gdv_68711d548bcf5currentSlideIndex = 0;
gdv_68711d548bcf5brightnessInput.addEventListener("input", gdv_68711d548bcf5drawImage); gdv_68711d548bcf5contrastInput.addEventListener("input", gdv_68711d548bcf5drawImage);
const gdv_68711d548bcf5imageUrls = [{"url":"https:\/\/drive.google.com\/thumbnail?id=1JTWOy6NfE3LodZZLyN12qBjGdf77M0R3&sz=w3000","name":"Delpech_concerne les esclaves re\u0301volte\u0301s de Macaya-Platon et autres lieux du Sud.jpg"}];
let gdv_68711d548bcf5scale = 1; let gdv_68711d548bcf5originX = 0; let gdv_68711d548bcf5originY = 0; const gdv_68711d548bcf5minScale = 0.1; const gdv_68711d548bcf5maxScale = 5; let gdv_68711d548bcf5currentImage = new Image();
let gdv_68711d548bcf5rotationAngle = 0;
gdv_68711d548bcf5rotateRightButton.addEventListener("click", function() { gdv_68711d548bcf5rotationAngle = (gdv_68711d548bcf5rotationAngle + 90) % 360; gdv_68711d548bcf5drawImage(); });
gdv_68711d548bcf5rotateLeftButton.addEventListener("click", function() { gdv_68711d548bcf5rotationAngle = (gdv_68711d548bcf5rotationAngle - 90 + 360) % 360; gdv_68711d548bcf5drawImage(); });
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_68711d548bcf5currentImage.src = gdv_68711d548bcf5imageUrls[0]["url"]; gdv_68711d548bcf5imageName.innerHTML = filtrerChaine(gdv_68711d548bcf5imageUrls[0]["name"], "rien"); gdv_68711d548bcf5currentImage.onload = function() {
gdv_68711d548bcf5updateSlideNumber(); gdv_68711d548bcf5resizeCanvas(); gdv_68711d548bcf5drawImage(); document.getElementById("gdv_68711d548bcf5controls").style.display = "block"; };
function gdv_68711d548bcf5updateSlideNumber() { gdv_68711d548bcf5slideNumberDisplay.textContent = `${gdv_68711d548bcf5currentSlideIndex + 1} / ${gdv_68711d548bcf5imageUrls.length}`; }
gdv_68711d548bcf5prevSlideButton.addEventListener("click", function() { if (gdv_68711d548bcf5currentSlideIndex > 0) { gdv_68711d548bcf5currentSlideIndex--; gdv_68711d548bcf5loadImage(gdv_68711d548bcf5currentSlideIndex); gdv_68711d548bcf5updateSlideNumber(); } });
gdv_68711d548bcf5nextSlideButton.addEventListener("click", function() { if (gdv_68711d548bcf5currentSlideIndex < gdv_68711d548bcf5imageUrls.length - 1) { gdv_68711d548bcf5currentSlideIndex++; gdv_68711d548bcf5loadImage(gdv_68711d548bcf5currentSlideIndex); gdv_68711d548bcf5updateSlideNumber(); } }); function gdv_68711d548bcf5resizeCanvas() { // Ajuster la taille du canvas pour correspondre à celle du conteneur const container = document.getElementById("gdv_68711d548bcf5canvasContainer"); gdv_68711d548bcf5canvas.width = container.clientWidth; gdv_68711d548bcf5canvas.height = container.clientHeight - 30; gdv_68711d548bcf5fitImageToCanvas(); // Redessiner le contenu du canvas ici gdv_68711d548bcf5drawImage(); } window.addEventListener("load", gdv_68711d548bcf5resizeCanvas); window.addEventListener("resize", gdv_68711d548bcf5resizeCanvas); function gdv_68711d548bcf5fitImageToCanvas() { const canvasAspect = gdv_68711d548bcf5canvas.width / gdv_68711d548bcf5canvas.height; const imageAspect = gdv_68711d548bcf5currentImage.width / gdv_68711d548bcf5currentImage.height; if (imageAspect > canvasAspect) { gdv_68711d548bcf5scale = gdv_68711d548bcf5canvas.width / gdv_68711d548bcf5currentImage.width; } else { gdv_68711d548bcf5scale = gdv_68711d548bcf5canvas.height / gdv_68711d548bcf5currentImage.height; } gdv_68711d548bcf5originX = gdv_68711d548bcf5canvas.width / 2; gdv_68711d548bcf5originY = gdv_68711d548bcf5canvas.height / 2; }
function gdv_68711d548bcf5drawImage() { gdv_68711d548bcf5ctx.clearRect(0, 0, gdv_68711d548bcf5canvas.width, gdv_68711d548bcf5canvas.height); gdv_68711d548bcf5ctx.save(); gdv_68711d548bcf5ctx.translate(gdv_68711d548bcf5originX, gdv_68711d548bcf5originY); gdv_68711d548bcf5ctx.rotate((Math.PI / 180) * gdv_68711d548bcf5rotationAngle); gdv_68711d548bcf5ctx.scale(gdv_68711d548bcf5scale, gdv_68711d548bcf5scale);
// Appliquer la luminosité et le contraste gdv_68711d548bcf5ctx.filter = `brightness(${gdv_68711d548bcf5brightnessInput.value}) contrast(${gdv_68711d548bcf5contrastInput.value})`; gdv_68711d548bcf5ctx.drawImage(gdv_68711d548bcf5currentImage, -gdv_68711d548bcf5currentImage.width/2, -gdv_68711d548bcf5currentImage.height/2); gdv_68711d548bcf5ctx.restore(); }
// Ajouter les miniatures des images gdv_68711d548bcf5imageUrls.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_68711d548bcf5loadImage(index); gdv_68711d548bcf5currentSlideIndex = index; gdv_68711d548bcf5updateSlideNumber(); }; slide.appendChild(img); gdv_68711d548bcf5thumbnailContainerWrapper.appendChild(slide); });
// Charger une image dans le canvas function gdv_68711d548bcf5loadImage(index) { gdv_68711d548bcf5currentImage.src = gdv_68711d548bcf5imageUrls[index]["url"]; gdv_68711d548bcf5imageName.innerHTML = filtrerChaine(gdv_68711d548bcf5imageUrls[index]["name"], "rien"); gdv_68711d548bcf5currentImage.onload = function() { gdv_68711d548bcf5scale = 1; gdv_68711d548bcf5originX = 0; gdv_68711d548bcf5originY = 0; gdv_68711d548bcf5fitImageToCanvas(); gdv_68711d548bcf5drawImage(); };
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_68711d548bcf5swiper = new Swiper(".gdv_68711d548bcf5swiper-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_68711d548bcf5swiper.on("slideChange", function () { // gdv_68711d548bcf5currentSlideIndex = gdv_68711d548bcf5swiper.activeIndex; // gdv_68711d548bcf5updateSlideNumber(); //});
// Plein écran gdv_68711d548bcf5fullscreenButton.addEventListener("click", function() { if (!document.fullscreenElement) { document.getElementById("gdv_68711d548bcf5gd-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_68711d548bcf5canvas.addEventListener("wheel", function(event) { event.preventDefault(); const zoomFactor = 0.025; const mouseX = event.offsetX; const mouseY = event.offsetY;
let newScale = gdv_68711d548bcf5scale; if (event.deltaY < 0) { newScale *= 1 + zoomFactor; } else { newScale /= 1 + zoomFactor; } newScale = Math.max(gdv_68711d548bcf5minScale, Math.min(gdv_68711d548bcf5maxScale, newScale)); const scaleRatio = newScale / gdv_68711d548bcf5scale; gdv_68711d548bcf5originX = mouseX - (mouseX - gdv_68711d548bcf5originX) * scaleRatio; gdv_68711d548bcf5originY = mouseY - (mouseY - gdv_68711d548bcf5originY) * scaleRatio; gdv_68711d548bcf5scale = newScale; gdv_68711d548bcf5drawImage(); }); // Gestion du déplacement (pan) let gdv_68711d548bcf5isDragging = false; let gdv_68711d548bcf5startX, gdv_68711d548bcf5startY; gdv_68711d548bcf5canvas.addEventListener("mousedown", function(event) { gdv_68711d548bcf5isDragging = true; gdv_68711d548bcf5startX = event.offsetX - gdv_68711d548bcf5originX; gdv_68711d548bcf5startY = event.offsetY - gdv_68711d548bcf5originY; gdv_68711d548bcf5canvas.style.cursor = "grabbing"; }); gdv_68711d548bcf5canvas.addEventListener("mousemove", function(event) { if (gdv_68711d548bcf5isDragging) { gdv_68711d548bcf5originX = event.offsetX - gdv_68711d548bcf5startX; gdv_68711d548bcf5originY = event.offsetY - gdv_68711d548bcf5startY; gdv_68711d548bcf5drawImage(); } }); // Gestion des événements tactiles gdv_68711d548bcf5canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 1) { gdv_68711d548bcf5isDragging = true; const touch = event.touches[0]; gdv_68711d548bcf5startX = touch.pageX - gdv_68711d548bcf5originX; gdv_68711d548bcf5startY = touch.pageY - gdv_68711d548bcf5originY; } }); gdv_68711d548bcf5canvas.addEventListener("touchmove", function(event) { event.preventDefault(); // Empêche le comportement par défaut du navigateur const touch = event.touches[0]; gdv_68711d548bcf5originX = touch.pageX - gdv_68711d548bcf5startX; gdv_68711d548bcf5originY = touch.pageY - gdv_68711d548bcf5startY; gdv_68711d548bcf5drawImage(); }); gdv_68711d548bcf5canvas.addEventListener("touchend", function() { gdv_68711d548bcf5isDragging = false; }); gdv_68711d548bcf5canvas.addEventListener("mouseup", function() { gdv_68711d548bcf5isDragging = false; gdv_68711d548bcf5canvas.style.cursor = "grab"; }); gdv_68711d548bcf5canvas.addEventListener("mouseleave", function() { gdv_68711d548bcf5isDragging = false; gdv_68711d548bcf5canvas.style.cursor = "grab"; }); gdv_68711d548bcf5zoomInButton.addEventListener("click", function() { let newScale = gdv_68711d548bcf5scale; const zoomFactor = 0.025; newScale *= 1 + zoomFactor; gdv_68711d548bcf5scale = Math.max(gdv_68711d548bcf5minScale, Math.min(gdv_68711d548bcf5maxScale, newScale)); gdv_68711d548bcf5drawImage(); }); gdv_68711d548bcf5zoomOutButton.addEventListener("click", function() { let newScale = gdv_68711d548bcf5scale; const zoomFactor = 0.025; newScale /= 1 + zoomFactor; gdv_68711d548bcf5scale = Math.max(gdv_68711d548bcf5minScale, Math.min(gdv_68711d548bcf5maxScale, newScale)); gdv_68711d548bcf5drawImage(); }); gdv_68711d548bcf5resetZoomButton.addEventListener("click", function() { gdv_68711d548bcf5rotationAngle = 0; gdv_68711d548bcf5fitImageToCanvas(); gdv_68711d548bcf5drawImage(); }); function gdv_68711d548bcf5getImageIdFromUrl(url) { const urlObj = new URL(url); return urlObj.searchParams.get("id"); } document.getElementById("gdv_68711d548bcf5downloadImage").addEventListener("click", function() { let url = gdv_68711d548bcf5currentImage.src; const imageId = gdv_68711d548bcf5getImageIdFromUrl(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_68711d548bcf5printImageFromApi(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_68711d548bcf5printButton = document.getElementById("gdv_68711d548bcf5printCanvas");
gdv_68711d548bcf5printButton.addEventListener("click", function() { let url = gdv_68711d548bcf5currentImage.src; const imageId = gdv_68711d548bcf5getImageIdFromUrl(url); gdv_68711d548bcf5printImageFromApi(imageId); });
let gdv_68711d548bcf5initialDistance = 0; let gdv_68711d548bcf5initialScale = 1;
gdv_68711d548bcf5canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 2) { event.preventDefault(); gdv_68711d548bcf5initialDistance = getDistance(event.touches[0], event.touches[1]); gdv_68711d548bcf5initialScale = gdv_68711d548bcf5scale; } });
gdv_68711d548bcf5canvas.addEventListener("touchmove", function(event) { if (event.touches.length === 2) { event.preventDefault(); const currentDistance = getDistance(event.touches[0], event.touches[1]); const scaleChange = currentDistance / gdv_68711d548bcf5initialDistance; let newScale = gdv_68711d548bcf5initialScale * scaleChange;
newScale = Math.max(gdv_68711d548bcf5minScale, Math.min(gdv_68711d548bcf5maxScale, 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_68711d548bcf5scale; gdv_68711d548bcf5originX = centerX - (centerX - gdv_68711d548bcf5originX) * scaleRatio; gdv_68711d548bcf5originY = centerY - (centerY - gdv_68711d548bcf5originY) * scaleRatio;
gdv_68711d548bcf5scale = newScale; gdv_68711d548bcf5drawImage(); // 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); }