返回 reveal.js
test-iframe-backgrounds.html
根目录 / test / test-iframe-backgrounds.html
1 <!doctype html>
2 <html lang="en">
3
4 <head>
5 <meta charset="utf-8">
6
7 <title>reveal.js - Test Iframe Backgrounds</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 data-background-iframe="https://revealjs.com">1</section>
20 <section data-background-iframe="https://revealjs.com">2</section>
21 <section data-background-iframe="https://revealjs.com" data-preload>3</section>
22 <section data-background-iframe="https://revealjs.com">4</section>
23 <section data-background-iframe="https://revealjs.com">5</section>
24 <section data-background-iframe="https://revealjs.com">6</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: 3 }).then( () => {
39
40 function getIframe( index ) {
41 return document.querySelectorAll( '.slide-background' )[index].querySelector( 'iframe' );
42 }
43
44 QUnit.module( 'Iframe' );
45
46 QUnit.test( 'Using default settings', function( assert ) {
47
48 Reveal.slide(0);
49 assert.strictEqual( getIframe(1).hasAttribute( 'src' ), false, 'not preloaded when within viewDistance' );
50
51 Reveal.slide(1);
52 assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
53
54 Reveal.slide(0);
55 assert.strictEqual( getIframe(1).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( getIframe(2).hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
63 assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
64
65 Reveal.slide(0);
66 assert.strictEqual( getIframe(3).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( getIframe(0).hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
76 assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
77 assert.strictEqual( getIframe(2).hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
78
79 });
80
81 QUnit.test( 'Using preloadIframes: false', function( assert ) {
82
83 Reveal.configure({ preloadIframes: false });
84
85 Reveal.slide(0);
86 assert.strictEqual( getIframe(1).hasAttribute( 'src' ), false, 'not preloaded within viewDistance' );
87 assert.strictEqual( getIframe(2).hasAttribute( 'src' ), false, 'not preloaded within viewDistance' );
88
89 Reveal.slide(1);
90 assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
91
92
93 });
94
95 } );
96 </script>
97
98 </body>
99 </html>
100
100 lines HTML