master.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. (function() {
  2. // don't emit events from inside the previews themselves
  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. }());