2017-10-29 14:11:24 +00:00
|
|
|
define(['infobox/link', 'infobox/node', 'infobox/location'], function (Link, Node, location) {
|
2017-01-29 23:51:08 +00:00
|
|
|
'use strict';
|
2016-05-27 21:59:01 +00:00
|
|
|
|
2017-11-03 21:07:22 +00:00
|
|
|
return function (sidebar, linkScale) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var self = this;
|
|
|
|
var el;
|
2017-10-29 14:11:24 +00:00
|
|
|
var node;
|
|
|
|
var link;
|
2015-03-25 10:21:09 +00:00
|
|
|
|
|
|
|
function destroy() {
|
|
|
|
if (el && el.parentNode) {
|
2016-05-22 11:23:43 +00:00
|
|
|
el.parentNode.removeChild(el);
|
2018-10-27 13:08:40 +00:00
|
|
|
node = link = el = undefined;
|
2016-05-22 11:23:43 +00:00
|
|
|
sidebar.reveal();
|
2015-03-25 10:21:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function create() {
|
2016-05-22 11:23:43 +00:00
|
|
|
destroy();
|
|
|
|
sidebar.ensureVisible();
|
|
|
|
sidebar.hide();
|
2015-03-25 10:21:09 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
el = document.createElement('div');
|
2017-04-16 12:30:30 +00:00
|
|
|
sidebar.container.children[1].appendChild(el);
|
2015-03-25 10:21:09 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
el.scrollIntoView(false);
|
2017-01-29 23:51:08 +00:00
|
|
|
el.classList.add('infobox');
|
2016-05-22 11:23:43 +00:00
|
|
|
el.destroy = destroy;
|
2015-03-25 10:21:09 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var closeButton = document.createElement('button');
|
|
|
|
closeButton.classList.add('close');
|
2017-02-04 19:01:49 +00:00
|
|
|
closeButton.classList.add('ion-close');
|
2017-10-21 00:06:42 +00:00
|
|
|
closeButton.setAttribute('aria-label', _.t('close'));
|
2017-03-05 11:29:21 +00:00
|
|
|
closeButton.onclick = function () {
|
|
|
|
router.fullUrl();
|
|
|
|
};
|
2016-06-22 01:15:53 +00:00
|
|
|
el.appendChild(closeButton);
|
|
|
|
}
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
self.resetView = destroy;
|
2015-03-25 10:21:09 +00:00
|
|
|
|
2017-10-29 15:10:25 +00:00
|
|
|
self.gotoNode = function gotoNode(d, nodeDict) {
|
2017-03-05 11:29:21 +00:00
|
|
|
create();
|
2017-11-03 21:07:22 +00:00
|
|
|
node = new Node(el, d, linkScale, nodeDict);
|
2017-10-29 14:11:24 +00:00
|
|
|
node.render();
|
2016-05-22 11:23:43 +00:00
|
|
|
};
|
2015-03-25 10:21:09 +00:00
|
|
|
|
2017-03-05 11:29:21 +00:00
|
|
|
self.gotoLink = function gotoLink(d) {
|
|
|
|
create();
|
2017-11-03 21:07:22 +00:00
|
|
|
link = new Link(el, d, linkScale);
|
2017-10-29 14:11:24 +00:00
|
|
|
link.render();
|
2016-05-22 11:23:43 +00:00
|
|
|
};
|
2015-03-25 10:21:09 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
self.gotoLocation = function gotoLocation(d) {
|
2016-05-22 11:23:43 +00:00
|
|
|
create();
|
2017-11-03 21:07:22 +00:00
|
|
|
location(el, d);
|
2016-05-22 11:23:43 +00:00
|
|
|
};
|
2016-02-25 14:47:07 +00:00
|
|
|
|
2017-10-15 19:59:31 +00:00
|
|
|
self.setData = function setData(d) {
|
2017-10-29 14:11:24 +00:00
|
|
|
if (typeof node === 'object') {
|
|
|
|
node.setData(d);
|
|
|
|
}
|
|
|
|
if (typeof link === 'object') {
|
|
|
|
link.setData(d);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
return self;
|
|
|
|
};
|
|
|
|
});
|