diff options
author | Hakim El Hattab | 2019-04-23 10:52:45 +0200 |
---|---|---|
committer | Hakim El Hattab | 2019-04-23 10:52:45 +0200 |
commit | a16b71a981e9385627959273bb4e910e1d502c92 (patch) | |
tree | e1af5701395a106af1313cf199766f74abc4e0b1 /js | |
parent | 32197bd77d079ca77b42340e3c2da6812c9cc174 (diff) |
the postMessage API now works for getter methods
Diffstat (limited to 'js')
-rw-r--r-- | js/reveal.js | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/js/reveal.js b/js/reveal.js index 20a967a..91e7396 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -1276,7 +1276,11 @@ // Check if the requested method can be found if( data.method && typeof Reveal[data.method] === 'function' ) { - Reveal[data.method].apply( Reveal, data.args ); + var result = Reveal[data.method].apply( Reveal, data.args ); + + // Dispatch a postMessage event with the returned value from + // our method invocation for getter functions + dispatchPostMessage( 'callback', { method: data.method, result: result } ); } } }, false ); @@ -1981,8 +1985,25 @@ // If we're in an iframe, post each reveal.js event to the // parent window. Used by the notes plugin + dispatchPostMessage( type ); + + } + + /** + * Dispatched a postMessage of the given type from our window. + */ + function dispatchPostMessage( type, data ) { + if( config.postMessageEvents && window.parent !== window.self ) { - window.parent.postMessage( JSON.stringify({ namespace: 'reveal', eventName: type, state: getState() }), '*' ); + var message = { + namespace: 'reveal', + eventName: type, + state: getState() + }; + + extend( message, data ); + + window.parent.postMessage( JSON.stringify( message ), '*' ); } } |