Update interface.js
Browse files- interface.js +34 -26
interface.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
// interface.js
|
| 2 |
// ==============================
|
| 3 |
|
|
|
|
| 4 |
const currentScriptTag = document.currentScript;
|
| 5 |
|
| 6 |
(async function() {
|
|
@@ -23,13 +24,15 @@ const currentScriptTag = document.currentScript;
|
|
| 23 |
let config = {};
|
| 24 |
if (configUrl) {
|
| 25 |
try {
|
| 26 |
-
|
| 27 |
-
const response = await fetch(configUrl, { cache: 'no-store' });
|
| 28 |
config = await response.json();
|
| 29 |
} catch (error) {
|
|
|
|
|
|
|
| 30 |
return;
|
| 31 |
}
|
| 32 |
} else {
|
|
|
|
| 33 |
return;
|
| 34 |
}
|
| 35 |
|
|
@@ -69,7 +72,7 @@ const currentScriptTag = document.currentScript;
|
|
| 69 |
}
|
| 70 |
}
|
| 71 |
|
| 72 |
-
// 5. Create the widget container
|
| 73 |
const widgetContainer = document.createElement('div');
|
| 74 |
widgetContainer.id = 'ply-widget-container-' + instanceId;
|
| 75 |
widgetContainer.classList.add('ply-widget-container');
|
|
@@ -77,18 +80,20 @@ const currentScriptTag = document.currentScript;
|
|
| 77 |
widgetContainer.style.paddingBottom = aspectPercent;
|
| 78 |
widgetContainer.setAttribute('data-original-aspect', aspectPercent);
|
| 79 |
|
|
|
|
| 80 |
const tooltipsButtonHTML = config.tooltips_url
|
| 81 |
-
? `<button id="tooltips-toggle-${instanceId}" class="widget-button tooltips-toggle"
|
| 82 |
: '';
|
| 83 |
|
|
|
|
| 84 |
widgetContainer.innerHTML = `
|
| 85 |
<div id="viewer-container-${instanceId}" class="viewer-container">
|
| 86 |
<div id="progress-dialog-${instanceId}" class="progress-dialog">
|
| 87 |
<progress id="progress-indicator-${instanceId}" max="100" value="0"></progress>
|
| 88 |
</div>
|
| 89 |
-
<button id="fullscreen-toggle-${instanceId}" class="widget-button fullscreen-toggle"
|
| 90 |
-
<button id="help-toggle-${instanceId}" class="widget-button help-toggle"
|
| 91 |
-
<button id="reset-camera-btn-${instanceId}" class="widget-button reset-camera-btn"
|
| 92 |
<span class="reset-icon">⟲</span>
|
| 93 |
</button>
|
| 94 |
${tooltipsButtonHTML}
|
|
@@ -106,7 +111,7 @@ const currentScriptTag = document.currentScript;
|
|
| 106 |
</div>
|
| 107 |
`;
|
| 108 |
|
| 109 |
-
// Append the widget container after the <script> tag
|
| 110 |
scriptTag.parentNode.appendChild(widgetContainer);
|
| 111 |
|
| 112 |
// 6. Grab references to new DOM elements
|
|
@@ -118,12 +123,14 @@ const currentScriptTag = document.currentScript;
|
|
| 118 |
const tooltipsToggleBtn = document.getElementById('tooltips-toggle-' + instanceId);
|
| 119 |
const menuContent = document.getElementById('menu-content-' + instanceId);
|
| 120 |
const helpTextDiv = menuContent.querySelector('.help-text');
|
| 121 |
-
const tooltipPanel = document.getElementById('tooltip-panel');
|
| 122 |
-
const tooltipTextDiv = document.getElementById('tooltip-text');
|
| 123 |
-
const tooltipImage = document.getElementById('tooltip-image');
|
| 124 |
-
const tooltipCloseBtn = document.getElementById('tooltip-close');
|
| 125 |
|
| 126 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
| 128 |
const isMobile = isIOS || /Android/i.test(navigator.userAgent);
|
| 129 |
|
|
@@ -132,9 +139,9 @@ const currentScriptTag = document.currentScript;
|
|
| 132 |
? '- Cliquez sur ⦿ pour afficher/masquer les tooltips.<br>'
|
| 133 |
: '';
|
| 134 |
|
| 135 |
-
// Fill help text with instructions plus French lines
|
| 136 |
if (isMobile) {
|
| 137 |
-
helpTextDiv.innerHTML =
|
| 138 |
'- Pour vous déplacer, glissez deux doigts sur l\'écran.<br>' +
|
| 139 |
'- Pour orbiter, utilisez un doigt.<br>' +
|
| 140 |
'- Pour zoomer, pincez avec deux doigts.<br>' +
|
|
@@ -142,7 +149,7 @@ const currentScriptTag = document.currentScript;
|
|
| 142 |
'- ⟲ Réinitialise la caméra.<br>' +
|
| 143 |
'- ⇱ Passe en plein écran.<br>';
|
| 144 |
} else {
|
| 145 |
-
helpTextDiv.innerHTML =
|
| 146 |
'- orbitez avec le clic droit<br>' +
|
| 147 |
'- zoomez avec la molette<br>' +
|
| 148 |
'- déplacez vous avec le clic gauche<br>' +
|
|
@@ -151,12 +158,14 @@ const currentScriptTag = document.currentScript;
|
|
| 151 |
'- ⇱ Passe en plein écran.<br>';
|
| 152 |
}
|
| 153 |
|
| 154 |
-
//
|
| 155 |
menuContent.style.display = 'block';
|
| 156 |
viewerContainerElem.style.display = 'block';
|
| 157 |
|
| 158 |
-
//
|
| 159 |
let dragHide = null;
|
|
|
|
|
|
|
| 160 |
function hideTooltipPanel() {
|
| 161 |
if (dragHide) {
|
| 162 |
viewerContainerElem.removeEventListener('pointermove', dragHide);
|
|
@@ -171,17 +180,17 @@ const currentScriptTag = document.currentScript;
|
|
| 171 |
// 7. Dynamically load viewer.js
|
| 172 |
let viewerModule;
|
| 173 |
try {
|
| 174 |
-
// For iOS: ensure PLY asset loading as ArrayBuffer
|
| 175 |
-
window.PLY_FORCE_ARRAYBUFFER = true;
|
| 176 |
viewerModule = await import('https://mikafil-viewer-gs.static.hf.space/viewer.js');
|
| 177 |
await viewerModule.initializeViewer(config, instanceId);
|
| 178 |
} catch (err) {
|
|
|
|
| 179 |
return;
|
| 180 |
}
|
|
|
|
| 181 |
const canvasId = 'canvas-' + instanceId;
|
| 182 |
const canvasEl = document.getElementById(canvasId);
|
| 183 |
|
| 184 |
-
// 8.
|
| 185 |
if (tooltipsToggleBtn) {
|
| 186 |
if (!config.tooltips_url) {
|
| 187 |
tooltipsToggleBtn.style.display = 'none';
|
|
@@ -217,6 +226,7 @@ const currentScriptTag = document.currentScript;
|
|
| 217 |
}
|
| 218 |
};
|
| 219 |
}
|
|
|
|
| 220 |
function restoreOriginalStyles() {
|
| 221 |
if (!savedState) return;
|
| 222 |
const aspectToUse = savedState.widget.paddingBottom;
|
|
@@ -250,6 +260,7 @@ const currentScriptTag = document.currentScript;
|
|
| 250 |
|
| 251 |
savedState = null;
|
| 252 |
}
|
|
|
|
| 253 |
function applyFullscreenStyles() {
|
| 254 |
widgetContainer.style.position = 'fixed';
|
| 255 |
widgetContainer.style.top = '0';
|
|
@@ -275,6 +286,7 @@ const currentScriptTag = document.currentScript;
|
|
| 275 |
fullscreenToggle.textContent = '⇲';
|
| 276 |
isFullscreen = true;
|
| 277 |
}
|
|
|
|
| 278 |
function enterFullscreen() {
|
| 279 |
if (!savedState) saveCurrentState();
|
| 280 |
if (isIOS) {
|
|
@@ -292,6 +304,7 @@ const currentScriptTag = document.currentScript;
|
|
| 292 |
widgetContainer.classList.add('fake-fullscreen');
|
| 293 |
}
|
| 294 |
}
|
|
|
|
| 295 |
function exitFullscreen() {
|
| 296 |
if (document.fullscreenElement === widgetContainer && document.exitFullscreen) {
|
| 297 |
document.exitFullscreen().catch(() => {});
|
|
@@ -327,16 +340,13 @@ const currentScriptTag = document.currentScript;
|
|
| 327 |
}
|
| 328 |
});
|
| 329 |
|
| 330 |
-
// Tooltips toggle: robust UI state
|
| 331 |
if (tooltipsToggleBtn) {
|
| 332 |
let tooltipsVisible = !!config.showTooltipsDefault;
|
| 333 |
tooltipsToggleBtn.style.opacity = tooltipsVisible ? '1' : '0.5';
|
| 334 |
-
tooltipsToggleBtn.setAttribute('aria-pressed', tooltipsVisible ? 'true' : 'false');
|
| 335 |
tooltipsToggleBtn.addEventListener('click', () => {
|
| 336 |
hideTooltipPanel();
|
| 337 |
tooltipsVisible = !tooltipsVisible;
|
| 338 |
tooltipsToggleBtn.style.opacity = tooltipsVisible ? '1' : '0.5';
|
| 339 |
-
tooltipsToggleBtn.setAttribute('aria-pressed', tooltipsVisible ? 'true' : 'false');
|
| 340 |
document.dispatchEvent(new CustomEvent('toggle-tooltips', { detail: { visible: tooltipsVisible } }));
|
| 341 |
});
|
| 342 |
}
|
|
@@ -361,8 +371,6 @@ const currentScriptTag = document.currentScript;
|
|
| 361 |
viewerContainerElem.addEventListener('pointermove', dragHide);
|
| 362 |
});
|
| 363 |
|
| 364 |
-
document.addEventListener('hide-tooltip', hideTooltipPanel);
|
| 365 |
-
|
| 366 |
if (canvasEl) {
|
| 367 |
canvasEl.addEventListener('wheel', hideTooltipPanel, { passive: true });
|
| 368 |
}
|
|
|
|
| 1 |
// interface.js
|
| 2 |
// ==============================
|
| 3 |
|
| 4 |
+
// Store a reference to the <script> tag that loaded this file
|
| 5 |
const currentScriptTag = document.currentScript;
|
| 6 |
|
| 7 |
(async function() {
|
|
|
|
| 24 |
let config = {};
|
| 25 |
if (configUrl) {
|
| 26 |
try {
|
| 27 |
+
const response = await fetch(configUrl);
|
|
|
|
| 28 |
config = await response.json();
|
| 29 |
} catch (error) {
|
| 30 |
+
// Silent fail, but log in dev environments
|
| 31 |
+
// console.error("Error loading config file:", error);
|
| 32 |
return;
|
| 33 |
}
|
| 34 |
} else {
|
| 35 |
+
// console.error("No config file provided. Please set a data-config attribute on the <script> tag.");
|
| 36 |
return;
|
| 37 |
}
|
| 38 |
|
|
|
|
| 72 |
}
|
| 73 |
}
|
| 74 |
|
| 75 |
+
// 5. Create the widget container (no GIF preview, no close button)
|
| 76 |
const widgetContainer = document.createElement('div');
|
| 77 |
widgetContainer.id = 'ply-widget-container-' + instanceId;
|
| 78 |
widgetContainer.classList.add('ply-widget-container');
|
|
|
|
| 80 |
widgetContainer.style.paddingBottom = aspectPercent;
|
| 81 |
widgetContainer.setAttribute('data-original-aspect', aspectPercent);
|
| 82 |
|
| 83 |
+
// Conditionally include the “tooltips-toggle” button only if config.tooltips_url is defined
|
| 84 |
const tooltipsButtonHTML = config.tooltips_url
|
| 85 |
+
? `<button id="tooltips-toggle-${instanceId}" class="widget-button tooltips-toggle">⦿</button>`
|
| 86 |
: '';
|
| 87 |
|
| 88 |
+
// Add the 3D-viewer HTML + tooltip + help HTML (all HTML in a template literal!)
|
| 89 |
widgetContainer.innerHTML = `
|
| 90 |
<div id="viewer-container-${instanceId}" class="viewer-container">
|
| 91 |
<div id="progress-dialog-${instanceId}" class="progress-dialog">
|
| 92 |
<progress id="progress-indicator-${instanceId}" max="100" value="0"></progress>
|
| 93 |
</div>
|
| 94 |
+
<button id="fullscreen-toggle-${instanceId}" class="widget-button fullscreen-toggle">⇱</button>
|
| 95 |
+
<button id="help-toggle-${instanceId}" class="widget-button help-toggle">?</button>
|
| 96 |
+
<button id="reset-camera-btn-${instanceId}" class="widget-button reset-camera-btn">
|
| 97 |
<span class="reset-icon">⟲</span>
|
| 98 |
</button>
|
| 99 |
${tooltipsButtonHTML}
|
|
|
|
| 111 |
</div>
|
| 112 |
`;
|
| 113 |
|
| 114 |
+
// Append the widget container immediately after the <script> tag
|
| 115 |
scriptTag.parentNode.appendChild(widgetContainer);
|
| 116 |
|
| 117 |
// 6. Grab references to new DOM elements
|
|
|
|
| 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 |
+
// Tooltip panel elements
|
| 128 |
+
const tooltipPanel = document.getElementById('tooltip-panel');
|
| 129 |
+
const tooltipTextDiv = document.getElementById('tooltip-text');
|
| 130 |
+
const tooltipImage = document.getElementById('tooltip-image');
|
| 131 |
+
const tooltipCloseBtn = document.getElementById('tooltip-close');
|
| 132 |
+
|
| 133 |
+
// 6a. Detect mobile vs. desktop
|
| 134 |
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
| 135 |
const isMobile = isIOS || /Android/i.test(navigator.userAgent);
|
| 136 |
|
|
|
|
| 139 |
? '- Cliquez sur ⦿ pour afficher/masquer les tooltips.<br>'
|
| 140 |
: '';
|
| 141 |
|
| 142 |
+
// Fill help text with instructions plus the two new French lines
|
| 143 |
if (isMobile) {
|
| 144 |
+
helpTextDiv.innerHTML =
|
| 145 |
'- Pour vous déplacer, glissez deux doigts sur l\'écran.<br>' +
|
| 146 |
'- Pour orbiter, utilisez un doigt.<br>' +
|
| 147 |
'- Pour zoomer, pincez avec deux doigts.<br>' +
|
|
|
|
| 149 |
'- ⟲ Réinitialise la caméra.<br>' +
|
| 150 |
'- ⇱ Passe en plein écran.<br>';
|
| 151 |
} else {
|
| 152 |
+
helpTextDiv.innerHTML =
|
| 153 |
'- orbitez avec le clic droit<br>' +
|
| 154 |
'- zoomez avec la molette<br>' +
|
| 155 |
'- déplacez vous avec le clic gauche<br>' +
|
|
|
|
| 158 |
'- ⇱ Passe en plein écran.<br>';
|
| 159 |
}
|
| 160 |
|
| 161 |
+
// Ensure instructions panel is visible by default
|
| 162 |
menuContent.style.display = 'block';
|
| 163 |
viewerContainerElem.style.display = 'block';
|
| 164 |
|
| 165 |
+
// Variable to hold the drag-hide listener reference
|
| 166 |
let dragHide = null;
|
| 167 |
+
|
| 168 |
+
// Utilities to hide panels
|
| 169 |
function hideTooltipPanel() {
|
| 170 |
if (dragHide) {
|
| 171 |
viewerContainerElem.removeEventListener('pointermove', dragHide);
|
|
|
|
| 180 |
// 7. Dynamically load viewer.js
|
| 181 |
let viewerModule;
|
| 182 |
try {
|
|
|
|
|
|
|
| 183 |
viewerModule = await import('https://mikafil-viewer-gs.static.hf.space/viewer.js');
|
| 184 |
await viewerModule.initializeViewer(config, instanceId);
|
| 185 |
} catch (err) {
|
| 186 |
+
// Do not break UI, but don't continue
|
| 187 |
return;
|
| 188 |
}
|
| 189 |
+
|
| 190 |
const canvasId = 'canvas-' + instanceId;
|
| 191 |
const canvasEl = document.getElementById(canvasId);
|
| 192 |
|
| 193 |
+
// 8. Conditional display of tooltips-toggle button
|
| 194 |
if (tooltipsToggleBtn) {
|
| 195 |
if (!config.tooltips_url) {
|
| 196 |
tooltipsToggleBtn.style.display = 'none';
|
|
|
|
| 226 |
}
|
| 227 |
};
|
| 228 |
}
|
| 229 |
+
|
| 230 |
function restoreOriginalStyles() {
|
| 231 |
if (!savedState) return;
|
| 232 |
const aspectToUse = savedState.widget.paddingBottom;
|
|
|
|
| 260 |
|
| 261 |
savedState = null;
|
| 262 |
}
|
| 263 |
+
|
| 264 |
function applyFullscreenStyles() {
|
| 265 |
widgetContainer.style.position = 'fixed';
|
| 266 |
widgetContainer.style.top = '0';
|
|
|
|
| 286 |
fullscreenToggle.textContent = '⇲';
|
| 287 |
isFullscreen = true;
|
| 288 |
}
|
| 289 |
+
|
| 290 |
function enterFullscreen() {
|
| 291 |
if (!savedState) saveCurrentState();
|
| 292 |
if (isIOS) {
|
|
|
|
| 304 |
widgetContainer.classList.add('fake-fullscreen');
|
| 305 |
}
|
| 306 |
}
|
| 307 |
+
|
| 308 |
function exitFullscreen() {
|
| 309 |
if (document.fullscreenElement === widgetContainer && document.exitFullscreen) {
|
| 310 |
document.exitFullscreen().catch(() => {});
|
|
|
|
| 340 |
}
|
| 341 |
});
|
| 342 |
|
|
|
|
| 343 |
if (tooltipsToggleBtn) {
|
| 344 |
let tooltipsVisible = !!config.showTooltipsDefault;
|
| 345 |
tooltipsToggleBtn.style.opacity = tooltipsVisible ? '1' : '0.5';
|
|
|
|
| 346 |
tooltipsToggleBtn.addEventListener('click', () => {
|
| 347 |
hideTooltipPanel();
|
| 348 |
tooltipsVisible = !tooltipsVisible;
|
| 349 |
tooltipsToggleBtn.style.opacity = tooltipsVisible ? '1' : '0.5';
|
|
|
|
| 350 |
document.dispatchEvent(new CustomEvent('toggle-tooltips', { detail: { visible: tooltipsVisible } }));
|
| 351 |
});
|
| 352 |
}
|
|
|
|
| 371 |
viewerContainerElem.addEventListener('pointermove', dragHide);
|
| 372 |
});
|
| 373 |
|
|
|
|
|
|
|
| 374 |
if (canvasEl) {
|
| 375 |
canvasEl.addEventListener('wheel', hideTooltipPanel, { passive: true });
|
| 376 |
}
|