test-iframe-backgrounds.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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="../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 data-background-iframe="#1">1</section>
  15. <section data-background-iframe="#2">2</section>
  16. <section data-background-iframe="#3" data-preload>3</section>
  17. <section data-background-iframe="#4">4</section>
  18. <section data-background-iframe="#5">5</section>
  19. <section data-background-iframe="#6">6</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. 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. Reveal.initialize({
  62. viewDistance: 3
  63. });
  64. </script>
  65. </body>
  66. </html>