meshviewer/lib/sidebar.js

53 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-05-27 21:59:01 +00:00
define(function () {
"use strict";
2015-03-25 14:33:36 +00:00
return function (el) {
var self = this;
2015-03-25 14:33:36 +00:00
var sidebar = document.createElement("div");
sidebar.classList.add("sidebar");
el.appendChild(sidebar);
2015-03-25 14:33:36 +00:00
var button = document.createElement("button");
sidebar.appendChild(button);
2015-03-25 14:33:36 +00:00
button.classList.add("sidebarhandle", "shadow");
2015-03-25 14:33:36 +00:00
button.onclick = function () {
sidebar.classList.toggle("hidden");
};
2015-03-25 14:33:36 +00:00
var container = document.createElement("div");
container.classList.add("container");
sidebar.appendChild(container);
2015-04-04 16:01:57 +00:00
2015-03-25 14:33:36 +00:00
self.getWidth = function () {
if (sidebar.classList.contains("hidden")) {
return 0;
}
2015-03-31 18:32:47 +00:00
var small = window.matchMedia("(max-width: 630pt)");
return small.matches ? 0 : sidebar.offsetWidth;
};
2015-03-25 14:33:36 +00:00
self.add = function (d) {
d.render(container);
};
2015-03-25 14:33:36 +00:00
self.ensureVisible = function () {
sidebar.classList.remove("hidden");
};
2015-07-06 20:27:16 +00:00
self.hide = function () {
container.classList.add("hidden");
};
2015-07-06 20:27:16 +00:00
self.reveal = function () {
container.classList.remove("hidden");
};
2015-07-06 20:27:16 +00:00
self.container = sidebar;
2015-03-25 14:33:36 +00:00
return self;
};
});