1 / X
const gdv_69b40bba00107canvas = document.getElementById("gdv_69b40bba00107imageCanvas"); const gdv_69b40bba00107ctx = gdv_69b40bba00107canvas.getContext("2d");
const gdv_69b40bba00107thumbnailContainer = document.getElementById("gdv_69b40bba00107thumbnailContainer"); const gdv_69b40bba00107thumbnailContainerWrapper = document.getElementById("gdv_69b40bba00107thumbnailContainerWrapper"); const gdv_69b40bba00107zoomInButton = document.getElementById("gdv_69b40bba00107zoomIn"); const gdv_69b40bba00107zoomOutButton = document.getElementById("gdv_69b40bba00107zoomOut"); const gdv_69b40bba00107resetZoomButton = document.getElementById("gdv_69b40bba00107resetZoom");
const gdv_69b40bba00107brightnessInput = document.getElementById("gdv_69b40bba00107brightness"); const gdv_69b40bba00107contrastInput = document.getElementById("gdv_69b40bba00107contrast"); const gdv_69b40bba00107fullscreenButton = document.getElementById("gdv_69b40bba00107fullscreen");
const gdv_69b40bba00107rotateRightButton = document.getElementById("gdv_69b40bba00107rotateRight"); const gdv_69b40bba00107rotateLeftButton = document.getElementById("gdv_69b40bba00107rotateLeft");
const gdv_69b40bba00107prevSlideButton = document.getElementById("gdv_69b40bba00107prevSlide"); const gdv_69b40bba00107nextSlideButton = document.getElementById("gdv_69b40bba00107nextSlide"); const gdv_69b40bba00107slideNumberDisplay = document.getElementById("gdv_69b40bba00107slideNumber"); const gdv_69b40bba00107imageName = document.getElementById("gdv_69b40bba00107imageName");
let gdv_69b40bba00107currentSlideIndex = 0;
gdv_69b40bba00107brightnessInput.addEventListener("input", gdv_69b40bba00107drawImage); gdv_69b40bba00107contrastInput.addEventListener("input", gdv_69b40bba00107drawImage);
const gdv_69b40bba00107imageUrls = [{"url":"https:\/\/drive.google.com\/thumbnail?id=11ul_NxiAeQimii1Rp69cvoRC5Q8wPtiW&sz=w3000","name":"1 ComCivils_Proclamation sur les assemble\u0301es coloniales.jpg"},{"url":"https:\/\/drive.google.com\/thumbnail?id=15BXaT0kWc4Zc5RjDDlBq4qazj1hpKS3F&sz=w3000","name":"2 ComCivils_Proclamation sur les assemble\u0301es coloniales.jpg"},{"url":"https:\/\/drive.google.com\/thumbnail?id=1Po6Cau1FNOzBARLD73DkoClfpw49bX0C&sz=w3000","name":"3 ComCivils_Proclamation sur les assemble\u0301es coloniales.jpg"},{"url":"https:\/\/drive.google.com\/thumbnail?id=1ZjUpBhcOctaCT77Czqh7ggFmiwQuA8V8&sz=w3000","name":"4 ComCivils_Proclamation sur les assemble\u0301es coloniales.jpg"},{"url":"https:\/\/drive.google.com\/thumbnail?id=17MnCr4Z2eBNKGSKbabQ7wupeOGeDArPH&sz=w3000","name":"5 ComCivils_Proclamation sur les assemble\u0301es coloniales.jpg"},{"url":"https:\/\/drive.google.com\/thumbnail?id=174ROyI6MUnc1Z8kRjl5xaxYeCjiMVK8W&sz=w3000","name":"6 ComCivils_Proclamation sur les assemble\u0301es coloniales.jpg"},{"url":"https:\/\/drive.google.com\/thumbnail?id=1OKpkjvKY1l4OcypizwVfddfpWfn6EXmm&sz=w3000","name":"7 ComCivils_Proclamation sur les assemble\u0301es coloniales.jpg"},{"url":"https:\/\/drive.google.com\/thumbnail?id=1acQf5Qk2LXwZQHQ8BjoiYrig0WnS7jdr&sz=w3000","name":"8 ComCivils_Proclamation sur les assemble\u0301es coloniales.jpg"}];
let gdv_69b40bba00107scale = 1; let gdv_69b40bba00107originX = 0; let gdv_69b40bba00107originY = 0; const gdv_69b40bba00107minScale = 0.1; const gdv_69b40bba00107maxScale = 5; let gdv_69b40bba00107currentImage = new Image();
let gdv_69b40bba00107rotationAngle = 0;
gdv_69b40bba00107rotateRightButton.addEventListener("click", function() { gdv_69b40bba00107rotationAngle = (gdv_69b40bba00107rotationAngle + 90) % 360; gdv_69b40bba00107drawImage(); });
gdv_69b40bba00107rotateLeftButton.addEventListener("click", function() { gdv_69b40bba00107rotationAngle = (gdv_69b40bba00107rotationAngle - 90 + 360) % 360; gdv_69b40bba00107drawImage(); });
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_69b40bba00107currentImage.src = gdv_69b40bba00107imageUrls[0]["url"]; gdv_69b40bba00107imageName.innerHTML = filtrerChaine(gdv_69b40bba00107imageUrls[0]["name"], "rien"); gdv_69b40bba00107currentImage.onload = function() {
gdv_69b40bba00107updateSlideNumber(); gdv_69b40bba00107resizeCanvas(); gdv_69b40bba00107drawImage(); document.getElementById("gdv_69b40bba00107controls").style.display = "block"; };
function gdv_69b40bba00107updateSlideNumber() { gdv_69b40bba00107slideNumberDisplay.textContent = `${gdv_69b40bba00107currentSlideIndex + 1} / ${gdv_69b40bba00107imageUrls.length}`; }
gdv_69b40bba00107prevSlideButton.addEventListener("click", function() { if (gdv_69b40bba00107currentSlideIndex > 0) { gdv_69b40bba00107currentSlideIndex--; gdv_69b40bba00107loadImage(gdv_69b40bba00107currentSlideIndex); gdv_69b40bba00107updateSlideNumber(); } });
gdv_69b40bba00107nextSlideButton.addEventListener("click", function() { if (gdv_69b40bba00107currentSlideIndex < gdv_69b40bba00107imageUrls.length - 1) { gdv_69b40bba00107currentSlideIndex++; gdv_69b40bba00107loadImage(gdv_69b40bba00107currentSlideIndex); gdv_69b40bba00107updateSlideNumber(); } }); function gdv_69b40bba00107resizeCanvas() { // Ajuster la taille du canvas pour correspondre à celle du conteneur const container = document.getElementById("gdv_69b40bba00107canvasContainer"); gdv_69b40bba00107canvas.width = container.clientWidth; gdv_69b40bba00107canvas.height = container.clientHeight - 30; gdv_69b40bba00107fitImageToCanvas(); // Redessiner le contenu du canvas ici gdv_69b40bba00107drawImage(); } window.addEventListener("load", gdv_69b40bba00107resizeCanvas); window.addEventListener("resize", gdv_69b40bba00107resizeCanvas); function gdv_69b40bba00107fitImageToCanvas() { const canvasAspect = gdv_69b40bba00107canvas.width / gdv_69b40bba00107canvas.height; const imageAspect = gdv_69b40bba00107currentImage.width / gdv_69b40bba00107currentImage.height; if (imageAspect > canvasAspect) { gdv_69b40bba00107scale = gdv_69b40bba00107canvas.width / gdv_69b40bba00107currentImage.width; } else { gdv_69b40bba00107scale = gdv_69b40bba00107canvas.height / gdv_69b40bba00107currentImage.height; } gdv_69b40bba00107originX = gdv_69b40bba00107canvas.width / 2; gdv_69b40bba00107originY = gdv_69b40bba00107canvas.height / 2; }
function gdv_69b40bba00107drawImage() { gdv_69b40bba00107ctx.clearRect(0, 0, gdv_69b40bba00107canvas.width, gdv_69b40bba00107canvas.height); gdv_69b40bba00107ctx.save(); gdv_69b40bba00107ctx.translate(gdv_69b40bba00107originX, gdv_69b40bba00107originY); gdv_69b40bba00107ctx.rotate((Math.PI / 180) * gdv_69b40bba00107rotationAngle); gdv_69b40bba00107ctx.scale(gdv_69b40bba00107scale, gdv_69b40bba00107scale);
// Appliquer la luminosité et le contraste gdv_69b40bba00107ctx.filter = `brightness(${gdv_69b40bba00107brightnessInput.value}) contrast(${gdv_69b40bba00107contrastInput.value})`; gdv_69b40bba00107ctx.drawImage(gdv_69b40bba00107currentImage, -gdv_69b40bba00107currentImage.width/2, -gdv_69b40bba00107currentImage.height/2); gdv_69b40bba00107ctx.restore(); }
// Ajouter les miniatures des images gdv_69b40bba00107imageUrls.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_69b40bba00107loadImage(index); gdv_69b40bba00107currentSlideIndex = index; gdv_69b40bba00107updateSlideNumber(); }; slide.appendChild(img); gdv_69b40bba00107thumbnailContainerWrapper.appendChild(slide); });
// Charger une image dans le canvas function gdv_69b40bba00107loadImage(index) { gdv_69b40bba00107currentImage.src = gdv_69b40bba00107imageUrls[index]["url"]; gdv_69b40bba00107imageName.innerHTML = filtrerChaine(gdv_69b40bba00107imageUrls[index]["name"], "rien"); gdv_69b40bba00107currentImage.onload = function() { gdv_69b40bba00107scale = 1; gdv_69b40bba00107originX = 0; gdv_69b40bba00107originY = 0; gdv_69b40bba00107fitImageToCanvas(); gdv_69b40bba00107drawImage(); };
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_69b40bba00107swiper = new Swiper(".gdv_69b40bba00107swiper-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_69b40bba00107swiper.on("slideChange", function () { // gdv_69b40bba00107currentSlideIndex = gdv_69b40bba00107swiper.activeIndex; // gdv_69b40bba00107updateSlideNumber(); //});
// Plein écran gdv_69b40bba00107fullscreenButton.addEventListener("click", function() { if (!document.fullscreenElement) { document.getElementById("gdv_69b40bba00107gd-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_69b40bba00107canvas.addEventListener("wheel", function(event) { event.preventDefault(); const zoomFactor = 0.025; const mouseX = event.offsetX; const mouseY = event.offsetY;
let newScale = gdv_69b40bba00107scale; if (event.deltaY < 0) { newScale *= 1 + zoomFactor; } else { newScale /= 1 + zoomFactor; } newScale = Math.max(gdv_69b40bba00107minScale, Math.min(gdv_69b40bba00107maxScale, newScale)); const scaleRatio = newScale / gdv_69b40bba00107scale; gdv_69b40bba00107originX = mouseX - (mouseX - gdv_69b40bba00107originX) * scaleRatio; gdv_69b40bba00107originY = mouseY - (mouseY - gdv_69b40bba00107originY) * scaleRatio; gdv_69b40bba00107scale = newScale; gdv_69b40bba00107drawImage(); }); // Gestion du déplacement (pan) let gdv_69b40bba00107isDragging = false; let gdv_69b40bba00107startX, gdv_69b40bba00107startY; gdv_69b40bba00107canvas.addEventListener("mousedown", function(event) { gdv_69b40bba00107isDragging = true; gdv_69b40bba00107startX = event.offsetX - gdv_69b40bba00107originX; gdv_69b40bba00107startY = event.offsetY - gdv_69b40bba00107originY; gdv_69b40bba00107canvas.style.cursor = "grabbing"; }); gdv_69b40bba00107canvas.addEventListener("mousemove", function(event) { if (gdv_69b40bba00107isDragging) { gdv_69b40bba00107originX = event.offsetX - gdv_69b40bba00107startX; gdv_69b40bba00107originY = event.offsetY - gdv_69b40bba00107startY; gdv_69b40bba00107drawImage(); } }); // Gestion des événements tactiles gdv_69b40bba00107canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 1) { gdv_69b40bba00107isDragging = true; const touch = event.touches[0]; gdv_69b40bba00107startX = touch.pageX - gdv_69b40bba00107originX; gdv_69b40bba00107startY = touch.pageY - gdv_69b40bba00107originY; } }); gdv_69b40bba00107canvas.addEventListener("touchmove", function(event) { event.preventDefault(); // Empêche le comportement par défaut du navigateur const touch = event.touches[0]; gdv_69b40bba00107originX = touch.pageX - gdv_69b40bba00107startX; gdv_69b40bba00107originY = touch.pageY - gdv_69b40bba00107startY; gdv_69b40bba00107drawImage(); }); gdv_69b40bba00107canvas.addEventListener("touchend", function() { gdv_69b40bba00107isDragging = false; }); gdv_69b40bba00107canvas.addEventListener("mouseup", function() { gdv_69b40bba00107isDragging = false; gdv_69b40bba00107canvas.style.cursor = "grab"; }); gdv_69b40bba00107canvas.addEventListener("mouseleave", function() { gdv_69b40bba00107isDragging = false; gdv_69b40bba00107canvas.style.cursor = "grab"; }); gdv_69b40bba00107zoomInButton.addEventListener("click", function() { let newScale = gdv_69b40bba00107scale; const zoomFactor = 0.025; newScale *= 1 + zoomFactor; gdv_69b40bba00107scale = Math.max(gdv_69b40bba00107minScale, Math.min(gdv_69b40bba00107maxScale, newScale)); gdv_69b40bba00107drawImage(); }); gdv_69b40bba00107zoomOutButton.addEventListener("click", function() { let newScale = gdv_69b40bba00107scale; const zoomFactor = 0.025; newScale /= 1 + zoomFactor; gdv_69b40bba00107scale = Math.max(gdv_69b40bba00107minScale, Math.min(gdv_69b40bba00107maxScale, newScale)); gdv_69b40bba00107drawImage(); }); gdv_69b40bba00107resetZoomButton.addEventListener("click", function() { gdv_69b40bba00107rotationAngle = 0; gdv_69b40bba00107fitImageToCanvas(); gdv_69b40bba00107drawImage(); }); function gdv_69b40bba00107getImageIdFromUrl(url) { const urlObj = new URL(url); return urlObj.searchParams.get("id"); } document.getElementById("gdv_69b40bba00107downloadImage").addEventListener("click", function() { let url = gdv_69b40bba00107currentImage.src; const imageId = gdv_69b40bba00107getImageIdFromUrl(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_69b40bba00107printImageFromApi(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_69b40bba00107printButton = document.getElementById("gdv_69b40bba00107printCanvas");
gdv_69b40bba00107printButton.addEventListener("click", function() { let url = gdv_69b40bba00107currentImage.src; const imageId = gdv_69b40bba00107getImageIdFromUrl(url); gdv_69b40bba00107printImageFromApi(imageId); });
let gdv_69b40bba00107initialDistance = 0; let gdv_69b40bba00107initialScale = 1;
gdv_69b40bba00107canvas.addEventListener("touchstart", function(event) { if (event.touches.length === 2) { event.preventDefault(); gdv_69b40bba00107initialDistance = getDistance(event.touches[0], event.touches[1]); gdv_69b40bba00107initialScale = gdv_69b40bba00107scale; } });
gdv_69b40bba00107canvas.addEventListener("touchmove", function(event) { if (event.touches.length === 2) { event.preventDefault(); const currentDistance = getDistance(event.touches[0], event.touches[1]); const scaleChange = currentDistance / gdv_69b40bba00107initialDistance; let newScale = gdv_69b40bba00107initialScale * scaleChange;
newScale = Math.max(gdv_69b40bba00107minScale, Math.min(gdv_69b40bba00107maxScale, 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_69b40bba00107scale; gdv_69b40bba00107originX = centerX - (centerX - gdv_69b40bba00107originX) * scaleRatio; gdv_69b40bba00107originY = centerY - (centerY - gdv_69b40bba00107originY) * scaleRatio;
gdv_69b40bba00107scale = newScale; gdv_69b40bba00107drawImage(); // 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); }