Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7eb03dd

Browse files
committed
Fix/improve the changelog filtering.
1 parent 77cddc3 commit 7eb03dd

2 files changed

Lines changed: 53 additions & 21 deletions

File tree

Doc/tools/sphinxext/layout.html

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,59 @@
1010
{% if not embedded %}<script type="text/javascript" src="{{ pathto('_static/copybutton.js', 1) }}"></script>{% endif %}
1111
{% if pagename == 'whatsnew/changelog' %}
1212
<script type="text/javascript">
13-
function dofilter() {
14-
var el = document.getElementById('searchbox');
15-
var string = el.value.toLowerCase();
16-
var litags = document.getElementsByTagName('li')
17-
for (var idx = 0; idx < litags.length; idx++) {
18-
var li = litags[idx];
19-
if (li.innerHTML.toLowerCase().indexOf(string) >= 0) {
20-
li.style.display = '';
21-
} else {
22-
li.style.display = 'none';
13+
$(document).ready(function() {
14+
// add the search form and bind the events
15+
$('h1').after([
16+
'<p>Filter entries by content:',
17+
'<input type="text" value="" id="searchbox" style="width: 50%">',
18+
'<input type="submit" id="searchbox-submit" value="Filter"></p>'
19+
].join('\n'));
20+
21+
function dofilter() {
22+
try {
23+
var query = new RegExp($('#searchbox').val(), 'i');
24+
}
25+
catch (e) {
26+
return; // not a valid regex (yet)
27+
}
28+
// find headers for the versions (What's new in Python X.Y.Z?)
29+
$('#changelog h2').each(function(index1, h2) {
30+
var h2_parent = $(h2).parent();
31+
var sections_found = 0;
32+
// find headers for the sections (Core, Library, etc.)
33+
h2_parent.find('h3').each(function(index2, h3) {
34+
var h3_parent = $(h3).parent();
35+
var entries_found = 0;
36+
// find all the entries
37+
h3_parent.find('li').each(function(index3, li) {
38+
var li = $(li);
39+
// check if the query matches the entry
40+
if (query.test(li.text())) {
41+
li.show();
42+
entries_found++;
43+
}
44+
else {
45+
li.hide();
46+
}
47+
});
48+
// if there are entries, show the section, otherwise hide it
49+
if (entries_found > 0) {
50+
h3_parent.show();
51+
sections_found++;
52+
}
53+
else {
54+
h3_parent.hide();
55+
}
56+
});
57+
if (sections_found > 0)
58+
h2_parent.show();
59+
else
60+
h2_parent.hide();
61+
});
2362
}
24-
}
25-
}
63+
$('#searchbox').keyup(dofilter);
64+
$('#searchbox-submit').click(dofilter);
65+
});
2666
</script>
2767
{% endif %}
2868
{{ super() }}
@@ -31,7 +71,7 @@
3171
<div class="footer">
3272
&copy; <a href="{{ pathto('copyright') }}">Copyright</a> {{ copyright|e }}.
3373
<br />
34-
The Python Software Foundation is a non-profit corporation.
74+
The Python Software Foundation is a non-profit corporation.
3575
<a href="http://www.python.org/psf/donations/">Please donate.</a>
3676
<br />
3777
Last updated on {{ last_updated|e }}.

Doc/whatsnew/changelog.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,5 @@
22
Changelog
33
+++++++++
44

5-
.. raw:: html
6-
7-
<p>
8-
Filter entries by content:
9-
<input type="text" value="" id="searchbox" style="width: 50%" onchange="dofilter()">
10-
<input type="submit" value="Filter" onclick="dofilter()">
11-
</p>
12-
135
.. miscnews:: ../../Misc/NEWS
146

0 commit comments

Comments
 (0)