2015-07-08 00:36:57 +02:00
|
|
|
define([], function () {
|
|
|
|
return function (distributor) {
|
2017-03-17 03:14:57 +01:00
|
|
|
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) {
|
2017-03-17 03:14:57 +01:00
|
|
|
el.appendChild(div);
|
2015-07-08 00:36:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function filtersChanged(filters) {
|
2017-03-17 03:14:57 +01:00
|
|
|
while (container.firstChild) {
|
|
|
|
container.removeChild(container.firstChild);
|
|
|
|
}
|
2015-07-08 00:36:57 +02:00
|
|
|
|
2017-03-17 03:14:57 +01: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
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
var button = document.createElement("button");
|
|
|
|
button.textContent = "";
|
2015-07-08 00:36:57 +02:00
|
|
|
button.onclick = function () {
|
2017-03-17 03:14:57 +01:00
|
|
|
distributor.removeFilter(d);
|
|
|
|
};
|
|
|
|
li.appendChild(button);
|
|
|
|
});
|
2015-07-08 17:20:56 +02:00
|
|
|
|
2017-03-17 03:14:57 +01: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
|
|
|
}
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
return {
|
|
|
|
render: render,
|
|
|
|
filtersChanged: filtersChanged
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|