Spaces:
Running
Running
Update interface.js
Browse files- interface.js +11 -195
interface.js
CHANGED
|
@@ -80,11 +80,7 @@ const currentScriptTag = document.currentScript;
|
|
| 80 |
widgetContainer.style.paddingBottom = aspectPercent;
|
| 81 |
widgetContainer.setAttribute('data-original-aspect', aspectPercent);
|
| 82 |
|
| 83 |
-
// Add the 3D-viewer HTML + ⦿ toggle + tooltip
|
| 84 |
-
const tooltipsButtonHTML = config.tooltips_url
|
| 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">
|
|
@@ -95,7 +91,7 @@ const currentScriptTag = document.currentScript;
|
|
| 95 |
<button id="reset-camera-btn-${instanceId}" class="widget-button reset-camera-btn">
|
| 96 |
<span class="reset-icon">⟲</span>
|
| 97 |
</button>
|
| 98 |
-
${
|
| 99 |
<div id="menu-content-${instanceId}" class="menu-content">
|
| 100 |
<span id="help-close-${instanceId}" class="help-close">×</span>
|
| 101 |
<div class="help-text"></div>
|
|
@@ -109,6 +105,8 @@ const currentScriptTag = document.currentScript;
|
|
| 109 |
</div>
|
| 110 |
</div>
|
| 111 |
`;
|
|
|
|
|
|
|
| 112 |
scriptTag.parentNode.appendChild(widgetContainer);
|
| 113 |
|
| 114 |
// ─── 6. Grab references to new DOM elements ──────────────────────────────────
|
|
@@ -136,14 +134,14 @@ const currentScriptTag = document.currentScript;
|
|
| 136 |
? '- Cliquez sur ⦿ pour afficher/masquer les tooltips.<br>'
|
| 137 |
: '';
|
| 138 |
|
| 139 |
-
// Fill help text with
|
| 140 |
if (isMobile) {
|
| 141 |
helpTextDiv.innerHTML = `
|
| 142 |
- Pour vous déplacer, glissez deux doigts sur l'écran.<br>
|
| 143 |
- Pour orbiter, utilisez un doigt.<br>
|
| 144 |
- Pour zoomer, pincez avec deux doigts.<br>
|
| 145 |
-
|
| 146 |
-
|
| 147 |
${tooltipInstruction}
|
| 148 |
`;
|
| 149 |
} else {
|
|
@@ -151,8 +149,8 @@ const currentScriptTag = document.currentScript;
|
|
| 151 |
- orbitez avec le clic droit<br>
|
| 152 |
- zoomez avec la molette<br>
|
| 153 |
- déplacez vous avec le clic gauche<br>
|
| 154 |
-
|
| 155 |
-
|
| 156 |
${tooltipInstruction}
|
| 157 |
`;
|
| 158 |
}
|
|
@@ -161,188 +159,6 @@ const currentScriptTag = document.currentScript;
|
|
| 161 |
menuContent.style.display = 'block';
|
| 162 |
viewerContainerElem.style.display = 'block';
|
| 163 |
|
| 164 |
-
//
|
| 165 |
-
let dragHide = null;
|
| 166 |
-
|
| 167 |
-
// Utility: hide tooltip panel
|
| 168 |
-
function hideTooltipPanel() {
|
| 169 |
-
if (dragHide) {
|
| 170 |
-
viewerContainerElem.removeEventListener('pointermove', dragHide);
|
| 171 |
-
dragHide = null;
|
| 172 |
-
}
|
| 173 |
-
tooltipPanel.style.display = 'none';
|
| 174 |
-
}
|
| 175 |
-
|
| 176 |
-
// Utility: hide help panel
|
| 177 |
-
function hideHelpPanel() {
|
| 178 |
-
menuContent.style.display = 'none';
|
| 179 |
-
}
|
| 180 |
|
| 181 |
-
|
| 182 |
-
let viewerModule;
|
| 183 |
-
try {
|
| 184 |
-
viewerModule = await import('./viewer.js');
|
| 185 |
-
await viewerModule.initializeViewer(config, instanceId);
|
| 186 |
-
} catch (err) {
|
| 187 |
-
console.error("Failed to load viewer.js or initialize the 3D viewer:", err);
|
| 188 |
-
return;
|
| 189 |
-
}
|
| 190 |
-
|
| 191 |
-
// After viewer is ready, grab the canvas element
|
| 192 |
-
const canvasId = 'canvas-' + instanceId;
|
| 193 |
-
const canvasEl = document.getElementById(canvasId);
|
| 194 |
-
|
| 195 |
-
// ─── 8. Conditional display of tooltips-toggle button ─────────────────────────
|
| 196 |
-
if (tooltipsToggleBtn) {
|
| 197 |
-
if (!config.tooltips_url) {
|
| 198 |
-
tooltipsToggleBtn.style.display = 'none';
|
| 199 |
-
} else {
|
| 200 |
-
fetch(config.tooltips_url)
|
| 201 |
-
.then(resp => {
|
| 202 |
-
if (!resp.ok) {
|
| 203 |
-
tooltipsToggleBtn.style.display = 'none';
|
| 204 |
-
}
|
| 205 |
-
})
|
| 206 |
-
.catch(() => {
|
| 207 |
-
tooltipsToggleBtn.style.display = 'none';
|
| 208 |
-
});
|
| 209 |
-
}
|
| 210 |
-
}
|
| 211 |
-
|
| 212 |
-
// ─── 9. Fullscreen / state-preservation logic ───────────────────────────────
|
| 213 |
-
let isFullscreen = false;
|
| 214 |
-
let savedState = null;
|
| 215 |
-
|
| 216 |
-
function saveCurrentState() {
|
| 217 |
-
if (isFullscreen) return;
|
| 218 |
-
const computedWidget = window.getComputedStyle(widgetContainer);
|
| 219 |
-
const computedViewer = window.getComputedStyle(viewerContainerElem);
|
| 220 |
-
const originalAspect = widgetContainer.getAttribute('data-original-aspect') || aspectPercent;
|
| 221 |
-
const containerWidth = widgetContainer.offsetWidth;
|
| 222 |
-
const containerHeight = widgetContainer.clientHeight || viewerContainerElem.offsetHeight;
|
| 223 |
-
const calculatedRatio = (containerHeight / containerWidth * 100) + '%';
|
| 224 |
-
|
| 225 |
-
savedState = {
|
| 226 |
-
widget: {
|
| 227 |
-
position: widgetContainer.style.position,
|
| 228 |
-
top: widgetContainer.style.top,
|
| 229 |
-
left: widgetContainer.style.left,
|
| 230 |
-
width: widgetContainer.style.width,
|
| 231 |
-
height: widgetContainer.style.height,
|
| 232 |
-
maxWidth: widgetContainer.style.maxWidth,
|
| 233 |
-
maxHeight: widgetContainer.style.maxHeight,
|
| 234 |
-
paddingBottom: widgetContainer.style.paddingBottom || originalAspect,
|
| 235 |
-
margin: widgetContainer.style.margin,
|
| 236 |
-
aspectPercent: originalAspect,
|
| 237 |
-
calculatedAspect: calculatedRatio,
|
| 238 |
-
computedWidth: computedWidget.width,
|
| 239 |
-
computedHeight: computedWidget.height,
|
| 240 |
-
offsetWidth: containerWidth,
|
| 241 |
-
offsetHeight: containerHeight
|
| 242 |
-
},
|
| 243 |
-
viewer: {
|
| 244 |
-
borderRadius: viewerContainerElem.style.borderRadius,
|
| 245 |
-
border: viewerContainerElem.style.border,
|
| 246 |
-
computedWidth: computedViewer.width,
|
| 247 |
-
computedHeight: computedViewer.height
|
| 248 |
-
}
|
| 249 |
-
};
|
| 250 |
-
}
|
| 251 |
-
|
| 252 |
-
function restoreOriginalStyles() {
|
| 253 |
-
if (!savedState) return;
|
| 254 |
-
let aspectToUse = aspectPercent;
|
| 255 |
-
if (savedState.widget.offsetWidth && savedState.widget.offsetHeight) {
|
| 256 |
-
const actualRatio = (savedState.widget.offsetHeight / savedState.widget.offsetWidth * 100) + '%';
|
| 257 |
-
aspectToUse = actualRatio;
|
| 258 |
-
} else if (savedState.widget.calculatedAspect) {
|
| 259 |
-
aspectToUse = savedState.widget.calculatedAspect;
|
| 260 |
-
} else if (savedState.widget.aspectPercent) {
|
| 261 |
-
aspectToUse = savedState.widget.aspectPercent;
|
| 262 |
-
} else if (savedState.widget.paddingBottom) {
|
| 263 |
-
aspectToUse = savedState.widget.paddingBottom;
|
| 264 |
-
}
|
| 265 |
-
|
| 266 |
-
widgetContainer.style.position = savedState.widget.position || "";
|
| 267 |
-
widgetContainer.style.top = savedState.widget.top || "";
|
| 268 |
-
widgetContainer.style.left = savedState.widget.left || "";
|
| 269 |
-
widgetContainer.style.width = "100%";
|
| 270 |
-
widgetContainer.style.height = "0";
|
| 271 |
-
widgetContainer.style.maxWidth = savedState.widget.maxWidth || "";
|
| 272 |
-
widgetContainer.style.maxHeight = savedState.widget.maxHeight || "";
|
| 273 |
-
widgetContainer.style.paddingBottom= aspectToUse;
|
| 274 |
-
widgetContainer.style.margin = savedState.widget.margin || "";
|
| 275 |
-
widgetContainer.style.border = savedState.widget.border || "";
|
| 276 |
-
widgetContainer.style.borderRadius = savedState.widget.borderRadius|| "";
|
| 277 |
-
widgetContainer.style.overflow = savedState.widget.overflow || "";
|
| 278 |
-
widgetContainer.classList.remove('fake-fullscreen');
|
| 279 |
-
|
| 280 |
-
viewerContainerElem.style.position = "absolute";
|
| 281 |
-
viewerContainerElem.style.top = "0";
|
| 282 |
-
viewerContainerElem.style.left = "0";
|
| 283 |
-
viewerContainerElem.style.right = "0";
|
| 284 |
-
viewerContainerElem.style.bottom = "0";
|
| 285 |
-
viewerContainerElem.style.width = "100%";
|
| 286 |
-
viewerContainerElem.style.height = "100%";
|
| 287 |
-
viewerContainerElem.style.borderRadius= savedState.viewer.borderRadius || "";
|
| 288 |
-
viewerContainerElem.style.border = savedState.viewer.border || "";
|
| 289 |
-
|
| 290 |
-
if (viewerModule.app) {
|
| 291 |
-
const cw = viewerContainerElem.clientWidth;
|
| 292 |
-
const ch = viewerContainerElem.clientHeight;
|
| 293 |
-
viewerModule.app.resizeCanvas(cw, ch);
|
| 294 |
-
}
|
| 295 |
-
|
| 296 |
-
savedState = null;
|
| 297 |
-
}
|
| 298 |
-
|
| 299 |
-
function applyFullscreenStyles() {
|
| 300 |
-
widgetContainer.style.position = 'fixed';
|
| 301 |
-
widgetContainer.style.top = '0';
|
| 302 |
-
widgetContainer.style.left = '0';
|
| 303 |
-
widgetContainer.style.width = '100vw';
|
| 304 |
-
widgetContainer.style.height = '100vh';
|
| 305 |
-
widgetContainer.style.maxWidth = '100vw';
|
| 306 |
-
widgetContainer.style.maxHeight = '100vh';
|
| 307 |
-
widgetContainer.style.paddingBottom= '0';
|
| 308 |
-
widgetContainer.style.margin = '0';
|
| 309 |
-
widgetContainer.style.border = 'none';
|
| 310 |
-
widgetContainer.style.borderRadius = '0';
|
| 311 |
-
|
| 312 |
-
viewerContainerElem.style.width = '100%';
|
| 313 |
-
viewerContainerElem.style.height = '100%';
|
| 314 |
-
viewerContainerElem.style.borderRadius= '0';
|
| 315 |
-
viewerContainerElem.style.border = 'none';
|
| 316 |
-
|
| 317 |
-
if (viewerModule.app) {
|
| 318 |
-
viewerModule.app.resizeCanvas(window.innerWidth, window.innerHeight);
|
| 319 |
-
}
|
| 320 |
-
|
| 321 |
-
fullscreenToggle.textContent = '⇲';
|
| 322 |
-
isFullscreen = true;
|
| 323 |
-
}
|
| 324 |
-
|
| 325 |
-
function enterFullscreen() {
|
| 326 |
-
if (!savedState) {
|
| 327 |
-
saveCurrentState();
|
| 328 |
-
}
|
| 329 |
-
if (isIOS) {
|
| 330 |
-
applyFullscreenStyles();
|
| 331 |
-
widgetContainer.classList.add('fake-fullscreen');
|
| 332 |
-
} else {
|
| 333 |
-
if (widgetContainer.requestFullscreen) {
|
| 334 |
-
widgetContainer.requestFullscreen()
|
| 335 |
-
.then(() => {
|
| 336 |
-
applyFullscreenStyles();
|
| 337 |
-
})
|
| 338 |
-
.catch(err => {
|
| 339 |
-
console.error("Fullscreen request failed:", err);
|
| 340 |
-
applyFullscreenStyles();
|
| 341 |
-
widgetContainer.classList.add('fake-fullscreen');
|
| 342 |
-
});
|
| 343 |
-
} else if (widgetContainer.webkitRequestFullscreen) {
|
| 344 |
-
widgetContainer.webkitRequestFullscreen();
|
| 345 |
-
applyFullscreenStyles();
|
| 346 |
-
} else if (widgetContainer.mozRequestFullScreen) {
|
| 347 |
-
widgetContainer.mozRequestFullScreen();
|
| 348 |
-
applyFullscreen
|
|
|
|
| 80 |
widgetContainer.style.paddingBottom = aspectPercent;
|
| 81 |
widgetContainer.setAttribute('data-original-aspect', aspectPercent);
|
| 82 |
|
| 83 |
+
// Add the 3D-viewer HTML + ⦿ toggle + tooltip + help HTML
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
widgetContainer.innerHTML = `
|
| 85 |
<div id="viewer-container-${instanceId}" class="viewer-container">
|
| 86 |
<div id="progress-dialog-${instanceId}" class="progress-dialog">
|
|
|
|
| 91 |
<button id="reset-camera-btn-${instanceId}" class="widget-button reset-camera-btn">
|
| 92 |
<span class="reset-icon">⟲</span>
|
| 93 |
</button>
|
| 94 |
+
${config.tooltips_url ? `<button id="tooltips-toggle-${instanceId}" class="widget-button tooltips-toggle">⦿</button>` : ''}
|
| 95 |
<div id="menu-content-${instanceId}" class="menu-content">
|
| 96 |
<span id="help-close-${instanceId}" class="help-close">×</span>
|
| 97 |
<div class="help-text"></div>
|
|
|
|
| 105 |
</div>
|
| 106 |
</div>
|
| 107 |
`;
|
| 108 |
+
|
| 109 |
+
// Append the widget container immediately after the <script> tag
|
| 110 |
scriptTag.parentNode.appendChild(widgetContainer);
|
| 111 |
|
| 112 |
// ─── 6. Grab references to new DOM elements ──────────────────────────────────
|
|
|
|
| 134 |
? '- Cliquez sur ⦿ pour afficher/masquer les tooltips.<br>'
|
| 135 |
: '';
|
| 136 |
|
| 137 |
+
// ─── Fill help text with instructions ────────────────────────────────────────
|
| 138 |
if (isMobile) {
|
| 139 |
helpTextDiv.innerHTML = `
|
| 140 |
- Pour vous déplacer, glissez deux doigts sur l'écran.<br>
|
| 141 |
- Pour orbiter, utilisez un doigt.<br>
|
| 142 |
- Pour zoomer, pincez avec deux doigts.<br>
|
| 143 |
+
⟲ Réinitialise la caméra.<br>
|
| 144 |
+
⇱ Passe en plein écran.<br>
|
| 145 |
${tooltipInstruction}
|
| 146 |
`;
|
| 147 |
} else {
|
|
|
|
| 149 |
- orbitez avec le clic droit<br>
|
| 150 |
- zoomez avec la molette<br>
|
| 151 |
- déplacez vous avec le clic gauche<br>
|
| 152 |
+
⟲ Réinitialise la caméra.<br>
|
| 153 |
+
⇱ Passe en plein écran.<br>
|
| 154 |
${tooltipInstruction}
|
| 155 |
`;
|
| 156 |
}
|
|
|
|
| 159 |
menuContent.style.display = 'block';
|
| 160 |
viewerContainerElem.style.display = 'block';
|
| 161 |
|
| 162 |
+
// ... rest of interface.js unchanged (tooltip-panel logic, viewer.js import, fullscreen, resize, etc.) ...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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