Skip to content

Commit

Permalink
Add some samples.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Jiang committed Feb 29, 2012
1 parent 38dc4f0 commit debe868
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 0 deletions.
55 changes: 55 additions & 0 deletions domain-iframe.html
@@ -0,0 +1,55 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="zh-tw">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Cross Frame Prototype</title>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.2.0/build/cssreset/reset-min.css">
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.2.0/build/cssfonts/fonts-min.css">
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.2.0/build/cssbase/base-min.css">
<script type="text/javascript" src="http://yui.yahooapis.com/3.2.0/build/yui/yui-min.js"></script>
<style>
body {
padding: 10px;
}
h1 {
font-family: Georgia;
}
h2 {
font-family: Georgia;
margin: 10px 0;
}
#data {
height: 300px;
border: dotted 1px #ccc;
}
.loading {
background: url(http://devm1-muchiii.dlink.com.tw/miiicasa/bg_loading.gif) center center no-repeat;
}
ul {
}
ul li {
margin-left: 25px;
list-style-type: decimal;
margin-bottom: 10px;
}
</style>
</head>
<body>
<div id="foo">
<h1>window.frames["domain-iframe"]</h1>
<a href="http://josephjiang.com/project/yui3-crossframe/domain-iframe.html">http://josephjiang.com/project/yui3-crossframe/domain-iframe.html</a>
<h2>Data Received:</h2>
<div id="data"></div>
</div>
<script type="text/javascript" src="yui-debug-fix.js"></script>
<script type="text/javascript" src="crossframe.js"></script>
<script type="text/javascript">
YUI().use("crossframe", "event-custom", function (Y) {
Y.Global.on("crossframe:message", function (e, data, callback) {
alert(e.origin);
Y.one("#data").set("innerHTML", data.message);
});
});
</script>
</body>
</html>
63 changes: 63 additions & 0 deletions domain.html
@@ -0,0 +1,63 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="zh-tw">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Cross Frame Prototype</title>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.2.0/build/cssreset/reset-min.css">
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.2.0/build/cssfonts/fonts-min.css">
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.2.0/build/cssbase/base-min.css">
<style type="text/css">
body {
padding: 10px;
}
h1 {
margin: 20px 0;
font-family: Georgia;
font-weight: bold;
}
iframe {
border: solid 3px #ccc;
position: fixed;
top: 10px;
right: 10px;
*position: absolute;
}
textarea {
width: 500px;
height: 200px;
}
</style>
<script type="text/javascript" src="yui-debug-fix.js"></script>
<script type="text/javascript" src="crossframe.js"></script>
<script type="text/javascript">
YUI().use("crossframe", "json-stringify", function (Y) {
var formNode = Y.one("form");
formNode.on("submit", function (e) {
e.preventDefault();
var frameName = "frames['domain-iframe']",
message = formNode.one("textarea").get("value"),
config = {
"proxy" : "http://josephjiang.com/project/yui3-crossframe/proxy.html",
"reverseProxy": "http://josephj.com/project/yui3-crossframe/proxy.html",
"callback" : function (o) {
alert(o.info);
}
};
Y.CrossFrame.postMessage(frameName, message, config);
});
});
</script>
</head>
<body>
<h1>Y.CrossFrame Simple Example</h1>
<p>
Current Location:
<a href="http://josephj.com/project/yui3-crossframe/domain.html">http://josephj.com/project/yui3-crossframe/domain.html</a>
</p>
<form>
<textarea>Hello World</textarea><br>
<input type="submit" value="Submit">
</form>
<iframe src="http://josephjiang.com/project/yui3-crossframe/domain-iframe.html" id="domain-iframe" name="domain-iframe" width="500" height="500" border="3" frameborder="3"></iframe>
</body>
</html>
49 changes: 49 additions & 0 deletions sample/two-way-iframe.html
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Cross Frame Prototype</title>
<style type="text/css">
body {
padding: 5px;
}
h1 {
font-family: Georgia;
font-size: 123.1%;
font-weight: bold;
}
</style>
</head>
<body>
<h1>Iframe Domain - josephjiang.com</h1>
<button id="button">Y.CrossFrame.postMessage("parent", $timestamp);</button>
<ul></ul>
<script type="text/javascript" src="http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js"></script>
<script type="text/javascript" src="../crossframe.js"></script>
<script type="text/javascript">
YUI().use("crossframe", function (Y) {
var PROXY_URL = "http://josephj.com/project/yui3-crossframe/proxy.html",
REVERSE_PROXY_URL = "http://josephjiang.com/project/yui3-crossframe/proxy.html",
timestamp;
Y.Global.on("crossframe:message", function (e, o, callback) {
Y.one("ul").append("<li>" + o.message + "</li>");
callback({response: "Callback - Get message from child iframe successfully."});
});
Y.one("#button").on("click", function () {
timestamp = parseInt((new Date()).getTime(), 10);
Y.CrossFrame.postMessage(
"parent",
timestamp + " from child iframe",
{
"proxy" : PROXY_URL,
"reverseProxy": REVERSE_PROXY_URL,
"callback": function (o) {
Y.one("ul").append("<li>" + o.response + "</li>");
}
}
);
});
});
</script>
</body>
</html>
59 changes: 59 additions & 0 deletions sample/two-way.html
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Two Way Sample of CrossFrame</title>
<style type="text/css">
body {
padding: 10px;
}
h1 {
margin: 20px 0;
font-family: Georgia;
font-size: 123.1%;
font-weight: bold;
}
iframe {
border: solid 3px #ccc;
position: fixed;
right: 10px;
top: 10px;
}
</style>
</head>
<body>
<h1>Base Page Domain - josephj.com</h1>
<button id="button">Y.CrossFrame.postMessage("child", $timestamp);</button>
<ul></ul>
<div>
<iframe id="child" src="http://josephjiang.com/project/yui3-crossframe/sample/two-way-iframe.html" name="child" width="500" height="500" border="3" frameborder="3"></iframe>
</div>
<script type="text/javascript" src="http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js"></script>
<script type="text/javascript" src="../crossframe.js"></script>
<script>
YUI().use("crossframe", function (Y) {
var PROXY_URL = "http://josephjiang.com/project/yui3-crossframe/proxy.html",
REVERSE_PROXY_URL = "http://josephj.com/project/yui3-crossframe/proxy.html",
timestamp;
Y.Global.on("crossframe:message", function (e, o, callback) {
Y.one("ul").append("<li>" + o.message + "</li>");
callback({response: "Callback - Get message from parent iframe successfully."});
});
Y.one("#button").on("click", function () {
timestamp = parseInt((new Date()).getTime(), 10);
Y.CrossFrame.postMessage(
'frames["child"]',
timestamp + " from parent",
{
"proxy" : PROXY_URL,
"reverseProxy": REVERSE_PROXY_URL,
"callback": function (o) {
Y.one("ul").append("<li>" + o.response + "</li>");
}
}
);
});
});
</script>
</body>
</html>

0 comments on commit debe868

Please sign in to comment.