Spaces:
Running
Running
Update interface.js
Browse files- interface.js +28 -63
interface.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
| 5 |
const currentScriptTag = document.currentScript;
|
| 6 |
|
| 7 |
(async function() {
|
| 8 |
-
// βββ 1. Locate <script> and load config
|
| 9 |
let scriptTag = currentScriptTag;
|
| 10 |
if (!scriptTag) {
|
| 11 |
const scripts = document.getElementsByTagName('script');
|
|
@@ -20,38 +20,45 @@ const currentScriptTag = document.currentScript;
|
|
| 20 |
|
| 21 |
const configUrl = scriptTag.getAttribute('data-config');
|
| 22 |
if (!configUrl) {
|
| 23 |
-
console.error("No data-config on <script>");
|
| 24 |
return;
|
| 25 |
}
|
| 26 |
let config = {};
|
| 27 |
try {
|
| 28 |
const resp = await fetch(configUrl);
|
| 29 |
config = await resp.json();
|
| 30 |
-
} catch (
|
| 31 |
-
console.error("
|
| 32 |
return;
|
| 33 |
}
|
| 34 |
|
| 35 |
-
// βββ 2.
|
| 36 |
if (config.css_url) {
|
| 37 |
-
const
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
document.head.appendChild(
|
| 41 |
}
|
| 42 |
|
| 43 |
-
// βββ 3.
|
| 44 |
const instanceId = Math.random().toString(36).substr(2, 8);
|
|
|
|
|
|
|
| 45 |
const widgetContainer = document.createElement('div');
|
| 46 |
-
widgetContainer.id =
|
| 47 |
widgetContainer.classList.add('ply-widget-container');
|
| 48 |
-
document.body.appendChild(widgetContainer);
|
| 49 |
|
| 50 |
-
// βββ
|
| 51 |
widgetContainer.innerHTML = `
|
| 52 |
-
<div id="viewer-container-${instanceId}" class="viewer-container"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
<!--
|
| 55 |
<button id="fullscreen-toggle-${instanceId}" class="widget-button fullscreen-toggle">β±</button>
|
| 56 |
<button id="help-toggle-${instanceId}" class="widget-button help-toggle">?</button>
|
| 57 |
<button id="reset-camera-btn-${instanceId}" class="widget-button reset-camera-btn">β²</button>
|
|
@@ -80,63 +87,21 @@ const currentScriptTag = document.currentScript;
|
|
| 80 |
<div id="tooltip-panel" class="tooltip-panel" style="display: none;">
|
| 81 |
<span id="tooltip-close" class="tooltip-close">Γ</span>
|
| 82 |
<div id="tooltip-text" class="tooltip-text"></div>
|
| 83 |
-
<img id="tooltip-image" class="tooltip-image" style="display:none" />
|
| 84 |
</div>
|
| 85 |
`;
|
| 86 |
|
| 87 |
-
// βββ
|
| 88 |
-
|
| 89 |
-
const helpToggle = document.getElementById(`help-toggle-${instanceId}`);
|
| 90 |
-
const resetCameraBtn = document.getElementById(`reset-camera-btn-${instanceId}`);
|
| 91 |
-
const tooltipsToggleBtn = document.getElementById(`tooltips-toggle-${instanceId}`);
|
| 92 |
-
const helpCloseBtn = document.getElementById(`help-close-${instanceId}`);
|
| 93 |
-
const menuContent = document.getElementById(`menu-content-${instanceId}`);
|
| 94 |
-
const tooltipCloseBtn = document.getElementById('tooltip-close');
|
| 95 |
-
|
| 96 |
-
// βββ 6. Bind click handlers with debug logs ββββββββοΏ½οΏ½βββββββββββββββββββββββ
|
| 97 |
-
fullscreenToggle.addEventListener('click', () => {
|
| 98 |
-
console.log('[UI-Debug] fullscreen clicked');
|
| 99 |
-
// existing fullscreen toggle logicβ¦
|
| 100 |
-
});
|
| 101 |
-
|
| 102 |
-
helpToggle.addEventListener('click', (e) => {
|
| 103 |
-
console.log('[UI-Debug] help clicked');
|
| 104 |
-
e.stopPropagation();
|
| 105 |
-
menuContent.style.display = menuContent.style.display === 'block' ? 'none' : 'block';
|
| 106 |
-
});
|
| 107 |
-
|
| 108 |
-
helpCloseBtn.addEventListener('click', () => {
|
| 109 |
-
console.log('[UI-Debug] help-close clicked');
|
| 110 |
-
menuContent.style.display = 'none';
|
| 111 |
-
});
|
| 112 |
-
|
| 113 |
-
resetCameraBtn.addEventListener('click', () => {
|
| 114 |
-
console.log('[UI-Debug] reset-camera clicked');
|
| 115 |
-
// existing reset-camera logicβ¦
|
| 116 |
-
});
|
| 117 |
-
|
| 118 |
-
if (tooltipsToggleBtn) {
|
| 119 |
-
tooltipsToggleBtn.addEventListener('click', () => {
|
| 120 |
-
console.log('[UI-Debug] tooltips-toggle clicked');
|
| 121 |
-
// existing toggle-tooltips logicβ¦
|
| 122 |
-
});
|
| 123 |
-
}
|
| 124 |
-
|
| 125 |
-
tooltipCloseBtn.addEventListener('click', () => {
|
| 126 |
-
console.log('[UI-Debug] tooltip-close clicked');
|
| 127 |
-
// existing hide-tooltip logicβ¦
|
| 128 |
-
});
|
| 129 |
|
| 130 |
-
// βββ 7. Now
|
| 131 |
try {
|
| 132 |
-
console.log('[UI-Debug] About to import viewer.js');
|
| 133 |
const viewerModule = await import('./viewer.js');
|
| 134 |
await viewerModule.initializeViewer(config, instanceId);
|
| 135 |
} catch (err) {
|
| 136 |
-
console.error("Failed to load viewer.js or initialize:", err);
|
| 137 |
}
|
| 138 |
|
| 139 |
-
// βββ 8.
|
| 140 |
-
// β¦rest of your existing interface.js codeβ¦
|
| 141 |
|
| 142 |
})();
|
|
|
|
| 5 |
const currentScriptTag = document.currentScript;
|
| 6 |
|
| 7 |
(async function() {
|
| 8 |
+
// βββ 1. Locate the <script> and load data-config βββββββββββββββββββββββββββββββ
|
| 9 |
let scriptTag = currentScriptTag;
|
| 10 |
if (!scriptTag) {
|
| 11 |
const scripts = document.getElementsByTagName('script');
|
|
|
|
| 20 |
|
| 21 |
const configUrl = scriptTag.getAttribute('data-config');
|
| 22 |
if (!configUrl) {
|
| 23 |
+
console.error("No config file provided. Please set a data-config attribute on the <script> tag.");
|
| 24 |
return;
|
| 25 |
}
|
| 26 |
let config = {};
|
| 27 |
try {
|
| 28 |
const resp = await fetch(configUrl);
|
| 29 |
config = await resp.json();
|
| 30 |
+
} catch (error) {
|
| 31 |
+
console.error("Error loading config file:", error);
|
| 32 |
return;
|
| 33 |
}
|
| 34 |
|
| 35 |
+
// βββ 2. Optionally inject CSS ββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 36 |
if (config.css_url) {
|
| 37 |
+
const linkEl = document.createElement('link');
|
| 38 |
+
linkEl.rel = "stylesheet";
|
| 39 |
+
linkEl.href = config.css_url;
|
| 40 |
+
document.head.appendChild(linkEl);
|
| 41 |
}
|
| 42 |
|
| 43 |
+
// βββ 3. Generate a unique instanceId βββββββββββββββββββββββββββββββββββββββββ
|
| 44 |
const instanceId = Math.random().toString(36).substr(2, 8);
|
| 45 |
+
|
| 46 |
+
// βββ 4. Create the widget container ββββββββββββββββββββββββββββββββββββββββββ
|
| 47 |
const widgetContainer = document.createElement('div');
|
| 48 |
+
widgetContainer.id = 'ply-widget-container-' + instanceId;
|
| 49 |
widgetContainer.classList.add('ply-widget-container');
|
| 50 |
+
document.body.appendChild(widgetContainer);
|
| 51 |
|
| 52 |
+
// βββ 5. Build inner HTML, including the progress dialog βββββββββββββββββββββ
|
| 53 |
widgetContainer.innerHTML = `
|
| 54 |
+
<div id="viewer-container-${instanceId}" class="viewer-container">
|
| 55 |
+
<!-- Progress dialog must exist for viewer.js -->
|
| 56 |
+
<div id="progress-dialog-${instanceId}" class="progress-dialog">
|
| 57 |
+
<progress id="progress-indicator-${instanceId}" max="100" value="0"></progress>
|
| 58 |
+
</div>
|
| 59 |
+
</div>
|
| 60 |
|
| 61 |
+
<!-- Control buttons -->
|
| 62 |
<button id="fullscreen-toggle-${instanceId}" class="widget-button fullscreen-toggle">β±</button>
|
| 63 |
<button id="help-toggle-${instanceId}" class="widget-button help-toggle">?</button>
|
| 64 |
<button id="reset-camera-btn-${instanceId}" class="widget-button reset-camera-btn">β²</button>
|
|
|
|
| 87 |
<div id="tooltip-panel" class="tooltip-panel" style="display: none;">
|
| 88 |
<span id="tooltip-close" class="tooltip-close">Γ</span>
|
| 89 |
<div id="tooltip-text" class="tooltip-text"></div>
|
| 90 |
+
<img id="tooltip-image" class="tooltip-image" style="display: none;" />
|
| 91 |
</div>
|
| 92 |
`;
|
| 93 |
|
| 94 |
+
// βββ 6. Grab elements and hook up any UI listeners ββββββββββββββββββββββββββ
|
| 95 |
+
// (your existing click/toggle/drag-hide logic remains hereβ¦)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
+
// βββ 7. Now dynamic-import viewer.js ββββββββββββββββββββββββββββββββββββββββ
|
| 98 |
try {
|
|
|
|
| 99 |
const viewerModule = await import('./viewer.js');
|
| 100 |
await viewerModule.initializeViewer(config, instanceId);
|
| 101 |
} catch (err) {
|
| 102 |
+
console.error("Failed to load viewer.js or initialize the 3D viewer:", err);
|
| 103 |
}
|
| 104 |
|
| 105 |
+
// βββ 8. (rest of your interface.js codeβ¦) βββββββββββββββββββββββββββββββββββ
|
|
|
|
| 106 |
|
| 107 |
})();
|