forked from vanilla/vanilla
-
Notifications
You must be signed in to change notification settings - Fork 12
/
container.html
135 lines (112 loc) · 4.42 KB
/
container.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!doctype html>
<html>
<head>
<title>Embed Container for easyXDM</title>
<script type="text/javascript" src="js/easyXDM/easyXDM.min.js"></script>
<script type="text/javascript">
// document.domain = document.domain;
easyXDM.DomHelper.requiresJSON("js/easyXDM/json2.js");
var callRemote = function(func, args, callback) {
var options = { func: func, args: args, success: success, failure: failure, id: Math.floor(Math.random()*4294967295) };
this.postMessage(JSON.stringify(options));
};
var callRemote = function(func, args, callback) {
var options = { func: func, args: args };
if (callback) {
options.callbackID = generateCbid();
callbacks[options.callbackID] = callback;
}
socket.postMessage(JSON.stringify(options));
};
var callback = function(callbackID, args) {
// if (callbacks[callbackID] == undefined) {
// Vanilla.error("Unkown callback ID: "+callbackID);
// }
args = args || [];
if ((typeof args) == 'string')
args = [args];
callbacks[callbackID].apply(this, args)
delete callbacks[callbackID];
}
// Generates a random ID for use as a callback id
var generateCbid = function() {
var genRand = function(){
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
};
return genRand() + genRand();
};
// Object containing callbacks
var iframe, callbacks = {};
function hide() {
iframe.style.visibility = "hidden";
}
function show() {
iframe.style.visibility = "visible";
};
var socket = new easyXDM.Socket({
swf: "js/easyXDM/easyxdm.swf",
onReady: function(){
iframe = document.createElement("iframe");
iframe.id = 'vanilla-iframe';
iframe.frameBorder = 0;
iframe.allowtransparency = true;
iframe.scrolling = "no";
iframe.style.visibility = "hidden";
document.body.appendChild(iframe);
iframe.src = easyXDM.query.url;
// if(iframe.addEventListener) {
// iframe.addEventListener('DOMContentLoaded', loaded, true);
// } else if(iframe.attachEvent) {
// iframe.attachEvent('onreadystatechange', loaded);
// } else
// loaded();
},
onMessage: function(message, origin) {
var data = JSON.parse(message);
var func = iframe.contentWindow.Vanilla.parent[data.func];
data.args = data.args || [];
if ((typeof data.args) == 'string')
data.args = [data.args];
if (data.func == 'setLocation') {
iframe.src = data.args[0];
return;
} else if (data.func == 'callback') {
var callbackID = data.args[0];
var args = data.args[1];
if (!args)
args = [];
callbacks[callbackID].apply(this, data.args[1]);
return;
}
if ((typeof func) != 'function')
throw new Error(data.func+' is not a function.');
if (data.callbackID) {
// The function was called with a callback.
var callback = function() {
callRemote("callback", [data.callbackID, Array.prototype.slice.call(arguments)]);
}
data.args.push(callback);
}
func.apply(this, data.args);
}
});
</script>
<style type="text/css">
html, body {
background-color:transparent;
overflow: hidden;
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
}
iframe {
width: 100%;
height: 100%;
border: 0px;
}
</style>
</head>
<body>
</body>
</html>