-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmdviewer.js
128 lines (106 loc) · 3.87 KB
/
mdviewer.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 setStatusBar() {
function showURL(ev) {
var msg = document.createElement("span");
if (this.pathname == window.location.pathname &&
this.protocol == window.location.protocol &&
this.host == window.location.host &&
this.hash) {
msg.innerHTML = this.hash;
} else if (this.protocol === "mailto:") {
msg.innerHTML = this.protocol + this.hostname + this.pathname;
} else {
msg.innerHTML = this.protocol + "//" + this.hostname
+ "<span class=\"secondary-text\">"
+ this.port + this.pathname + this.search + this.hash
+ "</span>";
}
var sbar = document.createElement("div");
sbar.id = "ui-status-bar";
sbar.appendChild(msg);
document.body.insertBefore(sbar, document.body.lastChild);
}
function hideURL(ev) {
var sbar = document.getElementById("ui-status-bar");
if (sbar) {
sbar.parentNode.removeChild(sbar);
}
}
var links = [].slice.call(document.links);
links.forEach(function(link) {
link.addEventListener("mouseover", showURL);
link.addEventListener("mouseout", hideURL);
});
}
function generateTOC() {
var toc = document.getElementById("ui-toc");
if (toc) { toc.parentNode.removeChild(toc) }
toc = document.createElement("nav");
toc.id = "ui-toc";
toc.style.display = "none";
toc.oncontextmenu = function() { return false };
document.body.insertBefore(toc, document.body.lastChild);
var headings = [].slice.call(document.body.querySelectorAll("h1, h2, h3, h4, h5, h6"));
headings.forEach(function(heading, i) {
var ref;
if (heading.id) {
ref = heading.getAttribute("id");
} else {
ref = "ui-toc-" + i;
heading.id = ref;
}
var link = document.createElement("a");
link.href = "#" + ref;
link.appendChild(document.createTextNode(heading.innerText || heading.textContent));
var entry = document.createElement("div");
entry.className = "ui-toc-" + heading.tagName.toLowerCase();
entry.appendChild(link);
toc.appendChild(entry);
});
var hidetoc = document.createElement("a");
hidetoc.id = "ui-toc-hide";
hidetoc.title = "Hide Navigation pane";
hidetoc.addEventListener ("click", function() { toc.style.display = "none" });
toc.appendChild(hidetoc);
if (typeof(window.MathJax) !== "undefined") {
let mjversion = parseInt(MathJax.version.split(".")[0]);
if (mjversion > 2) {
MathJax.typeset();
} else {
MathJax.Hub.Queue(["Typeset", MathJax.Hub, "ui-toc"]);
}
}
}
function toggleTOC() {
var toc = document.getElementById("ui-toc");
if (toc) {
if (toc.style.display === "none") {
toc.style.display = "block";
toc.getElementsByTagName("a")[0].focus()
} else {
toc.style.display = "none";
document.body.focus();
}
}
}
function procTaskList() {
var items = [].slice.call(document.body.querySelectorAll("li"));
items.forEach(function (item) {
element = item.firstChild;
if (element.nodeName === "INPUT" &&
element.getAttribute("type") === "checkbox") {
element.classList.add("task-list-item-checkbox");
item.classList.add("task-list-item");
} else {
if (element.tagName === "P") {
if (element.firstChild.nodeName === "INPUT" &&
element.firstChild.getAttribute("type") === "checkbox") {
element.firstChild.classList.add("task-list-item-checkbox");
item.classList.add("task-list-item");
}
}
}
});
}
setStatusBar();
generateTOC();
procTaskList();