-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathmain.html
208 lines (183 loc) · 5.23 KB
/
main.html
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>GIS兵器库</title>
<link href="lib/markdown/atom-one-dark.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<script src="lib/markdown/marked.min.js"></script>
<script src="lib/markdown/highlight.min.js"></script>
<script src="lib/jquery.min.js"></script>
<script src="lib/jquery.nicescroll.min.js"></script>
<script src="config_blog.js"></script>
<script src="config_demo.js"></script>
<script src="config_source.js"></script>
</head>
<body>
<nav class="navbar zs_navbar">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand zs_logo" href="index.html">
<img src="img/logo.png" alt="">
<span>GIS兵器库</span>
</a>
</div>
<div class="collapse navbar-collapse " id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li data-id="wechat">
<a>公众号</a>
</li>
<li data-id="github">
<a>github</a>
</li>
</ul>
</div>
</div>
</nav>
<div id="content">
<div id="mainContent"></div>
<div id="bottomContent">
<span class="aboutus-span" onclick="contactusClick()">联系我们:CSDN留言或私信</span><br>
<span class="aboutus-span" onclick="beianClick()">京ICP备20018340号-1</span>
</div>
</div>
</body>
<script>
//配置marked插件
configMarked();
init();
changeSelect()
//初始化
function init() {
$("#content").niceScroll();
var urlArg = getUrlArgObject();
if (urlArg && urlArg.blog) {
loadMarkdown(urlArg.blog)
} else if (urlArg && urlArg.demo) {
loadDemo(urlArg.demo)
} else if (urlArg && urlArg.source) {
loadSource(urlArg.source)
} else {
loadMarkdown("main")
}
}
function contactusClick(){
window.open('https://blog.csdn.net/gisarmory/')
}
function beianClick(){
window.open('https://beian.miit.gov.cn/')
}
function changeSelect() {
$(".navbar-nav li").click(function() {
doChangeSelect(this)
});
}
function doChangeSelect(_this){
// $(_this).siblings('li').removeClass('active'); // 删除其他兄弟元素的样式
// $(_this).addClass('active'); // 添加当前元素的样式
var blogid = $(_this).attr("data-id");
var blogObj = getBlogConfigById(blogid);
if(blogObj.href){
window.open(blogObj.href,"_blank");
}else if(blogObj.url){
loadMarkdown(blogid);
}
setTimeout(function(){
$("#content").niceScroll();
$("#content").getNiceScroll().resize();
},200)
}
//加载demo示例
function loadDemo(demoId) {
var demoObj = getDemoConfigById(demoId);
if (demoObj) {
window.location.href = demoObj.url;
}
}
//加载loadSource示例
function loadSource(sourceId) {
var sourceObj = getSourceConfigById(sourceId);
if (sourceObj) {
window.location.href = sourceObj.url;
}
}
//配置marked插件
function configMarked() {
hljs.initHighlightingOnLoad();
var rendererMD = new marked.Renderer();
marked.setOptions({
renderer: rendererMD,
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: false,
smartLists: true,
smartypants: false
});
marked.setOptions({
highlight: function(code) {
return hljs.highlightAuto(code).value;
}
});
}
//加载markdown文件
function loadMarkdown(blogid) {
var blogObj = getBlogConfigById(blogid);
if (blogObj) {
xhr = new XMLHttpRequest();
xhr.open('get', blogObj.url);
xhr.send('')
xhr.onload = function() {
var mdText = xhr.responseText;
var mdContent = document.getElementById('mainContent');
//replace是解决代码不显示黑色背景的问题
mdContent.innerHTML = marked(mdText).replace(/<pre>/g, "<pre class='hljs'>");
}
}
}
//根据blogid获取blog配置
function getBlogConfigById(blogId) {
for (var i = 0; i < blogList.length; i++) {
var blogObj = blogList[i];
if (blogObj.id == blogId) {
return blogObj;
}
}
}
//根据demoid获取demo配置
function getDemoConfigById(demoId) {
for (var i = 0; i < demoList.length; i++) {
var demoObj = demoList[i];
if (demoObj.id == demoId) {
return demoObj;
}
}
}
//根据sourceid获取source配置
function getSourceConfigById(sourceId) {
for (var i = 0; i < sourceList.length; i++) {
var sourceObj = sourceList[i];
if (sourceObj.id == sourceId) {
return sourceObj;
}
}
}
//返回的是对象形式的参数
function getUrlArgObject() {
var args = new Object();
var query = location.search.substring(1); //获取查询串
var pairs = query.split(","); //在逗号处断开
for (var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexOf('='); //查找name=value
if (pos == -1) { //如果没有找到就跳过
continue;
}
var argname = pairs[i].substring(0, pos); //提取name
var value = pairs[i].substring(pos + 1); //提取value
args[argname] = unescape(value); //存为属性
}
return args; //返回对象
}
</script>
</html>