refactor Infobox (own module)
This commit is contained in:
parent
648a8336d7
commit
5fb3cf5d20
6 changed files with 312 additions and 313 deletions
43
lib/infobox/main.js
Normal file
43
lib/infobox/main.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
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")
|
||||
sidebar.insertBefore(el, sidebar.firstChild)
|
||||
|
||||
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
|
||||
}
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue