rename gotoAnything to router
This commit is contained in:
parent
a2669373a0
commit
265cb2e5eb
|
@ -1,15 +1,15 @@
|
|||
define(function () {
|
||||
return function (config, el, gotoAnything, d) {
|
||||
return function (config, el, router, d) {
|
||||
var h2 = document.createElement("h2")
|
||||
a1 = document.createElement("a")
|
||||
a1.href = "#"
|
||||
a1.onclick = gotoAnything.node(d.source.node)
|
||||
a1.onclick = router.node(d.source.node)
|
||||
a1.textContent = d.source.node.nodeinfo.hostname
|
||||
h2.appendChild(a1)
|
||||
h2.appendChild(document.createTextNode(" – "))
|
||||
a2 = document.createElement("a")
|
||||
a2.href = "#"
|
||||
a2.onclick = gotoAnything.node(d.target.node)
|
||||
a2.onclick = router.node(d.target.node)
|
||||
a2.textContent = d.target.node.nodeinfo.hostname
|
||||
h2.appendChild(a2)
|
||||
el.appendChild(h2)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
define(["infobox/link", "infobox/node"], function (Link, Node) {
|
||||
return function (config, sidebar, gotoAnything) {
|
||||
return function (config, sidebar, router) {
|
||||
var self = this
|
||||
el = undefined
|
||||
|
||||
|
@ -22,7 +22,7 @@ define(["infobox/link", "infobox/node"], function (Link, Node) {
|
|||
|
||||
var closeButton = document.createElement("button")
|
||||
closeButton.classList.add("close")
|
||||
closeButton.onclick = gotoAnything.reset
|
||||
closeButton.onclick = router.reset
|
||||
el.appendChild(closeButton)
|
||||
}
|
||||
|
||||
|
@ -30,12 +30,12 @@ define(["infobox/link", "infobox/node"], function (Link, Node) {
|
|||
|
||||
self.gotoNode = function (d) {
|
||||
create()
|
||||
new Node(config, el, gotoAnything, d)
|
||||
new Node(config, el, router, d)
|
||||
}
|
||||
|
||||
self.gotoLink = function (d) {
|
||||
create()
|
||||
new Link(config, el, gotoAnything, d)
|
||||
new Link(config, el, router, d)
|
||||
}
|
||||
|
||||
return self
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
define(function () {
|
||||
return function(config, el, gotoAnything, d) {
|
||||
return function(config, el, router, d) {
|
||||
var h2 = document.createElement("h2")
|
||||
h2.textContent = d.nodeinfo.hostname
|
||||
var span = document.createElement("span")
|
||||
|
@ -62,7 +62,7 @@ define(function () {
|
|||
a1.classList.add("hostname")
|
||||
a1.textContent = d.node.nodeinfo.hostname
|
||||
a1.href = "#"
|
||||
a1.onclick = gotoAnything.node(d.node)
|
||||
a1.onclick = router.node(d.node)
|
||||
td1.appendChild(a1)
|
||||
|
||||
if (d.link.vpn)
|
||||
|
@ -81,7 +81,7 @@ define(function () {
|
|||
var a2 = document.createElement("a")
|
||||
a2.href = "#"
|
||||
a2.textContent = showTq(d.link)
|
||||
a2.onclick = gotoAnything.link(d.link)
|
||||
a2.onclick = router.link(d.link)
|
||||
td2.appendChild(a2)
|
||||
tr.appendChild(td2)
|
||||
|
||||
|
@ -89,7 +89,7 @@ define(function () {
|
|||
var a3 = document.createElement("a")
|
||||
a3.href = "#"
|
||||
a3.textContent = showDistance(d.link)
|
||||
a3.onclick = gotoAnything.link(d.link)
|
||||
a3.onclick = router.link(d.link)
|
||||
td3.appendChild(a3)
|
||||
td3.setAttribute("data-sort", d.link.distance !== undefined ? -d.link.distance : 1)
|
||||
tr.appendChild(td3)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
define(function () {
|
||||
return function(linkScale, gotoAnything) {
|
||||
return function(linkScale, router) {
|
||||
var self = this
|
||||
var el
|
||||
|
||||
|
@ -45,7 +45,7 @@ define(function () {
|
|||
var a = document.createElement("a")
|
||||
a.textContent = d.source.node.nodeinfo.hostname + " – " + d.target.node.nodeinfo.hostname
|
||||
a.href = "#"
|
||||
a.onclick = gotoAnything.link(d)
|
||||
a.onclick = router.link(d)
|
||||
td1.appendChild(a)
|
||||
row.appendChild(td1)
|
||||
|
||||
|
|
32
lib/main.js
32
lib/main.js
|
@ -10,25 +10,25 @@ function (Map, Sidebar, Meshstats, Linklist, SimpleNodelist, Infobox) {
|
|||
|
||||
var sidebar = new Sidebar(document.body)
|
||||
|
||||
var gotoAnything = new Router(config)
|
||||
var router = new Router(config)
|
||||
|
||||
var infobox = new Infobox(config, sidebar, gotoAnything)
|
||||
gotoAnything.addTarget(infobox)
|
||||
var infobox = new Infobox(config, sidebar, router)
|
||||
router.addTarget(infobox)
|
||||
|
||||
var map = new Map(linkScale, sidebar, gotoAnything)
|
||||
var map = new Map(linkScale, sidebar, router)
|
||||
document.body.insertBefore(map.div, document.body.firstChild)
|
||||
gotoAnything.addTarget(map)
|
||||
router.addTarget(map)
|
||||
|
||||
var meshstats = new Meshstats()
|
||||
sidebar.add(meshstats)
|
||||
|
||||
var newnodeslist = new SimpleNodelist(config, "firstseen", gotoAnything, "Neue Knoten")
|
||||
var newnodeslist = new SimpleNodelist(config, "firstseen", router, "Neue Knoten")
|
||||
sidebar.add(newnodeslist)
|
||||
|
||||
var lostnodeslist = new SimpleNodelist(config, "lastseen", gotoAnything, "Verschwundene Knoten")
|
||||
var lostnodeslist = new SimpleNodelist(config, "lastseen", router, "Verschwundene Knoten")
|
||||
sidebar.add(lostnodeslist)
|
||||
|
||||
var linklist = new Linklist(linkScale, gotoAnything)
|
||||
var linklist = new Linklist(linkScale, router)
|
||||
sidebar.add(linklist)
|
||||
|
||||
var urls = [ config.dataPath + 'nodes.json',
|
||||
|
@ -36,11 +36,11 @@ function (Map, Sidebar, Meshstats, Linklist, SimpleNodelist, Infobox) {
|
|||
]
|
||||
|
||||
var p = Promise.all(urls.map(getJSON))
|
||||
p.then(handle_data(sidebar, meshstats, linklist, newnodeslist, lostnodeslist, infobox, map, gotoAnything))
|
||||
p.then(handle_data(sidebar, meshstats, linklist, newnodeslist, lostnodeslist, infobox, map, router))
|
||||
})
|
||||
}
|
||||
|
||||
function handle_data(sidebar, meshstats, linklist, newnodeslist, lostnodeslist, infobox, map, gotoAnything) {
|
||||
function handle_data(sidebar, meshstats, linklist, newnodeslist, lostnodeslist, infobox, map, router) {
|
||||
return function (data) {
|
||||
var nodedict = data[0]
|
||||
var nodes = Object.keys(nodedict.nodes).map(function (key) { return nodedict.nodes[key] })
|
||||
|
@ -122,12 +122,12 @@ function (Map, Sidebar, Meshstats, Linklist, SimpleNodelist, Infobox) {
|
|||
historyDict.links[linkId(d)] = d
|
||||
})
|
||||
|
||||
gotoAnything.reset(false)
|
||||
router.reset(false)
|
||||
|
||||
gotoHistory(gotoAnything, historyDict, window.location.hash)
|
||||
gotoHistory(router, historyDict, window.location.hash)
|
||||
|
||||
window.onpopstate = function (d) {
|
||||
gotoHistory(gotoAnything, historyDict, d.state)
|
||||
gotoHistory(router, historyDict, d.state)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ function (Map, Sidebar, Meshstats, Linklist, SimpleNodelist, Infobox) {
|
|||
window.history.pushState(s, undefined, s)
|
||||
}
|
||||
|
||||
function gotoHistory(gotoAnything, dict, s) {
|
||||
function gotoHistory(router, dict, s) {
|
||||
if (!s.startsWith("#!"))
|
||||
return
|
||||
|
||||
|
@ -158,14 +158,14 @@ function (Map, Sidebar, Meshstats, Linklist, SimpleNodelist, Infobox) {
|
|||
var id = args[1]
|
||||
|
||||
if (id in dict.nodes)
|
||||
gotoAnything.node(dict.nodes[id], true, false)()
|
||||
router.node(dict.nodes[id], true, false)()
|
||||
}
|
||||
|
||||
if (args[0] === "l") {
|
||||
var id = args[1]
|
||||
|
||||
if (id in dict.links)
|
||||
gotoAnything.link(dict.links[id], true, false)()
|
||||
router.link(dict.links[id], true, false)()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
16
lib/map.js
16
lib/map.js
|
@ -2,7 +2,7 @@ define(function () {
|
|||
var options = { worldCopyJump: true,
|
||||
zoomControl: false
|
||||
}
|
||||
function mkMarker(dict, iconFunc, gotoAnything) {
|
||||
function mkMarker(dict, iconFunc, router) {
|
||||
return function (d) {
|
||||
var m = L.circleMarker([d.nodeinfo.location.latitude, d.nodeinfo.location.longitude], iconFunc(d))
|
||||
|
||||
|
@ -10,7 +10,7 @@ define(function () {
|
|||
m.setStyle(iconFunc(d))
|
||||
}
|
||||
|
||||
m.on('click', gotoAnything.node(d, false))
|
||||
m.on('click', router.node(d, false))
|
||||
m.bindLabel(d.nodeinfo.hostname)
|
||||
|
||||
dict[d.nodeinfo.node_id] = m
|
||||
|
@ -19,7 +19,7 @@ define(function () {
|
|||
}
|
||||
}
|
||||
|
||||
function addLinksToMap(dict, linkScale, graph, gotoAnything) {
|
||||
function addLinksToMap(dict, linkScale, graph, router) {
|
||||
graph = graph.filter( function (d) {
|
||||
return "distance" in d
|
||||
})
|
||||
|
@ -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', gotoAnything.link(d, false))
|
||||
line.on('click', router.link(d, false))
|
||||
|
||||
dict[linkId(d)] = line
|
||||
|
||||
|
@ -55,7 +55,7 @@ define(function () {
|
|||
|
||||
var groupOnline, group
|
||||
|
||||
return function (linkScale, sidebar, gotoAnything) {
|
||||
return function (linkScale, sidebar, router) {
|
||||
var self = this
|
||||
|
||||
var el = document.createElement("div")
|
||||
|
@ -80,7 +80,7 @@ define(function () {
|
|||
nodeDict = {}
|
||||
linkDict = {}
|
||||
|
||||
var lines = addLinksToMap(linkDict, linkScale, links, gotoAnything)
|
||||
var lines = addLinksToMap(linkDict, linkScale, links, router)
|
||||
|
||||
var nodes = newnodes.concat(lostnodes).filter(has_location)
|
||||
|
||||
|
@ -92,10 +92,10 @@ define(function () {
|
|||
return iconAlert
|
||||
|
||||
return iconOffline
|
||||
}, gotoAnything))
|
||||
}, router))
|
||||
|
||||
var onlinemarkers = subtract(onlinenodes.filter(has_location), newnodes)
|
||||
.map(mkMarker(nodeDict, function (d) { return iconOnline }, gotoAnything))
|
||||
.map(mkMarker(nodeDict, function (d) { return iconOnline }, router))
|
||||
|
||||
var groupLines = L.featureGroup(lines).addTo(map)
|
||||
groupOnline = L.featureGroup(onlinemarkers).addTo(map)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
define(function () {
|
||||
return function(config, field, gotoAnything, title) {
|
||||
return function(config, field, router, title) {
|
||||
var self = this
|
||||
var el
|
||||
|
||||
|
@ -30,7 +30,7 @@ define(function () {
|
|||
a.classList.add(d.flags.online ? "online" : "offline")
|
||||
a.textContent = d.nodeinfo.hostname
|
||||
a.href = "#"
|
||||
a.onclick = gotoAnything.node(d)
|
||||
a.onclick = router.node(d)
|
||||
td1.appendChild(a)
|
||||
|
||||
if (has_location(d)) {
|
||||
|
|
Loading…
Reference in a new issue