File: changelog_search.js

package info (click to toggle)
python3.14 3.14.0~rc1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 126,824 kB
  • sloc: python: 745,274; ansic: 713,752; xml: 31,250; sh: 5,822; cpp: 4,063; makefile: 1,988; objc: 787; lisp: 502; javascript: 136; asm: 75; csh: 12
file content (59 lines) | stat: -rw-r--r-- 1,917 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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() {
    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";
          }
        }
        // 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";
        }
      }
      if (sections_found > 0) {
        h2.parentNode.style.display = "block";
      } else {
        h2.parentNode.style.display = "none";
      }
    }
  }
  document.querySelector("#searchbox").addEventListener("keyup", doFilter);
  document
    .querySelector("#searchbox-submit")
    .addEventListener("click", doFilter);
});