|
3 | 3 | <input id="finder-input" type="search" autocomplete="off" placeholder="Search 113 HTML elements"> |
4 | 4 | <i class="icon is-search"></i> |
5 | 5 | </div> |
| 6 | + <div id="finder-checkboxes" class="finder-checkboxes"> |
| 7 | + <label class="light light--experimental is-active"><input type="checkbox" name="experimental" checked>experimental</label> |
| 8 | + <label class="light light--meta is-active"><input type="checkbox" name="meta" checked>meta</label> |
| 9 | + <label class="light light--selfclosing is-active"><input type="checkbox" name="selfclosing" checked>self-closing</label> |
| 10 | + <label class="light light--inline is-active"><input type="checkbox" name="inline" checked>inline</label> |
| 11 | + <label class="light light--block is-active"><input type="checkbox" name="block" checked>block</label> |
| 12 | + </div> |
6 | 13 | <div id="finder-list" class="finder-list"> |
7 | 14 | {% include lists/finder-list.html %} |
8 | 15 | </div> |
|
15 | 22 | var $searchInput = document.getElementById('finder-input'); |
16 | 23 | var $finderList = document.getElementById('finder-list'); |
17 | 24 | var $finderItems = document.querySelectorAll('.finder-item'); |
| 25 | + var $finderCheckboxes = document.querySelectorAll('#finder-checkboxes input'); |
| 26 | + var lights = { |
| 27 | + experimental: true, |
| 28 | + meta: true, |
| 29 | + selfClosing: true, |
| 30 | + inline: true, |
| 31 | + block: true, |
| 32 | + } |
18 | 33 | var isFocused = false; |
19 | 34 | var isSearching = false; |
20 | 35 | var isModaling = false; |
|
49 | 64 | var elementName = $el.dataset.elementName; |
50 | 65 | var isMatch = highlightQuery($el, elementName, query); |
51 | 66 |
|
52 | | - if (isMatch) { |
| 67 | + if (isMatch && !$el.classList.contains('is-hidden')) { |
53 | 68 | matches.push({ |
54 | 69 | DOMIndex: index, |
55 | 70 | elementName: elementName, |
|
66 | 81 | } |
67 | 82 | }); |
68 | 83 |
|
| 84 | + Array.prototype.forEach.call($finderCheckboxes, function($el) { |
| 85 | + $el.addEventListener('change', function(event) { |
| 86 | + lights[this.name] = this.checked; |
| 87 | + changeLights(); |
| 88 | + }); |
| 89 | + }); |
| 90 | + |
69 | 91 | window.addEventListener('click', function(event) { |
70 | 92 | if (!isFocused) { |
71 | 93 | isSearching = false; |
|
116 | 138 | } |
117 | 139 | }); |
118 | 140 |
|
| 141 | + function checkLights() { |
| 142 | + Array.prototype.forEach.call($finderCheckboxes, function($el) { |
| 143 | + lights[this.name] = this.checked; |
| 144 | + }); |
| 145 | + } |
| 146 | + |
| 147 | + function changeLights() { |
| 148 | + Array.prototype.forEach.call($finderItems, function($el, index) { |
| 149 | + var hide = false; |
| 150 | + |
| 151 | + Object.keys(lights).forEach(function(key) { |
| 152 | + // Check if we hide "experimental" |
| 153 | + if (!lights[key]) { |
| 154 | + hide = (hide) || ($el.dataset[key] == 'true'); |
| 155 | + } |
| 156 | + }); |
| 157 | + |
| 158 | + if (hide) { |
| 159 | + $el.classList.add('is-hidden'); |
| 160 | + } else { |
| 161 | + $el.classList.remove('is-hidden'); |
| 162 | + } |
| 163 | + }); |
| 164 | + } |
| 165 | + |
119 | 166 | function globalReset() { |
120 | 167 | isFocused = false; |
121 | 168 | $searchInput.value = ''; |
|
125 | 172 | $finderList.classList.remove('is-searching'); |
126 | 173 | cleanMenu($finderItems, true, true); |
127 | 174 | } |
| 175 | + |
| 176 | + checkLights(); |
| 177 | + changeLights(); |
128 | 178 | } |
129 | 179 |
|
130 | 180 | }); |
|
0 commit comments