1 / X
const gdv_69f41c0045106canvas = document.getElementById("gdv_69f41c0045106imageCanvas"); const gdv_69f41c0045106ctx = gdv_69f41c0045106canvas.getContext("2d");
const gdv_69f41c0045106thumbnailContainer = document.getElementById("gdv_69f41c0045106thumbnailContainer"); const gdv_69f41c0045106thumbnailContainerWrapper = document.getElementById("gdv_69f41c0045106thumbnailContainerWrapper"); const gdv_69f41c0045106zoomInButton = document.getElementById("gdv_69f41c0045106zoomIn"); const gdv_69f41c0045106zoomOutButton = document.getElementById("gdv_69f41c0045106zoomOut"); const gdv_69f41c0045106resetZoomButton = document.getElementById("gdv_69f41c0045106resetZoom");
const gdv_69f41c0045106brightnessInput = document.getElementById("gdv_69f41c0045106brightness"); const gdv_69f41c0045106contrastInput = document.getElementById("gdv_69f41c0045106contrast"); const gdv_69f41c0045106fullscreenButton = document.getElementById("gdv_69f41c0045106fullscreen");
const gdv_69f41c0045106rotateRightButton = document.getElementById("gdv_69f41c0045106rotateRight"); const gdv_69f41c0045106rotateLeftButton = document.getElementById("gdv_69f41c0045106rotateLeft");
const gdv_69f41c0045106prevSlideButton = document.getElementById("gdv_69f41c0045106prevSlide"); const gdv_69f41c0045106nextSlideButton = document.getElementById("gdv_69f41c0045106nextSlide"); const gdv_69f41c0045106slideNumberDisplay = document.getElementById("gdv_69f41c0045106slideNumber"); const gdv_69f41c0045106imageName = document.getElementById("gdv_69f41c0045106imageName");
let gdv_69f41c0045106currentSlideIndex = 0;
gdv_69f41c0045106brightnessInput.addEventListener("input", gdv_69f41c0045106drawImage); gdv_69f41c0045106contrastInput.addEventListener("input", gdv_69f41c0045106drawImage);
const gdv_69f41c0045106imageUrls = [{"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_69f41c0045106scale = 1; let gdv_69f41c0045106originX = 0; let gdv_69f41c0045106originY = 0; const gdv_69f41c0045106minScale = 0.1; const gdv_69f41c0045106maxScale = 5; let gdv_69f41c0045106currentImage = new Image();
let gdv_69f41c0045106rotationAngle = 0;
gdv_69f41c0045106rotateRightButton.addEventListener("click", function() { gdv_69f41c0045106rotationAngle = (gdv_69f41c0045106rotationAngle + 90) % 360; gdv_69f41c0045106drawImage(); });
gdv_69f41c0045106rotateLeftButton.addEventListener("click", function() { gdv_69f41c0045106rotationAngle = (gdv_69f41c0045106rotationAngle - 90 + 360) % 360; gdv_69f41c0045106drawImage(); });
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_69f41c0045106currentImage.src = gdv_69f41c0045106imageUrls[0]["url"]; gdv_69f41c0045106imageName.innerHTML = filtrerChaine(gdv_69f41c0045106imageUrls[0]["name"], "rien"); gdv_69f41c0045106currentImage.onload = function() {
gdv_69f41c0045106updateSlideNumber(); gdv_69f41c0045106resizeCanvas(); gdv_69f41c0045106drawImage(); document.getElementById("gdv_69f41c0045106controls").style.display = "block"; };
function gdv_69f41c0045106updateSlideNumber() { gdv_69f41c0045106slideNumberDisplay.textContent = `${gdv_69f41c0045106currentSlideIndex + 1} / ${gdv_69f41c0045106imageUrls.length}`; }
gdv_69f41c0045106prevSlideButton.addEventListener("click", function() { if (gdv_69f41c0045106currentSlideIndex > 0) { gdv_69f41c0045106currentSlideIndex--; gdv_69f41c0045106loadImage(gdv_69f41c0045106currentSlideIndex); gdv_69f41c0045106updateSlideNumber(); } });
gdv_69f41c0045106nextSlideButton.addEventListener("click", function() { if (gdv_69f41c0045106currentSlideIndex < gdv_69f41c0045106imageUrls.length - 1) { gdv_69f41c0045106currentSlideIndex++; gdv_69f41c0045106loadImage(gdv_69f41c0045106currentSlideIndex); gdv_69f41c0045106updateSlideNumber(); } }); function gdv_69f41c0045106resizeCanvas() { // Ajuster la taille du canvas pour correspondre à celle du conteneur const container = document.getElementById("gdv_69f41c0045106canvasContainer"); gdv_69f41c0045106canvas.width = container.clientWidth; gdv_69f41c0045106canvas.height = container.clientHeight - 30; gdv_69f41c0045106fitImageToCanvas(); // Redessiner le contenu du canvas ici gdv_69f41c0045106drawImage(); } window.addEventListener("load", gdv_69f41c0045106resizeCanvas); window.addEventListener("resize", gdv_69f41c0045106resizeCanvas); function gdv_69f41c0045106fitImageToCanvas() { const canvasAspect = gdv_69f41c0045106canvas.width / gdv_69f41c0045106canvas.height; const imageAspect = gdv_69f41c0045106currentImage.width / gdv_69f41c0045106currentImage.height; if (imageAspect > canvasAspect) { gdv_69f41c0045106scale = gdv_69f41c0045106canvas.width / gdv_69f41c0045106currentImage.width; } else { gdv_69f41c0045106scale = gdv_69f41c0045106canvas.height / gdv_69f41c0045106currentImage.height; } gdv_69f41c0045106originX = gdv_69f41c0045106canvas.width / 2; gdv_69f41c0045106originY = gdv_69f41c0045106canvas.height / 2; }
function gdv_69f41c0045106drawImage() { gdv_69f41c0045106ctx.clearRect(0, 0, gdv_69f41c0045106canvas.width, gdv_69f41c0045106canvas.height); gdv_69f41c0045106ctx.save(); gdv_69f41c0045106ctx.translate(gdv_69f41c0045106originX, gdv_69f41c0045106originY); gdv_69f41c0045106ctx.rotate((Math.PI / 180) * gdv_69f41c0045106rotationAngle); gdv_69f41c0045106ctx.scale(gdv_69f41c0045106scale, gdv_69f41c0045106scale);
// Appliquer la luminosité et le contraste gdv_69f41c0045106ctx.filter = `brightness(${gdv_69f41c0045106brightnessInput.value}) contrast(${gdv_69f41c0045106contrastInput.value})`; gdv_69f41c0045106ctx.drawImage(gdv_69f41c0045106currentImage, -gdv_69f41c0045106currentImage.width/2, -gdv_69f41c0045106currentImage.height/2); gdv_69f41c0045106ctx.restore(); }
// Ajouter les miniatures des images gdv_69f41c0045106imageUrls.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_69f41c0045106loadImage(index); gdv_69f41c0045106currentSlideIndex = index; gdv_69f41c0045106updateSlideNumber(); }; slide.appendChild(img); gdv_69f41c0045106thumbnailContainerWrapper.appendChild(slide); });
// Charger une image dans le canvas function gdv_69f41c0045106loadImage(index) { gdv_69f41c0045106currentImage.src = gdv_69f41c0045106imageUrls[index]["url"]; gdv_69f41c0045106imageName.innerHTML = filtrerChaine(gdv_69f41c0045106imageUrls[index]["name"], "rien"); gdv_69f41c0045106currentImage.onload = function() { gdv_69f41c0045106scale = 1; gdv_69f41c0045106originX = 0; gdv_69f41c0045106originY = 0; gdv_69f41c0045106fitImageToCanvas(); gdv_69f41c0045106drawImage(); };
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_69f41c0045106swiper = new Swiper(".gdv_69f41c0045106swiper-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_69f41c0045106swiper.on("slideChange", function () { // gdv_69f41c0045106currentSlideIndex = gdv_69f41c0045106swiper.activeIndex; // gdv_69f41c0045106updateSlideNumber(); //});
// Plein écran gdv_69f41c0045106fullscreenButton.addEventListener("click", function() { if (!document.fullscreenElement) { document.getElementById("gdv_69f41c0045106gd-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_69f41c0045106canvas.addEventListener("wheel", function(event) { event.preventDefault(); const zoomFactor = 0.025; const mouseX = event.offsetX; const mouseY = event.offsetY;
let newScale = gdv_69f41c0045106scale; if (event.deltaY < 0) { newScale *= 1 + zoomFactor; } else { newScale /= 1 + zoomFactor; } newScale = Math.max(gdv_69f41c0045106minScale, Math.min(gdv_69f41c0045106maxScale, newScale)); const scaleRatio = newScale / gdv_69f41c0045106scale; gdv_69f41c0045106originX = mouseX - (mouseX - gdv_69f41c0045106originX) * scaleRatio; gdv_69f41c0045106originY = mouseY - (mouseY - gdv_69f41c0045106originY) * scaleRatio; gdv_69f41c0045106scale = newScale; gdv_69f41c0045106drawImage(); }); // Gestion du déplacement (pan) let gdv_69f41c0045106isDragging = false; let gdv_69f41c0045106startX, gdv_69f41c0045106startY; gdv_69f41c0045106canvas.addEventListener("mousedown", function(event) { gdv_69f41c0045106isDragging = true; gdv_69f41c0045106startX = event.offsetX - gdv_69f41c0045106originX; gdv_69f41c0045106startY = event.offsetY - gdv_69f41c0045106originY; gdv_69f41c0045106canvas.style.cursor = "grabbing"; }); gdv_69f41c0045106canvas.addEventListener("mousemove", function(event) { if (gdv_69f41c0045106isDragging) { gdv_69f41c0045106originX = event.offsetX - gdv_69f41c0045106startX; gdv_69f41c0045106originY = event.offsetY - gdv_69f41c0045106startY; gdv_69f41c0045106drawImage(); } }); // Gestion des événements tactiles gdv_69f41c0045106canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 1) { gdv_69f41c0045106isDragging = true; const touch = event.touches[0]; gdv_69f41c0045106startX = touch.pageX - gdv_69f41c0045106originX; gdv_69f41c0045106startY = touch.pageY - gdv_69f41c0045106originY; } }); gdv_69f41c0045106canvas.addEventListener("touchmove", function(event) { event.preventDefault(); // Empêche le comportement par défaut du navigateur const touch = event.touches[0]; gdv_69f41c0045106originX = touch.pageX - gdv_69f41c0045106startX; gdv_69f41c0045106originY = touch.pageY - gdv_69f41c0045106startY; gdv_69f41c0045106drawImage(); }); gdv_69f41c0045106canvas.addEventListener("touchend", function() { gdv_69f41c0045106isDragging = false; }); gdv_69f41c0045106canvas.addEventListener("mouseup", function() { gdv_69f41c0045106isDragging = false; gdv_69f41c0045106canvas.style.cursor = "grab"; }); gdv_69f41c0045106canvas.addEventListener("mouseleave", function() { gdv_69f41c0045106isDragging = false; gdv_69f41c0045106canvas.style.cursor = "grab"; }); gdv_69f41c0045106zoomInButton.addEventListener("click", function() { let newScale = gdv_69f41c0045106scale; const zoomFactor = 0.025; newScale *= 1 + zoomFactor; gdv_69f41c0045106scale = Math.max(gdv_69f41c0045106minScale, Math.min(gdv_69f41c0045106maxScale, newScale)); gdv_69f41c0045106drawImage(); }); gdv_69f41c0045106zoomOutButton.addEventListener("click", function() { let newScale = gdv_69f41c0045106scale; const zoomFactor = 0.025; newScale /= 1 + zoomFactor; gdv_69f41c0045106scale = Math.max(gdv_69f41c0045106minScale, Math.min(gdv_69f41c0045106maxScale, newScale)); gdv_69f41c0045106drawImage(); }); gdv_69f41c0045106resetZoomButton.addEventListener("click", function() { gdv_69f41c0045106rotationAngle = 0; gdv_69f41c0045106fitImageToCanvas(); gdv_69f41c0045106drawImage(); }); function gdv_69f41c0045106getImageIdFromUrl(url) { const urlObj = new URL(url); return urlObj.searchParams.get("id"); } document.getElementById("gdv_69f41c0045106downloadImage").addEventListener("click", function() { let url = gdv_69f41c0045106currentImage.src; const imageId = gdv_69f41c0045106getImageIdFromUrl(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_69f41c0045106printImageFromApi(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_69f41c0045106printButton = document.getElementById("gdv_69f41c0045106printCanvas");
gdv_69f41c0045106printButton.addEventListener("click", function() { let url = gdv_69f41c0045106currentImage.src; const imageId = gdv_69f41c0045106getImageIdFromUrl(url); gdv_69f41c0045106printImageFromApi(imageId); });
let gdv_69f41c0045106initialDistance = 0; let gdv_69f41c0045106initialScale = 1;
gdv_69f41c0045106canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 2) { event.preventDefault(); gdv_69f41c0045106initialDistance = getDistance(event.touches[0], event.touches[1]); gdv_69f41c0045106initialScale = gdv_69f41c0045106scale; } });
gdv_69f41c0045106canvas.addEventListener("touchmove", function(event) { if (event.touches.length === 2) { event.preventDefault(); const currentDistance = getDistance(event.touches[0], event.touches[1]); const scaleChange = currentDistance / gdv_69f41c0045106initialDistance; let newScale = gdv_69f41c0045106initialScale * scaleChange;
newScale = Math.max(gdv_69f41c0045106minScale, Math.min(gdv_69f41c0045106maxScale, 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_69f41c0045106scale; gdv_69f41c0045106originX = centerX - (centerX - gdv_69f41c0045106originX) * scaleRatio; gdv_69f41c0045106originY = centerY - (centerY - gdv_69f41c0045106originY) * scaleRatio;
gdv_69f41c0045106scale = newScale; gdv_69f41c0045106drawImage(); // 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); }