aboutsummaryrefslogtreecommitdiff
path: root/router.js
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-03-07 20:20:35 +0100
committerJoris Guyonvarch2015-03-07 20:20:35 +0100
commit8e086a0cf8e8c3aa31f0b700399bccc4f735cd89 (patch)
tree057672c69ce50a217c5e82ef949ad134710a4fa6 /router.js
parent093a9ef7cf845b5056ba7e504a73757daf5f0ee2 (diff)
downloadmakeup-8e086a0cf8e8c3aa31f0b700399bccc4f735cd89.tar.gz
makeup-8e086a0cf8e8c3aa31f0b700399bccc4f735cd89.tar.bz2
makeup-8e086a0cf8e8c3aa31f0b700399bccc4f735cd89.zip
Adding a spinner to cursor when loading a page instead of putting the page to blank
Diffstat (limited to 'router.js')
-rw-r--r--router.js42
1 files changed, 25 insertions, 17 deletions
diff --git a/router.js b/router.js
index 234c50b..8af98ab 100644
--- a/router.js
+++ b/router.js
@@ -1,5 +1,30 @@
(function () {
+ this.addEventListener('hashchange', router);
+ this.addEventListener('load', router);
+
+ function router() {
+ var url = location.hash.slice(2) || 'presentation';
+ var contentElement = document.getElementById('content');
+ var htmlElement = document.querySelector('html');
+ addClass(htmlElement, 'waitCursor');
+ fetchFile('Pages/' + url + '.md', function(contentMd) {
+ removeClass(htmlElement, 'waitCursor');
+ contentElement.innerHTML = markdown.toHTML(contentMd);
+ }, function() {
+ var notFoundPage = '<h1>Page non trouvée</h1><a href="#">Retour à l\'accueil</a>';
+ contentElement.innerHTML = notFoundPage;
+ });
+ }
+
+ function addClass(element, myClass) {
+ element.className = element.className + ' waitCursor';
+ }
+
+ function removeClass(element, myClass) {
+ element.className = element.className.replace(new RegExp('(?:^|\\s)' + myClass + '(?!\\S)') , '');
+ }
+
function fetchFile(url, successHandler, errorHandler) {
var xhr = typeof XMLHttpRequest != 'undefined'
? new XMLHttpRequest()
@@ -26,21 +51,4 @@
}
};
- 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);
-
})();