MikaFil commited on
Commit
859d13e
·
verified ·
1 Parent(s): 6ac2e40

Update interface.js

Browse files
Files changed (1) hide show
  1. interface.js +68 -66
interface.js CHANGED
@@ -151,36 +151,33 @@ const currentScriptTag = document.currentScript;
151
 
152
  // --- DYNAMIC MENU SIZING ---
153
  function setMenuContentMaxSize() {
154
- // iOS fix: force reflow and update after orientation/fullscreen changes
155
- setTimeout(() => {
156
- if (!isMobile) {
157
- menuContent.style.maxWidth = "";
158
- menuContent.style.maxHeight = "";
159
- menuContent.style.width = "";
160
- menuContent.style.height = "";
161
- menuContent.style.overflowY = "";
162
- menuContent.style.overflowX = "";
163
- return;
164
- }
165
- let parent = viewerContainerElem;
166
- if (parent) {
167
- const vw = parent.offsetWidth;
168
- const vh = parent.offsetHeight;
169
- if (vw && vh) {
170
- menuContent.style.maxWidth = Math.round(vw * 0.8) + "px";
171
- menuContent.style.maxHeight = Math.round(vh * 0.8) + "px";
172
- menuContent.style.width = ""; // Let it shrink if smaller
173
- menuContent.style.height = "";
174
- menuContent.style.overflowY = "auto";
175
- menuContent.style.overflowX = "auto";
176
- } else {
177
- menuContent.style.maxWidth = "80vw";
178
- menuContent.style.maxHeight = "80vh";
179
- menuContent.style.overflowY = "auto";
180
- menuContent.style.overflowX = "auto";
181
- }
182
  }
183
- }, 150); // Delay to allow iOS to finish layout
184
  }
185
  setMenuContentMaxSize();
186
  window.addEventListener('resize', setMenuContentMaxSize);
@@ -189,6 +186,7 @@ const currentScriptTag = document.currentScript;
189
 
190
  // --- HELP PANEL DEFAULT VISIBILITY ---
191
  menuContent.style.display = 'block';
 
192
  viewerContainerElem.style.display = 'block';
193
 
194
  let dragHide = null;
@@ -321,14 +319,8 @@ const currentScriptTag = document.currentScript;
321
  function enterFullscreen() {
322
  if (!savedState) saveCurrentState();
323
  if (isIOS) {
324
- // iOS: Only fake fullscreen is possible, and must trigger resize manually
325
  applyFullscreenStyles();
326
  widgetContainer.classList.add('fake-fullscreen');
327
- setTimeout(() => {
328
- if (viewerModule.app) {
329
- viewerModule.app.resizeCanvas(window.innerWidth, window.innerHeight);
330
- }
331
- }, 200); // Give iOS time to update layout
332
  } else if (widgetContainer.requestFullscreen) {
333
  widgetContainer.requestFullscreen()
334
  .then(applyFullscreenStyles)
@@ -402,28 +394,6 @@ const currentScriptTag = document.currentScript;
402
 
403
  tooltipCloseBtn.addEventListener('click', hideTooltipPanel);
404
 
405
- // --- iOS Pointer Events Fix ---
406
- // iOS sometimes needs explicit touch-action CSS for pointer events
407
- if (isIOS && canvasEl) {
408
- canvasEl.style.touchAction = 'none';
409
- canvasEl.addEventListener('gesturestart', e => e.preventDefault());
410
- canvasEl.addEventListener('gesturechange', e => e.preventDefault());
411
- canvasEl.addEventListener('gestureend', e => e.preventDefault());
412
- }
413
-
414
- // --- iOS: force reflow on orientation change ---
415
- if (isIOS) {
416
- window.addEventListener('orientationchange', () => {
417
- setTimeout(() => {
418
- if (viewerModule.app) {
419
- viewerModule.app.resizeCanvas(window.innerWidth, window.innerHeight);
420
- }
421
- setMenuContentMaxSize();
422
- }, 300);
423
- });
424
- }
425
-
426
- // --- Custom Event Listeners (example for tooltips) ---
427
  document.addEventListener('tooltip-selected', (evt) => {
428
  // Always show panel, cancel hide first
429
  if (dragHide) {
@@ -432,21 +402,53 @@ const currentScriptTag = document.currentScript;
432
  }
433
  const { title, description, imgUrl } = evt.detail;
434
  tooltipTextDiv.innerHTML = `<strong>${title}</strong><br>${description}`;
 
 
 
435
  if (imgUrl) {
 
 
 
436
  tooltipImage.src = imgUrl;
437
- tooltipImage.style.display = 'block';
438
  } else {
439
  tooltipImage.style.display = 'none';
440
  }
441
- tooltipPanel.style.display = 'block';
442
-
443
- // Start drag-to-hide detection
444
- dragHide = function(e) {
445
- if (e.pointerType === 'touch') {
446
- hideTooltipPanel();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
447
  }
448
- };
449
- viewerContainerElem.addEventListener('pointermove', dragHide);
450
  });
451
 
 
 
 
 
 
 
452
  })();
 
