summaryrefslogtreecommitdiff
path: root/WebInterface/NodeJSServer/src/js/modules/ui/components/router.js
diff options
context:
space:
mode:
authorTrueKuehli <rctcoaster2000@hotmail.de>2018-11-27 12:16:33 +0100
committerTrueKuehli <rctcoaster2000@hotmail.de>2018-11-27 12:16:33 +0100
commit9f0b255f32dfa81bffe75f89335a78a659b4ce6a (patch)
treec4345ef6f98fee35f326bc06c29cada542a78e43 /WebInterface/NodeJSServer/src/js/modules/ui/components/router.js
parenta653a4efc60ef0bbc18e65cb11a4bd8c06c7ad5c (diff)
Reworked the code, but currently unable to test, so bugs are bound to be in there
Will test it sometime later. There also might still be stuff, that has yet to be reworked.
Diffstat (limited to 'WebInterface/NodeJSServer/src/js/modules/ui/components/router.js')
-rw-r--r--WebInterface/NodeJSServer/src/js/modules/ui/components/router.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/WebInterface/NodeJSServer/src/js/modules/ui/components/router.js b/WebInterface/NodeJSServer/src/js/modules/ui/components/router.js
new file mode 100644
index 0000000..c01c21b
--- /dev/null
+++ b/WebInterface/NodeJSServer/src/js/modules/ui/components/router.js
@@ -0,0 +1,44 @@
+/**
+ * Class for routing between pages
+ */
+export default class Router {
+ /**
+ * @param {Interface} iface Interface for comm. with other objects
+ */
+ constructor(iface) {
+ iface.addObject(this, 'serverListing', ['routePlay']);
+ this.iface = iface;
+ }
+
+ /**
+ * Routes to the play page
+ * @param {HubConnection} connection Connection to the server
+ */
+ routePlay(connection) {
+ window.history.pushState('object or string', 'Game Page',
+ 'play#game=' + this.serverName);
+ fetch('play').then((response) => {
+ response.text().then((htmlString) => {
+ // Replace all references, since we're starting one level farther up
+ htmlString = htmlString.replace(/\.\.\//g, './');
+ htmlString = /<body>((.)|(\n))*<\/body>/g.exec(htmlString)[0];
+ htmlString = htmlString.replace(/<script src=".*"><\/script>/, '');
+ htmlString = htmlString.replace(
+ /<remove_if_redirected>((.)|\n)*?<\/remove_if_redirected>/g, '');
+ document.body.innerHTML = htmlString;
+
+ let stylesheet = document.createElement('link');
+ stylesheet.rel = 'stylesheet';
+ stylesheet.type = 'text/css';
+ stylesheet.href = './style/play.css';
+ document.head.appendChild(stylesheet);
+
+
+ this.iface.callMethod('uiMananger', 'initPlay');
+ for (let ui of this.pageUI) {
+ ui.refresh();
+ }
+ });
+ });
+ }
+}