aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorHakim El Hattab <hakim.elhattab@gmail.com>2019-04-23 10:52:45 +0200
committerHakim El Hattab <hakim.elhattab@gmail.com>2019-04-23 10:52:45 +0200
commita16b71a981e9385627959273bb4e910e1d502c92 (patch)
treee1af5701395a106af1313cf199766f74abc4e0b1 /README.md
parent32197bd77d079ca77b42340e3c2da6812c9cc174 (diff)
downloadfosdem-2021-minimalism-presentation-a16b71a981e9385627959273bb4e910e1d502c92.tar
fosdem-2021-minimalism-presentation-a16b71a981e9385627959273bb4e910e1d502c92.tar.gz
the postMessage API now works for getter methods
Diffstat (limited to 'README.md')
-rw-r--r--README.md24
1 files changed, 22 insertions, 2 deletions
diff --git a/README.md b/README.md
index 33956e9..65f9332 100644
--- a/README.md
+++ b/README.md
@@ -1065,18 +1065,38 @@ The framework has a built-in postMessage API that can be used when communicating
<window>.postMessage( JSON.stringify({ method: 'slide', args: [ 2 ] }), '*' );
```
+#### postMessage Events
+
When reveal.js runs inside of an iframe it can optionally bubble all of its events to the parent. Bubbled events are stringified JSON with three fields: namespace, eventName and state. Here's how you subscribe to them from the parent window:
```javascript
window.addEventListener( 'message', function( event ) {
var data = JSON.parse( event.data );
- if( data.namespace === 'reveal' && data.eventName ==='slidechanged' ) {
+ if( data.namespace === 'reveal' && data.eventName === 'slidechanged' ) {
// Slide changed, see data.state for slide number
}
} );
```
-This cross-window messaging can be toggled on or off using configuration flags.
+#### postMessage Callbacks
+
+When you call any method via the postMessage API, reveal.js will dispatch a message with the return value. This is done so that you can call a getter method and see what the result is. Check out this example:
+
+```javascript
+<revealWindow>.postMessage( JSON.stringify({ method: 'getTotalSlides' }), '*' );
+
+window.addEventListener( 'message', function( event ) {
+ var data = JSON.parse( event.data );
+ // `data.method`` is the method that we invoked
+ if( data.namespace === 'reveal' && data.eventName === 'callback' && data.method === 'getTotalSlides' ) {
+ data.result // = the total number of slides
+ }
+} );
+```
+
+#### Turning postMessage on/off
+
+This cross-window messaging can be toggled on or off using configuration flags. These are the default values.
```javascript
Reveal.initialize({