Spaces:
Running
Running
Update interface.js
Browse files- interface.js +42 -22
interface.js
CHANGED
|
@@ -1,23 +1,28 @@
|
|
| 1 |
// interface.js
|
| 2 |
// ==============================
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
)
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
}
|
| 19 |
-
}
|
| 20 |
-
}
|
| 21 |
|
| 22 |
async function initViewerInstance(scriptTag) {
|
| 23 |
// 1) Lire la config
|
|
@@ -34,11 +39,26 @@ async function initViewerInstance(scriptTag) {
|
|
| 34 |
}
|
| 35 |
|
| 36 |
// 2) Injecter la CSS si nécessaire (une seule fois par href)
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
}
|
| 43 |
|
| 44 |
// 3) ID unique pour l’instance
|
|
@@ -124,6 +144,7 @@ async function initViewerInstance(scriptTag) {
|
|
| 124 |
const tooltipImage = document.getElementById("tooltip-image-" + instanceId);
|
| 125 |
const tooltipCloseBtn = document.getElementById("tooltip-close-" + instanceId);
|
| 126 |
|
|
|
|
| 127 |
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
| 128 |
const isMobile = isIOS || /Android/i.test(navigator.userAgent);
|
| 129 |
|
|
@@ -267,7 +288,6 @@ async function initViewerInstance(scriptTag) {
|
|
| 267 |
}, 100);
|
| 268 |
});
|
| 269 |
|
| 270 |
-
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
| 271 |
let isFullscreen = false;
|
| 272 |
let savedState = null;
|
| 273 |
|
|
|
|
| 1 |
// interface.js
|
| 2 |
// ==============================
|
| 3 |
|
| 4 |
+
// Garde global: si ce module a déjà initialisé toutes les balises, on ne refait pas
|
| 5 |
+
if (!window.__PLY_IFACE_INIT_DONE__) {
|
| 6 |
+
window.__PLY_IFACE_INIT_DONE__ = true;
|
| 7 |
+
|
| 8 |
+
(async function () {
|
| 9 |
+
// Trouve toutes les balises <script src=".../interface.js" data-config="...">
|
| 10 |
+
const scriptTags = Array.from(
|
| 11 |
+
document.querySelectorAll('script[type="module"][src*="interface.js"][data-config]')
|
| 12 |
+
);
|
| 13 |
+
if (!scriptTags.length) return;
|
| 14 |
+
|
| 15 |
+
// Initialise une instance par balise
|
| 16 |
+
for (const scriptTag of scriptTags) {
|
| 17 |
+
try {
|
| 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 |
// 1) Lire la config
|
|
|
|
| 39 |
}
|
| 40 |
|
| 41 |
// 2) Injecter la CSS si nécessaire (une seule fois par href)
|
| 42 |
+
try {
|
| 43 |
+
if (
|
| 44 |
+
config.css_url &&
|
| 45 |
+
!document.querySelector(
|
| 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;
|
| 60 |
+
document.head.appendChild(linkEl);
|
| 61 |
+
}
|
| 62 |
}
|
| 63 |
|
| 64 |
// 3) ID unique pour l’instance
|
|
|
|
| 144 |
const tooltipImage = document.getElementById("tooltip-image-" + instanceId);
|
| 145 |
const tooltipCloseBtn = document.getElementById("tooltip-close-" + instanceId);
|
| 146 |
|
| 147 |
+
// Détecteurs (déclarés UNE SEULE FOIS)
|
| 148 |
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
| 149 |
const isMobile = isIOS || /Android/i.test(navigator.userAgent);
|
| 150 |
|
|
|
|
| 288 |
}, 100);
|
| 289 |
});
|
| 290 |
|
|
|
|
| 291 |
let isFullscreen = false;
|
| 292 |
let savedState = null;
|
| 293 |
|