70 lines
1.6 KiB
JavaScript
70 lines
1.6 KiB
JavaScript
define(['infobox/link', 'infobox/node', 'infobox/location'], function (Link, Node, location) {
|
|
'use strict';
|
|
|
|
return function (config, sidebar, router, linkScale) {
|
|
var self = this;
|
|
var el;
|
|
var node;
|
|
var link;
|
|
|
|
function destroy() {
|
|
if (el && el.parentNode) {
|
|
el.parentNode.removeChild(el);
|
|
el = undefined;
|
|
sidebar.reveal();
|
|
}
|
|
}
|
|
|
|
function create() {
|
|
destroy();
|
|
sidebar.ensureVisible();
|
|
sidebar.hide();
|
|
|
|
el = document.createElement('div');
|
|
sidebar.container.children[1].appendChild(el);
|
|
|
|
el.scrollIntoView(false);
|
|
el.classList.add('infobox');
|
|
el.destroy = destroy;
|
|
|
|
var closeButton = document.createElement('button');
|
|
closeButton.classList.add('close');
|
|
closeButton.classList.add('ion-close');
|
|
closeButton.onclick = function () {
|
|
router.fullUrl();
|
|
};
|
|
el.appendChild(closeButton);
|
|
}
|
|
|
|
self.resetView = destroy;
|
|
|
|
self.gotoNode = function gotoNode(d, gateways) {
|
|
create();
|
|
node = new Node(config, el, router, d, linkScale, gateways);
|
|
node.render();
|
|
};
|
|
|
|
self.gotoLink = function gotoLink(d) {
|
|
create();
|
|
link = new Link(config, el, router, d, linkScale);
|
|
link.render();
|
|
};
|
|
|
|
self.gotoLocation = function gotoLocation(d) {
|
|
create();
|
|
location(config, el, router, d);
|
|
};
|
|
|
|
self.setData = function setData(d) {
|
|
if (typeof node === 'object') {
|
|
node.setData(d);
|
|
}
|
|
if (typeof link === 'object') {
|
|
link.setData(d);
|
|
}
|
|
};
|
|
|
|
return self;
|
|
};
|
|
});
|