From 002521a21b4c70ef16e356e31b34a328b194de2f Mon Sep 17 00:00:00 2001
From: Danny Yoo
Date: Mon, 5 Mar 2012 15:55:02 -0500
Subject: [PATCH] intra-iframe communication example
---
examples/js-get-message-parent.html | 28 +++++++++++++++++++++++++++
examples/js-get-message.rkt | 30 +++++++++++++++++++++++++++++
2 files changed, 58 insertions(+)
create mode 100644 examples/js-get-message-parent.html
create mode 100644 examples/js-get-message.rkt
diff --git a/examples/js-get-message-parent.html b/examples/js-get-message-parent.html
new file mode 100644
index 0000000..0462c1e
--- /dev/null
+++ b/examples/js-get-message-parent.html
@@ -0,0 +1,28 @@
+
+
+Testing message passing across windows
+
+
+
+
+
This is a world program:
+
+
+
+And this a regular JavaScript program:
+
+
+
+
+
+
+
diff --git a/examples/js-get-message.rkt b/examples/js-get-message.rkt
new file mode 100644
index 0000000..0fd068e
--- /dev/null
+++ b/examples/js-get-message.rkt
@@ -0,0 +1,30 @@
+#lang planet dyoo/whalesong
+(require (planet dyoo/whalesong/js/world)
+ (planet dyoo/whalesong/js)
+ (planet dyoo/whalesong/web-world))
+
+;; Test of getting world events from arbitrary JavaScript function application.
+
+;; We first define a new event handler type, by using make-js-world-event:
+(define-values (on-message send)
+ (make-js-world-event))
+
+;; It gives us two values back:
+;; 1. An event handler that can be passed to big-bang
+;; 2. A raw JavaScript function that can fire events
+
+
+;; Let's attach the send-event function to a toplevel function on the window.
+(void ((js-function (js-eval "function(send) { $(window).bind('message', function(e) { send(e.originalEvent.data); })}"))
+ send))
+;; js-function lifts JavaScript functions to regular function we can call.
+
+
+(define (get-message w v msg)
+ (cons msg w))
+
+
+;; Finally, let's use our big bang:
+(big-bang '("Initial")
+ (on-message get-message)) ;; Note the on-event here
+