libvirt/docs/js/main.js
Martin Kletzander d922e82b5b docs: Some JavaScript clean-up
Don't use the global namespace, unify quotes and semicolons at the end of lines
and "use strict".

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2019-06-20 14:58:43 +02:00

80 lines
2.6 KiB
JavaScript

"use strict";
function pageload() {
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");
if (distanceY > shrinkOn) {
if (home.className != "navhide") {
body.className = "navhide";
home.className = "navhide";
links.className = "navhide";
search.className = "navhide";
}
} else {
if (home.className == "navhide") {
body.className = "";
home.className = "";
links.className = "";
search.className = "";
}
}
});
/* Setting this class makes the advanced search options visible */
var advancedSearch = document.getElementById("advancedsearch");
advancedSearch.className = "advancedsearch";
var simpleSearch = document.getElementById("simplesearch");
simpleSearch.addEventListener("submit", advancedsearch);
}
function advancedsearch(e) {
e.preventDefault();
e.stopPropagation();
var form = document.createElement("form");
form.setAttribute("method", "get");
var newq = document.createElement("input");
newq.setAttribute("type", "hidden");
form.appendChild(newq);
var q = document.getElementById("searchq");
var whats = document.getElementsByName("what");
var what = "website";
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;
}