1
|
|
|
define(['infobox/link', 'infobox/node', 'infobox/location'], function (Link, Node, location) { |
2
|
|
|
'use strict'; |
3
|
|
|
|
4
|
|
|
return function (config, sidebar, router, linkScale) { |
5
|
|
|
var self = this; |
6
|
|
|
var el; |
7
|
|
|
var node; |
8
|
|
|
var link; |
9
|
|
|
|
10
|
|
|
function destroy() { |
11
|
|
|
if (el && el.parentNode) { |
12
|
|
|
el.parentNode.removeChild(el); |
13
|
|
|
el = undefined; |
14
|
|
|
sidebar.reveal(); |
15
|
|
|
} |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
function create() { |
19
|
|
|
destroy(); |
20
|
|
|
sidebar.ensureVisible(); |
21
|
|
|
sidebar.hide(); |
22
|
|
|
|
23
|
|
|
el = document.createElement('div'); |
24
|
|
|
sidebar.container.children[1].appendChild(el); |
25
|
|
|
|
26
|
|
|
el.scrollIntoView(false); |
27
|
|
|
el.classList.add('infobox'); |
28
|
|
|
el.destroy = destroy; |
29
|
|
|
|
30
|
|
|
var closeButton = document.createElement('button'); |
31
|
|
|
closeButton.classList.add('close'); |
32
|
|
|
closeButton.classList.add('ion-close'); |
33
|
|
|
closeButton.setAttribute('aria-label', _.t('close')); |
34
|
|
|
closeButton.onclick = function () { |
35
|
|
|
router.fullUrl(); |
36
|
|
|
}; |
37
|
|
|
el.appendChild(closeButton); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
self.resetView = destroy; |
41
|
|
|
|
42
|
|
|
self.gotoNode = function gotoNode(d, nodeDict) { |
43
|
|
|
create(); |
44
|
|
|
node = new Node(config, el, router, d, linkScale, nodeDict); |
45
|
|
|
node.render(); |
46
|
|
|
}; |
47
|
|
|
|
48
|
|
|
self.gotoLink = function gotoLink(d) { |
49
|
|
|
create(); |
50
|
|
|
link = new Link(config, el, router, d, linkScale); |
51
|
|
|
link.render(); |
52
|
|
|
}; |
53
|
|
|
|
54
|
|
|
self.gotoLocation = function gotoLocation(d) { |
55
|
|
|
create(); |
56
|
|
|
location(config, el, router, d); |
57
|
|
|
}; |
58
|
|
|
|
59
|
|
|
self.setData = function setData(d) { |
60
|
|
|
if (typeof node === 'object') { |
61
|
|
|
node.setData(d); |
62
|
|
|
} |
63
|
|
|
if (typeof link === 'object') { |
64
|
|
|
link.setData(d); |
65
|
|
|
} |
66
|
|
|
}; |
67
|
|
|
|
68
|
|
|
return self; |
69
|
|
|
}; |
70
|
|
|
}); |
71
|
|
|
|