hopglass/lib/filters/filtergui.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2015-07-08 00:36:57 +02:00
define([], function () {
return function (distributor) {
var container = document.createElement("ul");
container.classList.add("filters");
var div = document.createElement("div");
2015-07-08 00:36:57 +02:00
function render(el) {
el.appendChild(div);
2015-07-08 00:36:57 +02:00
}
function filtersChanged(filters) {
while (container.firstChild) {
container.removeChild(container.firstChild);
}
2015-07-08 00:36:57 +02:00
filters.forEach(function (d) {
var li = document.createElement("li");
var div = document.createElement("div");
container.appendChild(li);
li.appendChild(div);
d.render(div);
2015-07-08 00:36:57 +02:00
var button = document.createElement("button");
button.textContent = "";
2015-07-08 00:36:57 +02:00
button.onclick = function () {
distributor.removeFilter(d);
};
li.appendChild(button);
});
2015-07-08 17:20:56 +02:00
if (container.parentNode === div && filters.length === 0) {
div.removeChild(container);
} else if (filters.length > 0) {
div.appendChild(container);
}
2015-07-08 00:36:57 +02:00
}
return {
render: render,
filtersChanged: filtersChanged
};
};
});