Spaces:
Running
Running
Update interface.js
Browse files- interface.js +28 -54
interface.js
CHANGED
|
@@ -72,57 +72,35 @@ const currentScriptTag = document.currentScript;
|
|
| 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 |
: '';
|
| 78 |
|
| 79 |
-
// ---
|
| 80 |
-
const colorBtnContainerId = `color-btn-container-${instanceId}`;
|
| 81 |
-
// Only red and white for now. Extend array to add more colors later.
|
| 82 |
const colorButtonsConfig = [
|
| 83 |
-
{
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
title: 'Blanc',
|
| 87 |
-
color: [1, 1, 1],
|
| 88 |
-
style: 'background: #fff; border: 1.5px solid #bbb;'
|
| 89 |
-
},
|
| 90 |
-
{
|
| 91 |
-
id: `color-btn-red-${instanceId}`,
|
| 92 |
-
label: '',
|
| 93 |
-
title: 'Rouge',
|
| 94 |
-
color: [0.7, 0.05, 0.05],
|
| 95 |
-
style: 'background: #d00; border: 1.5px solid #b33;'
|
| 96 |
-
}
|
| 97 |
];
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
${colorButtonsConfig.map(btn => `
|
| 102 |
-
<button
|
| 103 |
-
id="${btn.id}"
|
| 104 |
-
class="widget-button color-btn"
|
| 105 |
-
title="${btn.title}"
|
| 106 |
-
style="${btn.style}; right: 172px; width: 32px; height: 32px; margin-bottom: 8px; display: flex; align-items: center; justify-content: center;"
|
| 107 |
-
tabindex="0"
|
| 108 |
-
></button>
|
| 109 |
-
`).join('\n')}
|
| 110 |
-
</div>
|
| 111 |
-
`;
|
| 112 |
-
// ---------------------------------
|
| 113 |
|
| 114 |
widgetContainer.innerHTML = `
|
| 115 |
<div id="viewer-container-${instanceId}" class="viewer-container">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
<div id="progress-dialog-${instanceId}" class="progress-dialog">
|
| 117 |
<progress id="progress-indicator-${instanceId}" max="100" value="0"></progress>
|
| 118 |
</div>
|
| 119 |
-
<button id="fullscreen-toggle-${instanceId}" class="widget-button fullscreen-toggle">⇱</button>
|
| 120 |
-
<button id="help-toggle-${instanceId}" class="widget-button help-toggle">?</button>
|
| 121 |
-
<button id="reset-camera-btn-${instanceId}" class="widget-button reset-camera-btn">
|
| 122 |
-
<span class="reset-icon">⟲</span>
|
| 123 |
-
</button>
|
| 124 |
-
${tooltipsButtonHTML}
|
| 125 |
-
${colorButtonsHTML}
|
| 126 |
<div id="menu-content-${instanceId}" class="menu-content">
|
| 127 |
<span id="help-close-${instanceId}" class="help-close">×</span>
|
| 128 |
<div class="help-text"></div>
|
|
@@ -152,9 +130,8 @@ const currentScriptTag = document.currentScript;
|
|
| 152 |
const tooltipImage = document.getElementById('tooltip-image');
|
| 153 |
const tooltipCloseBtn = document.getElementById('tooltip-close');
|
| 154 |
|
| 155 |
-
//
|
| 156 |
-
const
|
| 157 |
-
const colorBtnElements = colorButtonsConfig.map(btn => document.getElementById(btn.id));
|
| 158 |
|
| 159 |
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
| 160 |
const isMobile = isIOS || /Android/i.test(navigator.userAgent);
|
|
@@ -164,7 +141,7 @@ const currentScriptTag = document.currentScript;
|
|
| 164 |
: '';
|
| 165 |
|
| 166 |
if (isMobile) {
|
| 167 |
-
helpTextDiv.innerHTML =
|
| 168 |
'- Déplacez vous en glissant deux doigts sur l\'écran.<br>' +
|
| 169 |
'- Orbitez en glissant un doigt.<br>' +
|
| 170 |
'- Zoomez en pinçant avec deux doigts.<br>' +
|
|
@@ -172,7 +149,7 @@ const currentScriptTag = document.currentScript;
|
|
| 172 |
'- Cliquez sur ⟲ pour réinitialiser la caméra.<br>' +
|
| 173 |
'- Cliquez sur ⇱ pour passer en plein écran.<br>';
|
| 174 |
} else {
|
| 175 |
-
helpTextDiv.innerHTML =
|
| 176 |
'- Orbitez avec le clic droit<br>' +
|
| 177 |
'- Zoomez avec la molette<br>' +
|
| 178 |
'- Déplacez vous avec le clic gauche<br>' +
|
|
@@ -423,19 +400,16 @@ const currentScriptTag = document.currentScript;
|
|
| 423 |
|
| 424 |
tooltipCloseBtn.addEventListener('click', hideTooltipPanel);
|
| 425 |
|
| 426 |
-
//
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
// Defensive: Wait until changeColor function is available and model loaded
|
| 432 |
-
if (viewerModule && typeof viewerModule.changeColor === 'function') {
|
| 433 |
-
const [r, g, b] = colorButtonsConfig[idx].color;
|
| 434 |
viewerModule.changeColor(r, g, b);
|
| 435 |
}
|
| 436 |
});
|
| 437 |
});
|
| 438 |
-
//
|
| 439 |
|
| 440 |
document.addEventListener('tooltip-selected', (evt) => {
|
| 441 |
// Always show panel, cancel hide first
|
|
|
|
| 72 |
widgetContainer.style.paddingBottom = aspectPercent;
|
| 73 |
widgetContainer.setAttribute('data-original-aspect', aspectPercent);
|
| 74 |
|
| 75 |
+
// --- BEGIN CONTROL BUTTONS (in .viewer-controls for vertical stacking) ---
|
| 76 |
const tooltipsButtonHTML = config.tooltips_url
|
| 77 |
+
? `<button id="tooltips-toggle-${instanceId}" class="widget-button tooltips-toggle" title="Tooltips">⦿</button>`
|
| 78 |
: '';
|
| 79 |
|
| 80 |
+
// --- COLOR BUTTONS (easy to add more here) ---
|
|
|
|
|
|
|
| 81 |
const colorButtonsConfig = [
|
| 82 |
+
{ id: `color-btn-white-${instanceId}`, title: "Blanc", rgb: [1, 1, 1] },
|
| 83 |
+
{ id: `color-btn-red-${instanceId}`, title: "Rouge", rgb: [0.7, 0.05, 0.05] }
|
| 84 |
+
// Add more as desired
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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="viewer-controls">
|
| 93 |
+
<button id="fullscreen-toggle-${instanceId}" class="widget-button fullscreen-toggle" title="Plein écran">⇱</button>
|
| 94 |
+
<button id="help-toggle-${instanceId}" class="widget-button help-toggle" title="Aide">?</button>
|
| 95 |
+
<button id="reset-camera-btn-${instanceId}" class="widget-button reset-camera-btn" title="Réinitialiser la caméra">
|
| 96 |
+
<span class="reset-icon">⟲</span>
|
| 97 |
+
</button>
|
| 98 |
+
${tooltipsButtonHTML}
|
| 99 |
+
${colorButtonsHTML}
|
| 100 |
+
</div>
|
| 101 |
<div id="progress-dialog-${instanceId}" class="progress-dialog">
|
| 102 |
<progress id="progress-indicator-${instanceId}" max="100" value="0"></progress>
|
| 103 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
<div id="menu-content-${instanceId}" class="menu-content">
|
| 105 |
<span id="help-close-${instanceId}" class="help-close">×</span>
|
| 106 |
<div class="help-text"></div>
|
|
|
|
| 130 |
const tooltipImage = document.getElementById('tooltip-image');
|
| 131 |
const tooltipCloseBtn = document.getElementById('tooltip-close');
|
| 132 |
|
| 133 |
+
// Color button elements
|
| 134 |
+
const colorButtonElems = colorButtonsConfig.map(btn => document.getElementById(btn.id));
|
|
|
|
| 135 |
|
| 136 |
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
| 137 |
const isMobile = isIOS || /Android/i.test(navigator.userAgent);
|
|
|
|
| 141 |
: '';
|
| 142 |
|
| 143 |
if (isMobile) {
|
| 144 |
+
helpTextDiv.innerHTML =
|
| 145 |
'- Déplacez vous en glissant deux doigts sur l\'écran.<br>' +
|
| 146 |
'- Orbitez en glissant un doigt.<br>' +
|
| 147 |
'- Zoomez en pinçant avec deux doigts.<br>' +
|
|
|
|
| 149 |
'- Cliquez sur ⟲ pour réinitialiser la caméra.<br>' +
|
| 150 |
'- Cliquez sur ⇱ pour passer en plein écran.<br>';
|
| 151 |
} else {
|
| 152 |
+
helpTextDiv.innerHTML =
|
| 153 |
'- Orbitez avec le clic droit<br>' +
|
| 154 |
'- Zoomez avec la molette<br>' +
|
| 155 |
'- Déplacez vous avec le clic gauche<br>' +
|
|
|
|
| 400 |
|
| 401 |
tooltipCloseBtn.addEventListener('click', hideTooltipPanel);
|
| 402 |
|
| 403 |
+
// ========== COLOR BUTTON LOGIC ==========
|
| 404 |
+
colorButtonElems.forEach((btnElem, idx) => {
|
| 405 |
+
btnElem.addEventListener('click', () => {
|
| 406 |
+
if (viewerModule && viewerModule.changeColor) {
|
| 407 |
+
const [r, g, b] = colorButtonsConfig[idx].rgb;
|
|
|
|
|
|
|
|
|
|
| 408 |
viewerModule.changeColor(r, g, b);
|
| 409 |
}
|
| 410 |
});
|
| 411 |
});
|
| 412 |
+
// ========================================
|
| 413 |
|
| 414 |
document.addEventListener('tooltip-selected', (evt) => {
|
| 415 |
// Always show panel, cancel hide first
|