add config option for postMessage features

This commit is contained in:
Hakim El Hattab 2014-04-18 20:07:03 +02:00
parent a4b09aecda
commit fea11d24bc
1 changed files with 13 additions and 8 deletions

View File

@ -89,6 +89,9 @@ var Reveal = (function(){
// Opens links in an iframe preview overlay // Opens links in an iframe preview overlay
previewLinks: false, previewLinks: false,
// Flags if we should listen to and dispatch events through window.postMessage
postMessage: true,
// Focuses body when page changes visiblity to ensure keyboard shortcuts work // Focuses body when page changes visiblity to ensure keyboard shortcuts work
focusBodyOnPageVisiblityChange: true, focusBodyOnPageVisiblityChange: true,
@ -565,6 +568,7 @@ var Reveal = (function(){
*/ */
function setupPostMessage() { function setupPostMessage() {
if( config.postMessage ) {
window.addEventListener( 'message', function ( event ) { window.addEventListener( 'message', function ( event ) {
var data = JSON.parse( event.data ); var data = JSON.parse( event.data );
var method = Reveal[data.method]; var method = Reveal[data.method];
@ -573,6 +577,7 @@ var Reveal = (function(){
method.apply( Reveal, data.args ); method.apply( Reveal, data.args );
} }
}, false ); }, false );
}
} }
@ -967,7 +972,7 @@ var Reveal = (function(){
// If we're in an iframe, post each reveal.js event to the // If we're in an iframe, post each reveal.js event to the
// parent window. Used by the notes plugin // parent window. Used by the notes plugin
if( window.parent !== window.self ) { if( config.postMessage && window.parent !== window.self ) {
// Remove arguments that can't be stringified (circular structures) // Remove arguments that can't be stringified (circular structures)
if( args && args.currentSlide ) delete args.currentSlide; if( args && args.currentSlide ) delete args.currentSlide;
if( args && args.previousSlide ) delete args.previousSlide; if( args && args.previousSlide ) delete args.previousSlide;