-
Notifications
You must be signed in to change notification settings - Fork 2
/
sidebar.js
128 lines (122 loc) · 5.61 KB
/
sidebar.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
128
(function() {
'use strict';
var sidebarClass = function() {
this.init();
for (var key = 0; key < window.eocourse.sidebarConstant.list.length; key++) {
var val = window.eocourse.sidebarConstant.list[key];
val.level = 0;
this.paint(val, document.getElementById('sidebar_js'));
}
};
try {
var href = decodeURI(window.location.search).split('?target=/')[1].split(/&origin=\//g);
} catch (e) {
var href = '';
}
sidebarClass.prototype = {
init: function() {
var template = {
target: null
}
try {
template.target = decodeURI(window.location.search).split('?target=')[1].split(/&origin=/g)[0];
} catch (e) {
template.target = null;
}
editormd.emoji = {
path: "http://www.emoji-cheat-sheet.com/graphics/emojis/",
ext: ".png"
};
editormd.twemoji = {
path: "http://twemoji.maxcdn.com/72x72/",
ext: ".png"
};
if (template.target) {
var http = new XMLHttpRequest();
console.log()
http.open("GET", window.location.origin + window.location.pathname + template.target + '.md', true);
http.send(null);
http.onload = function() {
switch (http.status) {
case 200:
{
editormd.markdownToHTML("article-container-js", {
markdown: http.responseText,
sequenceDiagram: true,
flowChart: true,
emoji: true,
tex: true,
taskList: true
})
break;
}
default:
{
document.getElementById('article-container-js').innerHTML=http.responseText.replace(/<(.*)style(.*)>/g,'');
break;
}
}
}
} else {
window.location.href = window.location.href + '?target=/md/index';
}
},
paint: function(arg, elem) {
var template = {
target: (href[0] || '').replace(/\//g, '.'),
origin: (href[1] || '').replace(/\//g, '.'),
array: '',
icon: (arg.icon || '').replace(/\//g, ''),
title: arg.title.replace(/\//g, ''),
href: (arg.href || '').replace(/\//g, '.')
}
template.array = (template.origin || template.target).split('.');
var isCurrent = eval('/^' + (template.icon || template.title) + '$/').test(template.array[arg.level + 1]);
if (arg.href && isCurrent) {
if ((template.origin && !arg.originHref) || (!template.origin && arg.originHref) || !(eval('/' + (template.href) + '$/').test('.' + template.target))) {
isCurrent = false;
}
}
if (isCurrent && arg.href) {
window.document.title = arg.title + '-eoLinker官方支持手册';
}
var template = {
html: '<li class="common-level-' + arg.level + (isCurrent ? (arg.href ? (' elem-active level' + arg.level) : (' level' + arg.level)) : ' hidden') + '" >' +
'<p level="' + arg.level + '" class="' + (isCurrent ? 'ico_up' : 'ico_down') + '" onclick="eocourse.sidebarClass.click(this)"><a ' + (arg.href ? ('onclick="eocourse.sidebarClass.router(\'' + arg.href + '\'' + (arg.originHref ? (',\'' + arg.originHref + '\'') : '') + ')"') : '') + '>' + (arg.childList ? '<span class="pull-left ico"></span>' : '<span class="pull-left unchild-span"></span>') + arg.title + '</a></p>' +
'</li>',
elem: null
}
template.elem = document.createElement('ul');
template.elem.innerHTML = template.html;
elem.appendChild(template.elem);
if (arg.childList) {
for (var key = 0; key < arg.childList.length; key++) {
var val = arg.childList[key];
val.level = arg.level + 1;
this.paint(val, template.elem.firstChild);
}
}
},
click: function(arg) {
var template = {
class: arg.parentElement.getAttribute('class'),
level: arg.getAttribute('level')
}
if (/hidden/.test(arg.parentElement.getAttribute('class'))) {
arg.setAttribute('class', 'ico_up');
arg.parentElement.setAttribute('class', template.class.replace(/hidden/g, 'level' + template.level));
} else {
arg.parentElement.setAttribute('class', template.class + ' hidden');
arg.setAttribute('class', 'ico_down');
}
},
router: function(href, originHref) {
if (originHref) {
window.location.href = window.location.origin + window.location.pathname + '?target=' + href + '&origin=' + originHref;
} else {
window.location.href = window.location.origin + window.location.pathname + '?target=' + href;
}
}
}
window.eocourse.sidebarClass = new sidebarClass();
})();