bilca commited on
Commit
fba298f
Β·
verified Β·
1 Parent(s): 6ee6473

Update interface.js

Browse files
Files changed (1) hide show
  1. interface.js +27 -15
interface.js CHANGED
@@ -9,7 +9,6 @@ const currentScriptTag = document.currentScript;
9
  // ─── 1. Locate the <script> and read data-config ───────────────────────────────
10
  let scriptTag = currentScriptTag;
11
  if (!scriptTag) {
12
- // Fallback: scan all <script> tags for one whose src includes "interface.js" and has data-config
13
  const scripts = document.getElementsByTagName('script');
14
  for (let i = 0; i < scripts.length; i++) {
15
  if (scripts[i].src.includes('interface.js') && scripts[i].hasAttribute('data-config')) {
@@ -65,7 +64,6 @@ const currentScriptTag = document.currentScript;
65
  }
66
  }
67
  } else {
68
- // If no aspect in config, base it on the parent’s dimensions
69
  const parentContainer = scriptTag.parentNode;
70
  const containerWidth = parentContainer.offsetWidth;
71
  const containerHeight = parentContainer.offsetHeight;
@@ -74,7 +72,7 @@ const currentScriptTag = document.currentScript;
74
  }
75
  }
76
 
77
- // ─── 5. Create the widget container (no GIF preview anymore) ──────────────────
78
  const widgetContainer = document.createElement('div');
79
  widgetContainer.id = 'ply-widget-container-' + instanceId;
80
  widgetContainer.classList.add('ply-widget-container');
@@ -82,7 +80,7 @@ const currentScriptTag = document.currentScript;
82
  widgetContainer.style.paddingBottom = aspectPercent;
83
  widgetContainer.setAttribute('data-original-aspect', aspectPercent);
84
 
85
- // Insert only the 3D-viewer-related HTML (no GIF portion, no close button):
86
  widgetContainer.innerHTML = `
87
  <div id="viewer-container-${instanceId}" class="viewer-container">
88
  <div id="progress-dialog-${instanceId}" class="progress-dialog">
@@ -90,6 +88,7 @@ const currentScriptTag = document.currentScript;
90
  </div>
91
  <button id="fullscreen-toggle-${instanceId}" class="widget-button fullscreen-toggle">⇱</button>
92
  <button id="help-toggle-${instanceId}" class="widget-button help-toggle">?</button>
 
93
  <button id="reset-camera-btn-${instanceId}" class="widget-button reset-camera-btn">
94
  <span class="reset-icon">⟲</span>
95
  </button>
@@ -97,13 +96,13 @@ const currentScriptTag = document.currentScript;
97
  </div>
98
  `;
99
 
100
- // Append the widget container right after the <script> tag
101
  scriptTag.parentNode.appendChild(widgetContainer);
102
 
103
  // ─── 6. Grab references to newly created DOM elements ─────────────────────────
104
  const viewerContainerElem = document.getElementById('viewer-container-' + instanceId);
105
  const fullscreenToggle = document.getElementById('fullscreen-toggle-' + instanceId);
106
  const helpToggle = document.getElementById('help-toggle-' + instanceId);
 
107
  const resetCameraBtn = document.getElementById('reset-camera-btn-' + instanceId);
108
  const menuContent = document.getElementById('menu-content-' + instanceId);
109
 
@@ -137,13 +136,32 @@ const currentScriptTag = document.currentScript;
137
  return;
138
  }
139
 
140
- // ─── 8. Full-screen / state-saving machinery ─────────────────────────────────
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  let isFullscreen = false;
142
  let savedState = null;
143
 
