You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

105 line
3.1 KiB

  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. QUnit.config.testTimeout = 30000;
  26. Reveal.initialize({ viewDistance: 2 }).then( () => {
  27. var defaultIframe = document.querySelector( '.default-iframe' ),
  28. preloadIframe = document.querySelector( '.preload-iframe' );
  29. QUnit.module( 'Iframe' );
  30. QUnit.test( 'Using default settings', function( assert ) {
  31. Reveal.slide(1);
  32. assert.strictEqual( defaultIframe.hasAttribute( 'src' ), false, 'not preloaded when within viewDistance' );
  33. Reveal.slide(2);
  34. assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
  35. Reveal.slide(1);
  36. assert.strictEqual( defaultIframe.hasAttribute( 'src' ), false, 'unloaded when slide becomes invisible' );
  37. });
  38. QUnit.test( 'Using data-preload', function( assert ) {
  39. Reveal.slide(1);
  40. assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
  41. Reveal.slide(2);
  42. assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'loaded when slide becoems visible' );
  43. Reveal.slide(0);
  44. assert.strictEqual( preloadIframe.hasAttribute( 'src' ), false, 'unloads outside of viewDistance' );
  45. });
  46. QUnit.test( 'Using preloadIframes: true', function( assert ) {
  47. Reveal.configure({ preloadIframes: true });
  48. Reveal.slide(1);
  49. assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
  50. assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
  51. Reveal.slide(2);
  52. assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
  53. assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
  54. });
  55. QUnit.test( 'Using preloadIframes: false', function( assert ) {
  56. Reveal.configure({ preloadIframes: false });
  57. Reveal.slide(0);
  58. assert.strictEqual( defaultIframe.hasAttribute( 'src' ), false, 'not preloaded within viewDistance' );
  59. assert.strictEqual( preloadIframe.hasAttribute( 'src' ), false, 'not preloaded within viewDistance' );
  60. Reveal.slide(2);
  61. assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
  62. assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
  63. });
  64. } );
  65. </script>
  66. </body>
  67. </html>