2012-06-08 03:21:14 +00:00
|
|
|
(function() {
|
2014-05-04 07:32:00 +00:00
|
|
|
|
2012-07-01 20:43:43 +00:00
|
|
|
// don't emit events from inside the previews themselves
|
2014-02-17 19:07:41 +00:00
|
|
|
if( window.location.search.match( /receiver/gi ) ) { return; }
|
2012-06-08 03:21:14 +00:00
|
|
|
|
2014-05-04 07:32:00 +00:00
|
|
|
var socket = io.connect( window.location.origin ),
|
|
|
|
socketId = Math.random().toString().slice( 2 );
|
2014-02-17 19:07:41 +00:00
|
|
|
|
|
|
|
console.log( 'View slide notes at ' + window.location.origin + '/notes/' + socketId );
|
|
|
|
|
|
|
|
window.open( window.location.origin + '/notes/' + socketId, 'notes-' + socketId );
|
2012-06-17 22:43:29 +00:00
|
|
|
|
2014-05-04 07:32:00 +00:00
|
|
|
/**
|
|
|
|
* Posts the current slide data to the notes window
|
|
|
|
*/
|
|
|
|
function post() {
|
2012-10-18 22:04:40 +00:00
|
|
|
|
2014-05-04 07:32:00 +00:00
|
|
|
var slideElement = Reveal.getCurrentSlide(),
|
2014-02-17 19:07:41 +00:00
|
|
|
notesElement = slideElement.querySelector( 'aside.notes' );
|
2012-06-08 03:21:14 +00:00
|
|
|
|
2014-02-17 19:07:41 +00:00
|
|
|
var messageData = {
|
2014-05-04 07:32:00 +00:00
|
|
|
notes: '',
|
|
|
|
markdown: false,
|
|
|
|
socketId: socketId,
|
|
|
|
state: Reveal.getState()
|
2012-07-01 20:43:43 +00:00
|
|
|
};
|
2012-06-08 03:21:14 +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' );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look for notes defined in an aside element
|
|
|
|
if( notesElement ) {
|
|
|
|
messageData.notes = notesElement.innerHTML;
|
|
|
|
messageData.markdown = typeof notesElement.getAttribute( 'data-markdown' ) === 'string';
|
|
|
|
}
|
|
|
|
|
2014-05-04 08:10:21 +00:00
|
|
|
socket.emit( 'statechanged', messageData );
|
2014-05-04 07:32:00 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-05-04 08:10:21 +00:00
|
|
|
// When a new notes window connects, post our current state
|
2015-09-29 08:07:21 +00:00
|
|
|
socket.on( 'new-subscriber', function( data ) {
|
2014-05-04 08:10:21 +00:00
|
|
|
post();
|
|
|
|
} );
|
|
|
|
|
2015-11-09 15:23:57 +00:00
|
|
|
// When the state changes from inside of the speaker view
|
|
|
|
socket.on( 'statechanged-speaker', function( data ) {
|
|
|
|
Reveal.setState( data.state );
|
|
|
|
} );
|
|
|
|
|
2014-05-04 07:32:00 +00:00
|
|
|
// Monitor events that trigger a change in state
|
2020-04-07 07:05:56 +00:00
|
|
|
Reveal.on( 'slidechanged', post );
|
|
|
|
Reveal.on( 'fragmentshown', post );
|
|
|
|
Reveal.on( 'fragmenthidden', post );
|
|
|
|
Reveal.on( 'overviewhidden', post );
|
|
|
|
Reveal.on( 'overviewshown', post );
|
|
|
|
Reveal.on( 'paused', post );
|
|
|
|
Reveal.on( 'resumed', post );
|
2014-05-04 07:32:00 +00:00
|
|
|
|
|
|
|
// Post the initial state
|
|
|
|
post();
|
|
|
|
|
2012-06-17 22:43:54 +00:00
|
|
|
}());
|