2012-10-21 00:40:52 +00:00
|
|
|
/**
|
|
|
|
* Handles opening of and synchronization with the reveal.js
|
|
|
|
* notes window.
|
2014-04-19 08:54:14 +00:00
|
|
|
*
|
|
|
|
* Handshake process:
|
|
|
|
* 1. This window posts 'connect' to notes window
|
|
|
|
* - Includes URL of presentation to show
|
|
|
|
* 2. Notes window responds with 'connected' when it is available
|
|
|
|
* 3. This window proceeds to send the current presentation state
|
|
|
|
* to the notes window
|
2012-10-21 00:40:52 +00:00
|
|
|
*/
|
|
|
|
var RevealNotes = (function() {
|
|
|
|
|
2016-01-08 13:33:34 +00:00
|
|
|
function openNotes( notesFilePath ) {
|
|
|
|
|
|
|
|
if( !notesFilePath ) {
|
2015-03-05 21:48:26 +00:00
|
|
|
var jsFileLocation = document.querySelector('script[src$="notes.js"]').src; // this js file path
|
|
|
|
jsFileLocation = jsFileLocation.replace(/notes\.js(\?.*)?$/, ''); // the js folder path
|
2016-01-08 13:33:34 +00:00
|
|
|
notesFilePath = jsFileLocation + 'notes.html';
|
2015-03-05 21:48:26 +00:00
|
|
|
}
|
2016-01-08 13:33:34 +00:00
|
|
|
|
|
|
|
var notesPopup = window.open( notesFilePath, 'reveal.js - Notes', 'width=1100,height=700' );
|
2012-10-21 00:40:52 +00:00
|
|
|
|
2016-04-16 14:35:14 +00:00
|
|
|
// Allow popup window access to Reveal API
|
|
|
|
notesPopup.Reveal = this.Reveal;
|
|
|
|
|
2014-04-19 08:54:14 +00:00
|
|
|
/**
|
|
|
|
* Connect to the notes window through a postmessage handshake.
|
|
|
|
* Using postmessage enables us to work in situations where the
|
|
|
|
* origins differ, such as a presentation being opened from the
|
|
|
|
* file system.
|
|
|
|
*/
|
|
|
|
function connect() {
|
|
|
|
// Keep trying to connect until we get a 'connected' message back
|
|
|
|
var connectInterval = setInterval( function() {
|
|
|
|
notesPopup.postMessage( JSON.stringify( {
|
|
|
|
namespace: 'reveal-notes',
|
|
|
|
type: 'connect',
|
2015-04-02 05:06:03 +00:00
|
|
|
url: window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.search,
|
2014-04-19 08:54:14 +00:00
|
|
|
state: Reveal.getState()
|
|
|
|
} ), '*' );
|
|
|
|
}, 500 );
|
2012-10-21 00:40:52 +00:00
|
|
|
|
2014-04-19 08:54:14 +00:00
|
|
|
window.addEventListener( 'message', function( event ) {
|
|
|
|
var data = JSON.parse( event.data );
|
|
|
|
if( data && data.namespace === 'reveal-notes' && data.type === 'connected' ) {
|
|
|
|
clearInterval( connectInterval );
|
|
|
|
onConnected();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
2012-10-21 00:40:52 +00:00
|
|
|
|
2012-10-24 12:33:16 +00:00
|
|
|
/**
|
2012-10-25 13:36:25 +00:00
|
|
|
* Posts the current slide data to the notes window
|
2012-10-24 12:33:16 +00:00
|
|
|
*/
|
2017-01-31 16:08:08 +00:00
|
|
|
function post( event ) {
|
2014-04-19 08:54:14 +00:00
|
|
|
|
2012-10-21 00:40:52 +00:00
|
|
|
var slideElement = Reveal.getCurrentSlide(),
|
2017-01-31 16:08:08 +00:00
|
|
|
notesElement = slideElement.querySelector( 'aside.notes' ),
|
|
|
|
fragmentElement = slideElement.querySelector( '.current-fragment' );
|
2012-10-21 00:40:52 +00:00
|
|
|
|
2014-02-17 19:07:41 +00:00
|
|
|
var messageData = {
|
2014-04-19 08:54:14 +00:00
|
|
|
namespace: 'reveal-notes',
|
|
|
|
type: 'state',
|
|
|
|
notes: '',
|
|
|
|
markdown: false,
|
2015-09-25 07:41:05 +00:00
|
|
|
whitespace: 'normal',
|
2014-04-19 08:54:14 +00:00
|
|
|
state: Reveal.getState()
|
2013-07-26 13:48:21 +00:00
|
|
|
};
|
|
|
|
|
2014-02-17 19:07:41 +00:00
|
|
|
// Look for notes defined in a slide attribute
|
|
|
|
if( slideElement.hasAttribute( 'data-notes' ) ) {
|
|
|
|
messageData.notes = slideElement.getAttribute( 'data-notes' );
|
2015-09-25 07:41:05 +00:00
|
|
|
messageData.whitespace = 'pre-wrap';
|
2014-02-17 19:07:41 +00:00
|
|
|
}
|
|
|
|
|
2017-01-31 16:08:08 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-17 19:07:41 +00:00
|
|
|
// Look for notes defined in an aside element
|
|
|
|
if( notesElement ) {
|
|
|
|
messageData.notes = notesElement.innerHTML;
|
|
|
|
messageData.markdown = typeof notesElement.getAttribute( 'data-markdown' ) === 'string';
|
|
|
|
}
|
|
|
|
|
2012-10-25 13:36:25 +00:00
|
|
|
notesPopup.postMessage( JSON.stringify( messageData ), '*' );
|
2014-04-19 08:54:14 +00:00
|
|
|
|
2012-10-21 00:40:52 +00:00
|
|
|
}
|
|
|
|
|
2014-04-19 08:54:14 +00:00
|
|
|
/**
|
|
|
|
* Called once we have established a connection to the notes
|
|
|
|
* window.
|
|
|
|
*/
|
|
|
|
function onConnected() {
|
|
|
|
|
|
|
|
// Monitor events that trigger a change in state
|
|
|
|
Reveal.addEventListener( 'slidechanged', post );
|
|
|
|
Reveal.addEventListener( 'fragmentshown', post );
|
|
|
|
Reveal.addEventListener( 'fragmenthidden', post );
|
|
|
|
Reveal.addEventListener( 'overviewhidden', post );
|
|
|
|
Reveal.addEventListener( 'overviewshown', post );
|
|
|
|
Reveal.addEventListener( 'paused', post );
|
|
|
|
Reveal.addEventListener( 'resumed', post );
|
|
|
|
|
|
|
|
// Post the initial state
|
2013-07-26 13:48:21 +00:00
|
|
|
post();
|
2014-04-19 08:54:14 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
connect();
|
2016-01-08 13:33:34 +00:00
|
|
|
|
2012-10-21 00:40:52 +00:00
|
|
|
}
|
|
|
|
|
2014-09-27 14:19:39 +00:00
|
|
|
if( !/receiver/i.test( window.location.search ) ) {
|
2012-10-21 00:40:52 +00:00
|
|
|
|
2014-09-27 14:19:39 +00:00
|
|
|
// If the there's a 'notes' query set, open directly
|
|
|
|
if( window.location.search.match( /(\?|\&)notes/gi ) !== null ) {
|
2012-10-21 00:40:52 +00:00
|
|
|
openNotes();
|
|
|
|
}
|
2014-09-27 14:19:39 +00:00
|
|
|
|
|
|
|
// Open the notes when the 's' key is hit
|
|
|
|
document.addEventListener( 'keydown', function( event ) {
|
|
|
|
// Disregard the event if the target is editable or a
|
|
|
|
// modifier is present
|
|
|
|
if ( document.querySelector( ':focus' ) !== null || event.shiftKey || event.altKey || event.ctrlKey || event.metaKey ) return;
|
|
|
|
|
2015-10-08 18:44:02 +00:00
|
|
|
// Disregard the event if keyboard is disabled
|
|
|
|
if ( Reveal.getConfig().keyboard === false ) return;
|
|
|
|
|
2014-09-27 14:19:39 +00:00
|
|
|
if( event.keyCode === 83 ) {
|
|
|
|
event.preventDefault();
|
|
|
|
openNotes();
|
|
|
|
}
|
|
|
|
}, false );
|
|
|
|
|
2016-01-08 12:49:06 +00:00
|
|
|
// Show our keyboard shortcut in the reveal.js help overlay
|
|
|
|
if( window.Reveal ) Reveal.registerKeyboardShortcut( 'S', 'Speaker notes view' );
|
|
|
|
|
2014-09-27 14:19:39 +00:00
|
|
|
}
|
2012-10-21 00:40:52 +00:00
|
|
|
|
2012-10-24 12:33:16 +00:00
|
|
|
return { open: openNotes };
|
2014-09-27 14:19:39 +00:00
|
|
|
|
2012-10-24 12:33:16 +00:00
|
|
|
})();
|