main.js 955 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. define(["infobox/link", "infobox/node"], function (Link, Node) {
  2. return function (config, sidebar, router) {
  3. var self = this
  4. el = undefined
  5. function destroy() {
  6. if (el && el.parentNode) {
  7. el.parentNode.removeChild(el)
  8. el = undefined
  9. }
  10. }
  11. function create() {
  12. destroy()
  13. el = document.createElement("div")
  14. sidebar.container.insertBefore(el, sidebar.container.firstChild)
  15. el.scrollIntoView(false)
  16. el.classList.add("infobox")
  17. el.destroy = destroy
  18. var closeButton = document.createElement("button")
  19. closeButton.classList.add("close")
  20. closeButton.onclick = router.reset
  21. el.appendChild(closeButton)
  22. }
  23. self.resetView = destroy
  24. self.gotoNode = function (d) {
  25. create()
  26. new Node(config, el, router, d)
  27. }
  28. self.gotoLink = function (d) {
  29. create()
  30. new Link(config, el, router, d)
  31. }
  32. return self
  33. }
  34. })