summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-02-13 05:29:31 (GMT)
committerGitHub <noreply@github.com>2024-02-13 05:29:31 (GMT)
commit1b36a8fc6a13eda60a9078ab1c656896cd5e3f79 (patch)
tree608cc4536e582b493c88090b20a7ceaa4dcc5169
parent09c98e4633848ce05df8621f41eb09954b55217a (diff)
downloadcpython-1b36a8fc6a13eda60a9078ab1c656896cd5e3f79.zip
cpython-1b36a8fc6a13eda60a9078ab1c656896cd5e3f79.tar.gz
cpython-1b36a8fc6a13eda60a9078ab1c656896cd5e3f79.tar.bz2
[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 341d7874f063dcb141672b09f62c19ffedd0a557) Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Tomas R <tomas.roun8@gmail.com>
-rw-r--r--.editorconfig4
-rw-r--r--Doc/tools/static/changelog_search.js102
2 files changed, 56 insertions, 50 deletions
diff --git a/.editorconfig b/.editorconfig
index 0169eed..a6187d6 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,6 +1,6 @@
root = true
-[*.{py,c,cpp,h,rst,md,yml}]
+[*.{py,c,cpp,h,js,rst,md,yml}]
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
@@ -11,5 +11,5 @@ indent_size = 4
[*.rst]
indent_size = 3
-[*.yml]
+[*.{js,yml}]
indent_size = 2
diff --git a/Doc/tools/static/changelog_search.js b/Doc/tools/static/changelog_search.js
index c881a9b..0a77c0d 100644
--- a/Doc/tools/static/changelog_search.js
+++ b/Doc/tools/static/changelog_search.js
@@ -1,53 +1,59 @@
-$(document).ready(function() {
- // add the search form and bind the events
- $('h1').after([
- '<p>Filter entries by content:',
- '<input type="text" value="" id="searchbox" style="width: 50%">',
- '<input type="submit" id="searchbox-submit" value="Filter"></p>'
- ].join('\n'));
+document.addEventListener("DOMContentLoaded", function () {
+ // add the search form and bind the events
+ document
+ .querySelector("h1")
+ .insertAdjacentHTML(
+ "afterend",
+ [
+ "<p>Filter entries by content:",
+ '<input type="text" value="" id="searchbox" style="width: 50%">',
+ '<input type="submit" id="searchbox-submit" value="Filter"></p>',
+ ].join("\n"),
+ );
- function dofilter() {
- try {
- var query = new RegExp($('#searchbox').val(), 'i');
+ function doFilter() {
+ let query;
+ try {
+ query = new RegExp(document.querySelector("#searchbox").value, "i");
+ } catch (e) {
+ return; // not a valid regex (yet)
+ }
+ // find headers for the versions (What's new in Python X.Y.Z?)
+ const h2s = document.querySelectorAll("#changelog h2");
+ for (const h2 of h2s) {
+ let sections_found = 0;
+ // find headers for the sections (Core, Library, etc.)
+ const h3s = h2.parentNode.querySelectorAll("h3");
+ for (const h3 of h3s) {
+ let entries_found = 0;
+ // find all the entries
+ const lis = h3.parentNode.querySelectorAll("li");
+ for (let li of lis) {
+ // check if the query matches the entry
+ if (query.test(li.textContent)) {
+ li.style.display = "block";
+ entries_found++;
+ } else {
+ li.style.display = "none";
+ }
}
- catch (e) {
- return; // not a valid regex (yet)
+ // if there are entries, show the section, otherwise hide it
+ if (entries_found > 0) {
+ h3.parentNode.style.display = "block";
+ sections_found++;
+ } else {
+ h3.parentNode.style.display = "none";
}
- // find headers for the versions (What's new in Python X.Y.Z?)
- $('#changelog h2').each(function(index1, h2) {
- var h2_parent = $(h2).parent();
- var sections_found = 0;
- // find headers for the sections (Core, Library, etc.)
- h2_parent.find('h3').each(function(index2, h3) {
- var h3_parent = $(h3).parent();
- var entries_found = 0;
- // find all the entries
- h3_parent.find('li').each(function(index3, li) {
- var li = $(li);
- // check if the query matches the entry
- if (query.test(li.text())) {
- li.show();
- entries_found++;
- }
- else {
- li.hide();
- }
- });
- // if there are entries, show the section, otherwise hide it
- if (entries_found > 0) {
- h3_parent.show();
- sections_found++;
- }
- else {
- h3_parent.hide();
- }
- });
- if (sections_found > 0)
- h2_parent.show();
- else
- h2_parent.hide();
- });
+ }
+ if (sections_found > 0) {
+ h2.parentNode.style.display = "block";
+ } else {
+ h2.parentNode.style.display = "none";
+ }
}
- $('#searchbox').keyup(dofilter);
- $('#searchbox-submit').click(dofilter);
+ }
+ document.querySelector("#searchbox").addEventListener("keyup", doFilter);
+ document
+ .querySelector("#searchbox-submit")
+ .addEventListener("click", doFilter);
});