1 | define(function () { |
||
2 | 'use strict'; |
||
3 | |||
4 | return function (distributor) { |
||
5 | var container = document.createElement('ul'); |
||
6 | container.classList.add('filters'); |
||
7 | var div = document.createElement('div'); |
||
8 | |||
9 | function render(el) { |
||
10 | el.appendChild(div); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
11 | } |
||
12 | |||
13 | function filtersChanged(filters) { |
||
14 | while (container.firstChild) { |
||
15 | container.removeChild(container.firstChild); |
||
16 | } |
||
17 | |||
18 | filters.forEach(function (d) { |
||
19 | var li = document.createElement('li'); |
||
20 | container.appendChild(li); |
||
21 | d.render(li); |
||
22 | |||
23 | var button = document.createElement('button'); |
||
24 | button.classList.add('ion-close'); |
||
25 | button.setAttribute('aria-label', _.t('remove')); |
||
26 | button.onclick = function onclick() { |
||
27 | distributor.removeFilter(d); |
||
28 | }; |
||
29 | li.appendChild(button); |
||
30 | }); |
||
31 | |||
32 | if (container.parentNode === div && filters.length === 0) { |
||
33 | div.removeChild(container); |
||
34 | } else if (filters.length > 0) { |
||
35 | div.appendChild(container); |
||
36 | } |
||
37 | } |
||
38 | |||
39 | return { |
||
40 | render: render, |
||
41 | filtersChanged: filtersChanged |
||
42 | }; |
||
43 | }; |
||
44 | }); |
||
45 |