144
  function saveCurrentState() {
145
- if (isFullscreen) return; // don’t overwrite if already in fullscreen
146
-
147
  const computedWidget = window.getComputedStyle(widgetContainer);
148
  const computedViewer = window.getComputedStyle(viewerContainerElem);
149
  const originalAspect = widgetContainer.getAttribute('data-original-aspect') || aspectPercent;
@@ -181,7 +199,6 @@ const currentScriptTag = document.currentScript;
181
  function restoreOriginalStyles() {
182
  if (!savedState) return;
183
 
184
- // Determine which aspect to use on restore
185
  let aspectToUse = aspectPercent;
186
  if (savedState.widget.offsetWidth && savedState.widget.offsetHeight) {
187
  const actualRatio = (savedState.widget.offsetHeight / savedState.widget.offsetWidth * 100) + '%';
@@ -199,7 +216,7 @@ const currentScriptTag = document.currentScript;
199
  widgetContainer.style.top = savedState.widget.top || "";
200
  widgetContainer.style.left = savedState.widget.left || "";
201
  widgetContainer.style.width = "100%";
202
- widgetContainer.style.height = "0"; // always 0 because we rely on padding-bottom
203
  widgetContainer.style.maxWidth = savedState.widget.maxWidth || "";
204
  widgetContainer.style.maxHeight = savedState.widget.maxHeight || "";
205
  widgetContainer.style.paddingBottom = aspectToUse;
@@ -220,7 +237,6 @@ const currentScriptTag = document.currentScript;
220
  viewerContainerElem.style.borderRadius = savedState.viewer.borderRadius || "";
221
  viewerContainerElem.style.border = savedState.viewer.border || "";
222
 
223
- // If the PlayCanvas app still exists, resize its canvas back to the container’s dimensions
224
  if (viewerModule.app) {
225
  const cw = viewerContainerElem.clientWidth;
226
  const ch = viewerContainerElem.clientHeight;
@@ -255,7 +271,6 @@ const currentScriptTag = document.currentScript;
255
  fullscreenToggle.textContent = '⇲';
256
  isFullscreen = true;
257
 
258
- // After going fullscreen, reset the camera so it fits the new view
259
  if (viewerModule.resetViewerCamera) {
260
  viewerModule.resetViewerCamera();
261
  }
@@ -290,7 +305,6 @@ const currentScriptTag = document.currentScript;
290
  widgetContainer.msRequestFullscreen();
291
  applyFullscreenStyles();
292
  } else {
293
- // Fallback: fake-fullscreen
294
  applyFullscreenStyles();
295
  widgetContainer.classList.add('fake-fullscreen');
296
  }
@@ -320,8 +334,6 @@ const currentScriptTag = document.currentScript;
320
  isFullscreen = false;
321
  }
322
 
323
- // ─── 9. Hook up all event listeners ───────────────────────────────────────────
324
-
325
  // Fullscreen toggle button
326
  fullscreenToggle.addEventListener('click', function() {
327
  if (!isFullscreen) {
 
9
  // ─── 1. Locate the <script> and read data-config ───────────────────────────────
10
  let scriptTag = currentScriptTag;
11
  if (!scriptTag) {
 
12
  const scripts = document.getElementsByTagName('script');
13
  for (let i = 0; i < scripts.length; i++) {
14
  if (scripts[i].src.includes('interface.js') && scripts[i].hasAttribute('data-config')) {
 
64
  }
65
  }
66
  } else {
 
67
  const parentContainer = scriptTag.parentNode;
68
  const containerWidth = parentContainer.offsetWidth;
69
  const containerHeight = parentContainer.offsetHeight;
 
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
+ // Inject only the 3D-viewer-related HTML plus the new "points-toggle" button:
84
  widgetContainer.innerHTML = `
85
  <div id="viewer-container-${instanceId}" class="viewer-container">
86
  <div id="progress-dialog-${instanceId}" class="progress-dialog">
 
88
  </div>
89
  <button id="fullscreen-toggle-${instanceId}" class="widget-button fullscreen-toggle">⇱</button>
90
  <button id="help-toggle-${instanceId}" class="widget-button help-toggle">?</button>
91
+ <button id="points-toggle-${instanceId}" class="widget-button points-toggle">πŸ“</button>
92
  <button id="reset-camera-btn-${instanceId}" class="widget-button reset-camera-btn">
93
  <span class="reset-icon">⟲</span>
94
  </button>
 
96
  </div>
97
  `;
98
 
 
99
  scriptTag.parentNode.appendChild(widgetContainer);
100
 
101
  // ─── 6. Grab references to newly created DOM elements ─────────────────────────
102
  const viewerContainerElem = document.getElementById('viewer-container-' + instanceId);
103
  const fullscreenToggle = document.getElementById('fullscreen-toggle-' + instanceId);
104
  const helpToggle = document.getElementById('help-toggle-' + instanceId);
105
+ const pointsToggle = document.getElementById('points-toggle-' + instanceId);
106
  const resetCameraBtn = document.getElementById('reset-camera-btn-' + instanceId);
107
  const menuContent = document.getElementById('menu-content-' + instanceId);
108
 
 
136
  return;
137
  }
138
 
139
+ // ─── 8. Hook up the new Points‐Toggle logic ───────────────────────────────────
140
+ let pointsVisible = Boolean(config.showPointsDefault);
141
+ // Set initial visibility from config:
142
+ viewerModule.toggleInfopoints(pointsVisible);
143
+ // Style the button to reflect its state (e.g. .active class or opacity):
144
+ if (pointsVisible) {
145
+ pointsToggle.classList.add('active');
146
+ } else {
147
+ pointsToggle.classList.remove('active');
148
+ }
149
+ pointsToggle.addEventListener('click', () => {
150
+ pointsVisible = !pointsVisible;
151
+ viewerModule.toggleInfopoints(pointsVisible);
152
+ if (pointsVisible) {
153
+ pointsToggle.classList.add('active');
154
+ } else {
155
+ pointsToggle.classList.remove('active');
156
+ }
157
+ });
158
+
159
+ // ─── 9. Other UI event listeners (fullscreen, help, reset-camera) ───────────
160
  let isFullscreen = false;
161
  let savedState = null;
162
 
163
  function saveCurrentState() {
164
+ if (isFullscreen) return;
 
165
  const computedWidget = window.getComputedStyle(widgetContainer);
166
  const computedViewer = window.getComputedStyle(viewerContainerElem);
167
  const originalAspect = widgetContainer.getAttribute('data-original-aspect') || aspectPercent;
 
199
  function restoreOriginalStyles() {
200
  if (!savedState) return;
201
 
 
202
  let aspectToUse = aspectPercent;
203
  if (savedState.widget.offsetWidth && savedState.widget.offsetHeight) {
204
  const actualRatio = (savedState.widget.offsetHeight / savedState.widget.offsetWidth * 100) + '%';
 
216
  widgetContainer.style.top = savedState.widget.top || "";
217
  widgetContainer.style.left = savedState.widget.left || "";
218
  widgetContainer.style.width = "100%";
219
+ widgetContainer.style.height = "0";
220
  widgetContainer.style.maxWidth = savedState.widget.maxWidth || "";
221
  widgetContainer.style.maxHeight = savedState.widget.maxHeight || "";
222
  widgetContainer.style.paddingBottom = aspectToUse;
 
237
  viewerContainerElem.style.borderRadius = savedState.viewer.borderRadius || "";
238
  viewerContainerElem.style.border = savedState.viewer.border || "";
239
 
 
240
  if (viewerModule.app) {
241
  const cw = viewerContainerElem.clientWidth;
242
  const ch = viewerContainerElem.clientHeight;
 
271
  fullscreenToggle.textContent = '⇲';
272
  isFullscreen = true;
273
 
 
274
  if (viewerModule.resetViewerCamera) {
275
  viewerModule.resetViewerCamera();
276
  }
 
305
  widgetContainer.msRequestFullscreen();
306
  applyFullscreenStyles();
307
  } else {
 
308
  applyFullscreenStyles();
309
  widgetContainer.classList.add('fake-fullscreen');
310
  }
 
334
  isFullscreen = false;
335
  }
336
 
 
 
337
  // Fullscreen toggle button
338
  fullscreenToggle.addEventListener('click', function() {
339
  if (!isFullscreen) {