Spaces:
Running
Running
Update interface.js
Browse files- interface.js +65 -19
interface.js
CHANGED
|
@@ -72,7 +72,7 @@ const currentScriptTag = document.currentScript;
|
|
| 72 |
}
|
| 73 |
}
|
| 74 |
|
| 75 |
-
// βββ 5. Create the widget container
|
| 76 |
const widgetContainer = document.createElement('div');
|
| 77 |
widgetContainer.id = 'ply-widget-container-' + instanceId;
|
| 78 |
widgetContainer.classList.add('ply-widget-container');
|
|
@@ -80,11 +80,7 @@ const currentScriptTag = document.currentScript;
|
|
| 80 |
widgetContainer.style.paddingBottom = aspectPercent;
|
| 81 |
widgetContainer.setAttribute('data-original-aspect', aspectPercent);
|
| 82 |
|
| 83 |
-
|
| 84 |
-
? `<button id="tooltips-toggle-${instanceId}" class="widget-button tooltips-toggle">β¦Ώ</button>`
|
| 85 |
-
: '';
|
| 86 |
-
|
| 87 |
-
// **Entire block below is now properly wrapped as a single template literal:**
|
| 88 |
widgetContainer.innerHTML = `
|
| 89 |
<div id="viewer-container-${instanceId}" class="viewer-container">
|
| 90 |
<div id="progress-dialog-${instanceId}" class="progress-dialog">
|
|
@@ -95,35 +91,85 @@ const currentScriptTag = document.currentScript;
|
|
| 95 |
<button id="reset-camera-btn-${instanceId}" class="widget-button reset-camera-btn">
|
| 96 |
<span class="reset-icon">β²</span>
|
| 97 |
</button>
|
| 98 |
-
|
| 99 |
<div id="menu-content-${instanceId}" class="menu-content">
|
| 100 |
<span id="help-close-${instanceId}" class="help-close">Γ</span>
|
| 101 |
<div class="help-text"></div>
|
| 102 |
</div>
|
| 103 |
</div>
|
| 104 |
-
<div id="tooltip
|
| 105 |
-
<div class="tooltip-content">
|
| 106 |
-
<span id="tooltip-close" class="tooltip-close">Γ</span>
|
| 107 |
-
<div id="tooltip-text" class="tooltip-text"></div>
|
| 108 |
-
<img id="tooltip-image" class="tooltip-image" src="" alt="" style="display: none;" />
|
| 109 |
</div>
|
| 110 |
</div>
|
| 111 |
-
`;
|
| 112 |
|
| 113 |
-
// Append to DOM
|
| 114 |
scriptTag.parentNode.appendChild(widgetContainer);
|
| 115 |
|
| 116 |
-
// βββ 6. Grab
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
-
// βββ 7.
|
|
|
|
| 120 |
try {
|
| 121 |
-
|
| 122 |
await viewerModule.initializeViewer(config, instanceId);
|
| 123 |
} catch (err) {
|
| 124 |
console.error("Failed to load viewer.js or initialize the 3D viewer:", err);
|
|
|
|
| 125 |
}
|
| 126 |
|
| 127 |
-
//
|
| 128 |
|
| 129 |
})();
|
|
|
|
| 72 |
}
|
| 73 |
}
|
| 74 |
|
| 75 |
+
// βββ 5. Create the widget container (no GIF preview, no close button) βββββββββββ
|
| 76 |
const widgetContainer = document.createElement('div');
|
| 77 |
widgetContainer.id = 'ply-widget-container-' + instanceId;
|
| 78 |
widgetContainer.classList.add('ply-widget-container');
|
|
|
|
| 80 |
widgetContainer.style.paddingBottom = aspectPercent;
|
| 81 |
widgetContainer.setAttribute('data-original-aspect', aspectPercent);
|
| 82 |
|
| 83 |
+
// Add the 3D-viewer HTML + π toggle + tooltip markup
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
widgetContainer.innerHTML = `
|
| 85 |
<div id="viewer-container-${instanceId}" class="viewer-container">
|
| 86 |
<div id="progress-dialog-${instanceId}" class="progress-dialog">
|
|
|
|
| 91 |
<button id="reset-camera-btn-${instanceId}" class="widget-button reset-camera-btn">
|
| 92 |
<span class="reset-icon">β²</span>
|
| 93 |
</button>
|
| 94 |
+
<button id="points-toggle-${instanceId}" class="widget-button points-toggle">β¦Ώ</button>
|
| 95 |
<div id="menu-content-${instanceId}" class="menu-content">
|
| 96 |
<span id="help-close-${instanceId}" class="help-close">Γ</span>
|
| 97 |
<div class="help-text"></div>
|
| 98 |
</div>
|
| 99 |
</div>
|
| 100 |
+
<div id="point-tooltip" class="point-tooltip" style="display: none;">
|
| 101 |
+
<div class="point-tooltip-content">
|
| 102 |
+
<span id="point-tooltip-close" class="point-tooltip-close">Γ</span>
|
| 103 |
+
<div id="point-tooltip-text" class="point-tooltip-text"></div>
|
| 104 |
+
<img id="point-tooltip-image" class="point-tooltip-image" src="" alt="" style="display: none;" />
|
| 105 |
</div>
|
| 106 |
</div>
|
| 107 |
+
`;
|
| 108 |
|
|
|
|
| 109 |
scriptTag.parentNode.appendChild(widgetContainer);
|
| 110 |
|
| 111 |
+
// βββ 6. Grab references to new DOM elements ββββββββββββββββββββββββββββββββββ
|
| 112 |
+
const viewerContainerElem = document.getElementById('viewer-container-' + instanceId);
|
| 113 |
+
const fullscreenToggle = document.getElementById('fullscreen-toggle-' + instanceId);
|
| 114 |
+
const helpToggle = document.getElementById('help-toggle-' + instanceId);
|
| 115 |
+
const helpCloseBtn = document.getElementById('help-close-' + instanceId);
|
| 116 |
+
const resetCameraBtn = document.getElementById('reset-camera-btn-' + instanceId);
|
| 117 |
+
const pointsToggleBtn = document.getElementById('points-toggle-' + instanceId);
|
| 118 |
+
const menuContent = document.getElementById('menu-content-' + instanceId);
|
| 119 |
+
const helpTextDiv = menuContent.querySelector('.help-text');
|
| 120 |
+
|
| 121 |
+
// Tooltip elements
|
| 122 |
+
const tooltipDiv = document.getElementById('point-tooltip');
|
| 123 |
+
const tooltipTextDiv = document.getElementById('point-tooltip-text');
|
| 124 |
+
const tooltipImage = document.getElementById('point-tooltip-image');
|
| 125 |
+
const tooltipCloseBtn = document.getElementById('point-tooltip-close');
|
| 126 |
+
|
| 127 |
+
// Device detection for help text
|
| 128 |
+
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
| 129 |
+
const isMobile = isIOS || /Android/i.test(navigator.userAgent);
|
| 130 |
+
|
| 131 |
+
// Conditionally include tooltip instruction only if points_url exists
|
| 132 |
+
const tooltipInstruction = config.points_url
|
| 133 |
+
? '- Cliquez sur β¦Ώ pour afficher/masquer les points dβinformation.<br>'
|
| 134 |
+
: '';
|
| 135 |
+
|
| 136 |
+
// Fill help text with instructions, plus two new French lines
|
| 137 |
+
if (isMobile) {
|
| 138 |
+
helpTextDiv.innerHTML = `
|
| 139 |
+
- Pour vous dΓ©placer, glissez deux doigts sur l'Γ©cran.<br>
|
| 140 |
+
- Pour orbiter, utilisez un doigt.<br>
|
| 141 |
+
- Pour zoomer, pincez avec deux doigts.<br>
|
| 142 |
+
${tooltipInstruction}
|
| 143 |
+
- β² RΓ©initialise la camΓ©ra.<br>
|
| 144 |
+
- β± Passe en plein Γ©cran.<br>
|
| 145 |
+
`;
|
| 146 |
+
} else {
|
| 147 |
+
helpTextDiv.innerHTML = `
|
| 148 |
+
- orbitez avec le clic droit<br>
|
| 149 |
+
- zoomez avec la molette<br>
|
| 150 |
+
- dΓ©placez vous avec le clic gauche<br>
|
| 151 |
+
${tooltipInstruction}
|
| 152 |
+
- β² RΓ©initialise la camΓ©ra.<br>
|
| 153 |
+
- β± Passe en plein Γ©cran.<br>
|
| 154 |
+
`;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
// Ensure instructions panel is visible by default
|
| 158 |
+
menuContent.style.display = 'block';
|
| 159 |
+
viewerContainerElem.style.display = 'block';
|
| 160 |
+
|
| 161 |
+
// β¦rest of the original working tooltip, drag-hide, fullscreen, resize, dynamic-import logic remains unchangedβ¦
|
| 162 |
|
| 163 |
+
// βββ 7. Dynamically load viewer.js βββββββββββββββββββββββββββββββββββββββββ
|
| 164 |
+
let viewerModule;
|
| 165 |
try {
|
| 166 |
+
viewerModule = await import('./viewer.js');
|
| 167 |
await viewerModule.initializeViewer(config, instanceId);
|
| 168 |
} catch (err) {
|
| 169 |
console.error("Failed to load viewer.js or initialize the 3D viewer:", err);
|
| 170 |
+
return;
|
| 171 |
}
|
| 172 |
|
| 173 |
+
// β¦etc.
|
| 174 |
|
| 175 |
})();
|