-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnav.1.js
61 lines (51 loc) · 1.49 KB
/
nav.1.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
var server = '';
var basepath = '';
var contentPath = '';
$(document).ready(function() {
server = config.server;
basepath = config.basepath;
contentPath = config.contentPath;
updateContent(window.location.pathname);
});
// Update content with given markdown
// URL should be either full path or relative chrooted to content folder
function updateContent(url) {
if (url.match("^" + basepath)) {
// if (!url.match("^" + basepath + contentPath)) {
url = url.substring(basepath.length);
// }
}
if (!url) {
url = "index.md";
}
if (url.match(".md$")){
url = contentPath + url;
}
$.ajax({
method: 'GET',
url: url
}).done(setMarkdown);
}
function setMarkdown(content) {
$('#content').html(markdown.toHTML(content));
}
$(document).on('click', 'a', (function(e) {
var url = $(this).attr('href');
if (!url.match("^http") && url.match(".md$")) {
e.preventDefault();
updateContent(url);
var prevUrl = window.location.href;
var prevPath = window.location.pathname;
prevPath = prevPath.substring(basepath.length);
window.history.pushState({dest: url, path: prevPath}, "STEP wiki - " + prevPath, url);
}
})
);
window.onpopstate = function(e){
if(e.state){
updateContent(e.state.dest);
}
else {
updateContent("");
}
};