|
316 | 316 | }); |
317 | 317 |
|
318 | 318 | {% if one_file %} |
319 | | - // Fix found by @t-fritsch and @Rapsssito on GitHub |
320 | | - // see: https://github.com/hakimel/reveal.js/discussions/3362#discussioncomment-11733074. |
321 | | - function fixBase64VideoBackground(event) { |
322 | | - // Analyze all slides backgrounds |
323 | | - for (const slide of Reveal.getBackgroundsElement().querySelectorAll('.slide-background')) { |
324 | | - // Get the slide video and its sources for each background |
325 | | - const video = slide.querySelector('video'); |
326 | | - const sources = video.querySelectorAll('source'); |
327 | | - // Update the source of the video |
328 | | - sources.forEach((source, i) => { |
329 | | - const src = source.getAttribute('src'); |
330 | | - if(src.match(/^data:video.*;base64$/)) { |
331 | | - const nextSrc = sources[i+1]?.getAttribute('src'); |
332 | | - video.setAttribute('src', `${src},${nextSrc}`); |
| 319 | + // Fix found by @t-fritsch and @Rapsssito on GitHub |
| 320 | + // see: https://github.com/hakimel/reveal.js/discussions/3362#discussioncomment-11733074. |
| 321 | + function setVideoBase64(video) { |
| 322 | + const sources = video.querySelectorAll('source'); |
| 323 | + // Update the source of the video |
| 324 | + sources.forEach((source, i) => { |
| 325 | + const src = source.getAttribute('src'); |
| 326 | + if(src.match(/^data:video.*;base64$/)) { |
| 327 | + const nextSrc = sources[i+1]?.getAttribute('src'); |
| 328 | + video.setAttribute('src', `${src},${nextSrc}`); |
| 329 | + } |
| 330 | + }); |
| 331 | + } |
| 332 | + |
| 333 | + function fixBase64VideoBackground(event) { |
| 334 | + // Analyze all slides backgrounds |
| 335 | + for (const slide of Reveal.getBackgroundsElement().querySelectorAll('.slide-background')) { |
| 336 | + // Get the slide video and its sources for each background |
| 337 | + const video = slide.querySelector('video'); |
| 338 | + if (video) { |
| 339 | + setVideoBase64(video); |
| 340 | + } else { |
| 341 | + // Listen to the creation of the video element |
| 342 | + const observer = new MutationObserver((mutationsList) => { |
| 343 | + for (const mutation of mutationsList) { |
| 344 | + if (mutation.type === 'childList') { |
| 345 | + for (const addedNode of mutation.addedNodes) { |
| 346 | + if (addedNode.tagName === 'VIDEO') { |
| 347 | + setVideoBase64(addedNode); |
| 348 | + observer.disconnect(); // Stop observing once the video is handled |
| 349 | + } |
| 350 | + } |
| 351 | + } |
333 | 352 | } |
334 | 353 | }); |
| 354 | + observer.observe(slide, { childList: true, subtree: true }); |
335 | 355 | } |
336 | 356 | } |
337 | | - // Setup base64 videos |
338 | | - Reveal.on( 'ready', fixBase64VideoBackground ); |
| 357 | + } |
| 358 | + // Setup base64 videos |
| 359 | + Reveal.on( 'ready', fixBase64VideoBackground ); |
339 | 360 | {% endif %} |
340 | 361 | </script> |
341 | 362 |
|
|
0 commit comments