MikaFil commited on
Commit
fa92696
Β·
verified Β·
1 Parent(s): 6972ed9

Update fullscreen_playcanvas.js

Browse files
Files changed (1) hide show
  1. 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 du padding-bottom (aspect ratio) ──────────────────────────────
27
  function computeAspectPadding(aspectStr) {
28
  if (!aspectStr) return null;
29
  if (aspectStr.includes(':')) {
30
  const [w, h] = aspectStr.split(':').map(Number);
31
- if (w > 0 && h > 0) return (h / w) * 100 + '%';
32
- } else {
33
- const v = parseFloat(aspectStr);
34
- if (v > 0) return (100 / v) + '%';
35
  }
36
- return null;
 
37
  }
38
 
39
- const aspectPadding = computeAspectPadding(scriptTag.getAttribute('data-aspect')) || '56.25%';
 
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; /* Fallback */
59
- height: 100dvh !important; /* iOS 16+ dynamique */
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 = ''; // Nettoie les styles inline
159
- wrapper.style.paddingBottom = aspectPadding;
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;