improved fragment notes support #1636

edit
Hakim El Hattab 2017-01-31 17:08:08 +01:00
parent c49f76d271
commit f496613dd3
1 changed files with 18 additions and 11 deletions

View File

@ -53,7 +53,8 @@ var RevealNotes = (function() {
function post( event ) { function post( event ) {
var slideElement = Reveal.getCurrentSlide(), var slideElement = Reveal.getCurrentSlide(),
notesElement = slideElement.querySelector( 'aside.notes' ); notesElement = slideElement.querySelector( 'aside.notes' ),
fragmentElement = slideElement.querySelector( '.current-fragment' );
var messageData = { var messageData = {
namespace: 'reveal-notes', namespace: 'reveal-notes',
@ -64,21 +65,27 @@ var RevealNotes = (function() {
state: Reveal.getState() state: Reveal.getState()
}; };
// Look for notes defined in a fragment, if it is a fragmentshown event
if (event && event.hasOwnProperty('fragment')) {
var innerNotes = event.fragment.querySelector( 'aside.notes' );
if ( innerNotes) {
notesElement = innerNotes;
}
}
// Look for notes defined in a slide attribute // Look for notes defined in a slide attribute
if( slideElement.hasAttribute( 'data-notes' ) ) { if( slideElement.hasAttribute( 'data-notes' ) ) {
messageData.notes = slideElement.getAttribute( 'data-notes' ); messageData.notes = slideElement.getAttribute( 'data-notes' );
messageData.whitespace = 'pre-wrap'; messageData.whitespace = 'pre-wrap';
} }
// Look for notes defined in a fragment
if( fragmentElement ) {
var fragmentNotes = fragmentElement.querySelector( 'aside.notes' );
if( fragmentNotes ) {
notesElement = fragmentNotes;
}
else if( fragmentElement.hasAttribute( 'data-notes' ) ) {
messageData.notes = fragmentElement.getAttribute( 'data-notes' );
messageData.whitespace = 'pre-wrap';
// In case there are slide notes
notesElement = null;
}
}
// Look for notes defined in an aside element // Look for notes defined in an aside element
if( notesElement ) { if( notesElement ) {
messageData.notes = notesElement.innerHTML; messageData.notes = notesElement.innerHTML;