client.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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( 'connect', function( data ) {
  33. post();
  34. } );
  35. // Monitor events that trigger a change in state
  36. Reveal.addEventListener( 'slidechanged', post );
  37. Reveal.addEventListener( 'fragmentshown', post );
  38. Reveal.addEventListener( 'fragmenthidden', post );
  39. Reveal.addEventListener( 'overviewhidden', post );
  40. Reveal.addEventListener( 'overviewshown', post );
  41. Reveal.addEventListener( 'paused', post );
  42. Reveal.addEventListener( 'resumed', post );
  43. // Post the initial state
  44. post();
  45. }());