forked from I2P_Developers/i2p.i2p

Some checks failed
Java CI / build (push) Has been cancelled
Java CI / javadoc-latest (push) Has been cancelled
Java CI / build-java7 (push) Has been cancelled
Java with IzPack Snapshot Setup / setup (push) Has been cancelled
Sync Primary Repository to GitHub Mirror / sync (push) Has been cancelled
107 lines
2.9 KiB
JavaScript
107 lines
2.9 KiB
JavaScript
/* @license http://creativecommons.org/publicdomain/zero/1.0/legalcode CC0-1.0 */
|
|
|
|
// This component is dedicated to the public domain. It uses the CC0
|
|
// as a formal dedication to the public domain and in circumstances where
|
|
// a public domain is not usable.
|
|
|
|
/**
|
|
* Use the refresh delay set in head
|
|
*/
|
|
function requestAjax1() {
|
|
requestAjax2(ajaxDelay);
|
|
}
|
|
|
|
/**
|
|
* Use the refresh delay specified
|
|
*
|
|
* @param refreshtime do not refresh if less than or equal to 0
|
|
* @since 0.9.58
|
|
*/
|
|
function requestAjax2(refreshtime) {
|
|
var url = ".ajax/xhr1.html";
|
|
var query = window.location.search;
|
|
var box = document.getElementById("searchbox");
|
|
if (box != null) {
|
|
// put in, remove, or replace value from search form
|
|
var search = box.value;
|
|
if (search.length > 0) {
|
|
if (query == null) {
|
|
query = "";
|
|
}
|
|
var q = new URLSearchParams(query);
|
|
q.set("nf_s", encodeURIComponent(search));
|
|
query = "?" + q.toString();
|
|
} else {
|
|
if (query != null) {
|
|
var q = new URLSearchParams(query);
|
|
q.delete("nf_s");
|
|
var newq = q.toString();
|
|
if (newq != null && newq.length > 0) {
|
|
query = "?" + newq;
|
|
} else {
|
|
query = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (query)
|
|
url += query;
|
|
// tell ajax not to setTimeout(), and do our own
|
|
// setTimeout() so we update the URL every time
|
|
ajax(url, "mainsection", -1);
|
|
if (refreshtime > 0) {
|
|
setTimeout(requestAjax1, refreshtime);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Local fetch, backend does remote query
|
|
*
|
|
* @since 0.9.67
|
|
*/
|
|
function requestAjaxRemote() {
|
|
var url = ".ajax/xhr2.html";
|
|
var query = window.location.search;
|
|
var box = document.getElementById("searchbox");
|
|
if (box != null) {
|
|
// put in, remove, or replace value from search form
|
|
var search = box.value;
|
|
if (search.length > 0) {
|
|
if (query == null) {
|
|
query = "";
|
|
}
|
|
var q = new URLSearchParams(query);
|
|
q.set("nf_s", encodeURIComponent(search));
|
|
query = "?" + q.toString();
|
|
} else {
|
|
if (query != null) {
|
|
var q = new URLSearchParams(query);
|
|
q.delete("nf_s");
|
|
var newq = q.toString();
|
|
if (newq != null && newq.length > 0) {
|
|
query = "?" + newq;
|
|
} else {
|
|
query = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (query)
|
|
url += query;
|
|
// FIXME this will insert the 'router is down' message on failure
|
|
ajax(url, "remoteresulttablebody", -1);
|
|
}
|
|
|
|
|
|
function initAjax() {
|
|
if (ajaxDelay > 0) {
|
|
setTimeout(requestAjax1, ajaxDelay);
|
|
}
|
|
}
|
|
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
initAjax();
|
|
}, true);
|
|
|
|
/* #license-end */
|