| 12 | var RevealNotes = (function() { |
| 13 | |
| 14 | function openNotes( notesFilePath ) { |
| 15 | |
| 16 | if( !notesFilePath ) { |
| 17 | var jsFileLocation = document.querySelector('script[src$="notes.js"]').src; // this js file path |
| 18 | jsFileLocation = jsFileLocation.replace(/notes\.js(\?.*)?$/, ''); // the js folder path |
| 19 | notesFilePath = jsFileLocation + 'notes.html'; |
| 20 | } |
| 21 | |
| 22 | var notesPopup = window.open( notesFilePath, 'reveal.js - Notes', 'width=1100,height=700' ); |
| 23 | |
| 24 | if( !notesPopup ) { |
| 25 | alert( 'Speaker view popup failed to open. Please make sure popups are allowed and reopen the speaker view.' ); |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | // Allow popup window access to Reveal API |
| 30 | notesPopup.Reveal = window.Reveal; |
| 31 | |
| 32 | /** |
| 33 | * Connect to the notes window through a postmessage handshake. |
| 34 | * Using postmessage enables us to work in situations where the |
| 35 | * origins differ, such as a presentation being opened from the |
| 36 | * file system. |
| 37 | */ |
| 38 | function connect() { |
| 39 | // Keep trying to connect until we get a 'connected' message back |
| 40 | var connectInterval = setInterval( function() { |
| 41 | notesPopup.postMessage( JSON.stringify( { |
| 42 | namespace: 'reveal-notes', |
| 43 | type: 'connect', |
| 44 | url: window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.search, |
| 45 | state: Reveal.getState() |
| 46 | } ), '*' ); |
| 47 | }, 500 ); |
| 48 | |
| 49 | window.addEventListener( 'message', function( event ) { |
| 50 | var data = JSON.parse( event.data ); |
| 51 | if( data && data.namespace === 'reveal-notes' && data.type === 'connected' ) { |
| 52 | clearInterval( connectInterval ); |
| 53 | onConnected(); |
| 54 | } |
| 55 | } ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Posts the current slide data to the notes window |
| 60 | */ |
| 61 | function post( event ) { |
| 62 | |
| 63 | var slideElement = Reveal.getCurrentSlide(), |
| 64 | notesElement = slideElement.querySelector( 'aside.notes' ), |
| 65 | fragmentElement = slideElement.querySelector( '.current-fragment' ); |
| 66 | |
| 67 | var messageData = { |
| 68 | namespace: 'reveal-notes', |
| 69 | type: 'state', |
| 70 | notes: '', |
| 71 | markdown: false, |