Spaces:
Running
Running
Update interface.js
Browse files- interface.js +2 -13
interface.js
CHANGED
|
@@ -26,15 +26,12 @@ const currentScriptTag = document.currentScript;
|
|
| 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,10 +39,8 @@ const currentScriptTag = document.currentScript;
|
|
| 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,7 +57,6 @@ const currentScriptTag = document.currentScript;
|
|
| 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,7 +65,6 @@ const currentScriptTag = document.currentScript;
|
|
| 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,7 +103,6 @@ const currentScriptTag = document.currentScript;
|
|
| 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);
|
|
@@ -202,21 +194,18 @@ const currentScriptTag = document.currentScript;
|
|
| 202 |
menuContent.style.display = 'none';
|
| 203 |
}
|
| 204 |
|
| 205 |
-
// 7. Dynamically load viewer.js
|
| 206 |
let viewerModule;
|
| 207 |
try {
|
| 208 |
-
viewerModule = await import('https://mikafil-viewer-
|
| 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';
|
|
|
|
| 26 |
const response = await fetch(configUrl);
|
| 27 |
config = await response.json();
|
| 28 |
} catch (error) {
|
|
|
|
| 29 |
return;
|
| 30 |
}
|
| 31 |
} else {
|
|
|
|
| 32 |
return;
|
| 33 |
}
|
| 34 |
|
|
|
|
| 35 |
if (config.css_url) {
|
| 36 |
const linkEl = document.createElement('link');
|
| 37 |
linkEl.rel = "stylesheet";
|
|
|
|
| 39 |
document.head.appendChild(linkEl);
|
| 40 |
}
|
| 41 |
|
|
|
|
| 42 |
const instanceId = Math.random().toString(36).substr(2, 8);
|
| 43 |
|
|
|
|
| 44 |
let aspectPercent = "100%";
|
| 45 |
if (config.aspect) {
|
| 46 |
if (config.aspect.includes(":")) {
|
|
|
|
| 57 |
}
|
| 58 |
}
|
| 59 |
} else {
|
|
|
|
| 60 |
const parentContainer = scriptTag.parentNode;
|
| 61 |
const containerWidth = parentContainer.offsetWidth;
|
| 62 |
const containerHeight = parentContainer.offsetHeight;
|
|
|
|
| 65 |
}
|
| 66 |
}
|
| 67 |
|
|
|
|
| 68 |
const widgetContainer = document.createElement('div');
|
| 69 |
widgetContainer.id = 'ply-widget-container-' + instanceId;
|
| 70 |
widgetContainer.classList.add('ply-widget-container');
|
|
|
|
| 103 |
|
| 104 |
scriptTag.parentNode.appendChild(widgetContainer);
|
| 105 |
|
|
|
|
| 106 |
const viewerContainerElem = document.getElementById('viewer-container-' + instanceId);
|
| 107 |
const fullscreenToggle = document.getElementById('fullscreen-toggle-' + instanceId);
|
| 108 |
const helpToggle = document.getElementById('help-toggle-' + instanceId);
|
|
|
|
| 194 |
menuContent.style.display = 'none';
|
| 195 |
}
|
| 196 |
|
| 197 |
+
// 7. Dynamically load viewer.js
|
| 198 |
let viewerModule;
|
| 199 |
try {
|
| 200 |
+
viewerModule = await import('https://mikafil-viewer-gs.static.hf.space/viewer.js');
|
| 201 |
await viewerModule.initializeViewer(config, instanceId);
|
| 202 |
} catch (err) {
|
|
|
|
| 203 |
return;
|
| 204 |
}
|
| 205 |
|
|
|
|
| 206 |
const canvasId = 'canvas-' + instanceId;
|
| 207 |
const canvasEl = document.getElementById(canvasId);
|
| 208 |
|
|
|
|
| 209 |
if (tooltipsToggleBtn) {
|
| 210 |
if (!config.tooltips_url) {
|
| 211 |
tooltipsToggleBtn.style.display = 'none';
|