forked from jquery/api.jquery.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.js
50 lines (39 loc) · 1.32 KB
/
demo.js
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
$("code.demo-code").each(function(index) {
var $example = $(this),
$demo = $('div.code-demo').eq(index);
var source = $example.html()
.replace(/<\/?a.*?>/ig, "")
.replace(/<\/?strong.*?>/ig, "")
.replace(/</g, "<").replace(/>/g, ">")
.replace(/&/g, "&");
var iframe = document.createElement("iframe");
iframe.src = "/resources/index-blank.html";
iframe.width = "100%";
iframe.height = $demo.attr("rel") || "125";
iframe.style.border = "none";
$demo.html(iframe);
var doc = iframe.contentDocument ||
(iframe.contentWindow && iframe.contentWindow.document) ||
iframe.document ||
null;
if (doc == null) {
return true;
}
var example = $example.text();
var reTmpl = /((?:<|>|>|<)\/?)tmpl/g;
if ( reTmpl.test(example) ) {
$example.text( example.replace(reTmpl,'$1script') );
}
source = source
.replace(/<script>([^<])/g,"<script>window.onload = (function(){\r\ntry{$1")
.replace(/([^>])<\/sc/g, "$1\r\n}catch(e){}});</sc")
.replace(/(<\/?)tmpl/g,'$1script');
source = source
.replace("</head>", "<style>html,body{border:0; margin:0; padding:0;}</style></head>");
doc.open();
doc.write( source );
doc.close();
});
if (typeof prettyPrint == 'function') {
prettyPrint();
}