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