client.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. var 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. // Fires when a fragment is shown
  9. Reveal.addEventListener( 'fragmentshown', function( event ) {
  10. var fragmentData = {
  11. fragment : 'next',
  12. socketId : socketId
  13. };
  14. socket.emit('fragmentchanged', fragmentData);
  15. } );
  16. // Fires when a fragment is hidden
  17. Reveal.addEventListener( 'fragmenthidden', function( event ) {
  18. var fragmentData = {
  19. fragment : 'previous',
  20. socketId : socketId
  21. };
  22. socket.emit( 'fragmentchanged', fragmentData );
  23. } );
  24. // Fires when slide is changed
  25. Reveal.addEventListener( 'slidechanged', function( event ) {
  26. var nextindexh,
  27. nextindexv,
  28. slideElement = event.currentSlide,
  29. notesElement = slideElement.querySelector( 'aside.notes' );
  30. if( slideElement.nextElementSibling && slideElement.parentNode.nodeName == 'SECTION' ) {
  31. nextindexh = event.indexh;
  32. nextindexv = event.indexv + 1;
  33. } else {
  34. nextindexh = event.indexh + 1;
  35. nextindexv = 0;
  36. }
  37. var messageData = {
  38. notes : '',
  39. indexh : event.indexh,
  40. indexv : event.indexv,
  41. nextindexh : nextindexh,
  42. nextindexv : nextindexv,
  43. socketId : socketId,
  44. markdown : false
  45. };
  46. // Look for notes defined in a slide attribute
  47. if( slideElement.hasAttribute( 'data-notes' ) ) {
  48. messageData.notes = slideElement.getAttribute( 'data-notes' );
  49. }
  50. // Look for notes defined in an aside element
  51. if( notesElement ) {
  52. messageData.notes = notesElement.innerHTML;
  53. messageData.markdown = typeof notesElement.getAttribute( 'data-markdown' ) === 'string';
  54. }
  55. socket.emit( 'slidechanged', messageData );
  56. } );
  57. }());