MikaFil commited on
Commit
763a290
Β·
verified Β·
1 Parent(s): c00d1eb

Update interface.js

Browse files
Files changed (1) hide show
  1. interface.js +232 -5
interface.js CHANGED
@@ -80,7 +80,12 @@ 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 + help HTML
 
 
 
 
 
84
  widgetContainer.innerHTML = `
85
  <div id="viewer-container-${instanceId}" class="viewer-container">
86
  <div id="progress-dialog-${instanceId}" class="progress-dialog">
@@ -91,7 +96,7 @@ const currentScriptTag = document.currentScript;
91
  <button id="reset-camera-btn-${instanceId}" class="widget-button reset-camera-btn">
92
  <span class="reset-icon">⟲</span>
93
  </button>
94
- <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>
@@ -134,7 +139,7 @@ const currentScriptTag = document.currentScript;
134
  ? '- Cliquez sur β¦Ώ pour afficher/masquer les tooltips.<br>'
135
  : '';
136
 
137
- // Fill help text with appropriate instructions
138
  if (isMobile) {
139
  helpTextDiv.innerHTML = `
140
  - Pour vous dΓ©placer, glissez deux doigts sur l'Γ©cran.<br>
@@ -159,7 +164,20 @@ const currentScriptTag = document.currentScript;
159
  menuContent.style.display = 'block';
160
  viewerContainerElem.style.display = 'block';
161
 
162
- // …rest of your original logic remains unchanged…
 
 
 
 
 
 
 
 
 
 
 
 
 
163
 
164
  // ─── 7. Dynamically load viewer.js ─────────────────────────────────────────
165
  let viewerModule;
@@ -171,5 +189,214 @@ const currentScriptTag = document.currentScript;
171
  return;
172
  }
173
 
