test-iframes.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>reveal.js - Test Iframes</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>1</section>
  16. <section>2</section>
  17. <section>
  18. <iframe class="default-iframe" data-src="#"></iframe>
  19. <iframe class="preload-iframe" data-src="#" data-preload></iframe>
  20. </section>
  21. </div>
  22. </div>
  23. <script src="../dist/reveal.js"></script>
  24. <script>
  25. Reveal.initialize({ viewDistance: 2 }).then( () => {
  26. var defaultIframe = document.querySelector( '.default-iframe' ),
  27. preloadIframe = document.querySelector( '.preload-iframe' );
  28. QUnit.module( 'Iframe' );
  29. QUnit.test( 'Using default settings', function( assert ) {
  30. Reveal.slide(1);
  31. assert.strictEqual( defaultIframe.hasAttribute( 'src' ), false, 'not preloaded when within viewDistance' );
  32. Reveal.slide(2);
  33. assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
  34. Reveal.slide(1);
  35. assert.strictEqual( defaultIframe.hasAttribute( 'src' ), false, 'unloaded when slide becomes invisible' );
  36. });
  37. QUnit.test( 'Using data-preload', function( assert ) {
  38. Reveal.slide(1);
  39. assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
  40. Reveal.slide(2);
  41. assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'loaded when slide becoems visible' );
  42. Reveal.slide(0);
  43. assert.strictEqual( preloadIframe.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( defaultIframe.hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
  49. assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
  50. Reveal.slide(2);
  51. assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
  52. assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
  53. });
  54. QUnit.test( 'Using preloadIframes: false', function( assert ) {
  55. Reveal.configure({ preloadIframes: false });
  56. Reveal.slide(0);
  57. assert.strictEqual( defaultIframe.hasAttribute( 'src' ), false, 'not preloaded within viewDistance' );
  58. assert.strictEqual( preloadIframe.hasAttribute( 'src' ), false, 'not preloaded within viewDistance' );
  59. Reveal.slide(2);
  60. assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
  61. assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
  62. });
  63. } );
  64. </script>
  65. </body>
  66. </html>