Spaces:
Running
Running
Update interface.js
Browse files- interface.js +16 -11
interface.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
// interface.js
|
| 2 |
// ==============================
|
| 3 |
|
| 4 |
-
alert('interface.js loaded!');
|
| 5 |
-
|
| 6 |
const currentScriptTag = document.currentScript;
|
| 7 |
|
| 8 |
(async function() {
|
|
@@ -28,12 +26,15 @@ const currentScriptTag = document.currentScript;
|
|
| 28 |
const response = await fetch(configUrl);
|
| 29 |
config = await response.json();
|
| 30 |
} catch (error) {
|
|
|
|
| 31 |
return;
|
| 32 |
}
|
| 33 |
} else {
|
|
|
|
| 34 |
return;
|
| 35 |
}
|
| 36 |
|
|
|
|
| 37 |
if (config.css_url) {
|
| 38 |
const linkEl = document.createElement('link');
|
| 39 |
linkEl.rel = "stylesheet";
|
|
@@ -41,8 +42,10 @@ const currentScriptTag = document.currentScript;
|
|
| 41 |
document.head.appendChild(linkEl);
|
| 42 |
}
|
| 43 |
|
|
|
|
| 44 |
const instanceId = Math.random().toString(36).substr(2, 8);
|
| 45 |
|
|
|
|
| 46 |
let aspectPercent = "100%";
|
| 47 |
if (config.aspect) {
|
| 48 |
if (config.aspect.includes(":")) {
|
|
@@ -59,6 +62,7 @@ const currentScriptTag = document.currentScript;
|
|
| 59 |
}
|
| 60 |
}
|
| 61 |
} else {
|
|
|
|
| 62 |
const parentContainer = scriptTag.parentNode;
|
| 63 |
const containerWidth = parentContainer.offsetWidth;
|
| 64 |
const containerHeight = parentContainer.offsetHeight;
|
|
@@ -67,6 +71,7 @@ const currentScriptTag = document.currentScript;
|
|
| 67 |
}
|
| 68 |
}
|
| 69 |
|
|
|
|
| 70 |
const widgetContainer = document.createElement('div');
|
| 71 |
widgetContainer.id = 'ply-widget-container-' + instanceId;
|
| 72 |
widgetContainer.classList.add('ply-widget-container');
|
|
@@ -105,6 +110,7 @@ const currentScriptTag = document.currentScript;
|
|
| 105 |
|
| 106 |
scriptTag.parentNode.appendChild(widgetContainer);
|
| 107 |
|
|
|
|
| 108 |
const viewerContainerElem = document.getElementById('viewer-container-' + instanceId);
|
| 109 |
const fullscreenToggle = document.getElementById('fullscreen-toggle-' + instanceId);
|
| 110 |
const helpToggle = document.getElementById('help-toggle-' + instanceId);
|
|
@@ -180,6 +186,7 @@ const currentScriptTag = document.currentScript;
|
|
| 180 |
|
| 181 |
// --- HELP PANEL DEFAULT VISIBILITY ---
|
| 182 |
menuContent.style.display = 'block';
|
|
|
|
| 183 |
viewerContainerElem.style.display = 'block';
|
| 184 |
|
| 185 |
let dragHide = null;
|
|
@@ -195,23 +202,21 @@ const currentScriptTag = document.currentScript;
|
|
| 195 |
menuContent.style.display = 'none';
|
| 196 |
}
|
| 197 |
|
| 198 |
-
// 7. Dynamically load viewer.js
|
| 199 |
let viewerModule;
|
| 200 |
try {
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
alert('interface.js: viewer.js imported, about to call initializeViewer');
|
| 204 |
-
await viewerModule.initializeViewer(config, instanceId);
|
| 205 |
-
alert('interface.js: initializeViewer called');
|
| 206 |
} catch (err) {
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
return;
|
| 210 |
}
|
| 211 |
|
|
|
|
| 212 |
const canvasId = 'canvas-' + instanceId;
|
| 213 |
const canvasEl = document.getElementById(canvasId);
|
| 214 |
|
|
|
|
| 215 |
if (tooltipsToggleBtn) {
|
| 216 |
if (!config.tooltips_url) {
|
| 217 |
tooltipsToggleBtn.style.display = 'none';
|
|
|
|
| 1 |
// interface.js
|
| 2 |
// ==============================
|
| 3 |
|
|
|
|
|
|
|
| 4 |
const currentScriptTag = document.currentScript;
|
| 5 |
|
| 6 |
(async function() {
|
|
|
|
| 26 |
const response = await fetch(configUrl);
|
| 27 |
config = await response.json();
|
| 28 |
} catch (error) {
|
| 29 |
+
console.error("Could not load config: " + error);
|
| 30 |
return;
|
| 31 |
}
|
| 32 |
} else {
|
| 33 |
+
console.error("No configUrl found for viewer");
|
| 34 |
return;
|
| 35 |
}
|
| 36 |
|
| 37 |
+
// 2. Inject CSS if specified
|
| 38 |
if (config.css_url) {
|
| 39 |
const linkEl = document.createElement('link');
|
| 40 |
linkEl.rel = "stylesheet";
|
|
|
|
| 42 |
document.head.appendChild(linkEl);
|
| 43 |
}
|
| 44 |
|
| 45 |
+
// 3. Setup unique instanceId for this widget
|
| 46 |
const instanceId = Math.random().toString(36).substr(2, 8);
|
| 47 |
|
| 48 |
+
// 4. Calculate aspect ratio (for padding-bottom hack)
|
| 49 |
let aspectPercent = "100%";
|
| 50 |
if (config.aspect) {
|
| 51 |
if (config.aspect.includes(":")) {
|
|
|
|
| 62 |
}
|
| 63 |
}
|
| 64 |
} else {
|
| 65 |
+
// fallback: try to use parent container's aspect
|
| 66 |
const parentContainer = scriptTag.parentNode;
|
| 67 |
const containerWidth = parentContainer.offsetWidth;
|
| 68 |
const containerHeight = parentContainer.offsetHeight;
|
|
|
|
| 71 |
}
|
| 72 |
}
|
| 73 |
|
| 74 |
+
// 5. Create the widget container and controls
|
| 75 |
const widgetContainer = document.createElement('div');
|
| 76 |
widgetContainer.id = 'ply-widget-container-' + instanceId;
|
| 77 |
widgetContainer.classList.add('ply-widget-container');
|
|
|
|
| 110 |
|
| 111 |
scriptTag.parentNode.appendChild(widgetContainer);
|
| 112 |
|
| 113 |
+
// 6. Grab references for UI controls
|
| 114 |
const viewerContainerElem = document.getElementById('viewer-container-' + instanceId);
|
| 115 |
const fullscreenToggle = document.getElementById('fullscreen-toggle-' + instanceId);
|
| 116 |
const helpToggle = document.getElementById('help-toggle-' + instanceId);
|
|
|
|
| 186 |
|
| 187 |
// --- HELP PANEL DEFAULT VISIBILITY ---
|
| 188 |
menuContent.style.display = 'block';
|
| 189 |
+
|
| 190 |
viewerContainerElem.style.display = 'block';
|
| 191 |
|
| 192 |
let dragHide = null;
|
|
|
|
| 202 |
menuContent.style.display = 'none';
|
| 203 |
}
|
| 204 |
|
| 205 |
+
// 7. Dynamically load viewer.js (modern ES2024 import, always fresh load)
|
| 206 |
let viewerModule;
|
| 207 |
try {
|
| 208 |
+
viewerModule = await import('https://mikafil-viewer-sgos.static.hf.space/viewer.js?' + Date.now());
|
| 209 |
+
await viewerModule.initializeViewer(config, instanceId);
|
|
|
|
|
|
|
|
|
|
| 210 |
} catch (err) {
|
| 211 |
+
console.error("Could not load viewer.js: " + err);
|
| 212 |
+
return;
|
|
|
|
| 213 |
}
|
| 214 |
|
| 215 |
+
// 8. Canvas reference (for tooltips and resizing)
|
| 216 |
const canvasId = 'canvas-' + instanceId;
|
| 217 |
const canvasEl = document.getElementById(canvasId);
|
| 218 |
|
| 219 |
+
// 9. Tooltips toggle if any
|
| 220 |
if (tooltipsToggleBtn) {
|
| 221 |
if (!config.tooltips_url) {
|
| 222 |
tooltipsToggleBtn.style.display = 'none';
|