|
10 | 10 | {% if not embedded %}<script type="text/javascript" src="{{ pathto('_static/copybutton.js', 1) }}"></script>{% endif %} |
11 | 11 | {% if pagename == 'whatsnew/changelog' %} |
12 | 12 | <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 | + }); |
23 | 62 | } |
24 | | - } |
25 | | - } |
| 63 | + $('#searchbox').keyup(dofilter); |
| 64 | + $('#searchbox-submit').click(dofilter); |
| 65 | + }); |
26 | 66 | </script> |
27 | 67 | {% endif %} |
28 | 68 | {{ super() }} |
|
31 | 71 | <div class="footer"> |
32 | 72 | © <a href="{{ pathto('copyright') }}">Copyright</a> {{ copyright|e }}. |
33 | 73 | <br /> |
34 | | - The Python Software Foundation is a non-profit corporation. |
| 74 | + The Python Software Foundation is a non-profit corporation. |
35 | 75 | <a href="http://www.python.org/psf/donations/">Please donate.</a> |
36 | 76 | <br /> |
37 | 77 | Last updated on {{ last_updated|e }}. |
|
0 commit comments