61 lines
1.3 KiB
JavaScript
61 lines
1.3 KiB
JavaScript
define(["infobox/link", "infobox/node", "infobox/location"], function (Link, Node, Location) {
|
|
return function (config, sidebar, router) {
|
|
var self = this
|
|
var el
|
|
var nodeDict
|
|
|
|
function destroy() {
|
|
if (el && el.parentNode) {
|
|
el.parentNode.removeChild(el)
|
|
el = undefined
|
|
sidebar.reveal()
|
|
}
|
|
}
|
|
|
|
function create() {
|
|
destroy()
|
|
sidebar.ensureVisible()
|
|
sidebar.hide()
|
|
|
|
el = document.createElement("div")
|
|
sidebar.container.insertBefore(el, sidebar.container.firstChild)
|
|
|
|
el.scrollIntoView(false)
|
|
el.classList.add("infobox")
|
|
el.destroy = destroy
|
|
|
|
var closeButton = document.createElement("button")
|
|
closeButton.classList.add("close")
|
|
closeButton.onclick = router.reset
|
|
el.appendChild(closeButton)
|
|
}
|
|
|
|
self.resetView = destroy
|
|
|
|
self.gotoNode = function (d) {
|
|
create()
|
|
new Node(config, el, router, d, nodeDict)
|
|
}
|
|
|
|
self.gotoLink = function (d) {
|
|
create()
|
|
new Link(config, el, router, d)
|
|
}
|
|
|
|
self.gotoLocation = function (d) {
|
|
create()
|
|
new Location(config, el, router, d)
|
|
}
|
|
|
|
self.setData = function (d) {
|
|
nodeDict = {}
|
|
d.graph.nodes.forEach(function (d) {
|
|
nodeDict[d.id.substr(0, 8)] = d
|
|
})
|
|
|
|
}
|
|
|
|
return self
|
|
}
|
|
})
|