test-iframe-backgrounds.html 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>reveal.js - Test Iframe Backgrounds</title>
  6. <link rel="stylesheet" href="../dist/reveal.css">
  7. <link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css">
  8. <script src="../node_modules/qunit/qunit/qunit.js"></script>
  9. </head>
  10. <body style="overflow: auto;">
  11. <div id="qunit"></div>
  12. <div id="qunit-fixture"></div>
  13. <div class="reveal" style="display: none;">
  14. <div class="slides">
  15. <section data-background-iframe="https://revealjs.com">1</section>
  16. <section data-background-iframe="https://revealjs.com">2</section>
  17. <section data-background-iframe="https://revealjs.com" data-preload>3</section>
  18. <section data-background-iframe="https://revealjs.com">4</section>
  19. <section data-background-iframe="https://revealjs.com">5</section>
  20. <section data-background-iframe="https://revealjs.com">6</section>
  21. </div>
  22. </div>
  23. <script src="../dist/reveal.js"></script>
  24. <script>
  25. Reveal.initialize({ viewDistance: 3 }).then( () => {
  26. function getIframe( index ) {
  27. return document.querySelectorAll( '.slide-background' )[index].querySelector( 'iframe' );
  28. }
  29. QUnit.module( 'Iframe' );
  30. QUnit.test( 'Using default settings', function( assert ) {
  31. Reveal.slide(0);
  32. assert.strictEqual( getIframe(1).hasAttribute( 'src' ), false, 'not preloaded when within viewDistance' );
  33. Reveal.slide(1);
  34. assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
  35. Reveal.slide(0);
  36. assert.strictEqual( getIframe(1).hasAttribute( 'src' ), false, 'unloaded when slide becomes invisible' );
  37. });
  38. QUnit.test( 'Using data-preload', function( assert ) {
  39. Reveal.slide(1);
  40. assert.strictEqual( getIframe(2).hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
  41. assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
  42. Reveal.slide(0);
  43. assert.strictEqual( getIframe(3).hasAttribute( 'src' ), false, 'unloads outside of viewDistance' );
  44. });
  45. QUnit.test( 'Using preloadIframes: true', function( assert ) {
  46. Reveal.configure({ preloadIframes: true });
  47. Reveal.slide(1);
  48. assert.strictEqual( getIframe(0).hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
  49. assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
  50. assert.strictEqual( getIframe(2).hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
  51. });
  52. QUnit.test( 'Using preloadIframes: false', function( assert ) {
  53. Reveal.configure({ preloadIframes: false });
  54. Reveal.slide(0);
  55. assert.strictEqual( getIframe(1).hasAttribute( 'src' ), false, 'not preloaded within viewDistance' );
  56. assert.strictEqual( getIframe(2).hasAttribute( 'src' ), false, 'not preloaded within viewDistance' );
  57. Reveal.slide(1);
  58. assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
  59. });
  60. } );
  61. </script>
  62. </body>
  63. </html>