test-iframes.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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="../css/reveal.css">
  7. <link rel="stylesheet" href="qunit-2.5.0.css">
  8. </head>
  9. <body style="overflow: auto;">
  10. <div id="qunit"></div>
  11. <div id="qunit-fixture"></div>
  12. <div class="reveal" style="display: none;">
  13. <div class="slides">
  14. <section>1</section>
  15. <section>2</section>
  16. <section>
  17. <iframe class="default-iframe" data-src="#"></iframe>
  18. <iframe class="preload-iframe" data-src="#" data-preload></iframe>
  19. </section>
  20. </div>
  21. </div>
  22. <script src="../js/reveal.js"></script>
  23. <script src="qunit-2.5.0.js"></script>
  24. <script>
  25. Reveal.addEventListener( 'ready', function() {
  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. Reveal.initialize({
  65. viewDistance: 2
  66. });
  67. </script>
  68. </body>
  69. </html>