-
Notifications
You must be signed in to change notification settings - Fork 16
/
genproto.js
53 lines (42 loc) · 1.47 KB
/
genproto.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
// Highlight.js:
if (window.require) {
require(["./assets/js/highlight.js"], function() {
//This function is called after some/script.js has loaded.
});
} else {
document.write('<script src="./assets/js/highlight.js"></script>');
}
var link = document.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = "./assets/css/highlight.css";
document.getElementsByTagName("head")[0].appendChild(link);
function genProto() {
// save the body for goViewSource() before we modify it
window.bodyHTML = document.body.innerHTML;
window.bodyHTML = window.bodyHTML.replace(/</g, "<");
window.bodyHTML = window.bodyHTML.replace(/>/g, ">");
}
function goViewSource() {
// show the code:
var script = document.getElementById("code");
if (!script) {
var scripts = document.getElementsByTagName("script");
script = scripts[scripts.length - 1];
}
var sp1 = document.createElement("pre");
sp1.setAttribute("data-language", "javascript");
sp1.innerHTML = script.innerHTML;
var samplediv = document.getElementById("sample") || document.body;
samplediv.appendChild(sp1);
// show the body:
var sp2 = document.createElement("pre");
sp2.setAttribute("data-language", "javascript");
sp2.innerHTML = window.bodyHTML;
samplediv.appendChild(sp2);
window.hdr.children[0].style.display = "none"; // hide the "View Source" link
// apply formatting
hljs.highlightBlock(sp1);
hljs.highlightBlock(sp2);
window.scrollBy(0,100);
}