From e1d546a9f8b386248270dba6faca2f31e6497413 Mon Sep 17 00:00:00 2001 From: Adrien Vannson Date: Sat, 16 Oct 2021 13:49:33 +0200 Subject: [PATCH] Add links to search results --- index.html | 2 +- resources/script.js | 68 ++++++++++++++++++++++++++++++++------------- 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/index.html b/index.html index cb5641d..33e9100 100644 --- a/index.html +++ b/index.html @@ -156,7 +156,7 @@ - + diff --git a/resources/script.js b/resources/script.js index 9967323..f463247 100644 --- a/resources/script.js +++ b/resources/script.js @@ -1,15 +1,3 @@ -function httpGetAsync(theUrl, callback) -{ - var xmlHttp = new XMLHttpRequest(); - xmlHttp.onreadystatechange = function() { - if (xmlHttp.readyState == 4) { - callback(xmlHttp.responseText, xmlHttp.status); - } - } - xmlHttp.open("GET", theUrl, true); - xmlHttp.send(null); -} - function researchRoom() { var research = document.getElementById('research').value; @@ -26,13 +14,31 @@ function researchRoom() res = JSON.parse(xhr.responseText); for (var i=0; i' + res[i].name + ''; + table.innerHTML += '\ + \ + ' + res[i].name + '\ + \ + ' + '??' + '\ + '; } }; xhr.send(null); } +// Update the current room based on the current anchor +function updateCurrentRoom() +{ + // Hide room research modal + var modal = bootstrap.Modal.getInstance(document.getElementById('room-research-modal')); + if (modal != null) { + modal.hide(); + } + + var id = window.location.hash; + console.log(id); +} + function putWaitNetworkScreen() { outputDiv.innerHTML = "Récupération des informations auprès du serveur..."; @@ -45,6 +51,18 @@ function salleInfosToHtml(salle) return titres + ((salle.description!=null)?("\n
\n" + salle.description):"") + ((salle.locataires.length!=0)?("\n
\nLocataires: " + locataires):""); } +function httpGetAsync(theUrl, callback) +{ + var xmlHttp = new XMLHttpRequest(); + xmlHttp.onreadystatechange = function() { + if (xmlHttp.readyState == 4) { + callback(xmlHttp.responseText, xmlHttp.status); + } + } + xmlHttp.open("GET", theUrl, true); + xmlHttp.send(null); +} + function initSvgSupport() { var plan = document.getElementById('plan'); @@ -93,9 +111,21 @@ function initSvgSupport() } -// Initialisation du svg. -var plan = document.getElementById('plan'); -if(plan.contentDocument==null) - plan.addEventListener('load', initSvgSupport); -else - initSvgSupport(); +window.addEventListener("DOMContentLoaded", (event) => { + // Init SVG + var plan = document.getElementById('plan'); + if (plan.contentDocument == null) { + plan.addEventListener('load', initSvgSupport); + } else { + initSvgSupport(); + } + + // Update the current room + if (window.location.hash != "") { + updateCurrentRoom(); + } + + window.onhashchange = function() { + updateCurrentRoom(); + } +});