client.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. (function() {
  2. // don't emit events from inside the previews themselves
  3. if( window.location.search.match( /receiver/gi ) ) { return; }
  4. var socket = io.connect( window.location.origin ),
  5. socketId = Math.random().toString().slice( 2 );
  6. console.log( 'View slide notes at ' + window.location.origin + '/notes/' + socketId );
  7. window.open( window.location.origin + '/notes/' + socketId, 'notes-' + socketId );
  8. /**
  9. * Posts the current slide data to the notes window
  10. */
  11. function post() {
  12. var slideElement = Reveal.getCurrentSlide(),
  13. notesElement = slideElement.querySelector( 'aside.notes' );
  14. var messageData = {
  15. notes: '',
  16. markdown: false,
  17. socketId: socketId,
  18. state: Reveal.getState()
  19. };
  20. // Look for notes defined in a slide attribute
  21. if( slideElement.hasAttribute( 'data-notes' ) ) {
  22. messageData.notes = slideElement.getAttribute( 'data-notes' );
  23. }
  24. // Look for notes defined in an aside element
  25. if( notesElement ) {
  26. messageData.notes = notesElement.innerHTML;
  27. messageData.markdown = typeof notesElement.getAttribute( 'data-markdown' ) === 'string';
  28. }
  29. socket.emit( 'statechanged', messageData );
  30. }
  31. // When a new notes window connects, post our current state
  32. socket.on( 'new-subscriber', function( data ) {
  33. post();
  34. } );
  35. // When the state changes from inside of the speaker view
  36. socket.on( 'statechanged-speaker', function( data ) {
  37. Reveal.setState( data.state );
  38. } );
  39. // Monitor events that trigger a change in state
  40. Reveal.addEventListener( 'slidechanged', post );
  41. Reveal.addEventListener( 'fragmentshown', post );
  42. Reveal.addEventListener( 'fragmenthidden', post );
  43. Reveal.addEventListener( 'overviewhidden', post );
  44. Reveal.addEventListener( 'overviewshown', post );
  45. Reveal.addEventListener( 'paused', post );
  46. Reveal.addEventListener( 'resumed', post );
  47. // Post the initial state
  48. post();
  49. }());