| Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 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 |  | 
 | 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 data-background-iframe="https://revealjs.com">1</section> | 
 | 24 | 				<section data-background-iframe="https://revealjs.com">2</section> | 
 | 25 | 				<section data-background-iframe="https://revealjs.com" data-preload>3</section> | 
 | 26 | 				<section data-background-iframe="https://revealjs.com">4</section> | 
 | 27 | 				<section data-background-iframe="https://revealjs.com">5</section> | 
 | 28 | 				<section data-background-iframe="https://revealjs.com">6</section> | 
 | 29 |  | 
 | 30 | 			</div> | 
 | 31 |  | 
 | 32 | 		</div> | 
 | 33 |  | 
 | 34 | 		<script src="../dist/reveal.js"></script> | 
 | 35 | 		<script> | 
 | 36 |  | 
 | 37 | 			Reveal.initialize({ viewDistance: 3 }).then( () => { | 
 | 38 |  | 
 | 39 | 				function getIframe( index ) { | 
 | 40 | 					return document.querySelectorAll( '.slide-background' )[index].querySelector( 'iframe' ); | 
 | 41 | 				} | 
 | 42 |  | 
 | 43 | 				QUnit.module( 'Iframe' ); | 
 | 44 |  | 
 | 45 | 				QUnit.test( 'Using default settings', function( assert ) { | 
 | 46 |  | 
 | 47 | 					Reveal.slide(0); | 
 | 48 | 					assert.strictEqual( getIframe(1).hasAttribute( 'src' ), false, 'not preloaded when within viewDistance' ); | 
 | 49 |  | 
 | 50 | 					Reveal.slide(1); | 
 | 51 | 					assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); | 
 | 52 |  | 
 | 53 | 					Reveal.slide(0); | 
 | 54 | 					assert.strictEqual( getIframe(1).hasAttribute( 'src' ), false, 'unloaded when slide becomes invisible' ); | 
 | 55 |  | 
 | 56 | 				}); | 
 | 57 |  | 
 | 58 | 				QUnit.test( 'Using data-preload', function( assert ) { | 
 | 59 |  | 
 | 60 | 					Reveal.slide(1); | 
 | 61 | 					assert.strictEqual( getIframe(2).hasAttribute( 'src' ), true, 'preloaded within viewDistance' ); | 
 | 62 | 					assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); | 
 | 63 |  | 
 | 64 | 					Reveal.slide(0); | 
 | 65 | 					assert.strictEqual( getIframe(3).hasAttribute( 'src' ), false, 'unloads outside of viewDistance' ); | 
 | 66 |  | 
 | 67 | 				}); | 
 | 68 |  | 
 | 69 | 				QUnit.test( 'Using preloadIframes: true', function( assert ) { | 
 | 70 |  | 
 | 71 | 					Reveal.configure({ preloadIframes: true }); | 
 | 72 |  | 
 | 73 | 					Reveal.slide(1); | 
 | 74 | 					assert.strictEqual( getIframe(0).hasAttribute( 'src' ), true, 'preloaded within viewDistance' ); | 
 | 75 | 					assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'preloaded within viewDistance' ); | 
 | 76 | 					assert.strictEqual( getIframe(2).hasAttribute( 'src' ), true, 'preloaded within viewDistance' ); | 
 | 77 |  | 
 | 78 | 				}); | 
 | 79 |  | 
 | 80 | 				QUnit.test( 'Using preloadIframes: false', function( assert ) { | 
 | 81 |  | 
 | 82 | 					Reveal.configure({ preloadIframes: false }); | 
 | 83 |  | 
 | 84 | 					Reveal.slide(0); | 
 | 85 | 					assert.strictEqual( getIframe(1).hasAttribute( 'src' ), false, 'not preloaded within viewDistance' ); | 
 | 86 | 					assert.strictEqual( getIframe(2).hasAttribute( 'src' ), false, 'not preloaded within viewDistance' ); | 
 | 87 |  | 
 | 88 | 					Reveal.slide(1); | 
 | 89 | 					assert.strictEqual( getIframe(1).hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); | 
 | 90 |  | 
 | 91 |  | 
 | 92 | 				}); | 
 | 93 |  | 
 | 94 | 			} ); | 
 | 95 | 		</script> | 
 | 96 |  | 
 | 97 | 	</body> | 
 | 98 | </html> |