Spaces:
Running
Running
Update interface.js
Browse files- interface.js +105 -124
interface.js
CHANGED
|
@@ -1,31 +1,26 @@
|
|
| 1 |
// interface.js
|
| 2 |
// ==============================
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
await initViewerInstance(scriptTag);
|
| 19 |
-
} catch (e) {
|
| 20 |
-
// Évite qu'une erreur d'instance empêche les autres de se créer
|
| 21 |
-
console.error("[interface.js] Instance init error:", e);
|
| 22 |
-
}
|
| 23 |
}
|
| 24 |
-
}
|
| 25 |
-
}
|
| 26 |
|
| 27 |
async function initViewerInstance(scriptTag) {
|
| 28 |
-
//
|
| 29 |
const configUrl = scriptTag.getAttribute("data-config");
|
| 30 |
if (!configUrl) return;
|
| 31 |
|
|
@@ -38,22 +33,11 @@ async function initViewerInstance(scriptTag) {
|
|
| 38 |
return;
|
| 39 |
}
|
| 40 |
|
| 41 |
-
//
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
config.css_url
|
| 45 |
-
|
| 46 |
-
`link[rel="stylesheet"][href="${(window.CSS && CSS.escape) ? CSS.escape(config.css_url) : config.css_url}"]`
|
| 47 |
-
)
|
| 48 |
-
) {
|
| 49 |
-
const linkEl = document.createElement("link");
|
| 50 |
-
linkEl.rel = "stylesheet";
|
| 51 |
-
linkEl.href = config.css_url;
|
| 52 |
-
document.head.appendChild(linkEl);
|
| 53 |
-
}
|
| 54 |
-
} catch (e) {
|
| 55 |
-
// si CSS.escape indisponible, on ignore la vérif et on insère quand même
|
| 56 |
-
if (config.css_url && !document.querySelector(`link[rel="stylesheet"][href="${config.css_url}"]`)) {
|
| 57 |
const linkEl = document.createElement("link");
|
| 58 |
linkEl.rel = "stylesheet";
|
| 59 |
linkEl.href = config.css_url;
|
|
@@ -61,10 +45,10 @@ async function initViewerInstance(scriptTag) {
|
|
| 61 |
}
|
| 62 |
}
|
| 63 |
|
| 64 |
-
//
|
| 65 |
const instanceId = Math.random().toString(36).substr(2, 8);
|
| 66 |
|
| 67 |
-
//
|
| 68 |
let aspectPercent = "100%";
|
| 69 |
if (config.aspect) {
|
| 70 |
if (config.aspect.includes(":")) {
|
|
@@ -82,14 +66,14 @@ async function initViewerInstance(scriptTag) {
|
|
| 82 |
}
|
| 83 |
} else {
|
| 84 |
const parentContainer = scriptTag.parentNode;
|
| 85 |
-
const containerWidth = parentContainer
|
| 86 |
-
const containerHeight = parentContainer
|
| 87 |
if (containerWidth > 0 && containerHeight > 0) {
|
| 88 |
aspectPercent = (containerHeight / containerWidth) * 100 + "%";
|
| 89 |
}
|
| 90 |
}
|
| 91 |
|
| 92 |
-
//
|
| 93 |
const widgetContainer = document.createElement("div");
|
| 94 |
widgetContainer.id = "ply-widget-container-" + instanceId;
|
| 95 |
widgetContainer.classList.add("ply-widget-container");
|
|
@@ -101,7 +85,6 @@ async function initViewerInstance(scriptTag) {
|
|
| 101 |
? `<button id="tooltips-toggle-${instanceId}" class="widget-button tooltips-toggle">⦿</button>`
|
| 102 |
: "";
|
| 103 |
|
| 104 |
-
// NB: on rend le tooltip-panel unique par instance
|
| 105 |
widgetContainer.innerHTML = `
|
| 106 |
<div id="viewer-container-${instanceId}" class="viewer-container">
|
| 107 |
<div id="progress-dialog-${instanceId}" class="progress-dialog">
|
|
@@ -118,6 +101,7 @@ async function initViewerInstance(scriptTag) {
|
|
| 118 |
<div class="help-text"></div>
|
| 119 |
</div>
|
| 120 |
</div>
|
|
|
|
| 121 |
<div id="tooltip-panel-${instanceId}" class="tooltip-panel" style="display: none;">
|
| 122 |
<div class="tooltip-content">
|
| 123 |
<span id="tooltip-close-${instanceId}" class="tooltip-close">×</span>
|
|
@@ -130,24 +114,25 @@ async function initViewerInstance(scriptTag) {
|
|
| 130 |
// Insérer juste après la balise script courante
|
| 131 |
scriptTag.parentNode.appendChild(widgetContainer);
|
| 132 |
|
| 133 |
-
//
|
| 134 |
const viewerContainerElem = document.getElementById("viewer-container-" + instanceId);
|
| 135 |
-
const fullscreenToggle
|
| 136 |
-
const helpToggle
|
| 137 |
-
const helpCloseBtn
|
| 138 |
-
const resetCameraBtn
|
| 139 |
-
const tooltipsToggleBtn
|
| 140 |
-
const menuContent
|
| 141 |
-
const helpTextDiv
|
| 142 |
-
|
| 143 |
-
const
|
| 144 |
-
const
|
|
|
|
| 145 |
const tooltipCloseBtn = document.getElementById("tooltip-close-" + instanceId);
|
| 146 |
|
| 147 |
-
|
| 148 |
-
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
| 149 |
const isMobile = isIOS || /Android/i.test(navigator.userAgent);
|
| 150 |
|
|
|
|
| 151 |
const tooltipInstruction = config.tooltips_url
|
| 152 |
? "- Cliquez sur ⦿ pour afficher/masquer les tooltips.<br>"
|
| 153 |
: "";
|
|
@@ -170,13 +155,13 @@ async function initViewerInstance(scriptTag) {
|
|
| 170 |
"- Cliquez sur ⇱ pour passer en plein écran.<br>";
|
| 171 |
}
|
| 172 |
|
| 173 |
-
// ---
|
| 174 |
function setMenuContentMaxSize() {
|
| 175 |
if (!isMobile) {
|
| 176 |
-
menuContent.style.maxWidth
|
| 177 |
menuContent.style.maxHeight = "";
|
| 178 |
-
menuContent.style.width
|
| 179 |
-
menuContent.style.height
|
| 180 |
menuContent.style.overflowY = "";
|
| 181 |
menuContent.style.overflowX = "";
|
| 182 |
return;
|
|
@@ -186,14 +171,14 @@ async function initViewerInstance(scriptTag) {
|
|
| 186 |
const vw = parent.offsetWidth;
|
| 187 |
const vh = parent.offsetHeight;
|
| 188 |
if (vw && vh) {
|
| 189 |
-
menuContent.style.maxWidth
|
| 190 |
menuContent.style.maxHeight = Math.round(vh * 0.8) + "px";
|
| 191 |
-
menuContent.style.width
|
| 192 |
-
menuContent.style.height
|
| 193 |
menuContent.style.overflowY = "auto";
|
| 194 |
menuContent.style.overflowX = "auto";
|
| 195 |
} else {
|
| 196 |
-
menuContent.style.maxWidth
|
| 197 |
menuContent.style.maxHeight = "80vh";
|
| 198 |
menuContent.style.overflowY = "auto";
|
| 199 |
menuContent.style.overflowX = "auto";
|
|
@@ -205,12 +190,11 @@ async function initViewerInstance(scriptTag) {
|
|
| 205 |
document.addEventListener("fullscreenchange", setMenuContentMaxSize);
|
| 206 |
window.addEventListener("orientationchange", setMenuContentMaxSize);
|
| 207 |
|
| 208 |
-
// ---
|
| 209 |
menuContent.style.display = "block";
|
| 210 |
viewerContainerElem.style.display = "block";
|
| 211 |
|
| 212 |
-
//
|
| 213 |
-
// -> chaque instance obtient son propre module (et son propre état).
|
| 214 |
let viewerModule;
|
| 215 |
try {
|
| 216 |
const viewerUrl = `https://mikafil-viewer-sgos.static.hf.space/viewer.js?inst=${instanceId}`;
|
|
@@ -224,7 +208,7 @@ async function initViewerInstance(scriptTag) {
|
|
| 224 |
const canvasId = "canvas-" + instanceId;
|
| 225 |
const canvasEl = document.getElementById(canvasId);
|
| 226 |
|
| 227 |
-
//
|
| 228 |
if (tooltipsToggleBtn) {
|
| 229 |
if (!config.tooltips_url) {
|
| 230 |
tooltipsToggleBtn.style.display = "none";
|
|
@@ -239,7 +223,7 @@ async function initViewerInstance(scriptTag) {
|
|
| 239 |
}
|
| 240 |
}
|
| 241 |
|
| 242 |
-
//
|
| 243 |
let dragHide = null;
|
| 244 |
function hideTooltipPanel() {
|
| 245 |
if (dragHide) {
|
|
@@ -256,11 +240,11 @@ async function initViewerInstance(scriptTag) {
|
|
| 256 |
canvasEl.addEventListener("wheel", hideTooltipPanel, { passive: true });
|
| 257 |
}
|
| 258 |
|
| 259 |
-
// NB :
|
| 260 |
-
//
|
| 261 |
-
//
|
| 262 |
document.addEventListener("tooltip-selected", (evt) => {
|
| 263 |
-
//
|
| 264 |
if (dragHide) {
|
| 265 |
viewerContainerElem.removeEventListener("pointermove", dragHide);
|
| 266 |
dragHide = null;
|
|
@@ -270,14 +254,12 @@ async function initViewerInstance(scriptTag) {
|
|
| 270 |
tooltipImage.style.display = "none";
|
| 271 |
tooltipImage.src = "";
|
| 272 |
if (imgUrl) {
|
| 273 |
-
tooltipImage.onload = () => {
|
| 274 |
-
tooltipImage.style.display = "block";
|
| 275 |
-
};
|
| 276 |
tooltipImage.src = imgUrl;
|
| 277 |
}
|
| 278 |
tooltipPanel.style.display = "flex";
|
| 279 |
|
| 280 |
-
// Fermer en cas de drag (
|
| 281 |
setTimeout(() => {
|
| 282 |
dragHide = (e) => {
|
| 283 |
if ((e.pointerType === "mouse" && e.buttons !== 0) || e.pointerType === "touch") {
|
|
@@ -288,6 +270,7 @@ async function initViewerInstance(scriptTag) {
|
|
| 288 |
}, 100);
|
| 289 |
});
|
| 290 |
|
|
|
|
| 291 |
let isFullscreen = false;
|
| 292 |
let savedState = null;
|
| 293 |
|
|
@@ -296,19 +279,19 @@ async function initViewerInstance(scriptTag) {
|
|
| 296 |
const originalAspect = widgetContainer.getAttribute("data-original-aspect") || aspectPercent;
|
| 297 |
savedState = {
|
| 298 |
widget: {
|
| 299 |
-
position:
|
| 300 |
-
top:
|
| 301 |
-
left:
|
| 302 |
-
width:
|
| 303 |
-
height:
|
| 304 |
-
maxWidth:
|
| 305 |
-
maxHeight:
|
| 306 |
-
paddingBottom:
|
| 307 |
-
margin:
|
| 308 |
},
|
| 309 |
viewer: {
|
| 310 |
borderRadius: viewerContainerElem.style.borderRadius,
|
| 311 |
-
border:
|
| 312 |
}
|
| 313 |
};
|
| 314 |
}
|
|
@@ -317,26 +300,26 @@ async function initViewerInstance(scriptTag) {
|
|
| 317 |
if (!savedState) return;
|
| 318 |
const aspectToUse = savedState.widget.paddingBottom;
|
| 319 |
|
| 320 |
-
widgetContainer.style.position
|
| 321 |
-
widgetContainer.style.top
|
| 322 |
-
widgetContainer.style.left
|
| 323 |
-
widgetContainer.style.width
|
| 324 |
-
widgetContainer.style.height
|
| 325 |
-
widgetContainer.style.maxWidth
|
| 326 |
-
widgetContainer.style.maxHeight
|
| 327 |
widgetContainer.style.paddingBottom = aspectToUse;
|
| 328 |
-
widgetContainer.style.margin
|
| 329 |
widgetContainer.classList.remove("fake-fullscreen");
|
| 330 |
|
| 331 |
-
viewerContainerElem.style.position
|
| 332 |
-
viewerContainerElem.style.top
|
| 333 |
-
viewerContainerElem.style.left
|
| 334 |
-
viewerContainerElem.style.right
|
| 335 |
-
viewerContainerElem.style.bottom
|
| 336 |
-
viewerContainerElem.style.width
|
| 337 |
-
viewerContainerElem.style.height
|
| 338 |
viewerContainerElem.style.borderRadius = savedState.viewer.borderRadius || "";
|
| 339 |
-
viewerContainerElem.style.border
|
| 340 |
|
| 341 |
if (viewerModule.app) {
|
| 342 |
viewerModule.app.resizeCanvas(
|
|
@@ -352,22 +335,22 @@ async function initViewerInstance(scriptTag) {
|
|
| 352 |
}
|
| 353 |
|
| 354 |
function applyFullscreenStyles() {
|
| 355 |
-
widgetContainer.style.position
|
| 356 |
-
widgetContainer.style.top
|
| 357 |
-
widgetContainer.style.left
|
| 358 |
-
widgetContainer.style.width
|
| 359 |
-
widgetContainer.style.height
|
| 360 |
-
widgetContainer.style.maxWidth
|
| 361 |
-
widgetContainer.style.maxHeight
|
| 362 |
widgetContainer.style.paddingBottom = "0";
|
| 363 |
-
widgetContainer.style.margin
|
| 364 |
-
widgetContainer.style.border
|
| 365 |
-
widgetContainer.style.borderRadius
|
| 366 |
|
| 367 |
-
viewerContainerElem.style.width
|
| 368 |
-
viewerContainerElem.style.height
|
| 369 |
viewerContainerElem.style.borderRadius = "0";
|
| 370 |
-
viewerContainerElem.style.border
|
| 371 |
|
| 372 |
if (viewerModule.app) {
|
| 373 |
viewerModule.app.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
@@ -424,6 +407,7 @@ async function initViewerInstance(scriptTag) {
|
|
| 424 |
setMenuContentMaxSize();
|
| 425 |
});
|
| 426 |
|
|
|
|
| 427 |
helpToggle.addEventListener("click", (e) => {
|
| 428 |
hideTooltipPanel();
|
| 429 |
e.stopPropagation();
|
|
@@ -443,6 +427,7 @@ async function initViewerInstance(scriptTag) {
|
|
| 443 |
}
|
| 444 |
});
|
| 445 |
|
|
|
|
| 446 |
if (tooltipsToggleBtn) {
|
| 447 |
let tooltipsVisible = !!config.showTooltipsDefault;
|
| 448 |
tooltipsToggleBtn.style.opacity = tooltipsVisible ? "1" : "0.5";
|
|
@@ -458,10 +443,7 @@ async function initViewerInstance(scriptTag) {
|
|
| 458 |
|
| 459 |
tooltipCloseBtn.addEventListener("click", hideTooltipPanel);
|
| 460 |
|
| 461 |
-
|
| 462 |
-
if ((e.key === "Escape" || e.key === "Esc") && isFullscreen) exitFullscreen();
|
| 463 |
-
});
|
| 464 |
-
|
| 465 |
window.addEventListener("resize", () => {
|
| 466 |
if (viewerModule.app) {
|
| 467 |
if (isFullscreen) {
|
|
@@ -476,11 +458,10 @@ async function initViewerInstance(scriptTag) {
|
|
| 476 |
setMenuContentMaxSize();
|
| 477 |
});
|
| 478 |
|
| 479 |
-
// Init par défaut
|
| 480 |
setTimeout(() => {
|
| 481 |
-
// Sauvegarder l'état non-fullscreen courant
|
| 482 |
saveCurrentState();
|
| 483 |
-
// Propager l'état par défaut des tooltips (global
|
| 484 |
document.dispatchEvent(
|
| 485 |
new CustomEvent("toggle-tooltips", { detail: { visible: !!config.showTooltipsDefault } })
|
| 486 |
);
|
|
|
|
| 1 |
// interface.js
|
| 2 |
// ==============================
|
| 3 |
|
| 4 |
+
(async function () {
|
| 5 |
+
// 1) Récupère toutes les balises <script src=".../interface.js" data-config="...">
|
| 6 |
+
const scriptTags = Array.from(
|
| 7 |
+
document.querySelectorAll('script[src*="interface.js"][data-config]')
|
| 8 |
+
);
|
| 9 |
+
if (!scriptTags.length) return;
|
| 10 |
+
|
| 11 |
+
// 2) Initialise un viewer par balise
|
| 12 |
+
for (const scriptTag of scriptTags) {
|
| 13 |
+
try {
|
| 14 |
+
await initViewerInstance(scriptTag);
|
| 15 |
+
} catch (e) {
|
| 16 |
+
// Évite qu'une erreur d'instance empêche les autres de se créer
|
| 17 |
+
console.error("[interface.js] Instance init error:", e);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
}
|
| 19 |
+
}
|
| 20 |
+
})();
|
| 21 |
|
| 22 |
async function initViewerInstance(scriptTag) {
|
| 23 |
+
// --- Lire la config ---
|
| 24 |
const configUrl = scriptTag.getAttribute("data-config");
|
| 25 |
if (!configUrl) return;
|
| 26 |
|
|
|
|
| 33 |
return;
|
| 34 |
}
|
| 35 |
|
| 36 |
+
// --- Injecter la CSS si nécessaire (une seule fois par href absolu) ---
|
| 37 |
+
if (config.css_url) {
|
| 38 |
+
const already = Array.from(document.querySelectorAll('link[rel="stylesheet"]'))
|
| 39 |
+
.some(l => l.href === config.css_url || l.getAttribute("href") === config.css_url);
|
| 40 |
+
if (!already) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
const linkEl = document.createElement("link");
|
| 42 |
linkEl.rel = "stylesheet";
|
| 43 |
linkEl.href = config.css_url;
|
|
|
|
| 45 |
}
|
| 46 |
}
|
| 47 |
|
| 48 |
+
// --- ID unique pour l’instance ---
|
| 49 |
const instanceId = Math.random().toString(36).substr(2, 8);
|
| 50 |
|
| 51 |
+
// --- Calcul de l’aspect ratio ---
|
| 52 |
let aspectPercent = "100%";
|
| 53 |
if (config.aspect) {
|
| 54 |
if (config.aspect.includes(":")) {
|
|
|
|
| 66 |
}
|
| 67 |
} else {
|
| 68 |
const parentContainer = scriptTag.parentNode;
|
| 69 |
+
const containerWidth = parentContainer?.offsetWidth || 0;
|
| 70 |
+
const containerHeight = parentContainer?.offsetHeight || 0;
|
| 71 |
if (containerWidth > 0 && containerHeight > 0) {
|
| 72 |
aspectPercent = (containerHeight / containerWidth) * 100 + "%";
|
| 73 |
}
|
| 74 |
}
|
| 75 |
|
| 76 |
+
// --- Conteneur du widget ---
|
| 77 |
const widgetContainer = document.createElement("div");
|
| 78 |
widgetContainer.id = "ply-widget-container-" + instanceId;
|
| 79 |
widgetContainer.classList.add("ply-widget-container");
|
|
|
|
| 85 |
? `<button id="tooltips-toggle-${instanceId}" class="widget-button tooltips-toggle">⦿</button>`
|
| 86 |
: "";
|
| 87 |
|
|
|
|
| 88 |
widgetContainer.innerHTML = `
|
| 89 |
<div id="viewer-container-${instanceId}" class="viewer-container">
|
| 90 |
<div id="progress-dialog-${instanceId}" class="progress-dialog">
|
|
|
|
| 101 |
<div class="help-text"></div>
|
| 102 |
</div>
|
| 103 |
</div>
|
| 104 |
+
|
| 105 |
<div id="tooltip-panel-${instanceId}" class="tooltip-panel" style="display: none;">
|
| 106 |
<div class="tooltip-content">
|
| 107 |
<span id="tooltip-close-${instanceId}" class="tooltip-close">×</span>
|
|
|
|
| 114 |
// Insérer juste après la balise script courante
|
| 115 |
scriptTag.parentNode.appendChild(widgetContainer);
|
| 116 |
|
| 117 |
+
// --- Références DOM pour cette instance ---
|
| 118 |
const viewerContainerElem = document.getElementById("viewer-container-" + instanceId);
|
| 119 |
+
const fullscreenToggle = document.getElementById("fullscreen-toggle-" + instanceId);
|
| 120 |
+
const helpToggle = document.getElementById("help-toggle-" + instanceId);
|
| 121 |
+
const helpCloseBtn = document.getElementById("help-close-" + instanceId);
|
| 122 |
+
const resetCameraBtn = document.getElementById("reset-camera-btn-" + instanceId);
|
| 123 |
+
const tooltipsToggleBtn = document.getElementById("tooltips-toggle-" + instanceId);
|
| 124 |
+
const menuContent = document.getElementById("menu-content-" + instanceId);
|
| 125 |
+
const helpTextDiv = menuContent.querySelector(".help-text");
|
| 126 |
+
|
| 127 |
+
const tooltipPanel = document.getElementById("tooltip-panel-" + instanceId);
|
| 128 |
+
const tooltipTextDiv = document.getElementById("tooltip-text-" + instanceId);
|
| 129 |
+
const tooltipImage = document.getElementById("tooltip-image-" + instanceId);
|
| 130 |
const tooltipCloseBtn = document.getElementById("tooltip-close-" + instanceId);
|
| 131 |
|
| 132 |
+
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
|
|
|
| 133 |
const isMobile = isIOS || /Android/i.test(navigator.userAgent);
|
| 134 |
|
| 135 |
+
// --- Texte d’aide ---
|
| 136 |
const tooltipInstruction = config.tooltips_url
|
| 137 |
? "- Cliquez sur ⦿ pour afficher/masquer les tooltips.<br>"
|
| 138 |
: "";
|
|
|
|
| 155 |
"- Cliquez sur ⇱ pour passer en plein écran.<br>";
|
| 156 |
}
|
| 157 |
|
| 158 |
+
// --- Taille max du menu d’aide (mobile) ---
|
| 159 |
function setMenuContentMaxSize() {
|
| 160 |
if (!isMobile) {
|
| 161 |
+
menuContent.style.maxWidth = "";
|
| 162 |
menuContent.style.maxHeight = "";
|
| 163 |
+
menuContent.style.width = "";
|
| 164 |
+
menuContent.style.height = "";
|
| 165 |
menuContent.style.overflowY = "";
|
| 166 |
menuContent.style.overflowX = "";
|
| 167 |
return;
|
|
|
|
| 171 |
const vw = parent.offsetWidth;
|
| 172 |
const vh = parent.offsetHeight;
|
| 173 |
if (vw && vh) {
|
| 174 |
+
menuContent.style.maxWidth = Math.round(vw * 0.8) + "px";
|
| 175 |
menuContent.style.maxHeight = Math.round(vh * 0.8) + "px";
|
| 176 |
+
menuContent.style.width = "";
|
| 177 |
+
menuContent.style.height = "";
|
| 178 |
menuContent.style.overflowY = "auto";
|
| 179 |
menuContent.style.overflowX = "auto";
|
| 180 |
} else {
|
| 181 |
+
menuContent.style.maxWidth = "80vw";
|
| 182 |
menuContent.style.maxHeight = "80vh";
|
| 183 |
menuContent.style.overflowY = "auto";
|
| 184 |
menuContent.style.overflowX = "auto";
|
|
|
|
| 190 |
document.addEventListener("fullscreenchange", setMenuContentMaxSize);
|
| 191 |
window.addEventListener("orientationchange", setMenuContentMaxSize);
|
| 192 |
|
| 193 |
+
// --- Panneau d’aide visible par défaut ---
|
| 194 |
menuContent.style.display = "block";
|
| 195 |
viewerContainerElem.style.display = "block";
|
| 196 |
|
| 197 |
+
// --- Charger viewer.js avec un paramètre unique (évite le cache/état partagé) ---
|
|
|
|
| 198 |
let viewerModule;
|
| 199 |
try {
|
| 200 |
const viewerUrl = `https://mikafil-viewer-sgos.static.hf.space/viewer.js?inst=${instanceId}`;
|
|
|
|
| 208 |
const canvasId = "canvas-" + instanceId;
|
| 209 |
const canvasEl = document.getElementById(canvasId);
|
| 210 |
|
| 211 |
+
// --- Bouton Tooltips : cacher si URL invalide ---
|
| 212 |
if (tooltipsToggleBtn) {
|
| 213 |
if (!config.tooltips_url) {
|
| 214 |
tooltipsToggleBtn.style.display = "none";
|
|
|
|
| 223 |
}
|
| 224 |
}
|
| 225 |
|
| 226 |
+
// --- Panneau tooltips (local à l’instance) ---
|
| 227 |
let dragHide = null;
|
| 228 |
function hideTooltipPanel() {
|
| 229 |
if (dragHide) {
|
|
|
|
| 240 |
canvasEl.addEventListener("wheel", hideTooltipPanel, { passive: true });
|
| 241 |
}
|
| 242 |
|
| 243 |
+
// NB : 'tooltip-selected' est global (émis par tooltips.js).
|
| 244 |
+
// Ici, on affiche simplement le panneau local; si plusieurs viewers sont visibles,
|
| 245 |
+
// chacun recevra l’événement (comportement actuel).
|
| 246 |
document.addEventListener("tooltip-selected", (evt) => {
|
| 247 |
+
// Annule un hide différé si présent
|
| 248 |
if (dragHide) {
|
| 249 |
viewerContainerElem.removeEventListener("pointermove", dragHide);
|
| 250 |
dragHide = null;
|
|
|
|
| 254 |
tooltipImage.style.display = "none";
|
| 255 |
tooltipImage.src = "";
|
| 256 |
if (imgUrl) {
|
| 257 |
+
tooltipImage.onload = () => { tooltipImage.style.display = "block"; };
|
|
|
|
|
|
|
| 258 |
tooltipImage.src = imgUrl;
|
| 259 |
}
|
| 260 |
tooltipPanel.style.display = "flex";
|
| 261 |
|
| 262 |
+
// Fermer en cas de drag (petit délai pour éviter flicker)
|
| 263 |
setTimeout(() => {
|
| 264 |
dragHide = (e) => {
|
| 265 |
if ((e.pointerType === "mouse" && e.buttons !== 0) || e.pointerType === "touch") {
|
|
|
|
| 270 |
}, 100);
|
| 271 |
});
|
| 272 |
|
| 273 |
+
// --- Plein écran ---
|
| 274 |
let isFullscreen = false;
|
| 275 |
let savedState = null;
|
| 276 |
|
|
|
|
| 279 |
const originalAspect = widgetContainer.getAttribute("data-original-aspect") || aspectPercent;
|
| 280 |
savedState = {
|
| 281 |
widget: {
|
| 282 |
+
position: widgetContainer.style.position,
|
| 283 |
+
top: widgetContainer.style.top,
|
| 284 |
+
left: widgetContainer.style.left,
|
| 285 |
+
width: widgetContainer.style.width,
|
| 286 |
+
height: widgetContainer.style.height,
|
| 287 |
+
maxWidth: widgetContainer.style.maxWidth,
|
| 288 |
+
maxHeight: widgetContainer.style.maxHeight,
|
| 289 |
+
paddingBottom: widgetContainer.style.paddingBottom || originalAspect,
|
| 290 |
+
margin: widgetContainer.style.margin
|
| 291 |
},
|
| 292 |
viewer: {
|
| 293 |
borderRadius: viewerContainerElem.style.borderRadius,
|
| 294 |
+
border: viewerContainerElem.style.border
|
| 295 |
}
|
| 296 |
};
|
| 297 |
}
|
|
|
|
| 300 |
if (!savedState) return;
|
| 301 |
const aspectToUse = savedState.widget.paddingBottom;
|
| 302 |
|
| 303 |
+
widgetContainer.style.position = savedState.widget.position || "";
|
| 304 |
+
widgetContainer.style.top = savedState.widget.top || "";
|
| 305 |
+
widgetContainer.style.left = savedState.widget.left || "";
|
| 306 |
+
widgetContainer.style.width = "100%";
|
| 307 |
+
widgetContainer.style.height = "0";
|
| 308 |
+
widgetContainer.style.maxWidth = savedState.widget.maxWidth || "";
|
| 309 |
+
widgetContainer.style.maxHeight = savedState.widget.maxHeight || "";
|
| 310 |
widgetContainer.style.paddingBottom = aspectToUse;
|
| 311 |
+
widgetContainer.style.margin = savedState.widget.margin || "";
|
| 312 |
widgetContainer.classList.remove("fake-fullscreen");
|
| 313 |
|
| 314 |
+
viewerContainerElem.style.position = "absolute";
|
| 315 |
+
viewerContainerElem.style.top = "0";
|
| 316 |
+
viewerContainerElem.style.left = "0";
|
| 317 |
+
viewerContainerElem.style.right = "0";
|
| 318 |
+
viewerContainerElem.style.bottom = "0";
|
| 319 |
+
viewerContainerElem.style.width = "100%";
|
| 320 |
+
viewerContainerElem.style.height = "100%";
|
| 321 |
viewerContainerElem.style.borderRadius = savedState.viewer.borderRadius || "";
|
| 322 |
+
viewerContainerElem.style.border = savedState.viewer.border || "";
|
| 323 |
|
| 324 |
if (viewerModule.app) {
|
| 325 |
viewerModule.app.resizeCanvas(
|
|
|
|
| 335 |
}
|
| 336 |
|
| 337 |
function applyFullscreenStyles() {
|
| 338 |
+
widgetContainer.style.position = "fixed";
|
| 339 |
+
widgetContainer.style.top = "0";
|
| 340 |
+
widgetContainer.style.left = "0";
|
| 341 |
+
widgetContainer.style.width = "100vw";
|
| 342 |
+
widgetContainer.style.height = "100vh";
|
| 343 |
+
widgetContainer.style.maxWidth = "100vw";
|
| 344 |
+
widgetContainer.style.maxHeight = "100vh";
|
| 345 |
widgetContainer.style.paddingBottom = "0";
|
| 346 |
+
widgetContainer.style.margin = "0";
|
| 347 |
+
widgetContainer.style.border = "none";
|
| 348 |
+
widgetContainer.style.borderRadius = "0";
|
| 349 |
|
| 350 |
+
viewerContainerElem.style.width = "100%";
|
| 351 |
+
viewerContainerElem.style.height = "100%";
|
| 352 |
viewerContainerElem.style.borderRadius = "0";
|
| 353 |
+
viewerContainerElem.style.border = "none";
|
| 354 |
|
| 355 |
if (viewerModule.app) {
|
| 356 |
viewerModule.app.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
|
|
| 407 |
setMenuContentMaxSize();
|
| 408 |
});
|
| 409 |
|
| 410 |
+
// --- Aide / Reset ---
|
| 411 |
helpToggle.addEventListener("click", (e) => {
|
| 412 |
hideTooltipPanel();
|
| 413 |
e.stopPropagation();
|
|
|
|
| 427 |
}
|
| 428 |
});
|
| 429 |
|
| 430 |
+
// --- Bouton Tooltips ---
|
| 431 |
if (tooltipsToggleBtn) {
|
| 432 |
let tooltipsVisible = !!config.showTooltipsDefault;
|
| 433 |
tooltipsToggleBtn.style.opacity = tooltipsVisible ? "1" : "0.5";
|
|
|
|
| 443 |
|
| 444 |
tooltipCloseBtn.addEventListener("click", hideTooltipPanel);
|
| 445 |
|
| 446 |
+
// --- Redimensionnement ---
|
|
|
|
|
|
|
|
|
|
| 447 |
window.addEventListener("resize", () => {
|
| 448 |
if (viewerModule.app) {
|
| 449 |
if (isFullscreen) {
|
|
|
|
| 458 |
setMenuContentMaxSize();
|
| 459 |
});
|
| 460 |
|
| 461 |
+
// --- Init par défaut ---
|
| 462 |
setTimeout(() => {
|
|
|
|
| 463 |
saveCurrentState();
|
| 464 |
+
// Propager l'état par défaut des tooltips (événement global)
|
| 465 |
document.dispatchEvent(
|
| 466 |
new CustomEvent("toggle-tooltips", { detail: { visible: !!config.showTooltipsDefault } })
|
| 467 |
);
|