-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapi-demo.js
52 lines (45 loc) · 1.61 KB
/
api-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
51
52
(function() {
$( ".entry-example" ).each(function() {
var iframeSrc,
src = $( this ).find( ".syntaxhighlighter" ),
output = $( this ).find( ".code-demo" );
if ( !src.length || !output.length ) {
return;
}
// Get the original source
iframeSrc = src.find( "td.code .line" ).map(function() {
// Convert non-breaking spaces from highlighted code to normal spaces
return $( this ).text().replace( /\xa0/g, " " );
// Restore new lines from original source
}).get().join( "\n" );
iframeSrc = iframeSrc
// Insert styling for the live demo that we don't want in the
// highlighted code
.replace( "</head>",
"<style>" +
"html, body { border:0; margin:0; padding:0; }" +
"body { font-family: 'Helvetica', 'Arial', 'Verdana', 'sans-serif'; }" +
"</style>" +
"</head>" )
// IE <10 executes scripts in the order in which they're loaded,
// not the order in which they're written. So we need to defer inline
// scripts so that scripts which need to be fetched are executed first.
.replace( /<script>([\s\S]+)<\/script>/,
"<script>" +
"window.onload = function() {" +
"$1" +
"};" +
"</script>" );
var iframe = document.createElement( "iframe" );
iframe.width = "100%";
iframe.height = output.attr( "data-height" ) || 250;
output.append( iframe );
var doc = (iframe.contentWindow || iframe.contentDocument).document;
doc.write( iframeSrc );
doc.close();
});
// silly selector to match only the options for the validate() method
$("#content").find(".signature ul ul div > strong, h1, h2, h3, h4, h5").anchorify({
position: "prepend"
});
}());