Spaces:
Running
Running
Update interface.js
Browse files- interface.js +94 -29
interface.js
CHANGED
|
@@ -72,31 +72,52 @@ const currentScriptTag = document.currentScript;
|
|
| 72 |
widgetContainer.style.paddingBottom = aspectPercent;
|
| 73 |
widgetContainer.setAttribute('data-original-aspect', aspectPercent);
|
| 74 |
|
| 75 |
-
//
|
| 76 |
const tooltipsButtonHTML = config.tooltips_url
|
| 77 |
-
? `<button id="tooltips-toggle-${instanceId}" class="widget-button tooltips-toggle" title="Tooltips">⦿</button>`
|
| 78 |
: '';
|
| 79 |
|
| 80 |
-
//
|
| 81 |
-
const
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
];
|
| 86 |
-
const colorButtonsHTML = colorButtonsConfig.map(btn =>
|
| 87 |
-
`<button id="${btn.id}" class="widget-button color-btn" title="${btn.title}" tabindex="0"></button>`
|
| 88 |
-
).join('\n');
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
widgetContainer.innerHTML = `
|
| 91 |
<div id="viewer-container-${instanceId}" class="viewer-container">
|
| 92 |
-
<div class="
|
| 93 |
-
<button id="
|
| 94 |
-
<
|
| 95 |
-
|
| 96 |
-
<
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
| 100 |
</div>
|
| 101 |
<div id="progress-dialog-${instanceId}" class="progress-dialog">
|
| 102 |
<progress id="progress-indicator-${instanceId}" max="100" value="0"></progress>
|
|
@@ -117,6 +138,7 @@ const currentScriptTag = document.currentScript;
|
|
| 117 |
|
| 118 |
scriptTag.parentNode.appendChild(widgetContainer);
|
| 119 |
|
|
|
|
| 120 |
const viewerContainerElem = document.getElementById('viewer-container-' + instanceId);
|
| 121 |
const fullscreenToggle = document.getElementById('fullscreen-toggle-' + instanceId);
|
| 122 |
const helpToggle = document.getElementById('help-toggle-' + instanceId);
|
|
@@ -129,9 +151,9 @@ const currentScriptTag = document.currentScript;
|
|
| 129 |
const tooltipTextDiv = document.getElementById('tooltip-text');
|
| 130 |
const tooltipImage = document.getElementById('tooltip-image');
|
| 131 |
const tooltipCloseBtn = document.getElementById('tooltip-close');
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
const
|
| 135 |
|
| 136 |
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
| 137 |
const isMobile = isIOS || /Android/i.test(navigator.userAgent);
|
|
@@ -400,16 +422,62 @@ const currentScriptTag = document.currentScript;
|
|
| 400 |
|
| 401 |
tooltipCloseBtn.addEventListener('click', hideTooltipPanel);
|
| 402 |
|
| 403 |
-
//
|
| 404 |
-
|
| 405 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 406 |
if (viewerModule && viewerModule.changeColor) {
|
| 407 |
-
const
|
|
|
|
|
|
|
| 408 |
viewerModule.changeColor(r, g, b);
|
| 409 |
}
|
|
|
|
| 410 |
});
|
| 411 |
});
|
| 412 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
|
| 414 |
document.addEventListener('tooltip-selected', (evt) => {
|
| 415 |
// Always show panel, cancel hide first
|
|
@@ -445,9 +513,6 @@ const currentScriptTag = document.currentScript;
|
|
| 445 |
if (canvasEl) {
|
| 446 |
canvasEl.addEventListener('wheel', hideTooltipPanel, { passive: true });
|
| 447 |
}
|
| 448 |
-
document.addEventListener('keydown', (e) => {
|
| 449 |
-
if ((e.key === 'Escape' || e.key === 'Esc') && isFullscreen) exitFullscreen();
|
| 450 |
-
});
|
| 451 |
window.addEventListener('resize', () => {
|
| 452 |
if (viewerModule.app) {
|
| 453 |
if (isFullscreen) {
|
|
|
|
| 72 |
widgetContainer.style.paddingBottom = aspectPercent;
|
| 73 |
widgetContainer.setAttribute('data-original-aspect', aspectPercent);
|
| 74 |
|
| 75 |
+
// TOOLTIP BUTTON HTML IF NEEDED
|
| 76 |
const tooltipsButtonHTML = config.tooltips_url
|
| 77 |
+
? `<button id="tooltips-toggle-${instanceId}" class="widget-button tooltips-toggle" title="Tooltips" aria-label="Afficher/Masquer les tooltips">⦿</button>`
|
| 78 |
: '';
|
| 79 |
|
| 80 |
+
// COLOR BUTTON: will open the color panel
|
| 81 |
+
const colorButtonId = `color-btn-${instanceId}`;
|
| 82 |
+
const colorPanelId = `color-panel-${instanceId}`;
|
| 83 |
+
|
| 84 |
+
// Color choices: add more as needed
|
| 85 |
+
const colorChoices = [
|
| 86 |
+
{ title: "Blanc", color: [1, 1, 1], swatch: "#fff" },
|
| 87 |
+
{ title: "Rouge", color: [0.7, 0.05, 0.05], swatch: "#d00" }
|
| 88 |
+
// Add more: { title: "...", color: [r, g, b], swatch: "#hex" }
|
| 89 |
];
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
+
// Generate color swatch HTML
|
| 92 |
+
const colorPanelHTML = `
|
| 93 |
+
<div id="${colorPanelId}" class="color-panel" aria-label="Sélection de couleur" tabindex="-1" style="display:none;">
|
| 94 |
+
${colorChoices.map((c, i) => `
|
| 95 |
+
<button
|
| 96 |
+
class="color-swatch-btn"
|
| 97 |
+
style="background: ${c.swatch};"
|
| 98 |
+
data-r="${c.color[0]}" data-g="${c.color[1]}" data-b="${c.color[2]}"
|
| 99 |
+
aria-label="${c.title}"
|
| 100 |
+
title="${c.title}"
|
| 101 |
+
tabindex="0"
|
| 102 |
+
></button>
|
| 103 |
+
`).join("")}
|
| 104 |
+
</div>
|
| 105 |
+
`;
|
| 106 |
+
|
| 107 |
+
// --- Controls as vertical stack, with color button to the left (first row is horizontal) ---
|
| 108 |
widgetContainer.innerHTML = `
|
| 109 |
<div id="viewer-container-${instanceId}" class="viewer-container">
|
| 110 |
+
<div class="controls-row">
|
| 111 |
+
<button id="${colorButtonId}" class="widget-button color-menu-btn" aria-label="Ouvrir le menu de couleurs" title="Couleur"></button>
|
| 112 |
+
<div class="vertical-controls">
|
| 113 |
+
<button id="fullscreen-toggle-${instanceId}" class="widget-button fullscreen-toggle" title="Plein écran" aria-label="Plein écran">⇱</button>
|
| 114 |
+
<button id="help-toggle-${instanceId}" class="widget-button help-toggle" title="Aide" aria-label="Aide">?</button>
|
| 115 |
+
<button id="reset-camera-btn-${instanceId}" class="widget-button reset-camera-btn" title="Réinitialiser la caméra" aria-label="Réinitialiser la caméra">
|
| 116 |
+
<span class="reset-icon">⟲</span>
|
| 117 |
+
</button>
|
| 118 |
+
${tooltipsButtonHTML}
|
| 119 |
+
</div>
|
| 120 |
+
${colorPanelHTML}
|
| 121 |
</div>
|
| 122 |
<div id="progress-dialog-${instanceId}" class="progress-dialog">
|
| 123 |
<progress id="progress-indicator-${instanceId}" max="100" value="0"></progress>
|
|
|
|
| 138 |
|
| 139 |
scriptTag.parentNode.appendChild(widgetContainer);
|
| 140 |
|
| 141 |
+
// ---- Element references ----
|
| 142 |
const viewerContainerElem = document.getElementById('viewer-container-' + instanceId);
|
| 143 |
const fullscreenToggle = document.getElementById('fullscreen-toggle-' + instanceId);
|
| 144 |
const helpToggle = document.getElementById('help-toggle-' + instanceId);
|
|
|
|
| 151 |
const tooltipTextDiv = document.getElementById('tooltip-text');
|
| 152 |
const tooltipImage = document.getElementById('tooltip-image');
|
| 153 |
const tooltipCloseBtn = document.getElementById('tooltip-close');
|
| 154 |
+
const colorMenuBtn = document.getElementById(colorButtonId);
|
| 155 |
+
const colorPanelElem = document.getElementById(colorPanelId);
|
| 156 |
+
const colorSwatchBtns = colorPanelElem.querySelectorAll('.color-swatch-btn');
|
| 157 |
|
| 158 |
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
| 159 |
const isMobile = isIOS || /Android/i.test(navigator.userAgent);
|
|
|
|
| 422 |
|
| 423 |
tooltipCloseBtn.addEventListener('click', hideTooltipPanel);
|
| 424 |
|
| 425 |
+
// --------- COLOR BUTTON LOGIC ----------
|
| 426 |
+
let colorPanelOpen = false;
|
| 427 |
+
function openColorPanel() {
|
| 428 |
+
colorPanelElem.style.display = 'flex';
|
| 429 |
+
colorMenuBtn.classList.add('active');
|
| 430 |
+
colorPanelElem.focus();
|
| 431 |
+
colorPanelOpen = true;
|
| 432 |
+
}
|
| 433 |
+
function closeColorPanel() {
|
| 434 |
+
colorPanelElem.style.display = 'none';
|
| 435 |
+
colorMenuBtn.classList.remove('active');
|
| 436 |
+
colorPanelOpen = false;
|
| 437 |
+
}
|
| 438 |
+
function toggleColorPanel() {
|
| 439 |
+
if (colorPanelOpen) {
|
| 440 |
+
closeColorPanel();
|
| 441 |
+
} else {
|
| 442 |
+
openColorPanel();
|
| 443 |
+
}
|
| 444 |
+
}
|
| 445 |
+
// Toggle color panel on color button click
|
| 446 |
+
colorMenuBtn.addEventListener('click', (e) => {
|
| 447 |
+
e.stopPropagation();
|
| 448 |
+
toggleColorPanel();
|
| 449 |
+
});
|
| 450 |
+
|
| 451 |
+
// Change color on swatch click and close panel
|
| 452 |
+
colorSwatchBtns.forEach((btn) => {
|
| 453 |
+
btn.addEventListener('click', (e) => {
|
| 454 |
+
e.stopPropagation();
|
| 455 |
if (viewerModule && viewerModule.changeColor) {
|
| 456 |
+
const r = parseFloat(btn.getAttribute('data-r'));
|
| 457 |
+
const g = parseFloat(btn.getAttribute('data-g'));
|
| 458 |
+
const b = parseFloat(btn.getAttribute('data-b'));
|
| 459 |
viewerModule.changeColor(r, g, b);
|
| 460 |
}
|
| 461 |
+
closeColorPanel();
|
| 462 |
});
|
| 463 |
});
|
| 464 |
+
|
| 465 |
+
// Close color panel when clicking outside
|
| 466 |
+
document.addEventListener('mousedown', (e) => {
|
| 467 |
+
if (!colorPanelOpen) return;
|
| 468 |
+
if (!colorPanelElem.contains(e.target) && e.target !== colorMenuBtn) {
|
| 469 |
+
closeColorPanel();
|
| 470 |
+
}
|
| 471 |
+
});
|
| 472 |
+
// Accessibility: ESC closes panel
|
| 473 |
+
document.addEventListener('keydown', (e) => {
|
| 474 |
+
if (colorPanelOpen && (e.key === "Escape" || e.key === "Esc")) {
|
| 475 |
+
closeColorPanel();
|
| 476 |
+
colorMenuBtn.focus();
|
| 477 |
+
}
|
| 478 |
+
if ((e.key === 'Escape' || e.key === 'Esc') && isFullscreen) exitFullscreen();
|
| 479 |
+
});
|
| 480 |
+
// =======================================
|
| 481 |
|
| 482 |
document.addEventListener('tooltip-selected', (evt) => {
|
| 483 |
// Always show panel, cancel hide first
|
|
|
|
| 513 |
if (canvasEl) {
|
| 514 |
canvasEl.addEventListener('wheel', hideTooltipPanel, { passive: true });
|
| 515 |
}
|
|
|
|
|
|
|
|
|
|
| 516 |
window.addEventListener('resize', () => {
|
| 517 |
if (viewerModule.app) {
|
| 518 |
if (isFullscreen) {
|