|
1 | 1 | /*
|
2 |
| -simple postmessage plugin |
3 | 2 |
|
4 |
| -Useful when a reveal slideshow is inside an iframe. |
5 |
| -It allows to call reveal methods from outside. |
| 3 | + simple postmessage plugin |
6 | 4 |
|
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. |
9 | 7 |
|
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]; |
16 | 10 |
|
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]}), '*'); |
18 | 17 |
|
19 |
| - dependencies: [ |
20 |
| - ... |
21 |
| - { src: 'plugin/postmessage/postmessage.js', async: true, condition: function() { return !!document.body.classList; } } |
22 |
| - ] |
| 18 | + Add to the slideshow: |
23 | 19 |
|
| 20 | + dependencies: [ |
| 21 | + ... |
| 22 | + { src: 'plugin/postmessage/postmessage.js', async: true, condition: function() { return !!document.body.classList; } } |
| 23 | + ] |
24 | 24 |
|
25 | 25 | */
|
26 | 26 |
|
27 | 27 | (function (){
|
28 | 28 |
|
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 | + |
37 | 39 | }());
|
38 | 40 |
|
39 | 41 |
|
|
0 commit comments