Spaces:
Running
Running
Update fullscreen_playcanvas.js
Browse files- fullscreen_playcanvas.js +23 -27
fullscreen_playcanvas.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
| 1 |
// fullscreen.js
|
| 2 |
(function () {
|
| 3 |
// βββ 1. Localiser la balise <script> ββββββββββββββββββββββββββββββββββββββββ
|
| 4 |
-
const scriptTag =
|
| 5 |
-
document.currentScript ||
|
| 6 |
-
(function () {
|
| 7 |
const all = document.getElementsByTagName('script');
|
| 8 |
for (let i = all.length - 1; i >= 0; i--) {
|
| 9 |
if (all[i].src && all[i].src.includes('fullscreen.js')) return all[i];
|
|
@@ -12,51 +10,53 @@
|
|
| 12 |
})();
|
| 13 |
|
| 14 |
const playcanvasUrl = scriptTag.getAttribute('data-src');
|
| 15 |
-
if (!playcanvasUrl)
|
| 16 |
-
console.warn('[fullscreen.js] Attribut data-src manquant.');
|
| 17 |
-
return;
|
| 18 |
-
}
|
| 19 |
|
| 20 |
-
// βββ 2. DΓ©tection plateforme βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 21 |
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
| 22 |
-
|
| 23 |
-
// βββ 3. ID d'instance ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 24 |
const id = Math.random().toString(36).substr(2, 8);
|
| 25 |
|
| 26 |
-
// βββ 4. Calcul
|
| 27 |
function computeAspectPadding(aspectStr) {
|
| 28 |
if (!aspectStr) return null;
|
| 29 |
if (aspectStr.includes(':')) {
|
| 30 |
const [w, h] = aspectStr.split(':').map(Number);
|
| 31 |
-
|
| 32 |
-
} else {
|
| 33 |
-
const v = parseFloat(aspectStr);
|
| 34 |
-
if (v > 0) return (100 / v) + '%';
|
| 35 |
}
|
| 36 |
-
|
|
|
|
| 37 |
}
|
| 38 |
|
| 39 |
-
const
|
|
|
|
| 40 |
|
| 41 |
-
// βββ 5. Injection du CSS ββββββββββββββββββββββββββββββββββ
|
| 42 |
const style = document.createElement('style');
|
| 43 |
style.textContent = `
|
| 44 |
.pc-embed-wrapper-${id} {
|
| 45 |
position: relative;
|
| 46 |
width: 100%;
|
| 47 |
height: 0;
|
| 48 |
-
padding-bottom: ${aspectPadding};
|
| 49 |
overflow: hidden;
|
| 50 |
background: #000;
|
| 51 |
box-sizing: border-box;
|
|
|
|
|
|
|
| 52 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
.pc-embed-wrapper-${id}.fake-fullscreen {
|
| 54 |
position: fixed !important;
|
| 55 |
top: 0 !important;
|
| 56 |
left: 0 !important;
|
| 57 |
width: 100vw !important;
|
| 58 |
-
height: 100vh !important;
|
| 59 |
-
height: 100dvh !important;
|
| 60 |
max-width: 100vw !important;
|
| 61 |
max-height: 100dvh !important;
|
| 62 |
padding-bottom: 0 !important;
|
|
@@ -89,8 +89,6 @@
|
|
| 89 |
text-align: center;
|
| 90 |
cursor: pointer;
|
| 91 |
user-select: none;
|
| 92 |
-
-webkit-tap-highlight-color: transparent;
|
| 93 |
-
transition: background 0.2s;
|
| 94 |
}
|
| 95 |
`;
|
| 96 |
document.head.appendChild(style);
|
|
@@ -98,7 +96,6 @@
|
|
| 98 |
// βββ 6. Construction du DOM ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 99 |
const wrapper = document.createElement('div');
|
| 100 |
wrapper.className = `pc-embed-wrapper-${id}`;
|
| 101 |
-
wrapper.setAttribute('data-original-padding', aspectPadding);
|
| 102 |
|
| 103 |
const inner = document.createElement('div');
|
| 104 |
inner.className = `pc-embed-inner-${id}`;
|
|
@@ -125,7 +122,6 @@
|
|
| 125 |
let savedParent = null;
|
| 126 |
let savedNextSibling = null;
|
| 127 |
|
| 128 |
-
// DΓ©termine l'unitΓ© de hauteur Γ utiliser
|
| 129 |
function getHeightUnit() {
|
| 130 |
return (CSS && CSS.supports && CSS.supports('height', '100dvh')) ? '100dvh' : '100vh';
|
| 131 |
}
|
|
@@ -155,8 +151,8 @@
|
|
| 155 |
}
|
| 156 |
|
| 157 |
function restoreStyles() {
|
| 158 |
-
wrapper.style.cssText = '';
|
| 159 |
-
|
| 160 |
wrapper.classList.remove('fake-fullscreen');
|
| 161 |
fsBtn.textContent = 'β±';
|
| 162 |
isFullscreen = false;
|
|
|
|
| 1 |
// fullscreen.js
|
| 2 |
(function () {
|
| 3 |
// βββ 1. Localiser la balise <script> ββββββββββββββββββββββββββββββββββββββββ
|
| 4 |
+
const scriptTag = document.currentScript || (function () {
|
|
|
|
|
|
|
| 5 |
const all = document.getElementsByTagName('script');
|
| 6 |
for (let i = all.length - 1; i >= 0; i--) {
|
| 7 |
if (all[i].src && all[i].src.includes('fullscreen.js')) return all[i];
|
|
|
|
| 10 |
})();
|
| 11 |
|
| 12 |
const playcanvasUrl = scriptTag.getAttribute('data-src');
|
| 13 |
+
if (!playcanvasUrl) return;
|
|
|
|
|
|
|
|
|
|
| 14 |
|
|
|
|
| 15 |
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
|
|
|
|
|
|
| 16 |
const id = Math.random().toString(36).substr(2, 8);
|
| 17 |
|
| 18 |
+
// βββ 4. Calcul des ratios (Desktop & Mobile Portrait) ββββββββββββββββββββββββ
|
| 19 |
function computeAspectPadding(aspectStr) {
|
| 20 |
if (!aspectStr) return null;
|
| 21 |
if (aspectStr.includes(':')) {
|
| 22 |
const [w, h] = aspectStr.split(':').map(Number);
|
| 23 |
+
return (w > 0 && h > 0) ? (h / w) * 100 + '%' : null;
|
|
|
|
|
|
|
|
|
|
| 24 |
}
|
| 25 |
+
const v = parseFloat(aspectStr);
|
| 26 |
+
return (v > 0) ? (100 / v) + '%' : null;
|
| 27 |
}
|
| 28 |
|
| 29 |
+
const desktopPadding = computeAspectPadding(scriptTag.getAttribute('data-aspect')) || '56.25%';
|
| 30 |
+
const mobilePadding = computeAspectPadding(scriptTag.getAttribute('data-aspect-mobile')) || desktopPadding;
|
| 31 |
|
| 32 |
+
// βββ 5. Injection du CSS avec Media Queries ββββββββββββββββββββββββββββββββββ
|
| 33 |
const style = document.createElement('style');
|
| 34 |
style.textContent = `
|
| 35 |
.pc-embed-wrapper-${id} {
|
| 36 |
position: relative;
|
| 37 |
width: 100%;
|
| 38 |
height: 0;
|
|
|
|
| 39 |
overflow: hidden;
|
| 40 |
background: #000;
|
| 41 |
box-sizing: border-box;
|
| 42 |
+
/* Ratio par dΓ©faut (Paysage / Desktop) */
|
| 43 |
+
padding-bottom: ${desktopPadding};
|
| 44 |
}
|
| 45 |
+
|
| 46 |
+
/* Ratio Mobile Portrait : appliquΓ© uniquement si l'Γ©cran est plus haut que large */
|
| 47 |
+
@media (orientation: portrait) and (max-width: 768px) {
|
| 48 |
+
.pc-embed-wrapper-${id} {
|
| 49 |
+
padding-bottom: ${mobilePadding};
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
.pc-embed-wrapper-${id}.fake-fullscreen {
|
| 54 |
position: fixed !important;
|
| 55 |
top: 0 !important;
|
| 56 |
left: 0 !important;
|
| 57 |
width: 100vw !important;
|
| 58 |
+
height: 100vh !important;
|
| 59 |
+
height: 100dvh !important;
|
| 60 |
max-width: 100vw !important;
|
| 61 |
max-height: 100dvh !important;
|
| 62 |
padding-bottom: 0 !important;
|
|
|
|
| 89 |
text-align: center;
|
| 90 |
cursor: pointer;
|
| 91 |
user-select: none;
|
|
|
|
|
|
|
| 92 |
}
|
| 93 |
`;
|
| 94 |
document.head.appendChild(style);
|
|
|
|
| 96 |
// βββ 6. Construction du DOM ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 97 |
const wrapper = document.createElement('div');
|
| 98 |
wrapper.className = `pc-embed-wrapper-${id}`;
|
|
|
|
| 99 |
|
| 100 |
const inner = document.createElement('div');
|
| 101 |
inner.className = `pc-embed-inner-${id}`;
|
|
|
|
| 122 |
let savedParent = null;
|
| 123 |
let savedNextSibling = null;
|
| 124 |
|
|
|
|
| 125 |
function getHeightUnit() {
|
| 126 |
return (CSS && CSS.supports && CSS.supports('height', '100dvh')) ? '100dvh' : '100vh';
|
| 127 |
}
|
|
|
|
| 151 |
}
|
| 152 |
|
| 153 |
function restoreStyles() {
|
| 154 |
+
wrapper.style.cssText = '';
|
| 155 |
+
// Le CSS via les Media Queries reprendra le dessus automatiquement ici
|
| 156 |
wrapper.classList.remove('fake-fullscreen');
|
| 157 |
fsBtn.textContent = 'β±';
|
| 158 |
isFullscreen = false;
|