1 / X
const gdv_69b57d108b12dcanvas = document.getElementById("gdv_69b57d108b12dimageCanvas"); const gdv_69b57d108b12dctx = gdv_69b57d108b12dcanvas.getContext("2d");
const gdv_69b57d108b12dthumbnailContainer = document.getElementById("gdv_69b57d108b12dthumbnailContainer"); const gdv_69b57d108b12dthumbnailContainerWrapper = document.getElementById("gdv_69b57d108b12dthumbnailContainerWrapper"); const gdv_69b57d108b12dzoomInButton = document.getElementById("gdv_69b57d108b12dzoomIn"); const gdv_69b57d108b12dzoomOutButton = document.getElementById("gdv_69b57d108b12dzoomOut"); const gdv_69b57d108b12dresetZoomButton = document.getElementById("gdv_69b57d108b12dresetZoom");
const gdv_69b57d108b12dbrightnessInput = document.getElementById("gdv_69b57d108b12dbrightness"); const gdv_69b57d108b12dcontrastInput = document.getElementById("gdv_69b57d108b12dcontrast"); const gdv_69b57d108b12dfullscreenButton = document.getElementById("gdv_69b57d108b12dfullscreen");
const gdv_69b57d108b12drotateRightButton = document.getElementById("gdv_69b57d108b12drotateRight"); const gdv_69b57d108b12drotateLeftButton = document.getElementById("gdv_69b57d108b12drotateLeft");
const gdv_69b57d108b12dprevSlideButton = document.getElementById("gdv_69b57d108b12dprevSlide"); const gdv_69b57d108b12dnextSlideButton = document.getElementById("gdv_69b57d108b12dnextSlide"); const gdv_69b57d108b12dslideNumberDisplay = document.getElementById("gdv_69b57d108b12dslideNumber"); const gdv_69b57d108b12dimageName = document.getElementById("gdv_69b57d108b12dimageName");
let gdv_69b57d108b12dcurrentSlideIndex = 0;
gdv_69b57d108b12dbrightnessInput.addEventListener("input", gdv_69b57d108b12ddrawImage); gdv_69b57d108b12dcontrastInput.addEventListener("input", gdv_69b57d108b12ddrawImage);
const gdv_69b57d108b12dimageUrls = [{"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_69b57d108b12dscale = 1; let gdv_69b57d108b12doriginX = 0; let gdv_69b57d108b12doriginY = 0; const gdv_69b57d108b12dminScale = 0.1; const gdv_69b57d108b12dmaxScale = 5; let gdv_69b57d108b12dcurrentImage = new Image();
let gdv_69b57d108b12drotationAngle = 0;
gdv_69b57d108b12drotateRightButton.addEventListener("click", function() { gdv_69b57d108b12drotationAngle = (gdv_69b57d108b12drotationAngle + 90) % 360; gdv_69b57d108b12ddrawImage(); });
gdv_69b57d108b12drotateLeftButton.addEventListener("click", function() { gdv_69b57d108b12drotationAngle = (gdv_69b57d108b12drotationAngle - 90 + 360) % 360; gdv_69b57d108b12ddrawImage(); });
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_69b57d108b12dcurrentImage.src = gdv_69b57d108b12dimageUrls[0]["url"]; gdv_69b57d108b12dimageName.innerHTML = filtrerChaine(gdv_69b57d108b12dimageUrls[0]["name"], "rien"); gdv_69b57d108b12dcurrentImage.onload = function() {
gdv_69b57d108b12dupdateSlideNumber(); gdv_69b57d108b12dresizeCanvas(); gdv_69b57d108b12ddrawImage(); document.getElementById("gdv_69b57d108b12dcontrols").style.display = "block"; };
function gdv_69b57d108b12dupdateSlideNumber() { gdv_69b57d108b12dslideNumberDisplay.textContent = `${gdv_69b57d108b12dcurrentSlideIndex + 1} / ${gdv_69b57d108b12dimageUrls.length}`; }
gdv_69b57d108b12dprevSlideButton.addEventListener("click", function() { if (gdv_69b57d108b12dcurrentSlideIndex > 0) { gdv_69b57d108b12dcurrentSlideIndex--; gdv_69b57d108b12dloadImage(gdv_69b57d108b12dcurrentSlideIndex); gdv_69b57d108b12dupdateSlideNumber(); } });
gdv_69b57d108b12dnextSlideButton.addEventListener("click", function() { if (gdv_69b57d108b12dcurrentSlideIndex < gdv_69b57d108b12dimageUrls.length - 1) { gdv_69b57d108b12dcurrentSlideIndex++; gdv_69b57d108b12dloadImage(gdv_69b57d108b12dcurrentSlideIndex); gdv_69b57d108b12dupdateSlideNumber(); } }); function gdv_69b57d108b12dresizeCanvas() { // Ajuster la taille du canvas pour correspondre à celle du conteneur const container = document.getElementById("gdv_69b57d108b12dcanvasContainer"); gdv_69b57d108b12dcanvas.width = container.clientWidth; gdv_69b57d108b12dcanvas.height = container.clientHeight - 30; gdv_69b57d108b12dfitImageToCanvas(); // Redessiner le contenu du canvas ici gdv_69b57d108b12ddrawImage(); } window.addEventListener("load", gdv_69b57d108b12dresizeCanvas); window.addEventListener("resize", gdv_69b57d108b12dresizeCanvas); function gdv_69b57d108b12dfitImageToCanvas() { const canvasAspect = gdv_69b57d108b12dcanvas.width / gdv_69b57d108b12dcanvas.height; const imageAspect = gdv_69b57d108b12dcurrentImage.width / gdv_69b57d108b12dcurrentImage.height; if (imageAspect > canvasAspect) { gdv_69b57d108b12dscale = gdv_69b57d108b12dcanvas.width / gdv_69b57d108b12dcurrentImage.width; } else { gdv_69b57d108b12dscale = gdv_69b57d108b12dcanvas.height / gdv_69b57d108b12dcurrentImage.height; } gdv_69b57d108b12doriginX = gdv_69b57d108b12dcanvas.width / 2; gdv_69b57d108b12doriginY = gdv_69b57d108b12dcanvas.height / 2; }
function gdv_69b57d108b12ddrawImage() { gdv_69b57d108b12dctx.clearRect(0, 0, gdv_69b57d108b12dcanvas.width, gdv_69b57d108b12dcanvas.height); gdv_69b57d108b12dctx.save(); gdv_69b57d108b12dctx.translate(gdv_69b57d108b12doriginX, gdv_69b57d108b12doriginY); gdv_69b57d108b12dctx.rotate((Math.PI / 180) * gdv_69b57d108b12drotationAngle); gdv_69b57d108b12dctx.scale(gdv_69b57d108b12dscale, gdv_69b57d108b12dscale);
// Appliquer la luminosité et le contraste gdv_69b57d108b12dctx.filter = `brightness(${gdv_69b57d108b12dbrightnessInput.value}) contrast(${gdv_69b57d108b12dcontrastInput.value})`; gdv_69b57d108b12dctx.drawImage(gdv_69b57d108b12dcurrentImage, -gdv_69b57d108b12dcurrentImage.width/2, -gdv_69b57d108b12dcurrentImage.height/2); gdv_69b57d108b12dctx.restore(); }
// Ajouter les miniatures des images gdv_69b57d108b12dimageUrls.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_69b57d108b12dloadImage(index); gdv_69b57d108b12dcurrentSlideIndex = index; gdv_69b57d108b12dupdateSlideNumber(); }; slide.appendChild(img); gdv_69b57d108b12dthumbnailContainerWrapper.appendChild(slide); });
// Charger une image dans le canvas function gdv_69b57d108b12dloadImage(index) { gdv_69b57d108b12dcurrentImage.src = gdv_69b57d108b12dimageUrls[index]["url"]; gdv_69b57d108b12dimageName.innerHTML = filtrerChaine(gdv_69b57d108b12dimageUrls[index]["name"], "rien"); gdv_69b57d108b12dcurrentImage.onload = function() { gdv_69b57d108b12dscale = 1; gdv_69b57d108b12doriginX = 0; gdv_69b57d108b12doriginY = 0; gdv_69b57d108b12dfitImageToCanvas(); gdv_69b57d108b12ddrawImage(); };
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_69b57d108b12dswiper = new Swiper(".gdv_69b57d108b12dswiper-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_69b57d108b12dswiper.on("slideChange", function () { // gdv_69b57d108b12dcurrentSlideIndex = gdv_69b57d108b12dswiper.activeIndex; // gdv_69b57d108b12dupdateSlideNumber(); //});
// Plein écran gdv_69b57d108b12dfullscreenButton.addEventListener("click", function() { if (!document.fullscreenElement) { document.getElementById("gdv_69b57d108b12dgd-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_69b57d108b12dcanvas.addEventListener("wheel", function(event) { event.preventDefault(); const zoomFactor = 0.025; const mouseX = event.offsetX; const mouseY = event.offsetY;
let newScale = gdv_69b57d108b12dscale; if (event.deltaY < 0) { newScale *= 1 + zoomFactor; } else { newScale /= 1 + zoomFactor; } newScale = Math.max(gdv_69b57d108b12dminScale, Math.min(gdv_69b57d108b12dmaxScale, newScale)); const scaleRatio = newScale / gdv_69b57d108b12dscale; gdv_69b57d108b12doriginX = mouseX - (mouseX - gdv_69b57d108b12doriginX) * scaleRatio; gdv_69b57d108b12doriginY = mouseY - (mouseY - gdv_69b57d108b12doriginY) * scaleRatio; gdv_69b57d108b12dscale = newScale; gdv_69b57d108b12ddrawImage(); }); // Gestion du déplacement (pan) let gdv_69b57d108b12disDragging = false; let gdv_69b57d108b12dstartX, gdv_69b57d108b12dstartY; gdv_69b57d108b12dcanvas.addEventListener("mousedown", function(event) { gdv_69b57d108b12disDragging = true; gdv_69b57d108b12dstartX = event.offsetX - gdv_69b57d108b12doriginX; gdv_69b57d108b12dstartY = event.offsetY - gdv_69b57d108b12doriginY; gdv_69b57d108b12dcanvas.style.cursor = "grabbing"; }); gdv_69b57d108b12dcanvas.addEventListener("mousemove", function(event) { if (gdv_69b57d108b12disDragging) { gdv_69b57d108b12doriginX = event.offsetX - gdv_69b57d108b12dstartX; gdv_69b57d108b12doriginY = event.offsetY - gdv_69b57d108b12dstartY; gdv_69b57d108b12ddrawImage(); } }); // Gestion des événements tactiles gdv_69b57d108b12dcanvas.addEventListener("touchstart", function(event) { if (event.touches.length === 1) { gdv_69b57d108b12disDragging = true; const touch = event.touches[0]; gdv_69b57d108b12dstartX = touch.pageX - gdv_69b57d108b12doriginX; gdv_69b57d108b12dstartY = touch.pageY - gdv_69b57d108b12doriginY; } }); gdv_69b57d108b12dcanvas.addEventListener("touchmove", function(event) { event.preventDefault(); // Empêche le comportement par défaut du navigateur const touch = event.touches[0]; gdv_69b57d108b12doriginX = touch.pageX - gdv_69b57d108b12dstartX; gdv_69b57d108b12doriginY = touch.pageY - gdv_69b57d108b12dstartY; gdv_69b57d108b12ddrawImage(); }); gdv_69b57d108b12dcanvas.addEventListener("touchend", function() { gdv_69b57d108b12disDragging = false; }); gdv_69b57d108b12dcanvas.addEventListener("mouseup", function() { gdv_69b57d108b12disDragging = false; gdv_69b57d108b12dcanvas.style.cursor = "grab"; }); gdv_69b57d108b12dcanvas.addEventListener("mouseleave", function() { gdv_69b57d108b12disDragging = false; gdv_69b57d108b12dcanvas.style.cursor = "grab"; }); gdv_69b57d108b12dzoomInButton.addEventListener("click", function() { let newScale = gdv_69b57d108b12dscale; const zoomFactor = 0.025; newScale *= 1 + zoomFactor; gdv_69b57d108b12dscale = Math.max(gdv_69b57d108b12dminScale, Math.min(gdv_69b57d108b12dmaxScale, newScale)); gdv_69b57d108b12ddrawImage(); }); gdv_69b57d108b12dzoomOutButton.addEventListener("click", function() { let newScale = gdv_69b57d108b12dscale; const zoomFactor = 0.025; newScale /= 1 + zoomFactor; gdv_69b57d108b12dscale = Math.max(gdv_69b57d108b12dminScale, Math.min(gdv_69b57d108b12dmaxScale, newScale)); gdv_69b57d108b12ddrawImage(); }); gdv_69b57d108b12dresetZoomButton.addEventListener("click", function() { gdv_69b57d108b12drotationAngle = 0; gdv_69b57d108b12dfitImageToCanvas(); gdv_69b57d108b12ddrawImage(); }); function gdv_69b57d108b12dgetImageIdFromUrl(url) { const urlObj = new URL(url); return urlObj.searchParams.get("id"); } document.getElementById("gdv_69b57d108b12ddownloadImage").addEventListener("click", function() { let url = gdv_69b57d108b12dcurrentImage.src; const imageId = gdv_69b57d108b12dgetImageIdFromUrl(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_69b57d108b12dprintImageFromApi(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_69b57d108b12dprintButton = document.getElementById("gdv_69b57d108b12dprintCanvas");
gdv_69b57d108b12dprintButton.addEventListener("click", function() { let url = gdv_69b57d108b12dcurrentImage.src; const imageId = gdv_69b57d108b12dgetImageIdFromUrl(url); gdv_69b57d108b12dprintImageFromApi(imageId); });
let gdv_69b57d108b12dinitialDistance = 0; let gdv_69b57d108b12dinitialScale = 1;
gdv_69b57d108b12dcanvas.addEventListener("touchstart", function(event) { if (event.touches.length === 2) { event.preventDefault(); gdv_69b57d108b12dinitialDistance = getDistance(event.touches[0], event.touches[1]); gdv_69b57d108b12dinitialScale = gdv_69b57d108b12dscale; } });
gdv_69b57d108b12dcanvas.addEventListener("touchmove", function(event) { if (event.touches.length === 2) { event.preventDefault(); const currentDistance = getDistance(event.touches[0], event.touches[1]); const scaleChange = currentDistance / gdv_69b57d108b12dinitialDistance; let newScale = gdv_69b57d108b12dinitialScale * scaleChange;
newScale = Math.max(gdv_69b57d108b12dminScale, Math.min(gdv_69b57d108b12dmaxScale, 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_69b57d108b12dscale; gdv_69b57d108b12doriginX = centerX - (centerX - gdv_69b57d108b12doriginX) * scaleRatio; gdv_69b57d108b12doriginY = centerY - (centerY - gdv_69b57d108b12doriginY) * scaleRatio;
gdv_69b57d108b12dscale = newScale; gdv_69b57d108b12ddrawImage(); // 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); }