meshviewer/lib/infobox/main.js

71 lines
1.5 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
2015-03-25 18:45:21 +00:00
return function (config, sidebar, router) {
var self = this;
var el;
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');
2017-04-14 12:43:46 +00:00
sidebar.container.children[1].append(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');
closeButton.onclick = router.reset;
el.appendChild(closeButton);
2015-03-25 10:21:09 +00:00
}
function clear() {
var closeButton = el.firstChild;
while (el.firstChild) {
el.removeChild(el.firstChild);
}
el.appendChild(closeButton);
}
self.resetView = destroy;
2015-03-25 10:21:09 +00:00
self.gotoNode = function gotoNode(d, update) {
if (update !== true) {
create();
} else {
clear();
}
node(config, el, router, d);
};
2015-03-25 10:21:09 +00:00
self.gotoLink = function gotoLink(d, update) {
if (update !== true) {
create();
} else {
clear();
}
link(config, el, router, d);
};
2015-03-25 10:21:09 +00:00
self.gotoLocation = function gotoLocation(d) {
create();
location(config, el, router, d);
};
return self;
};
});