Permalink
Browse files

Adding iframe demo

  • Loading branch information...
mroderick committed Oct 11, 2012
1 parent b741b1a commit 058899f25cbfadc89e77c4edd967ea6c0e3e0029
Showing with 102 additions and 2 deletions.
  1. +28 −0 iframe/frame1.html
  2. +28 −0 iframe/frame2.html
  3. +41 −0 iframe/index.html
  4. +3 −0 iframe/pubsub-bridge.js
  5. +1 −1 src/pubsub.js
  6. +1 −1 test/test-module.js
View
@@ -0,0 +1,28 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <title>iframe demo frame 1</title>
+ <script src="pubsub-bridge.js"></script>
+ <script>
+ function init( PubSub ){
+ var btn = document.getElementById('publish-thing');
+
+ setPubSub( PubSub );
+ console.log( 'frame 1 init - ', window.PubSub );
+
+ PubSub.subscribe( 'hello-world', function( topic, data ){
+ console.log('hello-world received at frame 1 - ', data );
+ });
+
+ btn.onclick = function(){
+ PubSub.publish( 'hello-world', 'from button in frame 1' );
+ };
+ }
+ </script>
+ </head>
+ <body>
+ <p>frame1.html</p>
+ <button id="publish-thing">Test</button>
+ </body>
+</html>
View
@@ -0,0 +1,28 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <title>iframe demo frame 2</title>
+ <script src="pubsub-bridge.js"></script>
+ <script>
+ function init( PubSub ){
+ var btn = document.getElementById('publish-thing');
+
+ setPubSub( PubSub );
+ console.log( 'frame 2 init - ', window.PubSub );
+
+ PubSub.subscribe( 'hello-world', function( topic, data ){
+ console.log('hello-world received at frame 2 - ', data );
+ });
+
+ btn.onclick = function(){
+ PubSub.publish( 'hello-world', 'from button in frame 2' );
+ };
+ }
+ </script>
+ </head>
+ <body>
+ <p>frame2.html</p>
+ <button id="publish-thing">Test</button>
+ </body>
+</html>
View
@@ -0,0 +1,41 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <title>iframe demo</title>
+ <script src="../src/pubsub.js"></script>
+ <script>
+ console.log( 'PubSub: ', PubSub );
+ </script>
+ </head>
+ <body>
+ <h1>Cross iframe communication with PubSubJS</h1>
+ <p>
+ This is a small demonstration that shows that it is possible to use PubSubJS for communication across iframes.
+ </p>
+
+ <iframe id="frame-1" src="frame1.html"></iframe>
+ <iframe id="frame-2" src="frame2.html"></iframe>
+ <button id="publish-thing">Test</button>
+
+ <script>
+ window.onload = function(){
+ var f1w = document.getElementById('frame-1').contentWindow,
+ f2w = document.getElementById('frame-2').contentWindow,
+ btn = document.getElementById('publish-thing');
+
+
+ f1w.init( PubSub );
+ f2w.init( PubSub );
+
+ PubSub.subscribe( 'hello-world', function( topic, data ){
+ console.log('hello world received at parent - ', data );
+ });
+
+ btn.onclick = function(){
+ PubSub.publish( 'hello-world', 'from button in parent document' );
+ };
+ };
+ </script>
+ </body>
+</html>
View
@@ -0,0 +1,3 @@
+function setPubSub( PubSub ){
+ window.PubSub = PubSub;
+}
View
@@ -28,7 +28,7 @@ https://github.com/mroderick/PubSubJS
var PubSub = {
name: 'PubSubJS',
- version: '1.3.1-dev'
+ version: '1.3.2-dev'
},
messages = {},
lastUid = -1;
View
@@ -11,7 +11,7 @@
var PubSub = global.PubSub || require("../src/pubsub"),
TestHelper = global.TestHelper || require("../test/helper"),
- EXPECTED_VERSION = "1.3.1-dev";
+ EXPECTED_VERSION = "1.3.2-dev";
buster.testCase( "PubSub module", {
"should report version correctly" : function(){

0 comments on commit 058899f

Please sign in to comment.