1 / X
const gdv_687114b8631f4canvas = document.getElementById("gdv_687114b8631f4imageCanvas"); const gdv_687114b8631f4ctx = gdv_687114b8631f4canvas.getContext("2d");
const gdv_687114b8631f4thumbnailContainer = document.getElementById("gdv_687114b8631f4thumbnailContainer"); const gdv_687114b8631f4thumbnailContainerWrapper = document.getElementById("gdv_687114b8631f4thumbnailContainerWrapper"); const gdv_687114b8631f4zoomInButton = document.getElementById("gdv_687114b8631f4zoomIn"); const gdv_687114b8631f4zoomOutButton = document.getElementById("gdv_687114b8631f4zoomOut"); const gdv_687114b8631f4resetZoomButton = document.getElementById("gdv_687114b8631f4resetZoom");
const gdv_687114b8631f4brightnessInput = document.getElementById("gdv_687114b8631f4brightness"); const gdv_687114b8631f4contrastInput = document.getElementById("gdv_687114b8631f4contrast"); const gdv_687114b8631f4fullscreenButton = document.getElementById("gdv_687114b8631f4fullscreen");
const gdv_687114b8631f4rotateRightButton = document.getElementById("gdv_687114b8631f4rotateRight"); const gdv_687114b8631f4rotateLeftButton = document.getElementById("gdv_687114b8631f4rotateLeft");
const gdv_687114b8631f4prevSlideButton = document.getElementById("gdv_687114b8631f4prevSlide"); const gdv_687114b8631f4nextSlideButton = document.getElementById("gdv_687114b8631f4nextSlide"); const gdv_687114b8631f4slideNumberDisplay = document.getElementById("gdv_687114b8631f4slideNumber"); const gdv_687114b8631f4imageName = document.getElementById("gdv_687114b8631f4imageName");
let gdv_687114b8631f4currentSlideIndex = 0;
gdv_687114b8631f4brightnessInput.addEventListener("input", gdv_687114b8631f4drawImage); gdv_687114b8631f4contrastInput.addEventListener("input", gdv_687114b8631f4drawImage);
const gdv_687114b8631f4imageUrls = [{"url":"https:\/\/drive.google.com\/thumbnail?id=1TOwUwiwkLtxJq2OH2VMrA8DXyxTKJCUu&sz=w3000","name":"1 ComCivils_discipline des esclaves, application des e\u0301dits de 1685, 1724 et de l'ordonnance du 3 de\u0301c 1784.jpg"},{"url":"https:\/\/drive.google.com\/thumbnail?id=1IGYEepWc66ZiiOK8cy7jlAQLleRZF7Yt&sz=w3000","name":"2 ComCivils_discipline des esclaves, application des e\u0301dits de 1685, 1724 et de l'ordonnance du 3 de\u0301c 1784.jpg"},{"url":"https:\/\/drive.google.com\/thumbnail?id=1kXHvjSEOG3txyOZUn9Mfw3G3mWgd4t29&sz=w3000","name":"3 ComCivils_discipline des esclaves, application des e\u0301dits de 1685, 1724 et de l'ordonnance du 3 de\u0301c 1784.jpg"}];
let gdv_687114b8631f4scale = 1; let gdv_687114b8631f4originX = 0; let gdv_687114b8631f4originY = 0; const gdv_687114b8631f4minScale = 0.1; const gdv_687114b8631f4maxScale = 5; let gdv_687114b8631f4currentImage = new Image();
let gdv_687114b8631f4rotationAngle = 0;
gdv_687114b8631f4rotateRightButton.addEventListener("click", function() { gdv_687114b8631f4rotationAngle = (gdv_687114b8631f4rotationAngle + 90) % 360; gdv_687114b8631f4drawImage(); });
gdv_687114b8631f4rotateLeftButton.addEventListener("click", function() { gdv_687114b8631f4rotationAngle = (gdv_687114b8631f4rotationAngle - 90 + 360) % 360; gdv_687114b8631f4drawImage(); });
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_687114b8631f4currentImage.src = gdv_687114b8631f4imageUrls[0]["url"]; gdv_687114b8631f4imageName.innerHTML = filtrerChaine(gdv_687114b8631f4imageUrls[0]["name"], "rien"); gdv_687114b8631f4currentImage.onload = function() {
gdv_687114b8631f4updateSlideNumber(); gdv_687114b8631f4resizeCanvas(); gdv_687114b8631f4drawImage(); document.getElementById("gdv_687114b8631f4controls").style.display = "block"; };
function gdv_687114b8631f4updateSlideNumber() { gdv_687114b8631f4slideNumberDisplay.textContent = `${gdv_687114b8631f4currentSlideIndex + 1} / ${gdv_687114b8631f4imageUrls.length}`; }
gdv_687114b8631f4prevSlideButton.addEventListener("click", function() { if (gdv_687114b8631f4currentSlideIndex > 0) { gdv_687114b8631f4currentSlideIndex--; gdv_687114b8631f4loadImage(gdv_687114b8631f4currentSlideIndex); gdv_687114b8631f4updateSlideNumber(); } });
gdv_687114b8631f4nextSlideButton.addEventListener("click", function() { if (gdv_687114b8631f4currentSlideIndex < gdv_687114b8631f4imageUrls.length - 1) { gdv_687114b8631f4currentSlideIndex++; gdv_687114b8631f4loadImage(gdv_687114b8631f4currentSlideIndex); gdv_687114b8631f4updateSlideNumber(); } }); function gdv_687114b8631f4resizeCanvas() { // Ajuster la taille du canvas pour correspondre à celle du conteneur const container = document.getElementById("gdv_687114b8631f4canvasContainer"); gdv_687114b8631f4canvas.width = container.clientWidth; gdv_687114b8631f4canvas.height = container.clientHeight - 30; gdv_687114b8631f4fitImageToCanvas(); // Redessiner le contenu du canvas ici gdv_687114b8631f4drawImage(); } window.addEventListener("load", gdv_687114b8631f4resizeCanvas); window.addEventListener("resize", gdv_687114b8631f4resizeCanvas); function gdv_687114b8631f4fitImageToCanvas() { const canvasAspect = gdv_687114b8631f4canvas.width / gdv_687114b8631f4canvas.height; const imageAspect = gdv_687114b8631f4currentImage.width / gdv_687114b8631f4currentImage.height; if (imageAspect > canvasAspect) { gdv_687114b8631f4scale = gdv_687114b8631f4canvas.width / gdv_687114b8631f4currentImage.width; } else { gdv_687114b8631f4scale = gdv_687114b8631f4canvas.height / gdv_687114b8631f4currentImage.height; } gdv_687114b8631f4originX = gdv_687114b8631f4canvas.width / 2; gdv_687114b8631f4originY = gdv_687114b8631f4canvas.height / 2; }
function gdv_687114b8631f4drawImage() { gdv_687114b8631f4ctx.clearRect(0, 0, gdv_687114b8631f4canvas.width, gdv_687114b8631f4canvas.height); gdv_687114b8631f4ctx.save(); gdv_687114b8631f4ctx.translate(gdv_687114b8631f4originX, gdv_687114b8631f4originY); gdv_687114b8631f4ctx.rotate((Math.PI / 180) * gdv_687114b8631f4rotationAngle); gdv_687114b8631f4ctx.scale(gdv_687114b8631f4scale, gdv_687114b8631f4scale);
// Appliquer la luminosité et le contraste gdv_687114b8631f4ctx.filter = `brightness(${gdv_687114b8631f4brightnessInput.value}) contrast(${gdv_687114b8631f4contrastInput.value})`; gdv_687114b8631f4ctx.drawImage(gdv_687114b8631f4currentImage, -gdv_687114b8631f4currentImage.width/2, -gdv_687114b8631f4currentImage.height/2); gdv_687114b8631f4ctx.restore(); }
// Ajouter les miniatures des images gdv_687114b8631f4imageUrls.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_687114b8631f4loadImage(index); gdv_687114b8631f4currentSlideIndex = index; gdv_687114b8631f4updateSlideNumber(); }; slide.appendChild(img); gdv_687114b8631f4thumbnailContainerWrapper.appendChild(slide); });
// Charger une image dans le canvas function gdv_687114b8631f4loadImage(index) { gdv_687114b8631f4currentImage.src = gdv_687114b8631f4imageUrls[index]["url"]; gdv_687114b8631f4imageName.innerHTML = filtrerChaine(gdv_687114b8631f4imageUrls[index]["name"], "rien"); gdv_687114b8631f4currentImage.onload = function() { gdv_687114b8631f4scale = 1; gdv_687114b8631f4originX = 0; gdv_687114b8631f4originY = 0; gdv_687114b8631f4fitImageToCanvas(); gdv_687114b8631f4drawImage(); };
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_687114b8631f4swiper = new Swiper(".gdv_687114b8631f4swiper-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_687114b8631f4swiper.on("slideChange", function () { // gdv_687114b8631f4currentSlideIndex = gdv_687114b8631f4swiper.activeIndex; // gdv_687114b8631f4updateSlideNumber(); //});
// Plein écran gdv_687114b8631f4fullscreenButton.addEventListener("click", function() { if (!document.fullscreenElement) { document.getElementById("gdv_687114b8631f4gd-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_687114b8631f4canvas.addEventListener("wheel", function(event) { event.preventDefault(); const zoomFactor = 0.025; const mouseX = event.offsetX; const mouseY = event.offsetY;
let newScale = gdv_687114b8631f4scale; if (event.deltaY < 0) { newScale *= 1 + zoomFactor; } else { newScale /= 1 + zoomFactor; } newScale = Math.max(gdv_687114b8631f4minScale, Math.min(gdv_687114b8631f4maxScale, newScale)); const scaleRatio = newScale / gdv_687114b8631f4scale; gdv_687114b8631f4originX = mouseX - (mouseX - gdv_687114b8631f4originX) * scaleRatio; gdv_687114b8631f4originY = mouseY - (mouseY - gdv_687114b8631f4originY) * scaleRatio; gdv_687114b8631f4scale = newScale; gdv_687114b8631f4drawImage(); }); // Gestion du déplacement (pan) let gdv_687114b8631f4isDragging = false; let gdv_687114b8631f4startX, gdv_687114b8631f4startY; gdv_687114b8631f4canvas.addEventListener("mousedown", function(event) { gdv_687114b8631f4isDragging = true; gdv_687114b8631f4startX = event.offsetX - gdv_687114b8631f4originX; gdv_687114b8631f4startY = event.offsetY - gdv_687114b8631f4originY; gdv_687114b8631f4canvas.style.cursor = "grabbing"; }); gdv_687114b8631f4canvas.addEventListener("mousemove", function(event) { if (gdv_687114b8631f4isDragging) { gdv_687114b8631f4originX = event.offsetX - gdv_687114b8631f4startX; gdv_687114b8631f4originY = event.offsetY - gdv_687114b8631f4startY; gdv_687114b8631f4drawImage(); } }); // Gestion des événements tactiles gdv_687114b8631f4canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 1) { gdv_687114b8631f4isDragging = true; const touch = event.touches[0]; gdv_687114b8631f4startX = touch.pageX - gdv_687114b8631f4originX; gdv_687114b8631f4startY = touch.pageY - gdv_687114b8631f4originY; } }); gdv_687114b8631f4canvas.addEventListener("touchmove", function(event) { event.preventDefault(); // Empêche le comportement par défaut du navigateur const touch = event.touches[0]; gdv_687114b8631f4originX = touch.pageX - gdv_687114b8631f4startX; gdv_687114b8631f4originY = touch.pageY - gdv_687114b8631f4startY; gdv_687114b8631f4drawImage(); }); gdv_687114b8631f4canvas.addEventListener("touchend", function() { gdv_687114b8631f4isDragging = false; }); gdv_687114b8631f4canvas.addEventListener("mouseup", function() { gdv_687114b8631f4isDragging = false; gdv_687114b8631f4canvas.style.cursor = "grab"; }); gdv_687114b8631f4canvas.addEventListener("mouseleave", function() { gdv_687114b8631f4isDragging = false; gdv_687114b8631f4canvas.style.cursor = "grab"; }); gdv_687114b8631f4zoomInButton.addEventListener("click", function() { let newScale = gdv_687114b8631f4scale; const zoomFactor = 0.025; newScale *= 1 + zoomFactor; gdv_687114b8631f4scale = Math.max(gdv_687114b8631f4minScale, Math.min(gdv_687114b8631f4maxScale, newScale)); gdv_687114b8631f4drawImage(); }); gdv_687114b8631f4zoomOutButton.addEventListener("click", function() { let newScale = gdv_687114b8631f4scale; const zoomFactor = 0.025; newScale /= 1 + zoomFactor; gdv_687114b8631f4scale = Math.max(gdv_687114b8631f4minScale, Math.min(gdv_687114b8631f4maxScale, newScale)); gdv_687114b8631f4drawImage(); }); gdv_687114b8631f4resetZoomButton.addEventListener("click", function() { gdv_687114b8631f4rotationAngle = 0; gdv_687114b8631f4fitImageToCanvas(); gdv_687114b8631f4drawImage(); }); function gdv_687114b8631f4getImageIdFromUrl(url) { const urlObj = new URL(url); return urlObj.searchParams.get("id"); } document.getElementById("gdv_687114b8631f4downloadImage").addEventListener("click", function() { let url = gdv_687114b8631f4currentImage.src; const imageId = gdv_687114b8631f4getImageIdFromUrl(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_687114b8631f4printImageFromApi(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_687114b8631f4printButton = document.getElementById("gdv_687114b8631f4printCanvas");
gdv_687114b8631f4printButton.addEventListener("click", function() { let url = gdv_687114b8631f4currentImage.src; const imageId = gdv_687114b8631f4getImageIdFromUrl(url); gdv_687114b8631f4printImageFromApi(imageId); });
let gdv_687114b8631f4initialDistance = 0; let gdv_687114b8631f4initialScale = 1;
gdv_687114b8631f4canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 2) { event.preventDefault(); gdv_687114b8631f4initialDistance = getDistance(event.touches[0], event.touches[1]); gdv_687114b8631f4initialScale = gdv_687114b8631f4scale; } });
gdv_687114b8631f4canvas.addEventListener("touchmove", function(event) { if (event.touches.length === 2) { event.preventDefault(); const currentDistance = getDistance(event.touches[0], event.touches[1]); const scaleChange = currentDistance / gdv_687114b8631f4initialDistance; let newScale = gdv_687114b8631f4initialScale * scaleChange;
newScale = Math.max(gdv_687114b8631f4minScale, Math.min(gdv_687114b8631f4maxScale, 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_687114b8631f4scale; gdv_687114b8631f4originX = centerX - (centerX - gdv_687114b8631f4originX) * scaleRatio; gdv_687114b8631f4originY = centerY - (centerY - gdv_687114b8631f4originY) * scaleRatio;
gdv_687114b8631f4scale = newScale; gdv_687114b8631f4drawImage(); // 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); }