Skip to content

Commit aeb548a

Browse files
Put back interactions with settings menus
1 parent f2193c6 commit aeb548a

File tree

3 files changed

+91
-86
lines changed

3 files changed

+91
-86
lines changed

util/gh-pages/index_template.html

Lines changed: 26 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</head>
2828
<body>
2929
<div id="settings-dropdown">
30-
<div class="settings-icon" tabindex="-1"></div>
30+
<button class="settings-icon" tabindex="-1"></button>
3131
<div class="settings-menu" tabindex="-1">
3232
<div class="setting-radio-name">Theme</div>
3333
<select id="theme-choice" onchange="setTheme(this.value, true)">
@@ -59,88 +59,62 @@ <h1>Clippy Lints</h1>
5959
<div class="panel panel-default">
6060
<div class="panel-body row">
6161
<div id="upper-filters" class="col-12 col-md-5">
62-
<div class="btn-group">
62+
<div class="btn-group" id="lint-levels" tabindex="-1">
6363
<button type="button" class="btn btn-default dropdown-toggle">
6464
Lint levels <span class="badge" id="selected-levels">4</span> <span class="caret"></span>
6565
</button>
66-
<ul class="dropdown-menu" id="lint-levels">
66+
<ul class="dropdown-menu" id="lint-levels-selector">
6767
<li class="checkbox">
68-
<label onclick="toggleLevels(true)">
69-
<input type="checkbox" class="invisible" />
70-
All
71-
</label>
68+
<button onclick="toggleElements(this, true)">All</button>
7269
</li>
7370
<li class="checkbox">
74-
<label onclick="toggleLevels(false)">
75-
<input type="checkbox" class="invisible" />
76-
None
77-
</label>
71+
<button onclick="toggleElements(this, false)">None</button>
7872
</li>
7973
<li role="separator" class="divider"></li>
8074
</ul>
8175
</div>
82-
<div class="btn-group">
76+
<div class="btn-group" id="lint-groups" tabindex="-1">
8377
<button type="button" class="btn btn-default dropdown-toggle">
8478
Lint groups <span class="badge" id="selected-groups"></span> <span class="caret"></span>
8579
</button>
86-
<ul class="dropdown-menu" id="lint-groups">
80+
<ul class="dropdown-menu" id="lint-groups-selector">
8781
<li class="checkbox">
88-
<label onclick="toggleGroups(true)">
89-
<input type="checkbox" class="invisible" />
90-
All
91-
</label>
82+
<button onclick="toggleElements(this, true)">All</button>
9283
</li>
9384
<li class="checkbox">
94-
<label onclick="resetGroupsToDefault()">
95-
<input type="checkbox" class="invisible" />
96-
Default
97-
</label>
85+
<button onclick="resetGroupsToDefault()">Default</button>
9886
</li>
9987
<li class="checkbox">
100-
<label onclick="toggleGroups(false)">
101-
<input type="checkbox" class="invisible" />
102-
None
103-
</label>
88+
<button onclick="toggleElements(this, false)">None</button>
10489
</li>
10590
<li role="separator" class="divider"></li>
10691
</ul>
10792
</div>
108-
<div id="version-filter">
109-
<div class="btn-group">
110-
<button type="button" class="btn btn-default dropdown-toggle">
111-
Version
112-
<span id="version-filter-count" class="badge">0</span>
113-
<span class="caret"></span>
114-
</button>
115-
<ul id="version-filter-selector" class="dropdown-menu">
116-
<li class="checkbox">
117-
<label onclick="clearVersionFilters()">
118-
<input type="checkbox" class="invisible" />
119-
Clear filters
120-
</label>
121-
</li>
122-
<li role="separator" class="divider"></li>
123-
</ul>
124-
</div>
93+
<div class="btn-group" id="version-filter" tabindex="-1">
94+
<button type="button" class="btn btn-default dropdown-toggle">
95+
Version
96+
<span id="version-filter-count" class="badge">0</span>
97+
<span class="caret"></span>
98+
</button>
99+
<ul id="version-filter-selector" class="dropdown-menu">
100+
<li class="checkbox">
101+
<button onclick="clearVersionFilters()">Clear filters</button>
102+
</li>
103+
<li role="separator" class="divider"></li>
104+
</ul>
125105
</div>
126-
<div class="btn-group">
106+
<div class="btn-group", id="lint-applicabilities" tabindex="-1">
127107
<button type="button" class="btn btn-default dropdown-toggle">
128108
Applicability
129109
<span class="badge"></span>
130110
<span class="caret"></span>
131111
</button>
132-
<ul class="dropdown-menu" id="lint-applicabilities">
112+
<ul class="dropdown-menu" id="lint-applicabilities-selector">
133113
<li class="checkbox">
134-
<label onclick="toggleApplicabilities(true)">
135-
<input type="checkbox" class="invisible" />
136-
All
137-
</label>
114+
<button onclick="toggleElements(this, true)">All</button>
138115
</li>
139116
<li class="checkbox">
140-
<label onclick="toggleApplicabilities(false)">
141-
<input type="checkbox" class="invisible" />
142-
None
143-
</label>
117+
<button onclick="toggleElements(this, false)">None</button>
144118
</li>
145119
<li role="separator" class="divider"></li>
146120
</ul>

