@@ -151,6 +151,14 @@ function handleShortcut(ev) {
151
151
document . addEventListener ( "keypress" , handleShortcut ) ;
152
152
document . addEventListener ( "keydown" , handleShortcut ) ;
153
153
154
+ function toggleElements ( element , value ) {
155
+ // `element` is always a button in a `li` in a `ul`. We want the `input` in the `ul`.
156
+ onEachLazy (
157
+ element . parentElement . parentElement . getElementsByTagName ( "input" ) ,
158
+ el => el . checked = value ,
159
+ ) ;
160
+ }
161
+
154
162
function changeSetting ( elem ) {
155
163
if ( elem . id === "disable-shortcuts" ) {
156
164
disableShortcuts = elem . checked ;
@@ -211,8 +219,8 @@ function copyToClipboard(event) {
211
219
resetClipboardTimeout = setTimeout ( resetClipboard , 1000 ) ;
212
220
}
213
221
214
- function handleBlur ( event ) {
215
- const parent = document . getElementById ( "settings-dropdown" ) ;
222
+ function handleBlur ( event , elementId ) {
223
+ const parent = document . getElementById ( elementId ) ;
216
224
if ( ! parent . contains ( document . activeElement ) &&
217
225
! parent . contains ( event . relatedTarget )
218
226
) {
@@ -227,6 +235,30 @@ function toggleExpansion(expand) {
227
235
) ;
228
236
}
229
237
238
+ function clearVersionFilters ( ) {
239
+ onEachLazy ( document . querySelectorAll ( "#version-filter-count input" ) , el => el . value = "" ) ;
240
+ }
241
+
242
+ const GROUPS_FILTER_DEFAULT = {
243
+ cargo : true ,
244
+ complexity : true ,
245
+ correctness : true ,
246
+ deprecated : false ,
247
+ nursery : true ,
248
+ pedantic : true ,
249
+ perf : true ,
250
+ restriction : true ,
251
+ style : true ,
252
+ suspicious : true ,
253
+ } ;
254
+
255
+ function resetGroupsToDefault ( ) {
256
+ onEachLazy ( document . querySelectorAll ( "#lint-groups-selector input" ) , el => {
257
+ const key = el . getAttribute ( "data-value" ) ;
258
+ el . checked = GROUPS_FILTER_DEFAULT [ key ] ;
259
+ } ) ;
260
+ }
261
+
230
262
function generateListOfOptions ( list , elementId ) {
231
263
let html = '' ;
232
264
let nbEnabled = 0 ;
@@ -235,47 +267,41 @@ function generateListOfOptions(list, elementId) {
235
267
html += `\
236
268
<li class="checkbox">\
237
269
<label class="text-capitalize">\
238
- <input type="checkbox"${ attr } />${ key } \
270
+ <input type="checkbox" data-value=" ${ key } " ${ attr } />${ key } \
239
271
</label>\
240
272
</li>` ;
241
273
if ( value ) {
242
274
nbEnabled += 1 ;
243
275
}
244
276
}
245
277
246
- const elem = document . getElementById ( elementId ) ;
278
+ const elem = document . getElementById ( ` ${ elementId } -selector` ) ;
247
279
elem . previousElementSibling . querySelector ( ".badge" ) . innerText = `${ nbEnabled } ` ;
248
280
elem . innerHTML += html ;
281
+
282
+ setupDropdown ( elementId ) ;
283
+ }
284
+
285
+ function setupDropdown ( elementId ) {
286
+ const elem = document . getElementById ( elementId ) ;
287
+ const button = document . querySelector ( `#${ elementId } > button` ) ;
288
+ button . onclick = ( ) => elem . classList . toggle ( "open" ) ;
289
+
290
+ const setBlur = child => {
291
+ child . onblur = event => handleBlur ( event , elementId ) ;
292
+ } ;
293
+ onEachLazy ( elem . children , setBlur ) ;
294
+ onEachLazy ( elem . querySelectorAll ( "input" ) , setBlur ) ;
295
+ onEachLazy ( elem . querySelectorAll ( "ul button" ) , setBlur ) ;
249
296
}
250
297
251
298
function generateSettings ( ) {
252
- const settings = document . getElementById ( "settings-dropdown" ) ;
253
- const settingsButton = settings . querySelector ( ".settings-icon" )
254
- settingsButton . onclick = ( ) => settings . classList . toggle ( "open" ) ;
255
- settingsButton . onblur = handleBlur ;
256
- const settingsMenu = settings . querySelector ( ".settings-menu" ) ;
257
- settingsMenu . onblur = handleBlur ;
258
- onEachLazy (
259
- settingsMenu . querySelectorAll ( "input" ) ,
260
- el => el . onblur = handleBlur ,
261
- ) ;
299
+ setupDropdown ( "settings-dropdown" ) ;
262
300
263
301
const LEVEL_FILTERS_DEFAULT = { allow : true , warn : true , deny : true , none : true } ;
264
302
generateListOfOptions ( LEVEL_FILTERS_DEFAULT , "lint-levels" ) ;
265
303
266
304
// Generate lint groups.
267
- const GROUPS_FILTER_DEFAULT = {
268
- cargo : true ,
269
- complexity : true ,
270
- correctness : true ,
271
- deprecated : false ,
272
- nursery : true ,
273
- pedantic : true ,
274
- perf : true ,
275
- restriction : true ,
276
- style : true ,
277
- suspicious : true ,
278
- } ;
279
305
generateListOfOptions ( GROUPS_FILTER_DEFAULT , "lint-groups" ) ;
280
306
281
307
const APPLICABILITIES_FILTER_DEFAULT = {
@@ -287,12 +313,6 @@ function generateSettings() {
287
313
} ;
288
314
generateListOfOptions ( APPLICABILITIES_FILTER_DEFAULT , "lint-applicabilities" ) ;
289
315
290
- const VERSIONS_FILTERS = {
291
- "≥" : { enabled : false , minorVersion : null } ,
292
- "≤" : { enabled : false , minorVersion : null } ,
293
- "=" : { enabled : false , minorVersion : null } ,
294
- } ;
295
-
296
316
let html = '' ;
297
317
for ( const kind of [ "≥" , "≤" , "=" ] ) {
298
318
html += `\
@@ -309,6 +329,7 @@ function generateSettings() {
309
329
</li>` ;
310
330
}
311
331
document . getElementById ( "version-filter-selector" ) . innerHTML += html ;
332
+ setupDropdown ( "version-filter" ) ;
312
333
}
313
334
314
335
function generateSearch ( ) {
0 commit comments