aboutsummaryrefslogtreecommitdiff
path: root/router.js
diff options
context:
space:
mode:
Diffstat (limited to 'router.js')
-rw-r--r--router.js52
1 files changed, 0 insertions, 52 deletions
diff --git a/router.js b/router.js
deleted file mode 100644
index 2aac572..0000000
--- a/router.js
+++ /dev/null
@@ -1,52 +0,0 @@
-(function () {
-
- this.addEventListener('hashchange', router);
- this.addEventListener('load', router);
-
- function router() {
- const url = location.hash.slice(2) || 'presentation';
- const contentElement = document.getElementById('content');
- const htmlElement = document.querySelector('html');
- addClass(htmlElement, 'waitCursor');
- fetchFile('Pages/' + url + '.md', function(contentMd) {
- removeClass(htmlElement, 'waitCursor');
- contentElement.innerHTML = markdown.toHTML(contentMd);
- }, function() {
- const notFoundPage = '<h1>Page non trouvée</h1><a href="#">Retour à l\'accueil</a>';
- contentElement.innerHTML = notFoundPage;
- });
- }
-
- function addClass(element, myClass) {
- element.className = element.className + ' ' + myClass;
- }
-
- function removeClass(element, myClass) {
- element.className = element.className.replace(new RegExp('(?:^|\\s)' + myClass + '(?!\\S)') , '');
- }
-
- function fetchFile(url, successHandler, errorHandler) {
- const xhr = typeof XMLHttpRequest != 'undefined'
- ? new XMLHttpRequest()
- : new ActiveXObject('Microsoft.XMLHTTP');
- xhr.open('get', url, true);
- xhr.responseType = 'text';
- xhr.onreadystatechange = function() {
- if (xhr.readyState == 4) {
- const status = xhr.status;
- if (status === 200 || status === 0) {
- const data = xhr.responseText;
- successHandler && successHandler(data);
- } else {
- errorHandler && errorHandler(status);
- }
- }
- };
- try {
- xhr.send();
- } catch(err) {
- errorHandler && errorHandler(err);
- }
- };
-
-})();