util/gh-pages/script.js

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ function handleShortcut(ev) {
151151
document.addEventListener("keypress", handleShortcut);
152152
document.addEventListener("keydown", handleShortcut);
153153

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+
154162
function changeSetting(elem) {
155163
if (elem.id === "disable-shortcuts") {
156164
disableShortcuts = elem.checked;
@@ -211,8 +219,8 @@ function copyToClipboard(event) {
211219
resetClipboardTimeout = setTimeout(resetClipboard, 1000);
212220
}
213221

214-
function handleBlur(event) {
215-
const parent = document.getElementById("settings-dropdown");
222+
function handleBlur(event, elementId) {
223+
const parent = document.getElementById(elementId);
216224
if (!parent.contains(document.activeElement) &&
217225
!parent.contains(event.relatedTarget)
218226
) {
@@ -227,6 +235,30 @@ function toggleExpansion(expand) {
227235
);
228236
}
229237

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+
230262
function generateListOfOptions(list, elementId) {
231263
let html = '';
232264
let nbEnabled = 0;
@@ -235,47 +267,41 @@ function generateListOfOptions(list, elementId) {
235267
html += `\
236268
<li class="checkbox">\
237269
<label class="text-capitalize">\
238-
<input type="checkbox"${attr}/>${key}\
270+
<input type="checkbox" data-value="${key}"${attr}/>${key}\
239271
</label>\
240272
</li>`;
241273
if (value) {
242274
nbEnabled += 1;
243275
}
244276
}
245277

246-
const elem = document.getElementById(elementId);
278+
const elem = document.getElementById(`${elementId}-selector`);
247279
elem.previousElementSibling.querySelector(".badge").innerText = `${nbEnabled}`;
248280
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);
249296
}
250297

251298
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");
262300

263301
const LEVEL_FILTERS_DEFAULT = {allow: true, warn: true, deny: true, none: true};
264302
generateListOfOptions(LEVEL_FILTERS_DEFAULT, "lint-levels");
265303

266304
// 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-
};
279305
generateListOfOptions(GROUPS_FILTER_DEFAULT, "lint-groups");
280306

281307
const APPLICABILITIES_FILTER_DEFAULT = {
@@ -287,12 +313,6 @@ function generateSettings() {
287313
};
288314
generateListOfOptions(APPLICABILITIES_FILTER_DEFAULT, "lint-applicabilities");
289315

290-
const VERSIONS_FILTERS = {
291-
"≥": {enabled: false, minorVersion: null },
292-
"≤": {enabled: false, minorVersion: null },
293-
"=": {enabled: false, minorVersion: null },
294-
};
295-
296316
let html = '';
297317
for (const kind of ["≥", "≤", "="]) {
298318
html += `\
@@ -309,6 +329,7 @@ function generateSettings() {
309329
</li>`;
310330
}
311331
document.getElementById("version-filter-selector").innerHTML += html;
332+
setupDropdown("version-filter");
312333
}
313334

314335
function generateSearch() {

util/gh-pages/style.css

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,6 @@ L4.75,12h2.5l0.5393066-2.1572876 c0.2276001-0.1062012,0.4459839-0.2269287,0.649
272272
height: 18px;
273273
display: block;
274274
filter: invert(0.7);
275-
padding-left: 4px;
276-
padding-top: 3px;
277275
}
278276

279277
.settings-menu * {
@@ -329,6 +327,18 @@ L4.75,12h2.5l0.5393066-2.1572876 c0.2276001-0.1062012,0.4459839-0.2269287,0.649
329327
display: flex;
330328
}
331329

330+
ul.dropdown-menu li.checkbox > button {
331+
border: 0;
332+
width: 100%;
333+
background: var(--theme-popup-bg);
334+
color: var(--fg);
335+
}
336+
337+
ul.dropdown-menu li.checkbox > button:hover {
338+
background: var(--theme-hover);
339+
box-shadow: none;
340+
}
341+
332342
#version-filter {
333343
min-width: available;
334344
}

0 commit comments

Comments
 (0)