Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple aside notes elements per slide #3010

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions js/controllers/notes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Handles the showing and
* Handles the showing of speaker notes
*/
export default class Notes {

Expand Down Expand Up @@ -89,7 +89,7 @@ export default class Notes {
* Retrieves the speaker notes from a slide. Notes can be
* defined in two ways:
* 1. As a data-notes attribute on the slide <section>
* 2. As an <aside class="notes"> inside of the slide
* 2. With <aside class="notes"> elements inside the slide
*
* @param {HTMLElement} [slide=currentSlide]
* @return {(string|null)}
Expand All @@ -101,10 +101,14 @@ export default class Notes {
return slide.getAttribute( 'data-notes' );
}

// ... or using an <aside class="notes"> element
let notesElement = slide.querySelector( 'aside.notes' );
if( notesElement ) {
return notesElement.innerHTML;
// ... or using <aside class="notes"> elements
let notesElements = slide.querySelectorAll( 'aside.notes' );
if( notesElements ) {
let notes = "";
for (let i = 0; i < notesElements.length; i++) {
notes += notesElements[i].innerHTML + "\n";
}
return notes;
}

return null;
Expand Down
22 changes: 15 additions & 7 deletions plugin/notes/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const Plugin = () => {
function post( event ) {

let slideElement = deck.getCurrentSlide(),
notesElement = slideElement.querySelector( 'aside.notes' ),
notesElements = slideElement.querySelectorAll( 'aside.notes' ),
fragmentElement = slideElement.querySelector( '.current-fragment' );

let messageData = {
Expand All @@ -108,21 +108,29 @@ const Plugin = () => {
if( fragmentElement ) {
let fragmentNotes = fragmentElement.querySelector( 'aside.notes' );
if( fragmentNotes ) {
notesElement = fragmentNotes;
messageData.notes = fragmentNotes.innerHTML;
messageData.markdown = typeof fragmentNotes.getAttribute( 'data-markdown' ) === 'string';

// Ignore other slide notes
notesElements = null;
}
else if( fragmentElement.hasAttribute( 'data-notes' ) ) {
messageData.notes = fragmentElement.getAttribute( 'data-notes' );
messageData.whitespace = 'pre-wrap';

// In case there are slide notes
notesElement = null;
notesElements = null;
}
}

// Look for notes defined in an aside element
if( notesElement ) {
messageData.notes = notesElement.innerHTML;
messageData.markdown = typeof notesElement.getAttribute( 'data-markdown' ) === 'string';
// Look for notes defined in aside elements
if( notesElements ) {
let notes = "";
for (let i = 0; i < notesElements.length; i++) {
notes += notesElements[i].innerHTML + "\n";
}
messageData.notes = notes;
messageData.markdown = typeof notesElements[0].getAttribute( 'data-markdown' ) === 'string';
}

popup.postMessage( JSON.stringify( messageData ), '*' );
Expand Down