diff options
Diffstat (limited to 'plugin/notes/notes.js')
-rw-r--r-- | plugin/notes/notes.js | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/plugin/notes/notes.js b/plugin/notes/notes.js index 3f00eb6..8d58ad0 100644 --- a/plugin/notes/notes.js +++ b/plugin/notes/notes.js @@ -11,18 +11,27 @@ */ var RevealNotes = (function() { + var notesPopup = null; + function openNotes( notesFilePath ) { + if (notesPopup && !notesPopup.closed) { + notesPopup.focus(); + return; + } + if( !notesFilePath ) { var jsFileLocation = document.querySelector('script[src$="notes.js"]').src; // this js file path jsFileLocation = jsFileLocation.replace(/notes\.js(\?.*)?$/, ''); // the js folder path notesFilePath = jsFileLocation + 'notes.html'; } - var notesPopup = window.open( notesFilePath, 'reveal.js - Notes', 'width=1100,height=700' ); + notesPopup = window.open( notesFilePath, 'reveal.js - Notes', 'width=1100,height=700' ); - // Allow popup window access to Reveal API - notesPopup.Reveal = this.Reveal; + if( !notesPopup ) { + alert( 'Speaker view popup failed to open. Please make sure popups are allowed and reopen the speaker view.' ); + return; + } /** * Connect to the notes window through a postmessage handshake. @@ -47,10 +56,29 @@ var RevealNotes = (function() { clearInterval( connectInterval ); onConnected(); } + if( data && data.namespace === 'reveal-notes' && data.type === 'call' ) { + callRevealApi( data.methodName, data.arguments, data.callId ); + } } ); } /** + * Calls the specified Reveal.js method with the provided argument + * and then pushes the result to the notes frame. + */ + function callRevealApi( methodName, methodArguments, callId ) { + + var result = Reveal[methodName].call( Reveal, methodArguments ); + notesPopup.postMessage( JSON.stringify( { + namespace: 'reveal-notes', + type: 'return', + result: result, + callId: callId + } ), '*' ); + + } + + /** * Posts the current slide data to the notes window */ function post( event ) { |