Spaces:
Running
Running
Update interface.js
Browse files- interface.js +11 -11
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 |
-
// Silent fail
|
| 30 |
return;
|
| 31 |
}
|
| 32 |
} else {
|
| 33 |
-
// Silent fail
|
| 34 |
return;
|
| 35 |
}
|
| 36 |
|
| 37 |
-
// 2. If config.css_url is provided, inject a <link> to that CSS
|
| 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. Generate a unique instanceId for this widget
|
| 46 |
const instanceId = Math.random().toString(36).substr(2, 8);
|
| 47 |
|
| 48 |
-
// 4. Compute the aspect ratio (padding-bottom %)
|
| 49 |
let aspectPercent = "100%";
|
| 50 |
if (config.aspect) {
|
| 51 |
if (config.aspect.includes(":")) {
|
|
@@ -70,7 +65,6 @@ const currentScriptTag = document.currentScript;
|
|
| 70 |
}
|
| 71 |
}
|
| 72 |
|
| 73 |
-
// 5. Create the widget container
|
| 74 |
const widgetContainer = document.createElement('div');
|
| 75 |
widgetContainer.id = 'ply-widget-container-' + instanceId;
|
| 76 |
widgetContainer.classList.add('ply-widget-container');
|
|
@@ -78,7 +72,6 @@ const currentScriptTag = document.currentScript;
|
|
| 78 |
widgetContainer.style.paddingBottom = aspectPercent;
|
| 79 |
widgetContainer.setAttribute('data-original-aspect', aspectPercent);
|
| 80 |
|
| 81 |
-
// Conditionally include the “tooltips-toggle” button only if config.tooltips_url is defined
|
| 82 |
const tooltipsButtonHTML = config.tooltips_url
|
| 83 |
? `<button id="tooltips-toggle-${instanceId}" class="widget-button tooltips-toggle">⦿</button>`
|
| 84 |
: '';
|
|
@@ -110,7 +103,6 @@ const currentScriptTag = document.currentScript;
|
|
| 110 |
|
| 111 |
scriptTag.parentNode.appendChild(widgetContainer);
|
| 112 |
|
| 113 |
-
// 6. Grab references to new DOM elements
|
| 114 |
const viewerContainerElem = document.getElementById('viewer-container-' + instanceId);
|
| 115 |
const fullscreenToggle = document.getElementById('fullscreen-toggle-' + instanceId);
|
| 116 |
const helpToggle = document.getElementById('help-toggle-' + instanceId);
|
|
@@ -177,7 +169,6 @@ const currentScriptTag = document.currentScript;
|
|
| 177 |
const canvasId = 'canvas-' + instanceId;
|
| 178 |
const canvasEl = document.getElementById(canvasId);
|
| 179 |
|
| 180 |
-
// 8. Conditional display of tooltips-toggle button
|
| 181 |
if (tooltipsToggleBtn) {
|
| 182 |
if (!config.tooltips_url) {
|
| 183 |
tooltipsToggleBtn.style.display = 'none';
|
|
@@ -188,7 +179,6 @@ const currentScriptTag = document.currentScript;
|
|
| 188 |
}
|
| 189 |
}
|
| 190 |
|
| 191 |
-
// 9. Fullscreen / state-preservation logic
|
| 192 |
let isFullscreen = false;
|
| 193 |
let savedState = null;
|
| 194 |
|
|
@@ -347,11 +337,21 @@ const currentScriptTag = document.currentScript;
|
|
| 347 |
tooltipCloseBtn.addEventListener('click', hideTooltipPanel);
|
| 348 |
|
| 349 |
document.addEventListener('tooltip-selected', (evt) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
const { title, description, imgUrl } = evt.detail;
|
| 351 |
tooltipTextDiv.innerHTML = `<strong>${title}</strong><br>${description}`;
|
|
|
|
|
|
|
|
|
|
| 352 |
if (imgUrl) {
|
|
|
|
|
|
|
|
|
|
| 353 |
tooltipImage.src = imgUrl;
|
| 354 |
-
tooltipImage.style.display = 'block';
|
| 355 |
} else {
|
| 356 |
tooltipImage.style.display = 'none';
|
| 357 |
}
|
|
|
|
| 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(":")) {
|
|
|
|
| 65 |
}
|
| 66 |
}
|
| 67 |
|
|
|
|
| 68 |
const widgetContainer = document.createElement('div');
|
| 69 |
widgetContainer.id = 'ply-widget-container-' + instanceId;
|
| 70 |
widgetContainer.classList.add('ply-widget-container');
|
|
|
|
| 72 |
widgetContainer.style.paddingBottom = aspectPercent;
|
| 73 |
widgetContainer.setAttribute('data-original-aspect', aspectPercent);
|
| 74 |
|
|
|
|
| 75 |
const tooltipsButtonHTML = config.tooltips_url
|
| 76 |
? `<button id="tooltips-toggle-${instanceId}" class="widget-button tooltips-toggle">⦿</button>`
|
| 77 |
: '';
|
|
|
|
| 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);
|
|
|
|
| 169 |
const canvasId = 'canvas-' + instanceId;
|
| 170 |
const canvasEl = document.getElementById(canvasId);
|
| 171 |
|
|
|
|
| 172 |
if (tooltipsToggleBtn) {
|
| 173 |
if (!config.tooltips_url) {
|
| 174 |
tooltipsToggleBtn.style.display = 'none';
|
|
|
|
| 179 |
}
|
| 180 |
}
|
| 181 |
|
|
|
|
| 182 |
let isFullscreen = false;
|
| 183 |
let savedState = null;
|
| 184 |
|
|
|
|
| 337 |
tooltipCloseBtn.addEventListener('click', hideTooltipPanel);
|
| 338 |
|
| 339 |
document.addEventListener('tooltip-selected', (evt) => {
|
| 340 |
+
// Always show panel, cancel hide first
|
| 341 |
+
if (dragHide) {
|
| 342 |
+
viewerContainerElem.removeEventListener('pointermove', dragHide);
|
| 343 |
+
dragHide = null;
|
| 344 |
+
}
|
| 345 |
const { title, description, imgUrl } = evt.detail;
|
| 346 |
tooltipTextDiv.innerHTML = `<strong>${title}</strong><br>${description}`;
|
| 347 |
+
// Force a repaint: clear src before setting, for repeated images
|
| 348 |
+
tooltipImage.style.display = 'none';
|
| 349 |
+
tooltipImage.src = '';
|
| 350 |
if (imgUrl) {
|
| 351 |
+
tooltipImage.onload = () => {
|
| 352 |
+
tooltipImage.style.display = 'block';
|
| 353 |
+
};
|
| 354 |
tooltipImage.src = imgUrl;
|
|
|
|
| 355 |
} else {
|
| 356 |
tooltipImage.style.display = 'none';
|
| 357 |
}
|