| 1 | <!doctype html> |
| 2 | <html lang="en"> |
| 3 | |
| 4 | <head> |
| 5 | <meta charset="utf-8"> |
| 6 | |
| 7 | <title>reveal.js - Test Iframes</title> |
| 8 | </head> |
| 9 | |
| 10 | <body style="overflow: auto;"> |
| 11 | |
| 12 | <div id="qunit"></div> |
| 13 | <div id="qunit-fixture"></div> |
| 14 | |
| 15 | <div class="reveal" style="display: none;"> |
| 16 | |
| 17 | <div class="slides"> |
| 18 | |
| 19 | <section>1</section> |
| 20 | <section>2</section> |
| 21 | <section> |
| 22 | <iframe class="default-iframe" data-src="#"></iframe> |
| 23 | <iframe class="preload-iframe" data-src="#" data-preload></iframe> |
| 24 | </section> |
| 25 | |
| 26 | </div> |
| 27 | |
| 28 | </div> |
| 29 | |
| 30 | <script type="module"> |
| 31 | import 'reveal.css'; |
| 32 | import 'qunit/qunit/qunit.css'; |
| 33 | import QUnit from 'qunit'; |
| 34 | import Reveal from 'reveal.js'; |
| 35 | |
| 36 | QUnit.config.testTimeout = 30000; |
| 37 | |
| 38 | Reveal.initialize({ viewDistance: 2 }); |
| 39 | |
| 40 | var defaultIframe = document.querySelector( '.default-iframe' ), |
| 41 | preloadIframe = document.querySelector( '.preload-iframe' ); |
| 42 | |
| 43 | QUnit.module( 'Iframe' ); |
| 44 | |
| 45 | QUnit.test( 'Using default settings', function( assert ) { |
| 46 | |
| 47 | Reveal.slide(1); |
| 48 | assert.strictEqual( defaultIframe.hasAttribute( 'src' ), false, 'not preloaded when within viewDistance' ); |
| 49 | |
| 50 | Reveal.slide(2); |
| 51 | assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); |
| 52 | |
| 53 | Reveal.slide(1); |
| 54 | assert.strictEqual( defaultIframe.hasAttribute( 'src' ), false, 'unloaded when slide becomes invisible' ); |
| 55 | |
| 56 | }); |
| 57 | |
| 58 | QUnit.test( 'Using data-preload', function( assert ) { |
| 59 | |
| 60 | Reveal.slide(1); |
| 61 | assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'preloaded within viewDistance' ); |
| 62 | |
| 63 | Reveal.slide(2); |
| 64 | assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); |
| 65 | |
| 66 | Reveal.slide(0); |
| 67 | assert.strictEqual( preloadIframe.hasAttribute( 'src' ), false, 'unloads outside of viewDistance' ); |
| 68 | |
| 69 | }); |
| 70 | |
| 71 | QUnit.test( 'Using preloadIframes: true', function( assert ) { |
| 72 | |
| 73 | Reveal.configure({ preloadIframes: true }); |
| 74 | |
| 75 | Reveal.slide(1); |
| 76 | assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'preloaded within viewDistance' ); |
| 77 | assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'preloaded within viewDistance' ); |
| 78 | |
| 79 | Reveal.slide(2); |
| 80 | assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); |
| 81 | assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); |
| 82 | |
| 83 | }); |
| 84 | |
| 85 | QUnit.test( 'Using preloadIframes: false', function( assert ) { |
| 86 | |
| 87 | Reveal.configure({ preloadIframes: false }); |
| 88 | |
| 89 | Reveal.slide(0); |
| 90 | assert.strictEqual( defaultIframe.hasAttribute( 'src' ), false, 'not preloaded within viewDistance' ); |
| 91 | assert.strictEqual( preloadIframe.hasAttribute( 'src' ), false, 'not preloaded within viewDistance' ); |
| 92 | |
| 93 | Reveal.slide(2); |
| 94 | assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); |
| 95 | assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); |
| 96 | |
| 97 | }); |
| 98 | </script> |
| 99 | |
| 100 | </body> |
| 101 | </html> |
| 102 |