hopglass/lib/infobox/main.js

44 lines
979 B
JavaScript
Raw Normal View History

2015-03-25 11:21:09 +01:00
define(["infobox/link", "infobox/node"], function (Link, Node) {
return function (config, sidebar, gotoAnything) {
var self = this
el = undefined
function destroy() {
if (el && el.parentNode) {
el.parentNode.removeChild(el)
el = undefined
}
}
function create() {
destroy()
el = document.createElement("div")
2015-03-25 15:33:36 +01:00
sidebar.container.insertBefore(el, sidebar.container.firstChild)
2015-03-25 11:21:09 +01:00
el.scrollIntoView(false)
el.classList.add("infobox")
el.destroy = destroy
var closeButton = document.createElement("button")
closeButton.classList.add("close")
closeButton.onclick = gotoAnything.reset
el.appendChild(closeButton)
}
self.resetView = destroy
self.gotoNode = function (d) {
create()
new Node(config, el, gotoAnything, d)
}
self.gotoLink = function (d) {
create()
new Link(config, el, gotoAnything, d)
}
return self
}
})