diff options
author | Joris Guyonvarch | 2015-06-27 01:04:51 +0200 |
---|---|---|
committer | Joris Guyonvarch | 2015-06-27 01:04:51 +0200 |
commit | 6ec9a6fc1d43c8d2a1495e147157dc545175b129 (patch) | |
tree | 9e9809a02c937e6a95eb9c63890a945a250ffa11 /router.js | |
parent | b590ca0aea8bbae34885e98b59bc465c09400ca3 (diff) |
Generate static pages with a watcher and serve files with a simple http server
Diffstat (limited to 'router.js')
-rw-r--r-- | router.js | 52 |
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); - } - }; - -})(); |