This repository was archived by the owner on Apr 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinception.php
More file actions
executable file
·165 lines (138 loc) · 4.03 KB
/
inception.php
File metadata and controls
executable file
·165 lines (138 loc) · 4.03 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?PHP
header("Content-type: text/javascript");
?>
/**
** Inception - A safe way to allow cross site communications between iframes.
**
** @ Author Rulian Estivalletti - Vitals.com
**
**/
(function(){
var Inception = window.Inception = {
socket : null,
identifier: null,
iframe: null,
send : null,
local : null,
target: null,
window : window,
_construct : function(params){
if (params.level == "top" && window == window.top) Inception.top(params);
else if (params.level== "child") Inception.child(params);
else if (params.level== "channel") Inception.channel(params);
//// if page's get params, use them
var getParams = Inception.get(window.location.href);
if (getParams.length) Inception.command(getParams.value);
},
_event : function(element,event,listener){
if(element.addEventListener) {
element.addEventListener(event, listener, false);
}
else {
element.attachEvent("on" + event, listener);
}
},
get : function(path){
var ret = {};
if (path.indexOf('?') > -1) {
var uri = path.substring((path.indexOf('?') + 1),path.length);
var split = uri.split('&');
var hasVals = false;
for(var i =0; i<split.length; i++){
var vals = split[i].split('=');
ret[vals[0]] = vals[1];
hasVals = true;
}
return {length: split.length, value: ret};
}
else return {length: 0, value:ret}
},
setSocket : function(socket){
Inception.socket = socket;
},
createFrame: function(url){
Inception.iframe = document.createElement("iframe");
Inception.iframe.src = url;
Inception.iframe.width='1px';
Inception.iframe.height='1px';
Inception.iframe.style.position="absolute"
Inception.iframe.style.left="-100px"
Inception.iframe.style.top="-100px"
return Inception.iframe;
},
top : function(params){
Inception.identifier = window.location.href;
Inception.send = Inception.bubbleDown;
},
child : function(params){
Inception.identifier = window.location.href;
//window.Inception = Inception.bubbleUp;
if(params.target) {
Inception.target = params.target;
Inception.iframe = Inception.createFrame(params.target);
document.body.appendChild(Inception.iframe);
}
Inception.send = Inception.bubbleFrame;
},
channel: function(params){
Inception.identifier = window.location.href;
if(params.target) {
Inception.target = params.target;
Inception.iframe = Inception.createFrame(params.target)
document.body.appendChild(Inception.iframe);
Inception.send = Inception.bubbleOne;
}
else {
Inception.send = Inception.bubbleUp;
}
window.parent.parent.window.Inception.setSocket(Inception);
},
bubbleUp : function(params){
window.parent.parent.Inception.command(params);
},
bubbleDown: function(params){
params.command='bubbleUp';
params.next=false;
Inception.socket.send(params)
},
bubbleFrame: function(params){
params.command='bubbleUp';
params.next=false;
Inception.bubbleOne(params)
},
bubbleOne: function(params){
params.level = 'channel';
if (Inception.target) params.target = Inception.target;
Inception.iframe.src=Inception.target + '?' + Inception.convert(params);
},
convert: function(params){
var arr = [];
for(var a in params) {
arr.push(a + '=' + params[a]);
}
return arr.join("&");
},
log: function(params){
console.log(['log',params]);
},
command: function(params){
if (params.command && params.command !== "false") {
key = params.command;
if (typeof params.next !== 'undefined') {
params.command=params.next;
params.next=false;
}
Inception[key](params);
}
else {
if (params.execute) {
window[params.execute](params);
}
//else Inception.send(params);
}
}
}
Inception._event(window,'load', function(){
Inception._construct(<?PHP echo json_encode($_GET); ?>);
});
})();