1 / X
const gdv_6b04653b52f71canvas = document.getElementById("gdv_6b04653b52f71imageCanvas"); const gdv_6b04653b52f71ctx = gdv_6b04653b52f71canvas.getContext("2d");
const gdv_6b04653b52f71thumbnailContainer = document.getElementById("gdv_6b04653b52f71thumbnailContainer"); const gdv_6b04653b52f71thumbnailContainerWrapper = document.getElementById("gdv_6b04653b52f71thumbnailContainerWrapper"); const gdv_6b04653b52f71zoomInButton = document.getElementById("gdv_6b04653b52f71zoomIn"); const gdv_6b04653b52f71zoomOutButton = document.getElementById("gdv_6b04653b52f71zoomOut"); const gdv_6b04653b52f71resetZoomButton = document.getElementById("gdv_6b04653b52f71resetZoom");
const gdv_6b04653b52f71brightnessInput = document.getElementById("gdv_6b04653b52f71brightness"); const gdv_6b04653b52f71contrastInput = document.getElementById("gdv_6b04653b52f71contrast"); const gdv_6b04653b52f71fullscreenButton = document.getElementById("gdv_6b04653b52f71fullscreen");
const gdv_6b04653b52f71rotateRightButton = document.getElementById("gdv_6b04653b52f71rotateRight"); const gdv_6b04653b52f71rotateLeftButton = document.getElementById("gdv_6b04653b52f71rotateLeft");
const gdv_6b04653b52f71prevSlideButton = document.getElementById("gdv_6b04653b52f71prevSlide"); const gdv_6b04653b52f71nextSlideButton = document.getElementById("gdv_6b04653b52f71nextSlide"); const gdv_6b04653b52f71slideNumberDisplay = document.getElementById("gdv_6b04653b52f71slideNumber"); const gdv_6b04653b52f71imageName = document.getElementById("gdv_6b04653b52f71imageName");
let gdv_6b04653b52f71currentSlideIndex = 0;
gdv_6b04653b52f71brightnessInput.addEventListener("input", gdv_6b04653b52f71drawImage); gdv_6b04653b52f71contrastInput.addEventListener("input", gdv_6b04653b52f71drawImage);
const gdv_6b04653b52f71imageUrls = [{"url":"https:\/\/drive.google.com\/thumbnail?id=16cDja4AIJEqbWxSVGfPCqHZc1EczJBGw&sz=w3000","name":"LFS_interdiction des rassemblements_nov 1792.jpg"}];
let gdv_6b04653b52f71scale = 1; let gdv_6b04653b52f71originX = 0; let gdv_6b04653b52f71originY = 0; const gdv_6b04653b52f71minScale = 0.1; const gdv_6b04653b52f71maxScale = 5; let gdv_6b04653b52f71currentImage = new Image();
let gdv_6b04653b52f71rotationAngle = 0;
gdv_6b04653b52f71rotateRightButton.addEventListener("click", function() { gdv_6b04653b52f71rotationAngle = (gdv_6b04653b52f71rotationAngle + 90) % 360; gdv_6b04653b52f71drawImage(); });
gdv_6b04653b52f71rotateLeftButton.addEventListener("click", function() { gdv_6b04653b52f71rotationAngle = (gdv_6b04653b52f71rotationAngle - 90 + 360) % 360; gdv_6b04653b52f71drawImage(); });
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_6b04653b52f71currentImage.src = gdv_6b04653b52f71imageUrls[0]["url"]; gdv_6b04653b52f71imageName.innerHTML = filtrerChaine(gdv_6b04653b52f71imageUrls[0]["name"], "rien"); gdv_6b04653b52f71currentImage.onload = function() {
gdv_6b04653b52f71updateSlideNumber(); gdv_6b04653b52f71resizeCanvas(); gdv_6b04653b52f71drawImage(); document.getElementById("gdv_6b04653b52f71controls").style.display = "block"; };
function gdv_6b04653b52f71updateSlideNumber() { gdv_6b04653b52f71slideNumberDisplay.textContent = `${gdv_6b04653b52f71currentSlideIndex + 1} / ${gdv_6b04653b52f71imageUrls.length}`; }
gdv_6b04653b52f71prevSlideButton.addEventListener("click", function() { if (gdv_6b04653b52f71currentSlideIndex > 0) { gdv_6b04653b52f71currentSlideIndex--; gdv_6b04653b52f71loadImage(gdv_6b04653b52f71currentSlideIndex); gdv_6b04653b52f71updateSlideNumber(); } });
gdv_6b04653b52f71nextSlideButton.addEventListener("click", function() { if (gdv_6b04653b52f71currentSlideIndex < gdv_6b04653b52f71imageUrls.length - 1) { gdv_6b04653b52f71currentSlideIndex++; gdv_6b04653b52f71loadImage(gdv_6b04653b52f71currentSlideIndex); gdv_6b04653b52f71updateSlideNumber(); } }); function gdv_6b04653b52f71resizeCanvas() { // Ajuster la taille du canvas pour correspondre à celle du conteneur const container = document.getElementById("gdv_6b04653b52f71canvasContainer"); gdv_6b04653b52f71canvas.width = container.clientWidth; gdv_6b04653b52f71canvas.height = container.clientHeight - 30; gdv_6b04653b52f71fitImageToCanvas(); // Redessiner le contenu du canvas ici gdv_6b04653b52f71drawImage(); } window.addEventListener("load", gdv_6b04653b52f71resizeCanvas); window.addEventListener("resize", gdv_6b04653b52f71resizeCanvas); function gdv_6b04653b52f71fitImageToCanvas() { const canvasAspect = gdv_6b04653b52f71canvas.width / gdv_6b04653b52f71canvas.height; const imageAspect = gdv_6b04653b52f71currentImage.width / gdv_6b04653b52f71currentImage.height; if (imageAspect > canvasAspect) { gdv_6b04653b52f71scale = gdv_6b04653b52f71canvas.width / gdv_6b04653b52f71currentImage.width; } else { gdv_6b04653b52f71scale = gdv_6b04653b52f71canvas.height / gdv_6b04653b52f71currentImage.height; } gdv_6b04653b52f71originX = gdv_6b04653b52f71canvas.width / 2; gdv_6b04653b52f71originY = gdv_6b04653b52f71canvas.height / 2; }
function gdv_6b04653b52f71drawImage() { gdv_6b04653b52f71ctx.clearRect(0, 0, gdv_6b04653b52f71canvas.width, gdv_6b04653b52f71canvas.height); gdv_6b04653b52f71ctx.save(); gdv_6b04653b52f71ctx.translate(gdv_6b04653b52f71originX, gdv_6b04653b52f71originY); gdv_6b04653b52f71ctx.rotate((Math.PI / 180) * gdv_6b04653b52f71rotationAngle); gdv_6b04653b52f71ctx.scale(gdv_6b04653b52f71scale, gdv_6b04653b52f71scale);
// Appliquer la luminosité et le contraste gdv_6b04653b52f71ctx.filter = `brightness(${gdv_6b04653b52f71brightnessInput.value}) contrast(${gdv_6b04653b52f71contrastInput.value})`; gdv_6b04653b52f71ctx.drawImage(gdv_6b04653b52f71currentImage, -gdv_6b04653b52f71currentImage.width/2, -gdv_6b04653b52f71currentImage.height/2); gdv_6b04653b52f71ctx.restore(); }
// Ajouter les miniatures des images gdv_6b04653b52f71imageUrls.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_6b04653b52f71loadImage(index); gdv_6b04653b52f71currentSlideIndex = index; gdv_6b04653b52f71updateSlideNumber(); }; slide.appendChild(img); gdv_6b04653b52f71thumbnailContainerWrapper.appendChild(slide); });
// Charger une image dans le canvas function gdv_6b04653b52f71loadImage(index) { gdv_6b04653b52f71currentImage.src = gdv_6b04653b52f71imageUrls[index]["url"]; gdv_6b04653b52f71imageName.innerHTML = filtrerChaine(gdv_6b04653b52f71imageUrls[index]["name"], "rien"); gdv_6b04653b52f71currentImage.onload = function() { gdv_6b04653b52f71scale = 1; gdv_6b04653b52f71originX = 0; gdv_6b04653b52f71originY = 0; gdv_6b04653b52f71fitImageToCanvas(); gdv_6b04653b52f71drawImage(); };
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_6b04653b52f71swiper = new Swiper(".gdv_6b04653b52f71swiper-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_6b04653b52f71swiper.on("slideChange", function () { // gdv_6b04653b52f71currentSlideIndex = gdv_6b04653b52f71swiper.activeIndex; // gdv_6b04653b52f71updateSlideNumber(); //});
// Plein écran gdv_6b04653b52f71fullscreenButton.addEventListener("click", function() { if (!document.fullscreenElement) { document.getElementById("gdv_6b04653b52f71gd-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_6b04653b52f71canvas.addEventListener("wheel", function(event) { event.preventDefault(); const zoomFactor = 0.025; const mouseX = event.offsetX; const mouseY = event.offsetY;
let newScale = gdv_6b04653b52f71scale; if (event.deltaY < 0) { newScale *= 1 + zoomFactor; } else { newScale /= 1 + zoomFactor; } newScale = Math.max(gdv_6b04653b52f71minScale, Math.min(gdv_6b04653b52f71maxScale, newScale)); const scaleRatio = newScale / gdv_6b04653b52f71scale; gdv_6b04653b52f71originX = mouseX - (mouseX - gdv_6b04653b52f71originX) * scaleRatio; gdv_6b04653b52f71originY = mouseY - (mouseY - gdv_6b04653b52f71originY) * scaleRatio; gdv_6b04653b52f71scale = newScale; gdv_6b04653b52f71drawImage(); }); // Gestion du déplacement (pan) let gdv_6b04653b52f71isDragging = false; let gdv_6b04653b52f71startX, gdv_6b04653b52f71startY; gdv_6b04653b52f71canvas.addEventListener("mousedown", function(event) { gdv_6b04653b52f71isDragging = true; gdv_6b04653b52f71startX = event.offsetX - gdv_6b04653b52f71originX; gdv_6b04653b52f71startY = event.offsetY - gdv_6b04653b52f71originY; gdv_6b04653b52f71canvas.style.cursor = "grabbing"; }); gdv_6b04653b52f71canvas.addEventListener("mousemove", function(event) { if (gdv_6b04653b52f71isDragging) { gdv_6b04653b52f71originX = event.offsetX - gdv_6b04653b52f71startX; gdv_6b04653b52f71originY = event.offsetY - gdv_6b04653b52f71startY; gdv_6b04653b52f71drawImage(); } }); // Gestion des événements tactiles gdv_6b04653b52f71canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 1) { gdv_6b04653b52f71isDragging = true; const touch = event.touches[0]; gdv_6b04653b52f71startX = touch.pageX - gdv_6b04653b52f71originX; gdv_6b04653b52f71startY = touch.pageY - gdv_6b04653b52f71originY; } }); gdv_6b04653b52f71canvas.addEventListener("touchmove", function(event) { event.preventDefault(); // Empêche le comportement par défaut du navigateur const touch = event.touches[0]; gdv_6b04653b52f71originX = touch.pageX - gdv_6b04653b52f71startX; gdv_6b04653b52f71originY = touch.pageY - gdv_6b04653b52f71startY; gdv_6b04653b52f71drawImage(); }); gdv_6b04653b52f71canvas.addEventListener("touchend", function() { gdv_6b04653b52f71isDragging = false; }); gdv_6b04653b52f71canvas.addEventListener("mouseup", function() { gdv_6b04653b52f71isDragging = false; gdv_6b04653b52f71canvas.style.cursor = "grab"; }); gdv_6b04653b52f71canvas.addEventListener("mouseleave", function() { gdv_6b04653b52f71isDragging = false; gdv_6b04653b52f71canvas.style.cursor = "grab"; }); gdv_6b04653b52f71zoomInButton.addEventListener("click", function() { let newScale = gdv_6b04653b52f71scale; const zoomFactor = 0.025; newScale *= 1 + zoomFactor; gdv_6b04653b52f71scale = Math.max(gdv_6b04653b52f71minScale, Math.min(gdv_6b04653b52f71maxScale, newScale)); gdv_6b04653b52f71drawImage(); }); gdv_6b04653b52f71zoomOutButton.addEventListener("click", function() { let newScale = gdv_6b04653b52f71scale; const zoomFactor = 0.025; newScale /= 1 + zoomFactor; gdv_6b04653b52f71scale = Math.max(gdv_6b04653b52f71minScale, Math.min(gdv_6b04653b52f71maxScale, newScale)); gdv_6b04653b52f71drawImage(); }); gdv_6b04653b52f71resetZoomButton.addEventListener("click", function() { gdv_6b04653b52f71rotationAngle = 0; gdv_6b04653b52f71fitImageToCanvas(); gdv_6b04653b52f71drawImage(); }); function gdv_6b04653b52f71getImageIdFromUrl(url) { const urlObj = new URL(url); return urlObj.searchParams.get("id"); } document.getElementById("gdv_6b04653b52f71downloadImage").addEventListener("click", function() { let url = gdv_6b04653b52f71currentImage.src; const imageId = gdv_6b04653b52f71getImageIdFromUrl(url); const apiUrl = `${window.location.origin}/wp-json/gdv/v1/download-image?image_id=${imageId}`; fetch(apiUrl, {credentials: "same-origin", headers: {"X-WP-Nonce": "14da27bf18"}}) .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_6b04653b52f71printImageFromApi(imageId) { const apiUrl = `${window.location.origin}/wp-json/gdv/v1/download-image?image_id=${imageId}`;
fetch(apiUrl, {credentials: "same-origin", headers: {"X-WP-Nonce": "14da27bf18"}}) .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_6b04653b52f71printButton = document.getElementById("gdv_6b04653b52f71printCanvas");
gdv_6b04653b52f71printButton.addEventListener("click", function() { let url = gdv_6b04653b52f71currentImage.src; const imageId = gdv_6b04653b52f71getImageIdFromUrl(url); gdv_6b04653b52f71printImageFromApi(imageId); });
let gdv_6b04653b52f71initialDistance = 0; let gdv_6b04653b52f71initialScale = 1;
gdv_6b04653b52f71canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 2) { event.preventDefault(); gdv_6b04653b52f71initialDistance = getDistance(event.touches[0], event.touches[1]); gdv_6b04653b52f71initialScale = gdv_6b04653b52f71scale; } });
gdv_6b04653b52f71canvas.addEventListener("touchmove", function(event) { if (event.touches.length === 2) { event.preventDefault(); const currentDistance = getDistance(event.touches[0], event.touches[1]); const scaleChange = currentDistance / gdv_6b04653b52f71initialDistance; let newScale = gdv_6b04653b52f71initialScale * scaleChange;
newScale = Math.max(gdv_6b04653b52f71minScale, Math.min(gdv_6b04653b52f71maxScale, 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_6b04653b52f71scale; gdv_6b04653b52f71originX = centerX - (centerX - gdv_6b04653b52f71originX) * scaleRatio; gdv_6b04653b52f71originY = centerY - (centerY - gdv_6b04653b52f71originY) * scaleRatio;
gdv_6b04653b52f71scale = newScale; gdv_6b04653b52f71drawImage(); // 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); }