-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-115317: Rewrite changelog filter to use vanilla JavaScript #115324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5f5071d
Rewrite using vanilla JavaScript
hugovk e8c055c
Re-add comments
hugovk b38d840
Add braces
hugovk b96383a
Prefer const
hugovk a926364
Format with Prettier
hugovk dc1f94d
Use camelCase for function name
hugovk cccf0a7
Prefer const
hugovk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,53 +1,56 @@ | ||||||||
$(document).ready(function() { | ||||||||
document.addEventListener('DOMContentLoaded', function() { | ||||||||
// add the search form and bind the events | ||||||||
$('h1').after([ | ||||||||
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() { | ||||||||
let query; | ||||||||
try { | ||||||||
var query = new RegExp($('#searchbox').val(), 'i'); | ||||||||
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?) | ||||||||
$('#changelog h2').each(function(index1, h2) { | ||||||||
var h2_parent = $(h2).parent(); | ||||||||
var sections_found = 0; | ||||||||
const h2s = document.querySelectorAll('#changelog h2'); | ||||||||
for(let h2 of h2s) { | ||||||||
let 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; | ||||||||
const h3s = h2.parentNode.querySelectorAll('h3'); | ||||||||
for(let h3 of h3s) { | ||||||||
let entries_found = 0; | ||||||||
// find all the entries | ||||||||
h3_parent.find('li').each(function(index3, li) { | ||||||||
var li = $(li); | ||||||||
const lis = h3.parentNode.querySelectorAll('li'); | ||||||||
for(let li of lis) { | ||||||||
// check if the query matches the entry | ||||||||
if (query.test(li.text())) { | ||||||||
li.show(); | ||||||||
if (query.test(li.textContent)) { | ||||||||
li.style.display = 'block'; | ||||||||
entries_found++; | ||||||||
} | ||||||||
else { | ||||||||
li.hide(); | ||||||||
li.style.display = 'none'; | ||||||||
} | ||||||||
}); | ||||||||
} | ||||||||
// if there are entries, show the section, otherwise hide it | ||||||||
if (entries_found > 0) { | ||||||||
h3_parent.show(); | ||||||||
h3.parentNode.style.display = 'block'; | ||||||||
sections_found++; | ||||||||
} | ||||||||
else { | ||||||||
h3_parent.hide(); | ||||||||
h3.parentNode.style.display = 'none'; | ||||||||
} | ||||||||
}); | ||||||||
if (sections_found > 0) | ||||||||
h2_parent.show(); | ||||||||
else | ||||||||
h2_parent.hide(); | ||||||||
}); | ||||||||
} | ||||||||
if (sections_found > 0) { | ||||||||
h2.parentNode.style.display = 'block'; | ||||||||
} | ||||||||
else { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is the more common formatting for blocks in js
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'm going to just run Prettier on this :) |
||||||||
h2.parentNode.style.display = 'none'; | ||||||||
hugovk marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
} | ||||||||
} | ||||||||
} | ||||||||
$('#searchbox').keyup(dofilter); | ||||||||
$('#searchbox-submit').click(dofilter); | ||||||||
document.querySelector('#searchbox').addEventListener('keyup', dofilter); | ||||||||
document.querySelector('#searchbox-submit').addEventListener('click', dofilter); | ||||||||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.