hopglass/lib/sidebar.js
Xaver Maierhofer ed06ff6b09 [!!!][TASK] Refactor Scss, add Sass-lint and adjust styling
Add variables to allow easy modifications to color, font and also extending Style
2017-03-18 20:06:42 +01:00

53 lines
1.1 KiB
JavaScript

define(function () {
"use strict";
return function (el) {
var self = this;
var sidebar = document.createElement("div");
sidebar.classList.add("sidebar");
el.appendChild(sidebar);
var button = document.createElement("button");
sidebar.appendChild(button);
button.classList.add("sidebarhandle", "shadow");
button.onclick = function () {
sidebar.classList.toggle("hidden");
};
var container = document.createElement("div");
container.classList.add("container");
sidebar.appendChild(container);
self.getWidth = function () {
if (sidebar.classList.contains("hidden")) {
return 0;
}
var small = window.matchMedia("(max-width: 630pt)");
return small.matches ? 0 : sidebar.offsetWidth;
};
self.add = function (d) {
d.render(container);
};
self.ensureVisible = function () {
sidebar.classList.remove("hidden");
};
self.hide = function () {
container.classList.add("hidden");
};
self.reveal = function () {
container.classList.remove("hidden");
};
self.container = sidebar;
return self;
};
});