main.js 2.6 KB
Newer Older
1 2
"use strict";

3
function pageload() {
4 5 6 7 8 9 10
    window.addEventListener("scroll", function(e){
        var distanceY = window.pageYOffset || document.documentElement.scrollTop;
        var shrinkOn = 94;
        var home = document.getElementById("home");
        var links = document.getElementById("jumplinks");
        var search = document.getElementById("search");
        var body = document.getElementById("body");
11 12
        if (distanceY > shrinkOn) {
            if (home.className != "navhide") {
13 14 15 16
                body.className = "navhide";
                home.className = "navhide";
                links.className = "navhide";
                search.className = "navhide";
17 18 19
            }
        } else {
            if (home.className == "navhide") {
20 21 22 23
                body.className = "";
                home.className = "";
                links.className = "";
                search.className = "";
24 25 26
            }
        }
    });
27 28

    /* Setting this class makes the advanced search options visible */
29 30
    var advancedSearch = document.getElementById("advancedsearch");
    advancedSearch.className = "advancedsearch";
31

32 33
    var simpleSearch = document.getElementById("simplesearch");
    simpleSearch.addEventListener("submit", advancedsearch);
34 35 36 37 38 39
}

function advancedsearch(e) {
    e.preventDefault();
    e.stopPropagation();

40
    var form = document.createElement("form");
41 42
    form.setAttribute("method", "get");

43
    var newq = document.createElement("input");
44 45 46
    newq.setAttribute("type", "hidden");
    form.appendChild(newq);

47 48 49
    var q = document.getElementById("searchq");
    var whats = document.getElementsByName("what");
    var what = "website";
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
    for (var i = 0; i < whats.length; i++) {
        if (whats[i].checked) {
            what = whats[i].value;
            break;
        }
    }

    if (what == "website") {
        form.setAttribute("action", "https://google.com/search");
        newq.setAttribute("name", "q");
        newq.value = "site:libvirt.org " + q.value;
    } else if (what == "wiki") {
        form.setAttribute("action", "https://wiki.libvirt.org/index.php");
        newq.setAttribute("name", "search");
        newq.value = q.value;
    } else if (what == "devs") {
        form.setAttribute("action", "https://google.com/search");
        newq.setAttribute("name", "q");
        newq.value = "site:redhat.com/archives/libvir-list " + q.value;
    } else if (what == "users") {
        form.setAttribute("action", "https://google.com/search");
        newq.setAttribute("name", "q");
        newq.value = "site:redhat.com/archives/libvirt-users " + q.value;
    }

    document.body.appendChild(form);
    form.submit();

    return false;
79
}