diff options
Diffstat (limited to 'plugin/notes/notes.js')
-rw-r--r-- | plugin/notes/notes.js | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/plugin/notes/notes.js b/plugin/notes/notes.js index a5b15b4..8d58ad0 100644 --- a/plugin/notes/notes.js +++ b/plugin/notes/notes.js @@ -11,24 +11,28 @@ */ 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' ); if( !notesPopup ) { alert( 'Speaker view popup failed to open. Please make sure popups are allowed and reopen the speaker view.' ); return; } - // Allow popup window access to Reveal API - notesPopup.Reveal = window.Reveal; - /** * Connect to the notes window through a postmessage handshake. * Using postmessage enables us to work in situations where the @@ -52,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 ) { |