aboutsummaryrefslogtreecommitdiff
path: root/script.js
blob: e662ebba5516033ea56ff6dc7dc7436972554d66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
(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(1) || 'presentation';
    var contentElement = document.getElementById('content');
    fetchFile('Pages' + url + '.html', function(contentData) {
      fetchFile('Pages/contact.html', function(contactData) {
        contentElement.innerHTML = contentData + contactData;
      });
    });
  }

  this.addEventListener('hashchange', router);
  this.addEventListener('load', router);

})();