client.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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( 'state', messageData );
  30. }
  31. // Monitor events that trigger a change in state
  32. Reveal.addEventListener( 'slidechanged', post );
  33. Reveal.addEventListener( 'fragmentshown', post );
  34. Reveal.addEventListener( 'fragmenthidden', post );
  35. Reveal.addEventListener( 'overviewhidden', post );
  36. Reveal.addEventListener( 'overviewshown', post );
  37. Reveal.addEventListener( 'paused', post );
  38. Reveal.addEventListener( 'resumed', post );
  39. // Post the initial state
  40. post();
  41. }());