diff options
| author | Joris Guyonvarch | 2015-02-15 12:44:05 +0100 | 
|---|---|---|
| committer | Joris Guyonvarch | 2015-02-15 12:44:05 +0100 | 
| commit | 65bc73c3ad675dec2f4c630532fe94f7f7a70ac4 (patch) | |
| tree | f48dbf2d6a24ecd2d762d2ef04f921fe3ea6aaf3 /script.js | |
Bootstrap architecture
Diffstat (limited to 'script.js')
| -rw-r--r-- | script.js | 36 | 
1 files changed, 36 insertions, 0 deletions
| diff --git a/script.js b/script.js new file mode 100644 index 0000000..07feacd --- /dev/null +++ b/script.js @@ -0,0 +1,36 @@ +(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'; +    fetchFile('Pages/' + url + '.html', function(htmlData) { +      var viewElement = document.getElementById('content'); +      viewElement.innerHTML = htmlData; +    }); +  } + +  this.addEventListener('hashchange', router); +  this.addEventListener('load', router); + +})(); | 
