Skip to content

Commit 87591d9

Browse files
committed
cosmetical tweaks to postmessage plugin
1 parent 42766b1 commit 87591d9

File tree

3 files changed

+65
-58
lines changed

3 files changed

+65
-58
lines changed

plugin/postmessage/example.html

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<html>
2+
<body>
3+
4+
<iframe id="reveal" src="../../index.html" style="border: 0;" width="500" height="500"></iframe>
5+
6+
<div>
7+
<input id="back" type="button" value="go back"/>
8+
<input id="ahead" type="button" value="go ahead"/>
9+
<input id="slideto" type="button" value="slideto 2-2"/>
10+
</div>
11+
12+
<script>
13+
14+
(function (){
15+
16+
var back = document.getElementById( 'back' ),
17+
ahead = document.getElementById( 'ahead' ),
18+
slideto = document.getElementById( 'slideto' ),
19+
reveal = window.frames[0];
20+
21+
back.addEventListener( 'click', function () {
22+
23+
reveal.postMessage( JSON.stringify({method: 'prev', args: []}), '*' );
24+
}, false );
25+
26+
ahead.addEventListener( 'click', function (){
27+
reveal.postMessage( JSON.stringify({method: 'next', args: []}), '*' );
28+
}, false );
29+
30+
slideto.addEventListener( 'click', function (){
31+
reveal.postMessage( JSON.stringify({method: 'slide', args: [2,2]}), '*' );
32+
}, false );
33+
34+
}());
35+
36+
</script>
37+
38+
</body>
39+
</html>

plugin/postmessage/iframe_example.html

-34
This file was deleted.

plugin/postmessage/postmessage.js

+26-24
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
11
/*
2-
simple postmessage plugin
32
4-
Useful when a reveal slideshow is inside an iframe.
5-
It allows to call reveal methods from outside.
3+
simple postmessage plugin
64
7-
Example:
8-
var reveal = window.frames[0];
5+
Useful when a reveal slideshow is inside an iframe.
6+
It allows to call reveal methods from outside.
97
10-
// Reveal.prev();
11-
reveal.postMessage(JSON.stringify({method: 'prev', args: []}), '*');
12-
// Reveal.next();
13-
reveal.postMessage(JSON.stringify({method: 'next', args: []}), '*');
14-
// Reveal.slide(2, 2);
15-
reveal.postMessage(JSON.stringify({method: 'slide', args: [2,2]}), '*');
8+
Example:
9+
var reveal = window.frames[0];
1610
17-
Add to the slideshow:
11+
// Reveal.prev();
12+
reveal.postMessage(JSON.stringify({method: 'prev', args: []}), '*');
13+
// Reveal.next();
14+
reveal.postMessage(JSON.stringify({method: 'next', args: []}), '*');
15+
// Reveal.slide(2, 2);
16+
reveal.postMessage(JSON.stringify({method: 'slide', args: [2,2]}), '*');
1817
19-
dependencies: [
20-
...
21-
{ src: 'plugin/postmessage/postmessage.js', async: true, condition: function() { return !!document.body.classList; } }
22-
]
18+
Add to the slideshow:
2319
20+
dependencies: [
21+
...
22+
{ src: 'plugin/postmessage/postmessage.js', async: true, condition: function() { return !!document.body.classList; } }
23+
]
2424
2525
*/
2626

2727
(function (){
2828

29-
window.addEventListener("message", function (event){
30-
var data = JSON.parse(event.data),
31-
method = data.method,
32-
args = data.args;
33-
if (Reveal[method]){
34-
Reveal[method].apply(Reveal, data.args);
35-
}
36-
}, false);
29+
window.addEventListener( "message", function ( event ) {
30+
var data = JSON.parse( event.data ),
31+
method = data.method,
32+
args = data.args;
33+
34+
if( typeof Reveal[method] === 'function' ) {
35+
Reveal[method].apply( Reveal, data.args );
36+
}
37+
}, false);
38+
3739
}());
3840

3941

0 commit comments

Comments
 (0)