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