null and type check what comes through postmessage

This commit is contained in:
Hakim El Hattab 2014-04-22 19:01:59 +02:00
parent 167400ee8b
commit 53238c47ce
1 changed files with 9 additions and 4 deletions

View File

@ -575,11 +575,16 @@ var Reveal = (function(){
if( config.postMessage ) {
window.addEventListener( 'message', function ( event ) {
var data = JSON.parse( event.data );
var method = Reveal[data.method];
var data = event.data;
if( typeof method === 'function' ) {
method.apply( Reveal, data.args );
// Make sure we're dealing with JSON
if( data.charAt( 0 ) === '{' && data.charAt( data.length - 1 ) === '}' ) {
data = JSON.parse( data );
// Check if the requested method can be found
if( data.method && typeof Reveal[data.method] === 'function' ) {
Reveal[data.method].apply( Reveal, data.args );
}
}
}, false );
}