postmessage.js 912 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. simple postmessage plugin
  3. Useful when a reveal slideshow is inside an iframe.
  4. It allows to call reveal methods from outside.
  5. Example:
  6. var reveal = window.frames[0];
  7. // Reveal.prev();
  8. reveal.postMessage(JSON.stringify({method: 'prev', args: []}), '*');
  9. // Reveal.next();
  10. reveal.postMessage(JSON.stringify({method: 'next', args: []}), '*');
  11. // Reveal.slide(2, 2);
  12. reveal.postMessage(JSON.stringify({method: 'slide', args: [2,2]}), '*');
  13. Add to the slideshow:
  14. dependencies: [
  15. ...
  16. { src: 'plugin/postmessage/postmessage.js', async: true, condition: function() { return !!document.body.classList; } }
  17. ]
  18. */
  19. (function (){
  20. window.addEventListener("message", function (event){
  21. var data = JSON.parse(event.data),
  22. method = data.method,
  23. args = data.args;
  24. if (Reveal[method]){
  25. Reveal[method].apply(Reveal, data.args);
  26. }
  27. }, false);
  28. }());