summaryrefslogtreecommitdiff
path: root/2024-06-18-guix-social/reveal.js/test/test-iframe-backgrounds.html
blob: 7df99a14ebfa15b477f737902ecf227227da0f67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!doctype html>
<html lang="en">

	<head>
		<meta charset="utf-8">

		<title>reveal.js - Test Iframe Backgrounds</title>

		<link rel="stylesheet" href="../dist/reveal.css">
		<link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css">
		<script src="../node_modules/qunit/qunit/qunit.js"></script>
	</head>

	<body style="overflow: auto;">

		<div id="qunit"></div>
		<div id="qunit-fixture"></div>

		<div class="reveal" style="display: none;">

			<div class="slides">

				<section data-background-iframe="https://revealjs.com">1</section>
				<section data-background-iframe="https://revealjs.com">2</section>
				<section data-background-iframe="https://revealjs.com" data-preload>3</section>
				<section data-background-iframe="https://revealjs.com">4</section>
				<section data-background-iframe="https://revealjs.com">5</section>
				<section data-background-iframe="https://revealjs.com">6</section>

			</div>

		</div>

		<script src="../dist/reveal.js"></script>
		<script>

			QUnit.config.testTimeout = 30000;

			Reveal.initialize({ viewDistance: 3 }).then( () => {

				function getIframe( index ) {
					return document.querySelectorAll( '.slide-background' )[index].querySelector( 'iframe' );
				}

				QUnit.module( 'Iframe' );

				QUnit.test( 'Using default settings', function( assert ) {

					Reveal.slide(0);
					assert.strictEqual( getIframe(1).hasAttribute( 'src' ), false, 'not preloaded when within viewDistance' );

					Reveal.slide(1);
					assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );

					Reveal.slide(0);
					assert.strictEqual( getIframe(1).hasAttribute( 'src' ), false, 'unloaded when slide becomes invisible' );

				});

				QUnit.test( 'Using data-preload', function( assert ) {

					Reveal.slide(1);
					assert.strictEqual( getIframe(2).hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
					assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );

					Reveal.slide(0);
					assert.strictEqual( getIframe(3).hasAttribute( 'src' ), false, 'unloads outside of viewDistance' );

				});

				QUnit.test( 'Using preloadIframes: true', function( assert ) {

					Reveal.configure({ preloadIframes: true });

					Reveal.slide(1);
					assert.strictEqual( getIframe(0).hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
					assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
					assert.strictEqual( getIframe(2).hasAttribute( 'src' ), true, 'preloaded within viewDistance' );

				});

				QUnit.test( 'Using preloadIframes: false', function( assert ) {

					Reveal.configure({ preloadIframes: false });

					Reveal.slide(0);
					assert.strictEqual( getIframe(1).hasAttribute( 'src' ), false, 'not preloaded within viewDistance' );
					assert.strictEqual( getIframe(2).hasAttribute( 'src' ), false, 'not preloaded within viewDistance' );

					Reveal.slide(1);
					assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );


				});

			} );
		</script>

	</body>
</html>