master.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. (function() {
  2. // Don't emit events from inside of notes windows
  3. if ( window.location.search.match( /receiver/gi ) ) { return; }
  4. var multiplex = Reveal.getConfig().multiplex;
  5. var socket = io.connect(multiplex.url);
  6. var notify = function( slideElement, indexh, indexv, origin ) {
  7. if( typeof origin === 'undefined' && origin !== 'remote' ) {
  8. var nextindexh;
  9. var nextindexv;
  10. var fragmentindex = Reveal.getIndices().f;
  11. if (typeof fragmentindex == 'undefined') {
  12. fragmentindex = 0;
  13. }
  14. if (slideElement.nextElementSibling && slideElement.parentNode.nodeName == 'SECTION') {
  15. nextindexh = indexh;
  16. nextindexv = indexv + 1;
  17. } else {
  18. nextindexh = indexh + 1;
  19. nextindexv = 0;
  20. }
  21. var slideData = {
  22. indexh : indexh,
  23. indexv : indexv,
  24. indexf : fragmentindex,
  25. nextindexh : nextindexh,
  26. nextindexv : nextindexv,
  27. secret: multiplex.secret,
  28. socketId : multiplex.id
  29. };
  30. socket.emit('slidechanged', slideData);
  31. }
  32. }
  33. Reveal.addEventListener( 'slidechanged', function( event ) {
  34. notify( event.currentSlide, event.indexh, event.indexv, event.origin );
  35. } );
  36. var fragmentNotify = function( event ) {
  37. notify( Reveal.getCurrentSlide(), Reveal.getIndices().h, Reveal.getIndices().v, event.origin );
  38. };
  39. Reveal.addEventListener( 'fragmentshown', fragmentNotify );
  40. Reveal.addEventListener( 'fragmenthidden', fragmentNotify );
  41. }());