refactor router

This commit is contained in:
Nils Schneider 2015-03-25 20:55:49 +01:00
parent 26f6936d39
commit 1e6e868bfb
2 changed files with 27 additions and 25 deletions

View File

@ -10,7 +10,7 @@ define(function () {
m.setStyle(iconFunc(d))
}
m.on('click', router.node(d, false))
m.on('click', router.node(d))
m.bindLabel(d.nodeinfo.hostname)
dict[d.nodeinfo.node_id] = m
@ -38,7 +38,7 @@ define(function () {
}
line.bindLabel(d.source.node.nodeinfo.hostname + " " + d.target.node.nodeinfo.hostname + "<br><strong>" + showDistance(d) + " / " + showTq(d) + "</strong>")
line.on('click', router.link(d, false))
line.on('click', router.link(d))
dict[linkId(d)] = line

View File

@ -15,32 +15,16 @@ define(function () {
saveState()
}
function gotoNode(d, showMap, push) {
showMap = trueDefault(showMap)
push = trueDefault(push)
function gotoNode(d) {
targets.forEach( function (t) {
t.gotoNode(d)
})
if (push)
saveState( { node: d })
return false
}
function gotoLink(d, showMap, push) {
showMap = trueDefault(showMap)
push = trueDefault(push)
function gotoLink(d) {
targets.forEach( function (t) {
t.gotoLink(d)
})
if (push)
saveState( { link: d })
return false
}
function saveState(d) {
@ -73,20 +57,38 @@ define(function () {
var id = args[1]
if (id in objects.nodes)
gotoNode(objects.nodes[id], true, false)
gotoNode(objects.nodes[id])
}
if (args[0] === "l") {
var id = args[1]
if (id in objects.links)
gotoLink(objects.links[id], true, false)
gotoLink(objects.links[id])
}
}
self.node = function (d, m, p) { return function () { return gotoNode(d, m, p) }}
self.link = function (d, m, p) { return function () { return gotoLink(d, m, p) }}
self.reset = resetView
self.node = function (d) {
return function () {
gotoNode(d)
saveState({ node: d })
return false
}
}
self.link = function (d) {
return function () {
gotoLink(d)
saveState({ link: d })
return false
}
}
self.reset = function () {
resetView()
saveState()
}
self.addMarkers = function (d) {
markers = d
}