client.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. }());