1 / X
const gdv_69b40c062566ccanvas = document.getElementById("gdv_69b40c062566cimageCanvas"); const gdv_69b40c062566cctx = gdv_69b40c062566ccanvas.getContext("2d");
const gdv_69b40c062566cthumbnailContainer = document.getElementById("gdv_69b40c062566cthumbnailContainer"); const gdv_69b40c062566cthumbnailContainerWrapper = document.getElementById("gdv_69b40c062566cthumbnailContainerWrapper"); const gdv_69b40c062566czoomInButton = document.getElementById("gdv_69b40c062566czoomIn"); const gdv_69b40c062566czoomOutButton = document.getElementById("gdv_69b40c062566czoomOut"); const gdv_69b40c062566cresetZoomButton = document.getElementById("gdv_69b40c062566cresetZoom");
const gdv_69b40c062566cbrightnessInput = document.getElementById("gdv_69b40c062566cbrightness"); const gdv_69b40c062566ccontrastInput = document.getElementById("gdv_69b40c062566ccontrast"); const gdv_69b40c062566cfullscreenButton = document.getElementById("gdv_69b40c062566cfullscreen");
const gdv_69b40c062566crotateRightButton = document.getElementById("gdv_69b40c062566crotateRight"); const gdv_69b40c062566crotateLeftButton = document.getElementById("gdv_69b40c062566crotateLeft");
const gdv_69b40c062566cprevSlideButton = document.getElementById("gdv_69b40c062566cprevSlide"); const gdv_69b40c062566cnextSlideButton = document.getElementById("gdv_69b40c062566cnextSlide"); const gdv_69b40c062566cslideNumberDisplay = document.getElementById("gdv_69b40c062566cslideNumber"); const gdv_69b40c062566cimageName = document.getElementById("gdv_69b40c062566cimageName");
let gdv_69b40c062566ccurrentSlideIndex = 0;
gdv_69b40c062566cbrightnessInput.addEventListener("input", gdv_69b40c062566cdrawImage); gdv_69b40c062566ccontrastInput.addEventListener("input", gdv_69b40c062566cdrawImage);
const gdv_69b40c062566cimageUrls = [{"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_69b40c062566cscale = 1; let gdv_69b40c062566coriginX = 0; let gdv_69b40c062566coriginY = 0; const gdv_69b40c062566cminScale = 0.1; const gdv_69b40c062566cmaxScale = 5; let gdv_69b40c062566ccurrentImage = new Image();
let gdv_69b40c062566crotationAngle = 0;
gdv_69b40c062566crotateRightButton.addEventListener("click", function() { gdv_69b40c062566crotationAngle = (gdv_69b40c062566crotationAngle + 90) % 360; gdv_69b40c062566cdrawImage(); });
gdv_69b40c062566crotateLeftButton.addEventListener("click", function() { gdv_69b40c062566crotationAngle = (gdv_69b40c062566crotationAngle - 90 + 360) % 360; gdv_69b40c062566cdrawImage(); });
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_69b40c062566ccurrentImage.src = gdv_69b40c062566cimageUrls[0]["url"]; gdv_69b40c062566cimageName.innerHTML = filtrerChaine(gdv_69b40c062566cimageUrls[0]["name"], "rien"); gdv_69b40c062566ccurrentImage.onload = function() {
gdv_69b40c062566cupdateSlideNumber(); gdv_69b40c062566cresizeCanvas(); gdv_69b40c062566cdrawImage(); document.getElementById("gdv_69b40c062566ccontrols").style.display = "block"; };
function gdv_69b40c062566cupdateSlideNumber() { gdv_69b40c062566cslideNumberDisplay.textContent = `${gdv_69b40c062566ccurrentSlideIndex + 1} / ${gdv_69b40c062566cimageUrls.length}`; }
gdv_69b40c062566cprevSlideButton.addEventListener("click", function() { if (gdv_69b40c062566ccurrentSlideIndex > 0) { gdv_69b40c062566ccurrentSlideIndex--; gdv_69b40c062566cloadImage(gdv_69b40c062566ccurrentSlideIndex); gdv_69b40c062566cupdateSlideNumber(); } });
gdv_69b40c062566cnextSlideButton.addEventListener("click", function() { if (gdv_69b40c062566ccurrentSlideIndex < gdv_69b40c062566cimageUrls.length - 1) { gdv_69b40c062566ccurrentSlideIndex++; gdv_69b40c062566cloadImage(gdv_69b40c062566ccurrentSlideIndex); gdv_69b40c062566cupdateSlideNumber(); } }); function gdv_69b40c062566cresizeCanvas() { // Ajuster la taille du canvas pour correspondre à celle du conteneur const container = document.getElementById("gdv_69b40c062566ccanvasContainer"); gdv_69b40c062566ccanvas.width = container.clientWidth; gdv_69b40c062566ccanvas.height = container.clientHeight - 30; gdv_69b40c062566cfitImageToCanvas(); // Redessiner le contenu du canvas ici gdv_69b40c062566cdrawImage(); } window.addEventListener("load", gdv_69b40c062566cresizeCanvas); window.addEventListener("resize", gdv_69b40c062566cresizeCanvas); function gdv_69b40c062566cfitImageToCanvas() { const canvasAspect = gdv_69b40c062566ccanvas.width / gdv_69b40c062566ccanvas.height; const imageAspect = gdv_69b40c062566ccurrentImage.width / gdv_69b40c062566ccurrentImage.height; if (imageAspect > canvasAspect) { gdv_69b40c062566cscale = gdv_69b40c062566ccanvas.width / gdv_69b40c062566ccurrentImage.width; } else { gdv_69b40c062566cscale = gdv_69b40c062566ccanvas.height / gdv_69b40c062566ccurrentImage.height; } gdv_69b40c062566coriginX = gdv_69b40c062566ccanvas.width / 2; gdv_69b40c062566coriginY = gdv_69b40c062566ccanvas.height / 2; }
function gdv_69b40c062566cdrawImage() { gdv_69b40c062566cctx.clearRect(0, 0, gdv_69b40c062566ccanvas.width, gdv_69b40c062566ccanvas.height); gdv_69b40c062566cctx.save(); gdv_69b40c062566cctx.translate(gdv_69b40c062566coriginX, gdv_69b40c062566coriginY); gdv_69b40c062566cctx.rotate((Math.PI / 180) * gdv_69b40c062566crotationAngle); gdv_69b40c062566cctx.scale(gdv_69b40c062566cscale, gdv_69b40c062566cscale);
// Appliquer la luminosité et le contraste gdv_69b40c062566cctx.filter = `brightness(${gdv_69b40c062566cbrightnessInput.value}) contrast(${gdv_69b40c062566ccontrastInput.value})`; gdv_69b40c062566cctx.drawImage(gdv_69b40c062566ccurrentImage, -gdv_69b40c062566ccurrentImage.width/2, -gdv_69b40c062566ccurrentImage.height/2); gdv_69b40c062566cctx.restore(); }
// Ajouter les miniatures des images gdv_69b40c062566cimageUrls.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_69b40c062566cloadImage(index); gdv_69b40c062566ccurrentSlideIndex = index; gdv_69b40c062566cupdateSlideNumber(); }; slide.appendChild(img); gdv_69b40c062566cthumbnailContainerWrapper.appendChild(slide); });
// Charger une image dans le canvas function gdv_69b40c062566cloadImage(index) { gdv_69b40c062566ccurrentImage.src = gdv_69b40c062566cimageUrls[index]["url"]; gdv_69b40c062566cimageName.innerHTML = filtrerChaine(gdv_69b40c062566cimageUrls[index]["name"], "rien"); gdv_69b40c062566ccurrentImage.onload = function() { gdv_69b40c062566cscale = 1; gdv_69b40c062566coriginX = 0; gdv_69b40c062566coriginY = 0; gdv_69b40c062566cfitImageToCanvas(); gdv_69b40c062566cdrawImage(); };
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_69b40c062566cswiper = new Swiper(".gdv_69b40c062566cswiper-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_69b40c062566cswiper.on("slideChange", function () { // gdv_69b40c062566ccurrentSlideIndex = gdv_69b40c062566cswiper.activeIndex; // gdv_69b40c062566cupdateSlideNumber(); //});
// Plein écran gdv_69b40c062566cfullscreenButton.addEventListener("click", function() { if (!document.fullscreenElement) { document.getElementById("gdv_69b40c062566cgd-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_69b40c062566ccanvas.addEventListener("wheel", function(event) { event.preventDefault(); const zoomFactor = 0.025; const mouseX = event.offsetX; const mouseY = event.offsetY;
let newScale = gdv_69b40c062566cscale; if (event.deltaY < 0) { newScale *= 1 + zoomFactor; } else { newScale /= 1 + zoomFactor; } newScale = Math.max(gdv_69b40c062566cminScale, Math.min(gdv_69b40c062566cmaxScale, newScale)); const scaleRatio = newScale / gdv_69b40c062566cscale; gdv_69b40c062566coriginX = mouseX - (mouseX - gdv_69b40c062566coriginX) * scaleRatio; gdv_69b40c062566coriginY = mouseY - (mouseY - gdv_69b40c062566coriginY) * scaleRatio; gdv_69b40c062566cscale = newScale; gdv_69b40c062566cdrawImage(); }); // Gestion du déplacement (pan) let gdv_69b40c062566cisDragging = false; let gdv_69b40c062566cstartX, gdv_69b40c062566cstartY; gdv_69b40c062566ccanvas.addEventListener("mousedown", function(event) { gdv_69b40c062566cisDragging = true; gdv_69b40c062566cstartX = event.offsetX - gdv_69b40c062566coriginX; gdv_69b40c062566cstartY = event.offsetY - gdv_69b40c062566coriginY; gdv_69b40c062566ccanvas.style.cursor = "grabbing"; }); gdv_69b40c062566ccanvas.addEventListener("mousemove", function(event) { if (gdv_69b40c062566cisDragging) { gdv_69b40c062566coriginX = event.offsetX - gdv_69b40c062566cstartX; gdv_69b40c062566coriginY = event.offsetY - gdv_69b40c062566cstartY; gdv_69b40c062566cdrawImage(); } }); // Gestion des événements tactiles gdv_69b40c062566ccanvas.addEventListener("touchstart", function(event) { if (event.touches.length === 1) { gdv_69b40c062566cisDragging = true; const touch = event.touches[0]; gdv_69b40c062566cstartX = touch.pageX - gdv_69b40c062566coriginX; gdv_69b40c062566cstartY = touch.pageY - gdv_69b40c062566coriginY; } }); gdv_69b40c062566ccanvas.addEventListener("touchmove", function(event) { event.preventDefault(); // Empêche le comportement par défaut du navigateur const touch = event.touches[0]; gdv_69b40c062566coriginX = touch.pageX - gdv_69b40c062566cstartX; gdv_69b40c062566coriginY = touch.pageY - gdv_69b40c062566cstartY; gdv_69b40c062566cdrawImage(); }); gdv_69b40c062566ccanvas.addEventListener("touchend", function() { gdv_69b40c062566cisDragging = false; }); gdv_69b40c062566ccanvas.addEventListener("mouseup", function() { gdv_69b40c062566cisDragging = false; gdv_69b40c062566ccanvas.style.cursor = "grab"; }); gdv_69b40c062566ccanvas.addEventListener("mouseleave", function() { gdv_69b40c062566cisDragging = false; gdv_69b40c062566ccanvas.style.cursor = "grab"; }); gdv_69b40c062566czoomInButton.addEventListener("click", function() { let newScale = gdv_69b40c062566cscale; const zoomFactor = 0.025; newScale *= 1 + zoomFactor; gdv_69b40c062566cscale = Math.max(gdv_69b40c062566cminScale, Math.min(gdv_69b40c062566cmaxScale, newScale)); gdv_69b40c062566cdrawImage(); }); gdv_69b40c062566czoomOutButton.addEventListener("click", function() { let newScale = gdv_69b40c062566cscale; const zoomFactor = 0.025; newScale /= 1 + zoomFactor; gdv_69b40c062566cscale = Math.max(gdv_69b40c062566cminScale, Math.min(gdv_69b40c062566cmaxScale, newScale)); gdv_69b40c062566cdrawImage(); }); gdv_69b40c062566cresetZoomButton.addEventListener("click", function() { gdv_69b40c062566crotationAngle = 0; gdv_69b40c062566cfitImageToCanvas(); gdv_69b40c062566cdrawImage(); }); function gdv_69b40c062566cgetImageIdFromUrl(url) { const urlObj = new URL(url); return urlObj.searchParams.get("id"); } document.getElementById("gdv_69b40c062566cdownloadImage").addEventListener("click", function() { let url = gdv_69b40c062566ccurrentImage.src; const imageId = gdv_69b40c062566cgetImageIdFromUrl(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_69b40c062566cprintImageFromApi(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_69b40c062566cprintButton = document.getElementById("gdv_69b40c062566cprintCanvas");
gdv_69b40c062566cprintButton.addEventListener("click", function() { let url = gdv_69b40c062566ccurrentImage.src; const imageId = gdv_69b40c062566cgetImageIdFromUrl(url); gdv_69b40c062566cprintImageFromApi(imageId); });
let gdv_69b40c062566cinitialDistance = 0; let gdv_69b40c062566cinitialScale = 1;
gdv_69b40c062566ccanvas.addEventListener("touchstart", function(event) { if (event.touches.length === 2) { event.preventDefault(); gdv_69b40c062566cinitialDistance = getDistance(event.touches[0], event.touches[1]); gdv_69b40c062566cinitialScale = gdv_69b40c062566cscale; } });
gdv_69b40c062566ccanvas.addEventListener("touchmove", function(event) { if (event.touches.length === 2) { event.preventDefault(); const currentDistance = getDistance(event.touches[0], event.touches[1]); const scaleChange = currentDistance / gdv_69b40c062566cinitialDistance; let newScale = gdv_69b40c062566cinitialScale * scaleChange;
newScale = Math.max(gdv_69b40c062566cminScale, Math.min(gdv_69b40c062566cmaxScale, 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_69b40c062566cscale; gdv_69b40c062566coriginX = centerX - (centerX - gdv_69b40c062566coriginX) * scaleRatio; gdv_69b40c062566coriginY = centerY - (centerY - gdv_69b40c062566coriginY) * scaleRatio;
gdv_69b40c062566cscale = newScale; gdv_69b40c062566cdrawImage(); // 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); }