151
 
152
  // --- DYNAMIC MENU SIZING ---
153
  function setMenuContentMaxSize() {
154
+ if (!isMobile) {
155
+ menuContent.style.maxWidth = "";
156
+ menuContent.style.maxHeight = "";
157
+ menuContent.style.width = "";
158
+ menuContent.style.height = "";
159
+ menuContent.style.overflowY = "";
160
+ menuContent.style.overflowX = "";
161
+ return;
162
+ }
163
+ let parent = viewerContainerElem;
164
+ if (parent) {
165
+ const vw = parent.offsetWidth;
166
+ const vh = parent.offsetHeight;
167
+ if (vw && vh) {
168
+ menuContent.style.maxWidth = Math.round(vw * 0.8) + "px";
169
+ menuContent.style.maxHeight = Math.round(vh * 0.8) + "px";
170
+ menuContent.style.width = ""; // Let it shrink if smaller
171
+ menuContent.style.height = "";
172
+ menuContent.style.overflowY = "auto";
173
+ menuContent.style.overflowX = "auto";
174
+ } else {
175
+ menuContent.style.maxWidth = "80vw";
176
+ menuContent.style.maxHeight = "80vh";
177
+ menuContent.style.overflowY = "auto";
178
+ menuContent.style.overflowX = "auto";
 
 
 
179
  }
180
+ }
181
  }
182
  setMenuContentMaxSize();
183
  window.addEventListener('resize', setMenuContentMaxSize);
 
186
 
187
  // --- HELP PANEL DEFAULT VISIBILITY ---
188
  menuContent.style.display = 'block';
189
+
190
  viewerContainerElem.style.display = 'block';
191
 
192
  let dragHide = null;
 
319
  function enterFullscreen() {
320
  if (!savedState) saveCurrentState();
321
  if (isIOS) {
 
322
  applyFullscreenStyles();
323
  widgetContainer.classList.add('fake-fullscreen');
 
 
 
 
 
324
  } else if (widgetContainer.requestFullscreen) {
325
  widgetContainer.requestFullscreen()
326
  .then(applyFullscreenStyles)
 
394
 
395
  tooltipCloseBtn.addEventListener('click', hideTooltipPanel);
396
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
397
  document.addEventListener('tooltip-selected', (evt) => {
398
  // Always show panel, cancel hide first
399
  if (dragHide) {
 
402
  }
403
  const { title, description, imgUrl } = evt.detail;
404
  tooltipTextDiv.innerHTML = `<strong>${title}</strong><br>${description}`;
405
+ // Force a repaint: clear src before setting, for repeated images
406
+ tooltipImage.style.display = 'none';
407
+ tooltipImage.src = '';
408
  if (imgUrl) {
409
+ tooltipImage.onload = () => {
410
+ tooltipImage.style.display = 'block';
411
+ };
412
  tooltipImage.src = imgUrl;
 
413
  } else {
414
  tooltipImage.style.display = 'none';
415
  }
416
+ tooltipPanel.style.display = 'flex';
417
+ // --- DELAYED pointermove handler ---
418
+ setTimeout(() => {
419
+ dragHide = (e) => {
420
+ if ((e.pointerType === 'mouse' && e.buttons !== 0) || e.pointerType === 'touch') {
421
+ hideTooltipPanel();
422
+ }
423
+ };
424
+ viewerContainerElem.addEventListener('pointermove', dragHide);
425
+ }, 100);
426
+ });
427
+
428
+ if (canvasEl) {
429
+ canvasEl.addEventListener('wheel', hideTooltipPanel, { passive: true });
430
+ }
431
+ document.addEventListener('keydown', (e) => {
432
+ if ((e.key === 'Escape' || e.key === 'Esc') && isFullscreen) exitFullscreen();
433
+ });
434
+ window.addEventListener('resize', () => {
435
+ if (viewerModule.app) {
436
+ if (isFullscreen) {
437
+ viewerModule.app.resizeCanvas(window.innerWidth, window.innerHeight);
438
+ } else {
439
+ viewerModule.app.resizeCanvas(
440
+ viewerContainerElem.clientWidth,
441
+ viewerContainerElem.clientHeight
442
+ );
443
  }
444
+ }
445
+ setMenuContentMaxSize();
446
  });
447
 
448
+ setTimeout(() => {
449
+ saveCurrentState();
450
+ document.dispatchEvent(new CustomEvent('toggle-tooltips', { detail: { visible: !!config.showTooltipsDefault } }));
451
+ setMenuContentMaxSize();
452
+ }, 200);
453
+
454
  })();