diff --git a/lib/main.js b/lib/main.js index 2a58676..fdd2ebf 100644 --- a/lib/main.js +++ b/lib/main.js @@ -45,7 +45,7 @@ function (Router, Map, Sidebar, Tabs, Container, Meshstats, Linklist, Nodelist, Promise.all(urls.map(getJSON)) .then(function (d) { createGUI(); return d }) .then(handle_data) - .then(function () { router.loadState(window.location.hash) }) + .then(function () { router.start() }) function handle_data(data) { var nodedict = data[0] diff --git a/lib/map.js b/lib/map.js index 38ebbd3..2a3577d 100644 --- a/lib/map.js +++ b/lib/map.js @@ -108,8 +108,6 @@ define(function () { groupOnline = L.featureGroup(markersOnline).addTo(map) groupNew = L.featureGroup(markersNew).addTo(map) groupLost = L.featureGroup(markersLost).addTo(map) - - resetView() } function resetView() { diff --git a/lib/router.js b/lib/router.js index 0064680..25be296 100644 --- a/lib/router.js +++ b/lib/router.js @@ -43,28 +43,41 @@ define(function () { function loadState(s) { if (!s) - return + return false if (!s.startsWith("#!")) - return + return false var args = s.slice(2).split(":") - if (args.length == 1 && args[0] == "") - resetView(false) - if (args[0] === "n") { var id = args[1] - if (id in objects.nodes) + if (id in objects.nodes) { gotoNode(objects.nodes[id]) + return true + } } if (args[0] === "l") { var id = args[1] - if (id in objects.links) + if (id in objects.links) { gotoLink(objects.links[id]) + return true + } + } + + return false + } + + self.start = function () { + if (!loadState(window.location.hash)) + resetView(false) + + window.onpopstate = function (d) { + if (!loadState(d.state)) + resetView(false) } } @@ -94,8 +107,6 @@ define(function () { } self.addTarget = function (d) { targets.push(d) } - self.loadState = loadState - self.setData = function (nodes, links) { objects.nodes = {} objects.links = {} @@ -109,8 +120,6 @@ define(function () { }) } - window.onpopstate = function (d) { loadState(d.state) } - return self } })