popup is not playing
Browse files- components/youtube-modal.js +20 -13
components/youtube-modal.js
CHANGED
|
@@ -114,24 +114,28 @@ position: fixed;
|
|
| 114 |
setupEventListeners() {
|
| 115 |
this.modal = this.shadowRoot.getElementById('youtube-modal');
|
| 116 |
this.closeBtn = this.shadowRoot.getElementById('modal-close-btn');
|
| 117 |
-
this.backdrop = this.shadowRoot.getElementById('youtube-modal-backdrop');
|
| 118 |
-
|
| 119 |
-
if (this.closeBtn) {
|
| 120 |
this.closeBtn.addEventListener('click', () => this.close());
|
| 121 |
}
|
| 122 |
|
| 123 |
if (this.backdrop) {
|
| 124 |
-
this.backdrop.addEventListener('click', () =>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
}
|
| 126 |
|
| 127 |
document.addEventListener('keydown', (e) => {
|
| 128 |
if (e.key === 'Escape' && this.isOpen) {
|
|
|
|
| 129 |
this.close();
|
| 130 |
}
|
| 131 |
});
|
| 132 |
-
}
|
| 133 |
-
|
| 134 |
-
static get observedAttributes() {
|
| 135 |
return ['video-id'];
|
| 136 |
}
|
| 137 |
|
|
@@ -144,29 +148,32 @@ if (this.closeBtn) {
|
|
| 144 |
}
|
| 145 |
}
|
| 146 |
open(videoId) {
|
| 147 |
-
if (!videoId
|
| 148 |
|
| 149 |
this.activeVideoId = videoId;
|
| 150 |
const iframe = this.shadowRoot.getElementById('youtube-iframe');
|
| 151 |
-
iframe
|
|
|
|
|
|
|
| 152 |
|
| 153 |
this.modal.classList.add('active');
|
| 154 |
document.body.style.overflow = 'hidden';
|
| 155 |
document.documentElement.style.overflow = 'hidden';
|
| 156 |
this.isOpen = true;
|
| 157 |
}
|
| 158 |
-
|
|
|
|
| 159 |
if (!this.isOpen) return;
|
| 160 |
|
| 161 |
const iframe = this.shadowRoot.getElementById('youtube-iframe');
|
| 162 |
if (iframe) {
|
| 163 |
-
|
| 164 |
-
iframe.src = iframe.src.replace(/[\?&]autoplay=1/, '') + '&autoplay=0';
|
| 165 |
}
|
|
|
|
| 166 |
this.modal.classList.remove('active');
|
| 167 |
document.body.style.overflow = '';
|
| 168 |
document.documentElement.style.overflow = '';
|
| 169 |
-
this.isOpen = false;
|
| 170 |
}
|
| 171 |
}
|
| 172 |
|
|
|
|
| 114 |
setupEventListeners() {
|
| 115 |
this.modal = this.shadowRoot.getElementById('youtube-modal');
|
| 116 |
this.closeBtn = this.shadowRoot.getElementById('modal-close-btn');
|
| 117 |
+
this.backdrop = this.shadowRoot.getElementById('youtube-modal-backdrop');
|
| 118 |
+
|
| 119 |
+
if (this.closeBtn) {
|
| 120 |
this.closeBtn.addEventListener('click', () => this.close());
|
| 121 |
}
|
| 122 |
|
| 123 |
if (this.backdrop) {
|
| 124 |
+
this.backdrop.addEventListener('click', (e) => {
|
| 125 |
+
if (e.target === this.backdrop) {
|
| 126 |
+
this.close();
|
| 127 |
+
}
|
| 128 |
+
});
|
| 129 |
}
|
| 130 |
|
| 131 |
document.addEventListener('keydown', (e) => {
|
| 132 |
if (e.key === 'Escape' && this.isOpen) {
|
| 133 |
+
e.preventDefault();
|
| 134 |
this.close();
|
| 135 |
}
|
| 136 |
});
|
| 137 |
+
}
|
| 138 |
+
static get observedAttributes() {
|
|
|
|
| 139 |
return ['video-id'];
|
| 140 |
}
|
| 141 |
|
|
|
|
| 148 |
}
|
| 149 |
}
|
| 150 |
open(videoId) {
|
| 151 |
+
if (!videoId) return;
|
| 152 |
|
| 153 |
this.activeVideoId = videoId;
|
| 154 |
const iframe = this.shadowRoot.getElementById('youtube-iframe');
|
| 155 |
+
if (iframe) {
|
| 156 |
+
iframe.src = `https://www.youtube.com/embed/${videoId}?autoplay=1&rel=0&modestbranding=1`;
|
| 157 |
+
}
|
| 158 |
|
| 159 |
this.modal.classList.add('active');
|
| 160 |
document.body.style.overflow = 'hidden';
|
| 161 |
document.documentElement.style.overflow = 'hidden';
|
| 162 |
this.isOpen = true;
|
| 163 |
}
|
| 164 |
+
|
| 165 |
+
close() {
|
| 166 |
if (!this.isOpen) return;
|
| 167 |
|
| 168 |
const iframe = this.shadowRoot.getElementById('youtube-iframe');
|
| 169 |
if (iframe) {
|
| 170 |
+
iframe.src = '';
|
|
|
|
| 171 |
}
|
| 172 |
+
|
| 173 |
this.modal.classList.remove('active');
|
| 174 |
document.body.style.overflow = '';
|
| 175 |
document.documentElement.style.overflow = '';
|
| 176 |
+
this.isOpen = false;
|
| 177 |
}
|
| 178 |
}
|
| 179 |
|