i2psnark: Search CSS and JS

WIP, more polishing todo
default theme only, others to follow
This commit is contained in:
zzz
2023-01-18 11:15:22 -05:00
parent d45df857d6
commit 1dbd94d52d
5 changed files with 123 additions and 8 deletions

View File

@ -342,7 +342,8 @@ public class I2PSnarkServlet extends BasicServlet {
"var deleteMessage1 = \"" + _t("Are you sure you want to delete the file \\''{0}\\'' (downloaded data will not be deleted) ?") + "\";\n" +
"var deleteMessage2 = \"" + _t("Are you sure you want to delete the torrent \\''{0}\\'' and all downloaded data?") + "\";\n" +
"</script>\n" +
"<script src=\".resources/js/delete.js?" + CoreVersion.VERSION + "\" type=\"text/javascript\"></script>\n");
"<script src=\".resources/js/delete.js?" + CoreVersion.VERSION + "\" type=\"text/javascript\"></script>\n" +
"<script src=\".resources/js/search.js?" + CoreVersion.VERSION + "\" type=\"text/javascript\"></script>\n");
}
out.write(HEADER_A + _themePath + HEADER_B);
@ -381,18 +382,24 @@ public class I2PSnarkServlet extends BasicServlet {
out.write(" <a href=\"" + t.baseURL + "\" class=\"snarkNav nav_tracker\" target=\"_blank\">" + t.name + "</a>\n");
}
}
if (_manager.getTorrents().size() > 1) {
}
// end snarkNavBar
out.write("</div>\n");
if (!isConfigure) {
String search = req.getParameter("s");
if (_manager.getTorrents().size() > 1 || (search != null && search.length() > 0)) {
out.write("<form class=\"search\" id = \"search\" action=\"" + _contextPath + "\" method=\"GET\">" +
"<input type=\"text\" name=\"s\" size=\"20\" class=\"search snarkNav\" id=\"searchbox\"");
"<input type=\"text\" name=\"s\" size=\"20\" class=\"search\" id=\"searchbox\"");
String s = req.getParameter("s");
if (s != null)
out.write(" value=\"" + DataHelper.escapeHTML(s) + '"');
out.write(">" +
"<input type=\"reset\" class=\"cancel snarkNav\" value=\"\">" +
"<input type=\"reset\" class=\"cancel\" id=\"searchcancel\" value=\"\">" +
"</form>\n");
}
}
out.write("</div>\n");
String newURL = req.getParameter("newURL");
if (newURL != null && newURL.trim().length() > 0 && req.getMethod().equals("GET"))
_manager.addMessage(_t("Click \"Add torrent\" button to fetch torrent"));
@ -846,7 +853,7 @@ public class I2PSnarkServlet extends BasicServlet {
*
* @param search non-null
* @param snarks unmodified
* @return null if no valid search, or matching torrents in same order, empty if no match
* @return null if no valid search, or matching torrents in same order
* @since 0.9.58
*/
private static List<Snark> search(String search, Collection<Snark> snarks) {

View File

@ -4,12 +4,54 @@
// 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("s", search);
query = "?" + q.toString();
} else {
if (query != null) {
var q = new URLSearchParams(query);
q.delete("s");
var newq = q.toString();
if (newq != null && newq.length > 0) {
query = "?" + newq;
} else {
query = null;
}
}
}
}
if (query)
url += query;
ajax(url, "mainsection", ajaxDelay);
// 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);
}
}
function initAjax() {

View File

@ -0,0 +1,32 @@
/* @license http://www.gnu.org/licenses/gpl-2.0.html GPL-2.0 */
/* see also licenses/LICENSE-GPLv2.txt */
/**
* Search form helpers
*
* @since 0.9.58
*/
function initSearch()
{
var sch = document.getElementById("search");
if (sch != null) {
var box = document.getElementById("searchbox");
sch.addEventListener("reset", function(event) {
if (box.value !== "") {
box.value = "";
requestAjax2(-1);
}
event.preventDefault();
});
box.addEventListener("input", function(event) {
requestAjax2(-1);
});
}
}
document.addEventListener("DOMContentLoaded", function() {
initSearch();
}, true);
/* @license-end */

View File

@ -229,6 +229,28 @@ _:-ms-lang(x), .snarkNav:last-child[href="/i2psnark/"] {
border-radius: 2px 0 0 2px;
}
#search {
display: inline-block;
float: right;
position: absolute;
top: 6px;
right: 3px;
}
#searchbox {
background: #f60 url(/themes/console/images/buttons/search.png) 7px center no-repeat !important;
margin: 2px 4px 2px 24px !important;
padding: 4px 32px 4px 32px !important;
color: black;
}
#searchcancel {
background: url(images/cancel.png);
margin: 2px 4px 2px -28px;
color: transparent;
border: none;
}
/* end topnav */
/* screenlogger */

View File

@ -6,6 +6,11 @@
var fails = 0;
/**
*
* @param refresh as of 0.9.58, if less than or equal to zero, do not reschedule
*
*/
function ajax(url, target, refresh) {
// native XMLHttpRequest object
if (window.XMLHttpRequest) {
@ -28,6 +33,11 @@ function ajax(url, target, refresh) {
}
}
/**
*
* @param refresh as of 0.9.58, if less than or equal to zero, do not reschedule
*
*/
function ajaxDone(url, target, refresh) {
// only if req is "loaded"
if (req.readyState == 4) {
@ -51,7 +61,9 @@ function ajaxDone(url, target, refresh) {
graph.style.backgroundImage = "url(/viewstat.jsp?stat=bw.combined&periodCount=20&width=220&height=50&hideLegend=true&hideGrid=true&time=" + new Date().getTime();
}
setTimeout(function() {ajax(url, target, refresh);}, refresh);
if (refresh > 0) {
setTimeout(function() {ajax(url, target, refresh);}, refresh);
}
}
}