Prechádzať zdrojové kódy

broadcasting fragments state in multiplex plugin (#394)

tkaczmarzyk 11 rokov pred
rodič
commit
c12b780736
4 zmenil súbory, kde vykonal 69 pridanie a 24 odobranie
  1. 27 0
      js/reveal.js
  2. 1 1
      js/reveal.min.js
  3. 1 1
      plugin/multiplex/client.js
  4. 40 22
      plugin/multiplex/master.js

+ 27 - 0
js/reveal.js

@@ -645,6 +645,13 @@ var Reveal = (function(){
 
 	}
 
+	/**
+	 * Returns last element of an array
+	 */
+	function lastElem(array) {
+		return array.slice(-1)[0];
+	}
+
 	/**
 	 * Applies JavaScript-controlled layout rules to the
 	 * presentation.
@@ -2045,6 +2052,26 @@ var Reveal = (function(){
 			return config;
 		},
 
+		// Returns an index (1-based) of the current fragment
+		getCurrentFragmentIndex : function() {
+			var visibleFragments;
+			
+			// vertical slides:
+			if( document.querySelector( VERTICAL_SLIDES_SELECTOR + '.present' ) ) {
+				visibleFragments = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR + '.present .fragment.visible' );
+			}
+			// Horizontal slides:
+			else {
+				visibleFragments = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.present .fragment.visible' );
+			}
+			
+			if( visibleFragments.length) {
+				return visibleFragments.length;
+			} else {
+				return undefined;
+			}
+		},
+
 		// Helper method, retrieves query string as a key/value hash
 		getQueryHash: function() {
 			var query = {};

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 1 - 1
js/reveal.min.js


+ 1 - 1
plugin/multiplex/client.js

@@ -8,6 +8,6 @@
 		if (data.socketId !== socketId) { return; }
 		if( window.location.host === 'localhost:1947' ) return;
 
-		Reveal.slide(data.indexh, data.indexv, null, 'remote');
+		Reveal.slide(data.indexh, data.indexv, data.indexf, 'remote');
 	});
 }());

+ 40 - 22
plugin/multiplex/master.js

@@ -5,28 +5,46 @@
 
 	var socket = io.connect(multiplex.url);
 
-	Reveal.addEventListener( 'slidechanged', function( event ) {
-		var nextindexh;
-		var nextindexv;
-		var slideElement = event.currentSlide;
-
-		if (slideElement.nextElementSibling && slideElement.parentNode.nodeName == 'SECTION') {
-			nextindexh = event.indexh;
-			nextindexv = event.indexv + 1;
-		} else {
-			nextindexh = event.indexh + 1;
-			nextindexv = 0;
-		}
+	var notify = function( slideElement, indexh, indexv, origin ) {
+		if( typeof origin === 'undefined' && origin !== 'remote' ) {
+			var nextindexh;
+			var nextindexv;
+
+			var fragmentindex = Reveal.getCurrentFragmentIndex();
+			if (typeof fragmentindex == 'undefined') {
+				fragmentindex = 0;
+			}
 
-		var slideData = {
-			indexh : event.indexh,
-			indexv : event.indexv,
-			nextindexh : nextindexh,
-			nextindexv : nextindexv,
-			secret: multiplex.secret,
-			socketId : multiplex.id
-		};
+			if (slideElement.nextElementSibling && slideElement.parentNode.nodeName == 'SECTION') {
+				nextindexh = indexh;
+				nextindexv = indexv + 1;
+			} else {
+				nextindexh = indexh + 1;
+				nextindexv = 0;
+			}	
 
-		if( typeof event.origin === 'undefined' && event.origin !== 'remote' ) socket.emit('slidechanged', slideData);
+			var slideData = {
+				indexh : indexh,
+				indexv : indexv,
+				indexf : fragmentindex,
+				nextindexh : nextindexh,
+				nextindexv : nextindexv,
+				secret: multiplex.secret,
+				socketId : multiplex.id
+			};
+
+			socket.emit('slidechanged', slideData);
+		}
+	}
+
+	Reveal.addEventListener( 'slidechanged', function( event ) {
+		notify( event.currentSlide, event.indexh, event.indexv, event.origin );
 	} );
-}());
+
+	var fragmentNotify = function( event ) {
+		notify( Reveal.getCurrentSlide(), Reveal.getIndices().h, Reveal.getIndices().v, event.origin );
+	};
+
+	Reveal.addEventListener( 'fragmentshown', fragmentNotify );
+	Reveal.addEventListener( 'fragmenthidden', fragmentNotify );
+}());

Niektoré súbory nie sú zobrazené, pretože je v týchto rozdielových dátach zmenené mnoho súborov