refactor router
This commit is contained in:
parent
40ecf2641e
commit
f5dbd56a70
|
@ -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]
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue