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')); 8 9 function dofilter() { 10 try { 11 var query = new RegExp($('#searchbox').val(), 'i'); 12 } 13 catch (e) { 14 return; // not a valid regex (yet) 15 } 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 }); 50 } 51 $('#searchbox').keyup(dofilter); 52 $('#searchbox-submit').click(dofilter); 53}); 54