Skip to content

Commit 1b36a8f

Browse files
miss-islingtonhugovktomasr8
authored
[3.12] gh-115317: Rewrite changelog filter to use vanilla JavaScript (GH-115324) (#115372)
gh-115317: Rewrite changelog filter to use vanilla JavaScript (GH-115324) (cherry picked from commit 341d787) Co-authored-by: Hugo van Kemenade <[email protected]> Co-authored-by: Tomas R <[email protected]>
1 parent 09c98e4 commit 1b36a8f

File tree

2 files changed

+56
-50
lines changed

2 files changed

+56
-50
lines changed

.editorconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
root = true
22

3-
[*.{py,c,cpp,h,rst,md,yml}]
3+
[*.{py,c,cpp,h,js,rst,md,yml}]
44
trim_trailing_whitespace = true
55
insert_final_newline = true
66
indent_style = space
@@ -11,5 +11,5 @@ indent_size = 4
1111
[*.rst]
1212
indent_size = 3
1313

14-
[*.yml]
14+
[*.{js,yml}]
1515
indent_size = 2

Doc/tools/static/changelog_search.js

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,59 @@
1-
$(document).ready(function() {
2-
// add the search form and bind the events
3-
$('h1').after([
4-
'<p>Filter entries by content:',
5-
'<input type="text" value="" id="searchbox" style="width: 50%">',
6-
'<input type="submit" id="searchbox-submit" value="Filter"></p>'
7-
].join('\n'));
1+
document.addEventListener("DOMContentLoaded", function () {
2+
// add the search form and bind the events
3+
document
4+
.querySelector("h1")
5+
.insertAdjacentHTML(
6+
"afterend",
7+
[
8+
"<p>Filter entries by content:",
9+
'<input type="text" value="" id="searchbox" style="width: 50%">',
10+
'<input type="submit" id="searchbox-submit" value="Filter"></p>',
11+
].join("\n"),
12+
);
813

9-
function dofilter() {
10-
try {
11-
var query = new RegExp($('#searchbox').val(), 'i');
14+
function doFilter() {
15+
let query;
16+
try {
17+
query = new RegExp(document.querySelector("#searchbox").value, "i");
18+
} catch (e) {
19+
return; // not a valid regex (yet)
20+
}
21+
// find headers for the versions (What's new in Python X.Y.Z?)
22+
const h2s = document.querySelectorAll("#changelog h2");
23+
for (const h2 of h2s) {
24+
let sections_found = 0;
25+
// find headers for the sections (Core, Library, etc.)
26+
const h3s = h2.parentNode.querySelectorAll("h3");
27+
for (const h3 of h3s) {
28+
let entries_found = 0;
29+
// find all the entries
30+
const lis = h3.parentNode.querySelectorAll("li");
31+
for (let li of lis) {
32+
// check if the query matches the entry
33+
if (query.test(li.textContent)) {
34+
li.style.display = "block";
35+
entries_found++;
36+
} else {
37+
li.style.display = "none";
38+
}
1239
}
13-
catch (e) {
14-
return; // not a valid regex (yet)
40+
// if there are entries, show the section, otherwise hide it
41+
if (entries_found > 0) {
42+
h3.parentNode.style.display = "block";
43+
sections_found++;
44+
} else {
45+
h3.parentNode.style.display = "none";
1546
}
16-
// find headers for the versions (What's new in Python X.Y.Z?)
17-
$('#changelog h2').each(function(index1, h2) {
18-
var h2_parent = $(h2).parent();
19-
var sections_found = 0;
20-
// find headers for the sections (Core, Library, etc.)
21-
h2_parent.find('h3').each(function(index2, h3) {
22-
var h3_parent = $(h3).parent();
23-
var entries_found = 0;
24-
// find all the entries
25-
h3_parent.find('li').each(function(index3, li) {
26-
var li = $(li);
27-
// check if the query matches the entry
28-
if (query.test(li.text())) {
29-
li.show();
30-
entries_found++;
31-
}
32-
else {
33-
li.hide();
34-
}
35-
});
36-
// if there are entries, show the section, otherwise hide it
37-
if (entries_found > 0) {
38-
h3_parent.show();
39-
sections_found++;
40-
}
41-
else {
42-
h3_parent.hide();
43-
}
44-
});
45-
if (sections_found > 0)
46-
h2_parent.show();
47-
else
48-
h2_parent.hide();
49-
});
47+
}
48+
if (sections_found > 0) {
49+
h2.parentNode.style.display = "block";
50+
} else {
51+
h2.parentNode.style.display = "none";
52+
}
5053
}
51-
$('#searchbox').keyup(dofilter);
52-
$('#searchbox-submit').click(dofilter);
54+
}
55+
document.querySelector("#searchbox").addEventListener("keyup", doFilter);
56+
document
57+
.querySelector("#searchbox-submit")
58+
.addEventListener("click", doFilter);
5359
});

0 commit comments

Comments
 (0)