blob: fa4b434f4312cebaa06438b1334c87538f4ed787 [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
Marc Kupietz09b75752023-10-07 09:32:19 +020037 QUnit.config.testTimeout = 30000;
38
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +020039 Reveal.initialize({ viewDistance: 2 }).then( () => {
40
41 var defaultIframe = document.querySelector( '.default-iframe' ),
42 preloadIframe = document.querySelector( '.preload-iframe' );
43
44 QUnit.module( 'Iframe' );
45
46 QUnit.test( 'Using default settings', function( assert ) {
47
48 Reveal.slide(1);
49 assert.strictEqual( defaultIframe.hasAttribute( 'src' ), false, 'not preloaded when within viewDistance' );
50
51 Reveal.slide(2);
52 assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
53
54 Reveal.slide(1);
55 assert.strictEqual( defaultIframe.hasAttribute( 'src' ), false, 'unloaded when slide becomes invisible' );
56
57 });
58
59 QUnit.test( 'Using data-preload', function( assert ) {
60
61 Reveal.slide(1);
62 assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
63
64 Reveal.slide(2);
65 assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'loaded when slide becoems visible' );
66
67 Reveal.slide(0);
68 assert.strictEqual( preloadIframe.hasAttribute( 'src' ), false, 'unloads outside of viewDistance' );
69
70 });
71
72 QUnit.test( 'Using preloadIframes: true', function( assert ) {
73
74 Reveal.configure({ preloadIframes: true });
75
76 Reveal.slide(1);
77 assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
78 assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
79
80 Reveal.slide(2);
81 assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
82 assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
83
84 });
85
86 QUnit.test( 'Using preloadIframes: false', function( assert ) {
87
88 Reveal.configure({ preloadIframes: false });
89
90 Reveal.slide(0);
91 assert.strictEqual( defaultIframe.hasAttribute( 'src' ), false, 'not preloaded within viewDistance' );
92 assert.strictEqual( preloadIframe.hasAttribute( 'src' ), false, 'not preloaded within viewDistance' );
93
94 Reveal.slide(2);
95 assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
96 assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
97
98 });
99
100 } );
101 </script>
102
103 </body>
104</html>