MikaFil commited on
Commit
5b2c1d8
·
verified ·
1 Parent(s): ca2619f

Update interface.js

Browse files
Files changed (1) hide show
  1. interface.js +9 -177
interface.js CHANGED
@@ -80,12 +80,11 @@ const currentScriptTag = document.currentScript;
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 and non-empty
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 + ⦿ toggle + tooltip + help HTML
89
  widgetContainer.innerHTML = `
90
  <div id="viewer-container-${instanceId}" class="viewer-container">
91
  <div id="progress-dialog-${instanceId}" class="progress-dialog">
@@ -110,8 +109,6 @@ const currentScriptTag = document.currentScript;
110
  </div>
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 ──────────────────────────────────
@@ -139,12 +136,14 @@ const currentScriptTag = document.currentScript;
139
  ? '- Cliquez sur ⦿ pour afficher/masquer les tooltips.<br>'
140
  : '';
141
 
142
- // Fill help text with appropriate instructions
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>
 
 
148
  ${tooltipInstruction}
149
  `;
150
  } else {
@@ -152,19 +151,20 @@ const currentScriptTag = document.currentScript;
152
  - orbitez avec le clic droit<br>
153
  - zoomez avec la molette<br>
154
  - déplacez vous avec le clic gauche<br>
 
 
155
  ${tooltipInstruction}
156
  `;
157
  }
158
 
159
  // Ensure instructions panel is visible by default
160
  menuContent.style.display = 'block';
161
-
162
  viewerContainerElem.style.display = 'block';
163
 
164
  // Variable to hold the drag-hide listener reference
165
  let dragHide = null;
166
 
167
- // Utility: hide tooltip and remove drag-hide listener
168
  function hideTooltipPanel() {
169
  if (dragHide) {
170
  viewerContainerElem.removeEventListener('pointermove', dragHide);
@@ -173,7 +173,7 @@ const currentScriptTag = document.currentScript;
173
  tooltipPanel.style.display = 'none';
174
  }
175
 
176
- // Utility: hide instructions panel
177
  function hideHelpPanel() {
178
  menuContent.style.display = 'none';
179
  }
@@ -345,172 +345,4 @@ const currentScriptTag = document.currentScript;
345
  applyFullscreenStyles();
346
  } else if (widgetContainer.mozRequestFullScreen) {
347
  widgetContainer.mozRequestFullScreen();
348
- applyFullscreenStyles();
349
- } else if (widgetContainer.msRequestFullscreen) {
350
- widgetContainer.msRequestFullscreen();
351
- applyFullscreenStyles();
352
- } else {
353
- applyFullscreenStyles();
354
- widgetContainer.classList.add('fake-fullscreen');
355
- }
356
- }
357
- }
358
-
359
- function exitFullscreen() {
360
- if (document.fullscreenElement === widgetContainer) {
361
- if (document.exitFullscreen) {
362
- document.exitFullscreen().catch(err => {
363
- console.error("Error exiting fullscreen:", err);
364
- });
365
- } else if (document.webkitExitFullscreen) {
366
- document.webkitExitFullscreen();
367
- } else if (document.mozCancelFullScreen) {
368
- document.mozCancelFullScreen();
369
- } else if (document.msExitFullscreen) {
370
- document.msExitFullscreen();
371
- }
372
- }
373
-
374
- widgetContainer.classList.remove('fake-fullscreen');
375
- restoreOriginalStyles();
376
- isFullscreen = false;
377
- }
378
-
379
- // ─── 10. Hook up event listeners ───────────────────────────────────────────
380
-
381
- fullscreenToggle.addEventListener('click', () => {
382
- hideTooltipPanel();
383
- if (!isFullscreen) {
384
- enterFullscreen();
385
- } else {
386
- exitFullscreen();
387
- }
388
- });
389
-
390
- document.addEventListener('fullscreenchange', () => {
391
- if (document.fullscreenElement === widgetContainer) {
392
- isFullscreen = true;
393
- applyFullscreenStyles();
394
- } else if (isFullscreen) {
395
- isFullscreen = false;
396
- restoreOriginalStyles();
397
- }
398
- });
399
- document.addEventListener('webkitfullscreenchange', () => {
400
- if (document.webkitFullscreenElement === widgetContainer) {
401
- isFullscreen = true;
402
- applyFullscreenStyles();
403
- } else if (isFullscreen) {
404
- isFullscreen = false;
405
- restoreOriginalStyles();
406
- }
407
- });
408
- document.addEventListener('mozfullscreenchange', () => {
409
- if (document.mozFullScreenElement === widgetContainer) {
410
- isFullscreen = true;
411
- applyFullscreenStyles();
412
- } else if (isFullscreen) {
413
- isFullscreen = false;
414
- restoreOriginalStyles();
415
- }
416
- });
417
- document.addEventListener('MSFullscreenChange', () => {
418
- if (document.msFullscreenElement === widgetContainer) {
419
- isFullscreen = true;
420
- applyFullscreenStyles();
421
- } else if (isFullscreen) {
422
- isFullscreen = false;
423
- restoreOriginalStyles();
424
- }
425
- });
426
-
427
- helpToggle.addEventListener('click', (e) => {
428
- hideTooltipPanel();
429
- e.stopPropagation();
430
- menuContent.style.display = (menuContent.style.display === 'block') ? 'none' : 'block';
431
- });
432
-
433
- helpCloseBtn.addEventListener('click', () => {
434
- hideHelpPanel();
435
- });
436
-
437
- resetCameraBtn.addEventListener('click', () => {
438
- hideTooltipPanel();
439
- if (viewerModule.resetViewerCamera) {
440
- viewerModule.resetViewerCamera();
441
- }
442
- });
443
-
444
- // ⦿ toggle button: only if it exists in the DOM
445
- let tooltipsVisible = !!config.showTooltipsDefault;
446
- if (tooltipsToggleBtn && tooltipsToggleBtn.style.display !== 'none') {
447
- if (!tooltipsVisible) {
448
- tooltipsToggleBtn.style.opacity = '0.5';
449
- }
450
- tooltipsToggleBtn.addEventListener('click', () => {
451
- hideTooltipPanel();
452
- tooltipsVisible = !tooltipsVisible;
453
- tooltipsToggleBtn.style.opacity = tooltipsVisible ? '1' : '0.5';
454
- document.dispatchEvent(new CustomEvent('toggle-tooltips', { detail: { visible: tooltipsVisible } }));
455
- });
456
- }
457
-
458
- // Close tooltip panel on button click
459
- tooltipCloseBtn.addEventListener('click', () => {
460
- hideTooltipPanel();
461
- });
462
-
463
- // Listen for tooltip-selection events and show tooltip panel
464
- document.addEventListener('tooltip-selected', (evt) => {
465
- const { title, description, imgUrl } = evt.detail;
466
- tooltipTextDiv.innerHTML = `<strong>${title}</strong><br>${description}`;
467
- if (imgUrl) {
468
- tooltipImage.src = imgUrl;
469
- tooltipImage.style.display = 'block';
470
- } else {
471
- tooltipImage.style.display = 'none';
472
- }
473
- tooltipPanel.style.display = 'flex';
474
-
475
- // Attach drag-based hide listener
476
- dragHide = (e) => {
477
- if ((e.pointerType === 'mouse' && e.buttons !== 0) ||
478
- (e.pointerType === 'touch')) {
479
- hideTooltipPanel();
480
- }
481
- };
482
- viewerContainerElem.addEventListener('pointermove', dragHide);
483
- });
484
-
485
- // Hide on any wheel event (zoom)
486
- if (canvasEl) {
487
- canvasEl.addEventListener('wheel', () => {
488
- hideTooltipPanel();
489
- }, { passive: true });
490
- }
491
-
492
- // Escape key also exits fullscreen
493
- document.addEventListener('keydown', (e) => {
494
- if ((e.key === 'Escape' || e.key === 'Esc') && isFullscreen) {
495
- exitFullscreen();
496
- }
497
- });
498
-
499
- // Window resize → resize PlayCanvas canvas
500
- window.addEventListener('resize', () => {
501
- if (isFullscreen && viewerModule.app) {
502
- viewerModule.app.resizeCanvas(window.innerWidth, window.innerHeight);
503
- } else if (viewerModule.app) {
504
- const cw = viewerContainerElem.clientWidth;
505
- const ch = viewerContainerElem.clientHeight;
506
- viewerModule.app.resizeCanvas(cw, ch);
507
- }
508
- });
509
-
510
- // Save “initial state” after a brief delay
511
- setTimeout(() => {
512
- saveCurrentState();
513
- document.dispatchEvent(new CustomEvent('toggle-tooltips', { detail: { visible: tooltipsVisible } }));
514
- }, 200);
515
-
516
- })();
 
80
  widgetContainer.style.paddingBottom = aspectPercent;
81
  widgetContainer.setAttribute('data-original-aspect', aspectPercent);
82
 
83
+ // Add the 3D-viewer HTML + ⦿ toggle + tooltip panel + help panel
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">
 
109
  </div>
110
  </div>
111
  `;
 
 
112
  scriptTag.parentNode.appendChild(widgetContainer);
113
 
114
  // ─── 6. Grab references to new DOM elements ──────────────────────────────────
 
136
  ? '- Cliquez sur ⦿ pour afficher/masquer les tooltips.<br>'
137
  : '';
138
 
139
+ // Fill help text with appropriate instructions, including new lines for reset & fullscreen
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
+ - ⟲ Réinitialise la caméra.<br>
146
+ - ⇱ Passe en plein écran.<br>
147
  ${tooltipInstruction}
148
  `;
149
  } else {
 
151
  - orbitez avec le clic droit<br>
152
  - zoomez avec la molette<br>
153
  - déplacez vous avec le clic gauche<br>
154
+ - ⟲ Réinitialise la caméra.<br>
155
+ - ⇱ Passe en plein écran.<br>
156
  ${tooltipInstruction}
157
  `;
158
  }
159
 
160
  // Ensure instructions panel is visible by default
161
  menuContent.style.display = 'block';
 
162
  viewerContainerElem.style.display = 'block';
163
 
164
  // Variable to hold the drag-hide listener reference
165
  let dragHide = null;
166
 
167
+ // Utility: hide tooltip panel
168
  function hideTooltipPanel() {
169
  if (dragHide) {
170
  viewerContainerElem.removeEventListener('pointermove', dragHide);
 
173
  tooltipPanel.style.display = 'none';
174
  }
175
 
176
+ // Utility: hide help panel
177
  function hideHelpPanel() {
178
  menuContent.style.display = 'none';
179
  }
 
345
  applyFullscreenStyles();
346
  } else if (widgetContainer.mozRequestFullScreen) {
347
  widgetContainer.mozRequestFullScreen();
348
+ applyFullscreen