aboutsummaryrefslogtreecommitdiff
path: root/test/test-iframes.html
blob: 979bb7d60939a22ac0575e5a18d69ac5eb1941af (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
105
106
107
108
<!doctype html>
<html lang="en">

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

		<title>reveal.js - Test Iframes</title>

		<link rel="stylesheet" href="../css/reveal.css">
		<link rel="stylesheet" href="qunit-2.5.0.css">
	</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="../js/reveal.js"></script>
		<script src="qunit-2.5.0.js"></script>

		<script>


			Reveal.addEventListener( 'ready', function() {

				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' );

				});

			} );

			Reveal.initialize({
				viewDistance: 2
			});
		</script>

	</body>
</html>