diff --git a/README.md b/README.md index b72e69f..8b7cab5 100644 --- a/README.md +++ b/README.md @@ -81,11 +81,11 @@ Reveal.addEventListener( 'somestate', function() { ### Slide change event -An 'slidechanged' event is fired each time the slide is changed (regardless of state). The event object holds the index of the current slide. +An 'slidechanged' event is fired each time the slide is changed (regardless of state). The event object holds the index values of the current slide as well as a reference to the previous and current slide HTML nodes. ``` Reveal.addEventListener( 'slidechanged', function( event ) { - // event.indexh & event.indexv + // event.previousSlide, event.currentSlide, event.indexh, event.indexv } ); ``` diff --git a/index.html b/index.html index 691ff4b..a68dd6a 100644 --- a/index.html +++ b/index.html @@ -279,7 +279,7 @@ linkify( 'a' ); // Fires each time a new slide is activated Reveal.addEventListener( 'slidechanged', function( event ) { - // event.indexh & event.indexv + // event.previousSlide, event.currentSlide, event.indexh, event.indexv } ); Reveal.initialize({ diff --git a/js/reveal.js b/js/reveal.js index dbe11f5..8ff8e0b 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -661,11 +661,29 @@ var Reveal = (function(){ clearTimeout( writeURLTimeout ); writeURLTimeout = setTimeout( writeURL, 1500 ); + // Only fire if the slide index is different from before if( indexh !== indexhBefore || indexv !== indexvBefore ) { + // Query all horizontal slides in the deck + var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ); + + // Find the previous and current horizontal slides + var previousHorizontalSlide = horizontalSlides[ indexhBefore ], + currentHorizontalSlide = horizontalSlides[ indexh ]; + + // Query all vertical slides inside of the previous and current horizontal slides + var previousVerticalSlides = previousHorizontalSlide.querySelectorAll( 'section' ); + currentVerticalSlides = currentHorizontalSlide.querySelectorAll( 'section' ); + // Dispatch an event notifying observers of the change in slide dispatchEvent( 'slidechanged', { + // Include the current indices in the event 'indexh': indexh, - 'indexv': indexv + 'indexv': indexv, + + // Passes direct references to the slide HTML elements, attempts to find + // a vertical slide and falls back on the horizontal parent + 'previousSlide': previousVerticalSlides[ indexvBefore ] || previousHorizontalSlide, + 'currentSlide': currentVerticalSlides[ indexv ] || currentHorizontalSlide } ); } } diff --git a/js/reveal.min.js b/js/reveal.min.js index 065cd2f..095f6c2 100644 --- a/js/reveal.min.js +++ b/js/reveal.min.js @@ -42,17 +42,17 @@ c=this.getAttribute("data-index-v");b();}}function U(W,Y){var aa=Array.prototype if(Y<0){Y=ab+Y;}}Y=Math.max(Math.min(Y,ab-1),0);for(var Z=0;Z3?"none":"block"; }aa[Z].classList.remove("past");aa[Z].classList.remove("present");aa[Z].classList.remove("future");if(ZY){aa[Z].classList.add("future"); }}if(V.querySelector("section")){aa[Z].classList.add("stack");}}aa[Y].classList.add("present");var X=aa[Y].getAttribute("data-state");if(X){T=T.concat(X.split(" ")); -}}else{Y=0;}return Y;}function b(aa,W){var ac=T.concat();T.length=0;var ab=k,Z=c;k=U(j,aa===undefined?k:aa);c=U(a,W===undefined?c:W);stateLoop:for(var Y=0,V=T.length; -Y0,right:k0,down:c0||c>0){V+=k; -}if(c>0){V+="/"+c;}window.location.hash=V;}}function o(W,V){var X=document.createEvent("HTMLEvents",1,2);X.initEvent(W,true,true);q(X,V);d.wrapper.dispatchEvent(X); -}function s(){if(document.querySelector(a+".present")){var W=document.querySelectorAll(a+".present .fragment:not(.visible)");if(W.length){W[0].classList.add("visible"); -o("fragmentshown",{fragment:W[0]});return true;}}else{var V=document.querySelectorAll(j+".present .fragment:not(.visible)");if(V.length){V[0].classList.add("visible"); -o("fragmentshown",{fragment:V[0]});return true;}}return false;}function G(){if(document.querySelector(a+".present")){var W=document.querySelectorAll(a+".present .fragment.visible"); +writeURLTimeout=setTimeout(g,1500);if(k!==ab||c!==V){var ac=document.querySelectorAll(j);slidesv=document.querySelectorAll(a);o("slidechanged",{indexh:k,indexv:c,slide:slidesv.length?slidesv[c]:ac[k]}); +}}function p(){var V=f();[d.controlsLeft,d.controlsRight,d.controlsUp,d.controlsDown].forEach(function(W){W.classList.remove("enabled");});if(V.left){d.controlsLeft.classList.add("enabled"); +}if(V.right){d.controlsRight.classList.add("enabled");}if(V.up){d.controlsUp.classList.add("enabled");}if(V.down){d.controlsDown.classList.add("enabled"); +}}function f(){var V=document.querySelectorAll(j);var W=document.querySelectorAll(a);return{left:k>0,right:k0,down:c0||c>0){V+=k;}if(c>0){V+="/"+c;}window.location.hash=V;}}function o(W,V){var X=document.createEvent("HTMLEvents",1,2); +X.initEvent(W,true,true);q(X,V);d.wrapper.dispatchEvent(X);}function s(){if(document.querySelector(a+".present")){var W=document.querySelectorAll(a+".present .fragment:not(.visible)"); +if(W.length){W[0].classList.add("visible");o("fragmentshown",{fragment:W[0]});return true;}}else{var V=document.querySelectorAll(j+".present .fragment:not(.visible)"); +if(V.length){V[0].classList.add("visible");o("fragmentshown",{fragment:V[0]});return true;}}return false;}function G(){if(document.querySelector(a+".present")){var W=document.querySelectorAll(a+".present .fragment.visible"); if(W.length){W[W.length-1].classList.remove("visible");o("fragmenthidden",{fragment:W[0]});return true;}}else{var V=document.querySelectorAll(j+".present .fragment.visible"); if(V.length){V[V.length-1].classList.remove("visible");o("fragmenthidden",{fragment:V[0]});return true;}}return false;}function F(W,V){b(W,V);}function w(){if(O()||G()===false){b(k-1,0); }}function i(){if(O()||s()===false){b(k+1,0);}}function r(){if(O()||G()===false){b(k,c-1);}}function A(){if(O()||s()===false){b(k,c+1);}}function N(){if(G()===false){if(f().up){r();