blob: 234c50b9e4ce09f9d500e59b8e0d6bb0b8872079 (
plain)
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
|
(function () {
function fetchFile(url, successHandler, errorHandler) {
var xhr = typeof XMLHttpRequest != 'undefined'
? new XMLHttpRequest()
: new ActiveXObject('Microsoft.XMLHTTP');
xhr.open('get', url, true);
xhr.responseType = 'text';
xhr.onreadystatechange = function() {
var status;
var data;
if (xhr.readyState == 4) {
status = xhr.status;
if (status === 200 || status === 0) {
data = xhr.responseText;
successHandler && successHandler(data);
} else {
errorHandler && errorHandler(status);
}
}
};
try {
xhr.send();
} catch(err) {
errorHandler && errorHandler(err);
}
};
function router() {
var url = location.hash.slice(2) || 'presentation';
var contentElement = document.getElementById('content');
contentElement.style.height = contentElement.offsetHeight + 'px';
contentElement.innerHTML = '';
fetchFile('Pages/' + url + '.md', function(contentMd) {
contentElement.style.height = 'auto';
contentElement.innerHTML = markdown.toHTML(contentMd);
}, function() {
var notFoundPage = '<h1>Page non trouvée</h1><a href="#">Retour à l\'accueil</a>';
contentElement.innerHTML = notFoundPage;
});
}
this.addEventListener('hashchange', router);
this.addEventListener('load', router);
})();
|