summaryrefslogtreecommitdiff
path: root/2024-06-18-guix-social/reveal.js/test/test-iframes.html
blob: fa4b434f4312cebaa06438b1334c87538f4ed787 (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
101
102
103
104
<!doctype html>
<html lang="en">

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

		<title>reveal.js - Test Iframes</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>1</section>
				<section>2</section>
				<section>
					<iframe class="default-iframe" data-src="#"></iframe>
					<iframe class="preload-iframe" data-src="#" data-preload></iframe>
				</section>

			</div>

		</div>

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

			QUnit.config.testTimeout = 30000;

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

				var defaultIframe = document.querySelector( '.default-iframe' ),
					preloadIframe = document.querySelector( '.preload-iframe' );

				QUnit.module( 'Iframe' );

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

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

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

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

				});

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

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

					Reveal.slide(2);
					assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'loaded when slide becoems visible' );

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

				});

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

					Reveal.configure({ preloadIframes: true });

					Reveal.slide(1);
					assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'preloaded within viewDistance' );
					assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'preloaded within viewDistance' );

					Reveal.slide(2);
					assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
					assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );

				});

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

					Reveal.configure({ preloadIframes: false });

					Reveal.slide(0);
					assert.strictEqual( defaultIframe.hasAttribute( 'src' ), false, 'not preloaded within viewDistance' );
					assert.strictEqual( preloadIframe.hasAttribute( 'src' ), false, 'not preloaded within viewDistance' );

					Reveal.slide(2);
					assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );
					assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' );

				});

			} );
		</script>

	</body>
</html>