This repository was archived by the owner on Aug 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 604
Expand file tree
/
Copy pathiframe.html
More file actions
executable file
·192 lines (159 loc) · 5.46 KB
/
iframe.html
File metadata and controls
executable file
·192 lines (159 loc) · 5.46 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<!DOCTYPE html>
<html>
<head>
<script src='//code.jquery.com/jquery-latest.js'></script>
<script src='//cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.6/prefixfree.min.js'></script>
<script src='/js/prefixfree.dynamic-dom.min.js'></script>
<style type="text/css" id="codeshare_style"></style>
<script type="text/javascript">
function sanitizeWindow() {
// these methods need to be cleared
window.confirm = function () {}
window.prompt = function () {}
window.open = function () {}
window.print = function () {}
}
function handleDefaults() {
if (!this.defaultValues) {
this.defaultValues = {};
for (var variable in window) {
// keep default window values when resetting JS
this.defaultValues[variable] = !0;
}
// overload setInterval and setTimeout to have a clearAll method
window.setInterval = function (e) {
var t = [],
n = function (n, r) {
return t[t.length] = e(n, r)
};
return n.clearAll = function () {
var e;
while (e = t.pop()) clearInterval(e)
}, n
}(window.setInterval)
window.setTimeout = function (e) {
var t = [],
n = function (n, r) {
return t[t.length] = e(n, r)
};
return n.clearAll = function () {
var e;
while (e = t.pop()) clearTimeout(e)
}, n
}(window.setTimeout)
}
}
function resetFrame(){
this.stopFrame();
$("body").empty();
$("head style#codeshare_style").empty();
$("head link#reset-style").remove();
$("head link.external-style").remove();
}
function stopFrame(){
for (var e in window) typeof this.defaultValues[e] == "undefined" && delete window[e];
setTimeout.clearAll(), setInterval.clearAll()
$("*").stop(true,true).clearQueue().unbind();
}
function loadLibs(data, libraries){
if (libraries.length>0){
var currentLib = libraries.shift();
$.getScript(currentLib).done($.proxy(function(){
this.loadLibs(data,libraries)
}, this)).fail($.proxy(function(){
this.loadLibs(data,libraries)
},this));
} else
// Eval JS
try {
js = $.globalEval(data.js), $(window).load()
} catch (err) {
typeof console != "undefined" && console.log('Your Javascript resulted in this error: '+err.message)
}
}
function renderFrame(codeshare){
var x, _i, _len, _ref, libList = [];
// Load and Inject CSS (Resets -> (Prefixed) User -> Externals )
// Load Reset Stylesheet
// - the meyerweb css reset
if (codeshare.cssResets === "reset"){
$('head').prepend('<link id="reset-style" rel="stylesheet" type="text/css" href="../css/reset.css">');
} else if (codeshare.cssResets === "normalize"){
// the normalize css reset
$('head').prepend('<link id="reset-style" rel="stylesheet" type="text/css" href="../css/normalize.css">');
}
// Prefix
if (codeshare.cssPrefix === true) {
codeshare.css = PrefixFree.prefixCSS(codeshare.css, true);
}
// Inject User CSS
$("head style#codeshare_style").html(codeshare.css, true);
// Load External Stylesheets (raw css only)
if (codeshare.cssExternals !== ''){
_ref = codeshare.cssExternals.split(";");
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
x = _ref[_i];
$('head').append('<link class="external-style" rel="stylesheet" type="text/css" href="' + x + '">');
}
}
// Inject HTML into BODY
$("body#codeshare_body").html(codeshare.html);
if (codeshare.htmlClass !== '') $("html").addClass(codeshare.htmlClass);
if (codeshare.htmlExtras !== '') $("html head").append(codeshare.htmlExtras);
// Load and Execute JS (Libraries -> Modernizr -> User)
switch(codeshare.jsLibs){
case "jquery-latest-with-ui-1-8-23":
libList.push("//ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js");
break;
case "mootools-1-4-5":
libList.push("//ajax.googleapis.com/ajax/libs/mootools/1.4.5/mootools-yui-compressed.js");
break;
case "dojo-1-8-0":
libList.push("//ajax.googleapis.com/ajax/libs/dojo/1.8.0/dojo/dojo.js");
break;
case "ext-core-3-1-0":
libList.push("//ajax.googleapis.com/ajax/libs/ext-core/3.1.0/ext-core.js");
break;
case "prototype-1-7-1-0":
libList.push("//ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js");
break;
case "scriptaculous-1-9-0":
libList.push("//ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/scriptaculous.js");
break;
default:
}
// Load Modernizr
if (codeshare.jsModernizr === true) libList.push("//cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js");
// Load Externals
if (codeshare.jsExternals !== ''){
_ref = codeshare.jsExternals.split(";");
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
x = _ref[_i];
libList.push(x);
}
}
// Fetch files, load them, then evaluate JS
$.ajaxSetup({async:false});
this.loadLibs(codeshare,libList);
$.ajaxSetup({async:true});
}
function receiveMessage(event)
{
var codeshare, share_script;
if (event.data != null) codeshare = JSON.parse(event.data);
if (codeshare.resetFrame === true) this.resetFrame();
else if (codeshare.stopFrame === true) this.stopFrame();
else if (codeshare.renderFrame === true) this.renderFrame(codeshare);
}
$(window).load(function(){
// Initialize
this.handleDefaults();
this.sanitizeWindow();
// Fetch the postMessage from the parent App
window.addEventListener("message", this.receiveMessage, false);
});
</script>
</head>
<body id="codeshare_body">
</body>
</html>