Skip to content

Commit 0338f28

Browse files
committed
add getSlideNotes API method and tests
1 parent 5a40b44 commit 0338f28

4 files changed

Lines changed: 44 additions & 18 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,9 @@ Reveal.getIndices(); // { h: 0, v: 0 } }
372372
Reveal.getProgress(); // 0-1
373373
Reveal.getTotalSlides();
374374

375+
// Returns the speaker notes for the current slide
376+
Reveal.getSlideNotes();
377+
375378
// State checks
376379
Reveal.isFirstSlide();
377380
Reveal.isLastSlide();

js/reveal.js

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,22 +2475,7 @@
24752475

24762476
if( config.showNotes && dom.speakerNotes && currentSlide && !isPrintingPDF() ) {
24772477

2478-
var notes = '';
2479-
2480-
// Notes can be specified via the data-notes attribute...
2481-
if( currentSlide.hasAttribute( 'data-notes' ) ) {
2482-
notes = currentSlide.getAttribute( 'data-notes' );
2483-
}
2484-
2485-
// ... or using an <aside class="notes"> element
2486-
if( !notes ) {
2487-
var notesElement = currentSlide.querySelector( 'aside.notes' );
2488-
if( notesElement ) {
2489-
notes = notesElement.innerHTML;
2490-
}
2491-
}
2492-
2493-
dom.speakerNotes.innerHTML = notes;
2478+
dom.speakerNotes.innerHTML = getSlideNotes() || '';
24942479

24952480
}
24962481

@@ -3335,6 +3320,32 @@
33353320

33363321
}
33373322

3323+
/**
3324+
* Retrieves the speaker notes from a slide. Notes can be
3325+
* defined in two ways:
3326+
* 1. As a data-notes attribute on the slide <section>
3327+
* 2. As an <aside class="notes"> inside of the slide
3328+
*/
3329+
function getSlideNotes( slide ) {
3330+
3331+
// Default to the current slide
3332+
slide = slide || currentSlide;
3333+
3334+
// Notes can be specified via the data-notes attribute...
3335+
if( slide.hasAttribute( 'data-notes' ) ) {
3336+
return slide.getAttribute( 'data-notes' );
3337+
}
3338+
3339+
// ... or using an <aside class="notes"> element
3340+
var notesElement = slide.querySelector( 'aside.notes' );
3341+
if( notesElement ) {
3342+
return notesElement.innerHTML;
3343+
}
3344+
3345+
return null;
3346+
3347+
}
3348+
33383349
/**
33393350
* Retrieves the current state of the presentation as
33403351
* an object. This state can then be restored at any
@@ -4486,6 +4497,9 @@
44864497
// Returns the slide background element at the specified index
44874498
getSlideBackground: getSlideBackground,
44884499

4500+
// Returns the speaker notes string for a slide, or null
4501+
getSlideNotes: getSlideNotes,
4502+
44894503
// Returns the previous slide element, may be null
44904504
getPreviousSlide: function() {
44914505
return previousSlide;

test/test.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ <h1>1</h1>
2424
<img data-src="fake-url.png">
2525
<video data-src="fake-url.mp4"></video>
2626
<audio data-src="fake-url.mp3"></audio>
27+
<aside class="notes">speaker notes 1</aside>
2728
</section>
2829

2930
<section>
30-
<section data-background="examples/assets/image2.png">
31+
<section data-background="examples/assets/image2.png" data-notes="speaker notes 2">
3132
<h1>2.1</h1>
3233
</section>
3334
<section>

test/test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Reveal.addEventListener( 'ready', function() {
8989

9090
test( 'Reveal.isLastSlide after vertical slide', function() {
9191
var lastSlideIndex = document.querySelectorAll( '.reveal .slides>section' ).length - 1;
92-
92+
9393
Reveal.slide( 1, 1 );
9494
Reveal.slide( lastSlideIndex );
9595
strictEqual( Reveal.isLastSlide(), true, 'true after Reveal.slide( 1, 1 ) and then Reveal.slide( '+ lastSlideIndex +', 0 )' );
@@ -139,6 +139,14 @@ Reveal.addEventListener( 'ready', function() {
139139
strictEqual( Reveal.getSlideBackground( 1, 100 ), undefined, 'undefined when out of vertical bounds' );
140140
});
141141

142+
test( 'Reveal.getSlideNotes', function() {
143+
Reveal.slide( 0, 0 );
144+
ok( Reveal.getSlideNotes() === 'speaker notes 1', 'works with <aside class="notes">' );
145+
146+
Reveal.slide( 1, 0 );
147+
ok( Reveal.getSlideNotes() === 'speaker notes 2', 'works with <section data-notes="">' );
148+
});
149+
142150
test( 'Reveal.getPreviousSlide/getCurrentSlide', function() {
143151
Reveal.slide( 0, 0 );
144152
Reveal.slide( 1, 0 );

0 commit comments

Comments
 (0)