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