From 42e796afb2a4db10772cf0f4b517094c0fbec644 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Fri, 26 Oct 2018 11:29:08 +0200 Subject: [PATCH] dispatch state events after current slide has updated #2264 --- js/reveal.js | 44 +++++++------- test/test-state.html | 139 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+), 22 deletions(-) create mode 100644 test/test-state.html diff --git a/js/reveal.js b/js/reveal.js index f797084..1c0e69d 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -2671,28 +2671,6 @@ layout(); - // Apply the new state - stateLoop: for( var i = 0, len = state.length; i < len; i++ ) { - // Check if this state existed on the previous slide. If it - // did, we will avoid adding it repeatedly - for( var j = 0; j < stateBefore.length; j++ ) { - if( stateBefore[j] === state[i] ) { - stateBefore.splice( j, 1 ); - continue stateLoop; - } - } - - document.documentElement.classList.add( state[i] ); - - // Dispatch custom event matching the state's name - dispatchEvent( state[i] ); - } - - // Clean up the remains of the previous state - while( stateBefore.length ) { - document.documentElement.classList.remove( stateBefore.pop() ); - } - // Update the overview if it's currently active if( isOverview() ) { updateOverview(); @@ -2741,6 +2719,28 @@ } } + // Apply the new state + stateLoop: for( var i = 0, len = state.length; i < len; i++ ) { + // Check if this state existed on the previous slide. If it + // did, we will avoid adding it repeatedly + for( var j = 0; j < stateBefore.length; j++ ) { + if( stateBefore[j] === state[i] ) { + stateBefore.splice( j, 1 ); + continue stateLoop; + } + } + + document.documentElement.classList.add( state[i] ); + + // Dispatch custom event matching the state's name + dispatchEvent( state[i] ); + } + + // Clean up the remains of the previous state + while( stateBefore.length ) { + document.documentElement.classList.remove( stateBefore.pop() ); + } + if( slideChanged ) { dispatchEvent( 'slidechanged', { 'indexh': indexh, diff --git a/test/test-state.html b/test/test-state.html new file mode 100644 index 0000000..e6ae423 --- /dev/null +++ b/test/test-state.html @@ -0,0 +1,139 @@ + + + + + + + reveal.js - Test State + + + + + + + +
+
+ + + + + + + + + +