-
Notifications
You must be signed in to change notification settings - Fork 1
/
highlightCode.js
127 lines (92 loc) · 3.38 KB
/
highlightCode.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
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
function showSourceJS()
{
var jsString=myScript.text
jsString=jsString.replace(/\</g,"<")
jsString=jsString.replace(/\>/g,">")
jsCodeDiv.innerHTML='<pre><code id="codeJS" class="javascript">'+jsString+'</code></pre>'
var aCode = document.getElementById('codeJS');
hljs.highlightBlock(aCode);
}
function showSourceSVG()
{
var svgString=svgDiv.innerHTML
svgString=svgString.replace(/\</g,"<")
svgString=svgString.replace(/\>/g,">\n")
svgSourceDiv.innerHTML='<pre><code id="codeSVG" class="xml">'+svgString+'</code></pre>'
var aCode = document.getElementById('codeSVG');
hljs.highlightBlock(aCode);
if(svgSourceDiv.scrollHeight<300)
svgSourceDiv.style.height=+svgSourceDiv.scrollHeight+"px"
else
svgSourceDiv.style.height="300px"
}
//=================js file code======================================
function showJSfile(fileJs)
{
var http = new XMLHttpRequest();
http .onload = callback;
http .open("GET", fileJs, true);
http .send()
function callback()
{
var jsString=http.responseText
jsString=jsString.replace(/\</g,"<")
jsString=jsString.replace(/\>/g,">")
jsFileDiv.innerHTML='<pre><code id=codeFile class="javascript">'+jsString+'</code></pre>'
jsFileDiv.style.width="800px"
jsFileDiv.style.visibility="visible"
var aCode = document.getElementById('codeFile');
hljs.highlightBlock(aCode);
}
}
function showJSfile2(fileJs)
{
var http = new XMLHttpRequest();
http .onload = callback;
http .open("GET", fileJs, true);
http .send()
function callback()
{
var jsString=http.responseText
jsString=jsString.replace(/\</g,"<")
jsString=jsString.replace(/\>/g,">")
jsFile2Div.innerHTML='<pre><code id=codeFile2 class="javascript">'+jsString+'</code></pre>'
jsFile2Div.style.width="800px"
jsFile2Div.style.visibility="visible"
var aCode = document.getElementById('codeFile2');
hljs.highlightBlock(aCode);
}
}
//---double click---
function closeJsFileDiv()
{
jsFileDiv.style.visibility = 'hidden';
}
//==================================show HTML================================
//---double click---
function closeHTMLDiv()
{
showHTMLDiv.style.visibility = 'hidden';
}
function showHTML(fileURL)
{
var http = new XMLHttpRequest();
http .onload = callback;
http .open("GET", fileURL, true);
http .send()
function callback()
{
showFunctionStringDiv.innerHTML=""
showFunctionStringDiv.style.visibility="hidden"
jsFileDiv.innerHTML=""
jsFileDiv.style.visibility="hidden"
var htmlString=http.responseText
htmlString=htmlString.replace(/\</g,"<")
htmlString=htmlString.replace(/\>/g,">")
showHTMLDiv.innerHTML='<div style=font-size:120%;position:absolute;top:0px;left:0px;><pre><code class="html">'+htmlString+'</code></pre></div>'
var aCode = document.getElementsByTagName('code')[0];
hljs.highlightBlock(aCode);
showHTMLDiv.style.visibility="visible"
showHTMLDiv.scrollTop=0
}
}