Spaces:
Running
Running
Update interface.js
Browse files- interface.js +17 -18
interface.js
CHANGED
|
@@ -49,11 +49,9 @@ const currentScriptTag = document.currentScript;
|
|
| 49 |
const instanceId = Math.random().toString(36).substr(2, 8);
|
| 50 |
|
| 51 |
// 4) Aspect ratio
|
| 52 |
-
// ββ DΓ©tection mobile anticipΓ©e (isMobile est redΓ©fini proprement en Β§7) ββ
|
| 53 |
const _isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
| 54 |
const _isMobile = _isIOS || /Android/i.test(navigator.userAgent);
|
| 55 |
|
| 56 |
-
// SΓ©lection de la clΓ© d'aspect : mobile-aspect en prioritΓ© sur mobile, sinon aspect
|
| 57 |
const activeAspectValue = (_isMobile && config['mobile-aspect'])
|
| 58 |
? config['mobile-aspect']
|
| 59 |
: config.aspect;
|
|
@@ -94,7 +92,6 @@ const currentScriptTag = document.currentScript;
|
|
| 94 |
? `<button id="tooltips-toggle-${instanceId}" class="widget-button tooltips-toggle">β¦Ώ</button>`
|
| 95 |
: '';
|
| 96 |
|
| 97 |
-
// HTML du widget
|
| 98 |
widgetContainer.innerHTML = `
|
| 99 |
<div id="viewer-container-${instanceId}" class="viewer-container">
|
| 100 |
<div id="progress-dialog-${instanceId}" class="progress-dialog">
|
|
@@ -113,10 +110,9 @@ const currentScriptTag = document.currentScript;
|
|
| 113 |
</div>
|
| 114 |
`;
|
| 115 |
|
| 116 |
-
// InsΓ©rer dans le DOM
|
| 117 |
scriptTag.parentNode.appendChild(widgetContainer);
|
| 118 |
|
| 119 |
-
// 6) RΓ©fΓ©rences DOM
|
| 120 |
const viewerContainerElem = document.getElementById('viewer-container-' + instanceId);
|
| 121 |
const fullscreenToggle = document.getElementById('fullscreen-toggle-' + instanceId);
|
| 122 |
const helpToggle = document.getElementById('help-toggle-' + instanceId);
|
|
@@ -126,7 +122,6 @@ const currentScriptTag = document.currentScript;
|
|
| 126 |
const menuContent = document.getElementById('menu-content-' + instanceId);
|
| 127 |
const helpTextDiv = menuContent.querySelector('.help-text');
|
| 128 |
|
| 129 |
-
// ββ btnRight : false β boutons Γ gauche ββββββββββββββββββββββββββββββββββ
|
| 130 |
if (config.btnRight === false) {
|
| 131 |
viewerContainerElem.classList.add('btn-left');
|
| 132 |
fullscreenToggle.style.display = 'none';
|
|
@@ -196,14 +191,11 @@ const currentScriptTag = document.currentScript;
|
|
| 196 |
|
| 197 |
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 198 |
// 10) Overlay d'annotation
|
| 199 |
-
// Appended dans widgetContainer β fonctionne en fullscreen natif, fake et normal.
|
| 200 |
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 201 |
|
| 202 |
-
// β Overlay principal β
|
| 203 |
const annOverlay = document.createElement('div');
|
| 204 |
annOverlay.className = 'ann-overlay';
|
| 205 |
|
| 206 |
-
// β Modal tooltip β
|
| 207 |
const annTooltip = document.createElement('div');
|
| 208 |
annTooltip.className = 'ann-tooltip';
|
| 209 |
|
|
@@ -230,6 +222,8 @@ const currentScriptTag = document.currentScript;
|
|
| 230 |
// β Footer avec bouton lien β
|
| 231 |
const annFooter = document.createElement('div');
|
| 232 |
annFooter.className = 'ann-footer';
|
|
|
|
|
|
|
| 233 |
const annLinkBtn = document.createElement('button');
|
| 234 |
annLinkBtn.className = 'ann-link-btn';
|
| 235 |
annFooter.appendChild(annLinkBtn);
|
|
@@ -256,12 +250,11 @@ const currentScriptTag = document.currentScript;
|
|
| 256 |
annLbWrap.appendChild(annLbClose);
|
| 257 |
annLightbox.appendChild(annLbWrap);
|
| 258 |
|
| 259 |
-
// Injection dans widgetContainer (fonctionne en fullscreen natif)
|
| 260 |
widgetContainer.appendChild(annOverlay);
|
| 261 |
widgetContainer.appendChild(annLightbox);
|
| 262 |
|
| 263 |
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 264 |
-
// 11) Charger viewer.js
|
| 265 |
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 266 |
let viewerModule;
|
| 267 |
try {
|
|
@@ -300,13 +293,18 @@ const currentScriptTag = document.currentScript;
|
|
| 300 |
menuContent.style.display = 'none';
|
| 301 |
}
|
| 302 |
|
| 303 |
-
// Affichage de l'annotation
|
| 304 |
document.addEventListener('tooltip-selected', (evt) => {
|
| 305 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 306 |
|
| 307 |
annTitle.textContent = title || '';
|
| 308 |
|
| 309 |
-
// Support des sauts de ligne dans la description
|
| 310 |
annBody.innerHTML = (description || '')
|
| 311 |
.replace(/\\n/g, '<br>')
|
| 312 |
.replace(/\n/g, '<br>');
|
|
@@ -325,13 +323,16 @@ const currentScriptTag = document.currentScript;
|
|
| 325 |
annImgWrap.style.display = 'none';
|
| 326 |
}
|
| 327 |
|
| 328 |
-
// Bouton lien
|
| 329 |
if (currentLinkUrl) {
|
| 330 |
annLinkBtn.textContent = linkText || 'En savoir plus';
|
| 331 |
annFooter.style.display = 'flex';
|
|
|
|
| 332 |
} else {
|
| 333 |
annFooter.style.display = 'none';
|
|
|
|
| 334 |
}
|
|
|
|
| 335 |
|
| 336 |
annIsOpen = true;
|
| 337 |
annOverlay.classList.add('ann-open');
|
|
@@ -341,7 +342,7 @@ const currentScriptTag = document.currentScript;
|
|
| 341 |
annCloseBtn.addEventListener('click', (e) => { e.stopPropagation(); hideAnnotation(); });
|
| 342 |
annOverlay.addEventListener('click', (e) => { if (e.target === annOverlay) hideAnnotation(); });
|
| 343 |
|
| 344 |
-
// Lien externe
|
| 345 |
annLinkBtn.addEventListener('click', (e) => {
|
| 346 |
e.stopPropagation();
|
| 347 |
if (currentLinkUrl) window.open(currentLinkUrl, '_blank');
|
|
@@ -444,7 +445,6 @@ const currentScriptTag = document.currentScript;
|
|
| 444 |
viewerContainerElem.style.borderRadius = savedState.viewer.borderRadius || '';
|
| 445 |
viewerContainerElem.style.border = savedState.viewer.border || '';
|
| 446 |
|
| 447 |
-
// ββ Remettre le nΕud Γ sa place d'origine dans le DOM (iOS) ββ
|
| 448 |
if (savedParent) {
|
| 449 |
savedParent.insertBefore(widgetContainer, savedSibling);
|
| 450 |
savedParent = null;
|
|
@@ -542,7 +542,6 @@ const currentScriptTag = document.currentScript;
|
|
| 542 |
setMenuContentMaxSize();
|
| 543 |
});
|
| 544 |
|
| 545 |
-
// ββ Resize : recalcule la hauteur en dvh sur iOS ββ
|
| 546 |
window.addEventListener('resize', () => {
|
| 547 |
if (viewerModule.app) {
|
| 548 |
if (isFullscreen) {
|
|
|
|
| 49 |
const instanceId = Math.random().toString(36).substr(2, 8);
|
| 50 |
|
| 51 |
// 4) Aspect ratio
|
|
|
|
| 52 |
const _isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
| 53 |
const _isMobile = _isIOS || /Android/i.test(navigator.userAgent);
|
| 54 |
|
|
|
|
| 55 |
const activeAspectValue = (_isMobile && config['mobile-aspect'])
|
| 56 |
? config['mobile-aspect']
|
| 57 |
: config.aspect;
|
|
|
|
| 92 |
? `<button id="tooltips-toggle-${instanceId}" class="widget-button tooltips-toggle">β¦Ώ</button>`
|
| 93 |
: '';
|
| 94 |
|
|
|
|
| 95 |
widgetContainer.innerHTML = `
|
| 96 |
<div id="viewer-container-${instanceId}" class="viewer-container">
|
| 97 |
<div id="progress-dialog-${instanceId}" class="progress-dialog">
|
|
|
|
| 110 |
</div>
|
| 111 |
`;
|
| 112 |
|
|
|
|
| 113 |
scriptTag.parentNode.appendChild(widgetContainer);
|
| 114 |
|
| 115 |
+
// 6) RΓ©fΓ©rences DOM
|
| 116 |
const viewerContainerElem = document.getElementById('viewer-container-' + instanceId);
|
| 117 |
const fullscreenToggle = document.getElementById('fullscreen-toggle-' + instanceId);
|
| 118 |
const helpToggle = document.getElementById('help-toggle-' + instanceId);
|
|
|
|
| 122 |
const menuContent = document.getElementById('menu-content-' + instanceId);
|
| 123 |
const helpTextDiv = menuContent.querySelector('.help-text');
|
| 124 |
|
|
|
|
| 125 |
if (config.btnRight === false) {
|
| 126 |
viewerContainerElem.classList.add('btn-left');
|
| 127 |
fullscreenToggle.style.display = 'none';
|
|
|
|
| 191 |
|
| 192 |
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 193 |
// 10) Overlay d'annotation
|
|
|
|
| 194 |
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 195 |
|
|
|
|
| 196 |
const annOverlay = document.createElement('div');
|
| 197 |
annOverlay.className = 'ann-overlay';
|
| 198 |
|
|
|
|
| 199 |
const annTooltip = document.createElement('div');
|
| 200 |
annTooltip.className = 'ann-tooltip';
|
| 201 |
|
|
|
|
| 222 |
// β Footer avec bouton lien β
|
| 223 |
const annFooter = document.createElement('div');
|
| 224 |
annFooter.className = 'ann-footer';
|
| 225 |
+
annFooter.style.display = 'none'; // cachΓ© par dΓ©faut, affichΓ© par JS si linkUrl prΓ©sent
|
| 226 |
+
|
| 227 |
const annLinkBtn = document.createElement('button');
|
| 228 |
annLinkBtn.className = 'ann-link-btn';
|
| 229 |
annFooter.appendChild(annLinkBtn);
|
|
|
|
| 250 |
annLbWrap.appendChild(annLbClose);
|
| 251 |
annLightbox.appendChild(annLbWrap);
|
| 252 |
|
|
|
|
| 253 |
widgetContainer.appendChild(annOverlay);
|
| 254 |
widgetContainer.appendChild(annLightbox);
|
| 255 |
|
| 256 |
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 257 |
+
// 11) Charger viewer.js
|
| 258 |
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 259 |
let viewerModule;
|
| 260 |
try {
|
|
|
|
| 293 |
menuContent.style.display = 'none';
|
| 294 |
}
|
| 295 |
|
|
|
|
| 296 |
document.addEventListener('tooltip-selected', (evt) => {
|
| 297 |
+
const detail = evt.detail || {};
|
| 298 |
+
const { title, description, imgUrl, linkUrl, linkText } = detail;
|
| 299 |
+
|
| 300 |
+
// ββ DEBUG ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 301 |
+
console.log('[interface.js] tooltip-selected reΓ§u β detail complet :', detail);
|
| 302 |
+
console.log(' linkText :', linkText);
|
| 303 |
+
console.log(' linkUrl :', linkUrl);
|
| 304 |
+
// ββββοΏ½οΏ½βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 305 |
|
| 306 |
annTitle.textContent = title || '';
|
| 307 |
|
|
|
|
| 308 |
annBody.innerHTML = (description || '')
|
| 309 |
.replace(/\\n/g, '<br>')
|
| 310 |
.replace(/\n/g, '<br>');
|
|
|
|
| 323 |
annImgWrap.style.display = 'none';
|
| 324 |
}
|
| 325 |
|
| 326 |
+
// ββ Bouton lien ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 327 |
if (currentLinkUrl) {
|
| 328 |
annLinkBtn.textContent = linkText || 'En savoir plus';
|
| 329 |
annFooter.style.display = 'flex';
|
| 330 |
+
console.log('[interface.js] Footer affichΓ© β bouton :', annLinkBtn.textContent);
|
| 331 |
} else {
|
| 332 |
annFooter.style.display = 'none';
|
| 333 |
+
console.log('[interface.js] Footer masquΓ© (linkUrl vide ou absent)');
|
| 334 |
}
|
| 335 |
+
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 336 |
|
| 337 |
annIsOpen = true;
|
| 338 |
annOverlay.classList.add('ann-open');
|
|
|
|
| 342 |
annCloseBtn.addEventListener('click', (e) => { e.stopPropagation(); hideAnnotation(); });
|
| 343 |
annOverlay.addEventListener('click', (e) => { if (e.target === annOverlay) hideAnnotation(); });
|
| 344 |
|
| 345 |
+
// Lien externe
|
| 346 |
annLinkBtn.addEventListener('click', (e) => {
|
| 347 |
e.stopPropagation();
|
| 348 |
if (currentLinkUrl) window.open(currentLinkUrl, '_blank');
|
|
|
|
| 445 |
viewerContainerElem.style.borderRadius = savedState.viewer.borderRadius || '';
|
| 446 |
viewerContainerElem.style.border = savedState.viewer.border || '';
|
| 447 |
|
|
|
|
| 448 |
if (savedParent) {
|
| 449 |
savedParent.insertBefore(widgetContainer, savedSibling);
|
| 450 |
savedParent = null;
|
|
|
|
| 542 |
setMenuContentMaxSize();
|
| 543 |
});
|
| 544 |
|
|
|
|
| 545 |
window.addEventListener('resize', () => {
|
| 546 |
if (viewerModule.app) {
|
| 547 |
if (isFullscreen) {
|