hopglass/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 23:59:01 +02:00
"use strict";
2015-03-25 19:45:21 +01:00
return function (config, sidebar, router) {
var self = this;
var el;
2015-03-25 11:21:09 +01:00
function destroy() {
if (el && el.parentNode) {
el.parentNode.removeChild(el);
el = undefined;
sidebar.reveal();
2015-03-25 11:21:09 +01:00
}
}
function create() {
destroy();
sidebar.ensureVisible();
sidebar.hide();
2015-03-25 11:21:09 +01:00
el = document.createElement("div");
sidebar.container.insertBefore(el, sidebar.container.firstChild);
2015-03-25 11:21:09 +01:00
el.scrollIntoView(false);
el.classList.add("infobox");
el.destroy = destroy;
2015-03-25 11:21:09 +01:00
var closeButton = document.createElement("button");
closeButton.classList.add("close");
closeButton.onclick = router.reset;
el.appendChild(closeButton);
2015-03-25 11:21:09 +01:00
}
self.resetView = destroy;
2015-03-25 11:21:09 +01:00
self.gotoNode = function (d) {
create();
2017-03-18 15:33:49 +01:00
Node(config, el, router, d);
};
2015-03-25 11:21:09 +01:00
self.gotoLink = function (d) {
create();
2017-03-18 15:33:49 +01:00
Link(config, el, router, d);
};
2015-03-25 11:21:09 +01:00
self.gotoLocation = function (d) {
create();
2017-03-18 15:33:49 +01:00
Location(config, el, router, d);
};
return self;
};
});