diff options
author | Noah Loomans <noahloomans@gmail.com> | 2016-12-09 15:14:15 +0100 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2016-12-09 15:14:15 +0100 |
commit | 998744084264dcf4fbbd2c52ab76cf392803fb05 (patch) | |
tree | 157d9d6f6e4fedef5c5e3baae1998d3a89fc985a /public/javascripts/schedule.js | |
parent | c1a50798fbf547acd8466d02ce97811106cc622a (diff) |
switched to non-iframe schedule viewer
Diffstat (limited to 'public/javascripts/schedule.js')
-rw-r--r-- | public/javascripts/schedule.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/public/javascripts/schedule.js b/public/javascripts/schedule.js new file mode 100644 index 0000000..4e5cbf4 --- /dev/null +++ b/public/javascripts/schedule.js @@ -0,0 +1,45 @@ +const getURLOfUser = require('./getURLOfUser') + +const self = {} + +self._nodes = { + schedule: document.querySelector('#schedule') +} + +self._parseMeetingpointHTML = function (htmlStr) { + const html = document.createElement('html') + html.innerHTML = htmlStr + const centerNode = html.querySelector('center') + return centerNode +} + +self._handleLoad = function (event) { + const request = event.target + if (request.status < 200 || request.status >= 400) { + self._handleError(event) + return + } + const document = self._parseMeetingpointHTML(request.response) + self._nodes.schedule.appendChild(document) +} + +self._handleError = function (event) { + const request = event.target + console.error(request) +} + +self.viewItem = function (offset, selectedUser) { + const url = getURLOfUser(offset, selectedUser.type, selectedUser.index + 1) + + while (self._nodes.schedule.firstChild) { + self._nodes.schedule.removeChild(self._nodes.schedule.firstChild) + } + + const request = new window.XMLHttpRequest() + request.addEventListener('load', self._handleLoad) + request.addEventListener('error', self._handleError) + request.open('GET', url, true) + request.send() +} + +module.exports = self |