aboutsummaryrefslogtreecommitdiff
path: root/router.js
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-02-15 17:51:17 +0100
committerJoris Guyonvarch2015-02-15 17:51:17 +0100
commit056f5c75f1abf4ef196418834145e5f140d32796 (patch)
treeee51463b5b76e9e427397b866aa04894090b92c5 /router.js
parent5473dc553ecf68af54de4282a81ed5b657df305e (diff)
downloadmakeup-056f5c75f1abf4ef196418834145e5f140d32796.tar.gz
makeup-056f5c75f1abf4ef196418834145e5f140d32796.tar.bz2
makeup-056f5c75f1abf4ef196418834145e5f140d32796.zip
Modifying javascript file name
Diffstat (limited to 'router.js')
-rw-r--r--router.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/router.js b/router.js
new file mode 100644
index 0000000..a14a308
--- /dev/null
+++ b/router.js
@@ -0,0 +1,39 @@
+(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);
+ }
+ }
+ };
+ xhr.send();
+ };
+
+ function router() {
+ var url = location.hash.slice(2) || 'presentation';
+ var contentElement = document.getElementById('content');
+ fetchFile('Pages/' + url + '.md', function(contentMd) {
+ fetchFile('Pages/contact.html', function(contactHtml) {
+ var contentHtml = markdown.toHTML(contentMd);
+ contentElement.innerHTML = contentHtml + contactHtml;
+ });
+ });
+ }
+
+ this.addEventListener('hashchange', router);
+ this.addEventListener('load', router);
+
+})();