174
- // …and so on…
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  })();
 
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
89
  widgetContainer.innerHTML = `
90
  <div id="viewer-container-${instanceId}" class="viewer-container">
91
  <div id="progress-dialog-${instanceId}" class="progress-dialog">
 
96
  <button id="reset-camera-btn-${instanceId}" class="widget-button reset-camera-btn">
97
  <span class="reset-icon">⟲</span>
98
  </button>
99
+ ${tooltipsButtonHTML}
100
  <div id="menu-content-${instanceId}" class="menu-content">
101
  <span id="help-close-${instanceId}" class="help-close">Γ—</span>
102
  <div class="help-text"></div>
 
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>
 
164
  menuContent.style.display = 'block';
165
  viewerContainerElem.style.display = 'block';
166
 
167
+ // Variable to hold the drag-hide listener reference
168
+ let dragHide = null;
169
+
170
+ // Utilities to hide panels
171
+ function hideTooltipPanel() {
172
+ if (dragHide) {
173
+ viewerContainerElem.removeEventListener('pointermove', dragHide);
174
+ dragHide = null;
175
+ }
176
+ tooltipPanel.style.display = 'none';
177
+ }
178
+ function hideHelpPanel() {
179
+ menuContent.style.display = 'none';
180
+ }
181
 
182
  // ─── 7. Dynamically load viewer.js ─────────────────────────────────────────
183
  let viewerModule;
 
189
  return;
190
  }
191
 
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 => { if (!resp.ok) tooltipsToggleBtn.style.display = 'none'; })
202
+ .catch(() => { tooltipsToggleBtn.style.display = 'none'; });
203
+ }
204
+ }
205
+
206
+ // ─── 9. Fullscreen / state-preservation logic ───────────────────────────────
207
+ let isFullscreen = false;
208
+ let savedState = null;
209
+
210
+ function saveCurrentState() {
211
+ if (isFullscreen) return;
212
+ const computedWidget = window.getComputedStyle(widgetContainer);
213
+ const computedViewer = window.getComputedStyle(viewerContainerElem);
214
+ const originalAspect = widgetContainer.getAttribute('data-original-aspect') || aspectPercent;
215
+ const containerWidth = widgetContainer.offsetWidth;
216
+ const containerHeight = widgetContainer.clientHeight || viewerContainerElem.offsetHeight;
217
+ const calculatedRatio = (containerHeight / containerWidth * 100) + '%';
218
+ savedState = {
219
+ widget: {
220
+ position: widgetContainer.style.position,
221
+ top: widgetContainer.style.top,
222
+ left: widgetContainer.style.left,
223
+ width: widgetContainer.style.width,
224
+ height: widgetContainer.style.height,
225
+ maxWidth: widgetContainer.style.maxWidth,
226
+ maxHeight: widgetContainer.style.maxHeight,
227
+ paddingBottom: widgetContainer.style.paddingBottom || originalAspect,
228
+ margin: widgetContainer.style.margin,
229
+ aspectPercent: originalAspect,
230
+ calculatedAspect: calculatedRatio,
231
+ },
232
+ viewer: {
233
+ borderRadius: viewerContainerElem.style.borderRadius,
234
+ border: viewerContainerElem.style.border,
235
+ }
236
+ };
237
+ }
238
+
239
+ function restoreOriginalStyles() {
240
+ if (!savedState) return;
241
+ let aspectToUse = savedState.widget.calculatedAspect || savedState.widget.aspectPercent || savedState.widget.paddingBottom;
242
+ widgetContainer.style.position = savedState.widget.position || "";
243
+ widgetContainer.style.top = savedState.widget.top || "";
244
+ widgetContainer.style.left = savedState.widget.left || "";
245
+ widgetContainer.style.width = "100%";
246
+ widgetContainer.style.height = "0";
247
+ widgetContainer.style.maxWidth = savedState.widget.maxWidth || "";
248
+ widgetContainer.style.maxHeight = savedState.widget.maxHeight || "";
249
+ widgetContainer.style.paddingBottom= aspectToUse;
250
+ widgetContainer.style.margin = savedState.widget.margin || "";
251
+ widgetContainer.classList.remove('fake-fullscreen');
252
+
253
+ viewerContainerElem.style.position = "absolute";
254
+ viewerContainerElem.style.top = "0";
255
+ viewerContainerElem.style.left = "0";
256
+ viewerContainerElem.style.right = "0";
257
+ viewerContainerElem.style.bottom = "0";
258
+ viewerContainerElem.style.width = "100%";
259
+ viewerContainerElem.style.height = "100%";
260
+ viewerContainerElem.style.borderRadius = savedState.viewer.borderRadius || "";
261
+ viewerContainerElem.style.border = savedState.viewer.border || "";
262
+
263
+ if (viewerModule.app) {
264
+ const cw = viewerContainerElem.clientWidth;
265
+ const ch = viewerContainerElem.clientHeight;
266
+ viewerModule.app.resizeCanvas(cw, ch);
267
+ }
268
+ savedState = null;
269
+ }
270
+
271
+ function applyFullscreenStyles() {
272
+ widgetContainer.style.position = 'fixed';
273
+ widgetContainer.style.top = '0';
274
+ widgetContainer.style.left = '0';
275
+ widgetContainer.style.width = '100vw';
276
+ widgetContainer.style.height = '100vh';
277
+ widgetContainer.style.maxWidth = '100vw';
278
+ widgetContainer.style.maxHeight = '100vh';
279
+ widgetContainer.style.paddingBottom = '0';
280
+ widgetContainer.style.margin = '0';
281
+ widgetContainer.style.border = 'none';
282
+ widgetContainer.style.borderRadius = '0';
283
+
284
+ viewerContainerElem.style.width = '100%';
285
+ viewerContainerElem.style.height = '100%';
286
+ viewerContainerElem.style.borderRadius= '0';
287
+ viewerContainerElem.style.border = 'none';
288
+
289
+ if (viewerModule.app) {
290
+ viewerModule.app.resizeCanvas(window.innerWidth, window.innerHeight);
291
+ }
292
+ fullscreenToggle.textContent = '⇲';
293
+ isFullscreen = true;
294
+ }
295
+
296
+ function enterFullscreen() {
297
+ if (!savedState) saveCurrentState();
298
+ if (isIOS) {
299
+ applyFullscreenStyles();
300
+ widgetContainer.classList.add('fake-fullscreen');
301
+ } else if (widgetContainer.requestFullscreen) {
302
+ widgetContainer.requestFullscreen()
303
+ .then(applyFullscreenStyles)
304
+ .catch(() => {
305
+ applyFullscreenStyles();
306
+ widgetContainer.classList.add('fake-fullscreen');
307
+ });
308
+ } else {
309
+ applyFullscreenStyles();
310
+ widgetContainer.classList.add('fake-fullscreen');
311
+ }
312
+ }
313
+
314
+ function exitFullscreen() {
315
+ if (document.fullscreenElement === widgetContainer && document.exitFullscreen) {
316
+ document.exitFullscreen().catch(() => {});
317
+ }
318
+ widgetContainer.classList.remove('fake-fullscreen');
319
+ restoreOriginalStyles();
320
+ isFullscreen = false;
321
+ }
322
+
323
+ // ─── 10. Hook up event listeners ───────────────────────────────────────────
324
+ fullscreenToggle.addEventListener('click', () => {
325
+ hideTooltipPanel();
326
+ isFullscreen ? exitFullscreen() : enterFullscreen();
327
+ });
328
+ document.addEventListener('fullscreenchange', () => {
329
+ if (!document.fullscreenElement && isFullscreen) {
330
+ isFullscreen = false;
331
+ restoreOriginalStyles();
332
+ }
333
+ });
334
+
335
+ helpToggle.addEventListener('click', (e) => {
336
+ hideTooltipPanel();
337
+ e.stopPropagation();
338
+ menuContent.style.display = menuContent.style.display === 'block' ? 'none' : 'block';
339
+ });
340
+ helpCloseBtn.addEventListener('click', hideHelpPanel);
341
+
342
+ resetCameraBtn.addEventListener('click', () => {
343
+ hideTooltipPanel();
344
+ if (viewerModule.resetViewerCamera) {
345
+ viewerModule.resetViewerCamera();
346
+ }
347
+ });
348
+
349
+ if (tooltipsToggleBtn) {
350
+ let tooltipsVisible = !!config.showTooltipsDefault;
351
+ if (!tooltipsVisible) tooltipsToggleBtn.style.opacity = '0.5';
352
+ tooltipsToggleBtn.addEventListener('click', () => {
353
+ hideTooltipPanel();
354
+ tooltipsVisible = !tooltipsVisible;
355
+ tooltipsToggleBtn.style.opacity = tooltipsVisible ? '1' : '0.5';
356
+ document.dispatchEvent(new CustomEvent('toggle-tooltips', { detail: { visible: tooltipsVisible } }));
357
+ });
358
+ }
359
+
360
+ tooltipCloseBtn.addEventListener('click', hideTooltipPanel);
361
+
362
+ document.addEventListener('tooltip-selected', (evt) => {
363
+ const { title, description, imgUrl } = evt.detail;
364
+ tooltipTextDiv.innerHTML = `<strong>${title}</strong><br>${description}`;
365
+ if (imgUrl) {
366
+ tooltipImage.src = imgUrl;
367
+ tooltipImage.style.display = 'block';
368
+ } else {
369
+ tooltipImage.style.display = 'none';
370
+ }
371
+ tooltipPanel.style.display = 'flex';
372
+ dragHide = (e) => {
373
+ if ((e.pointerType === 'mouse' && e.buttons !== 0) || e.pointerType === 'touch') {
374
+ hideTooltipPanel();
375
+ }
376
+ };
377
+ viewerContainerElem.addEventListener('pointermove', dragHide);
378
+ });
379
+
380
+ if (canvasEl) {
381
+ canvasEl.addEventListener('wheel', hideTooltipPanel, { passive: true });
382
+ }
383
+ document.addEventListener('keydown', (e) => {
384
+ if ((e.key === 'Escape' || e.key === 'Esc') && isFullscreen) exitFullscreen();
385
+ });
386
+ window.addEventListener('resize', () => {
387
+ if (viewerModule.app) {
388
+ if (isFullscreen) {
389
+ viewerModule.app.resizeCanvas(window.innerWidth, window.innerHeight);
390
+ } else {
391
+ viewerModule.app.resizeCanvas(viewerContainerElem.clientWidth, viewerContainerElem.clientHeight);
392
+ }
393
+ }
394
+ });
395
+
396
+ // Save β€œinitial state” after a brief delay
397
+ setTimeout(() => {
398
+ saveCurrentState();
399
+ document.dispatchEvent(new CustomEvent('toggle-tooltips', { detail: { visible: !!config.showTooltipsDefault } }));
400
+ }, 200);
401
+
402
  })();