4
0

main.js 1023 B

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