meshviewer/lib/infobox/main.js

54 lines
1.2 KiB
JavaScript
Raw Normal View History

define(["infobox/link", "infobox/node", "infobox/location"], function (Link, Node, Location) {
2016-05-27 21:59:01 +00:00
"use strict";
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");
sidebar.container.insertBefore(el, sidebar.container.firstChild);
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.onclick = router.reset;
el.appendChild(closeButton);
2015-03-25 10:21:09 +00:00
}
self.resetView = destroy;
2015-03-25 10:21:09 +00:00
self.gotoNode = function (d) {
create();
2016-05-26 16:37:24 +00:00
Node(config, el, router, d);
};
2015-03-25 10:21:09 +00:00
self.gotoLink = function (d) {
create();
2016-05-26 16:37:24 +00:00
Link(config, el, router, d);
};
2015-03-25 10:21:09 +00:00
self.gotoLocation = function (d) {
create();
2016-05-26 16:37:24 +00:00
Location(config, el, router, d);
};
return self;
};
});