Skip to content

Commit 860580d

Browse files
committed
getSlideBackground now works in pdf mode, add pdf tests
1 parent 41e1e01 commit 860580d

4 files changed

Lines changed: 108 additions & 2 deletions

File tree

css/print/pdf.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ ul, ol, div, p {
152152

153153
/* Slide backgrounds are placed inside of their slide when exporting to PDF */
154154
.reveal section .slide-background {
155+
display: block !important;
155156
position: absolute;
156157
top: 0;
157158
left: 0;

js/reveal.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,11 +2693,18 @@ var Reveal = (function(){
26932693
/**
26942694
* Returns the background element for the given slide.
26952695
* All slides, even the ones with no background properties
2696-
* defined, have a background element so this never returns
2697-
* null.
2696+
* defined, have a background element so as long as the
2697+
* index is valid an element will be returned.
26982698
*/
26992699
function getSlideBackground( x, y ) {
27002700

2701+
// When printing to PDF the slide backgrounds are nested
2702+
// inside of the slides
2703+
if( isPrintingPDF() ) {
2704+
var slide = getSlide( x, y );
2705+
return slide ? slide.querySelector( '.slide-background' ) : undefined;
2706+
}
2707+
27012708
var horizontalBackground = document.querySelectorAll( '.backgrounds>.slide-background' )[ x ];
27022709
var verticalBackgrounds = horizontalBackground && horizontalBackground.querySelectorAll( '.slide-background' );
27032710

test/test-pdf.html

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<!doctype html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8">
6+
7+
<title>reveal.js - Test PDF exports</title>
8+
9+
<link rel="stylesheet" href="../css/reveal.css">
10+
<link rel="stylesheet" href="../css/print/pdf.css">
11+
<link rel="stylesheet" href="qunit-1.12.0.css">
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>
24+
<h1>1</h1>
25+
<img data-src="fake-url.png">
26+
</section>
27+
28+
<section>
29+
<section>
30+
<h1>2.1</h1>
31+
</section>
32+
<section>
33+
<h1>2.2</h1>
34+
</section>
35+
<section>
36+
<h1>2.3</h1>
37+
</section>
38+
</section>
39+
40+
<section id="fragment-slides">
41+
<section>
42+
<h1>3.1</h1>
43+
<ul>
44+
<li class="fragment">4.1</li>
45+
<li class="fragment">4.2</li>
46+
<li class="fragment">4.3</li>
47+
</ul>
48+
</section>
49+
50+
<section>
51+
<h1>3.2</h1>
52+
<ul>
53+
<li class="fragment" data-fragment-index="0">4.1</li>
54+
<li class="fragment" data-fragment-index="0">4.2</li>
55+
</ul>
56+
</section>
57+
58+
<section>
59+
<h1>3.3</h1>
60+
<ul>
61+
<li class="fragment" data-fragment-index="1">3.3.1</li>
62+
<li class="fragment" data-fragment-index="4">3.3.2</li>
63+
<li class="fragment" data-fragment-index="4">3.3.3</li>
64+
</ul>
65+
</section>
66+
</section>
67+
68+
<section>
69+
<h1>4</h1>
70+
</section>
71+
72+
</div>
73+
74+
</div>
75+
76+
<script src="../lib/js/head.min.js"></script>
77+
<script src="../js/reveal.js"></script>
78+
<script src="qunit-1.12.0.js"></script>
79+
80+
<script src="test-pdf.js"></script>
81+
82+
</body>
83+
</html>

test/test-pdf.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
Reveal.addEventListener( 'ready', function() {
3+
4+
// Only one test for now, we're mainly ensuring that there
5+
// are no execution errors when running PDF mode
6+
7+
test( 'Reveal.isReady', function() {
8+
strictEqual( Reveal.isReady(), true, 'returns true' );
9+
});
10+
11+
12+
} );
13+
14+
Reveal.initialize({ pdf: true });
15+

0 commit comments

Comments
 (0)