client.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. showFragment : true,
  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. hideFragment : true,
  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. var nextindexv;
  28. var slideElement = event.currentSlide;
  29. if (slideElement.nextElementSibling && slideElement.parentNode.nodeName == 'SECTION') {
  30. nextindexh = event.indexh;
  31. nextindexv = event.indexv + 1;
  32. } else {
  33. nextindexh = event.indexh + 1;
  34. nextindexv = 0;
  35. }
  36. var notes = slideElement.querySelector('aside.notes');
  37. var slideData = {
  38. notes : notes ? notes.innerHTML : '',
  39. indexh : event.indexh,
  40. indexv : event.indexv,
  41. nextindexh : nextindexh,
  42. nextindexv : nextindexv,
  43. socketId : socketId,
  44. markdown : notes ? typeof notes.getAttribute('data-markdown') === 'string' : false
  45. };
  46. socket.emit('slidechanged', slideData);
  47. } );
  48. }());