From 6ec9a6fc1d43c8d2a1495e147157dc545175b129 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Sat, 27 Jun 2015 01:04:51 +0200 Subject: Generate static pages with a watcher and serve files with a simple http server --- router.js | 52 ---------------------------------------------------- 1 file changed, 52 deletions(-) delete mode 100644 router.js (limited to 'router.js') 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 = '

Page non trouvée

Retour à l\'accueil'; - 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); - } - }; - -})(); -- cgit v1.2.3