meshviewer/lib/infobox/main.js

71 lines
1.6 KiB
JavaScript
Raw Normal View History

define(['infobox/link', 'infobox/node', 'infobox/location'], function (Link, Node, location) {
'use strict';
2016-05-27 21:59:01 +00:00
return function (config, sidebar, router, linkScale) {
var self = this;
var el;
var node;
var link;
2015-03-25 10:21:09 +00:00
function destroy() {
if (el && el.parentNode) {
el.parentNode.removeChild(el);
el = undefined;
sidebar.reveal();
2015-03-25 10:21:09 +00:00
}
}
function create() {
destroy();
sidebar.ensureVisible();
sidebar.hide();
2015-03-25 10:21:09 +00:00
el = document.createElement('div');
sidebar.container.children[1].appendChild(el);
2015-03-25 10:21:09 +00:00
el.scrollIntoView(false);
el.classList.add('infobox');
el.destroy = destroy;
2015-03-25 10:21:09 +00:00
var closeButton = document.createElement('button');
closeButton.classList.add('close');
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();
};
el.appendChild(closeButton);
}
self.resetView = destroy;
2015-03-25 10:21:09 +00:00
self.gotoNode = function gotoNode(d, nodeDict) {
2017-03-05 11:29:21 +00:00
create();
node = new Node(config, el, router, d, linkScale, nodeDict);
node.render();
};
2015-03-25 10:21:09 +00:00
2017-03-05 11:29:21 +00:00
self.gotoLink = function gotoLink(d) {
create();
link = new Link(config, el, router, d, linkScale);
link.render();
};
2015-03-25 10:21:09 +00:00
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;
};
});