Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

Add UI for numbered page navigation when Javascript re-sorting is enabled.

JeremyRanda888254769c6
diff --git a/htroot/js/yacysearch.js b/htroot/js/yacysearch.js
index 8ae63aa59..3bb9001cc 100644
--- a/htroot/js/yacysearch.js
+++ b/htroot/js/yacysearch.js
@@ -42,9 +42,12 @@ function fadeOutBar() {
}
/**
+ * @param offset item number to start with
+ * @param itemsperpage count of items requested per page
+ * @param totalcount count of items available from YaCy node for this query
* @returns pagination buttons
*/
-function renderPaginationButtons(offset, itemsperpage, totalcount, navurlbase, localQuery) {
+function renderPaginationButtons(offset, itemsperpage, totalcount, navurlbase, localQuery, jsResort) {
var resnav = "<ul class=\"pagination\">";
var thispage = Math.floor(offset / itemsperpage);
var firstPage = thispage - (thispage % 10);
@@ -52,7 +55,11 @@ function renderPaginationButtons(offset, itemsperpage, totalcount, navurlbase, l
resnav += "<li class=\"disabled\"><a title=\"Previous page\" href=\"#\">&laquo;</a></li>";
} else {
resnav += "<li><a id=\"prevpage\" title=\"Previous page\" accesskey=\"p\" href=\"";
- resnav += (navurlbase + "&amp;startRecord=" + ((thispage - 1) * itemsperpage));
+ if (jsResort) {
+ resnav += ("javascript:numberedPage(" + (thispage - 1) + ");");
+ } else {
+ resnav += (navurlbase + "&amp;startRecord=" + ((thispage - 1) * itemsperpage));
+ }
resnav += "\">&laquo;</a></li>";
}
@@ -66,7 +73,11 @@ function renderPaginationButtons(offset, itemsperpage, totalcount, navurlbase, l
resnav += "</a></li>";
} else {
resnav += "<li><a href=\"";
- resnav += (navurlbase + "&amp;startRecord=" + (i * itemsperpage));
+ if (jsResort) {
+ resnav += ("javascript:numberedPage(" + (i) + ");");
+ } else {
+ resnav += (navurlbase + "&amp;startRecord=" + (i * itemsperpage));
+ }
resnav += "\">" + (i + 1) + "</a></li>";
}
}
@@ -74,7 +85,11 @@ function renderPaginationButtons(offset, itemsperpage, totalcount, navurlbase, l
resnav += "<li class=\"disabled\"><a href=\"#\" title=\"Next page\">&raquo;</a></li>";
} else {
resnav += "<li><a id=\"nextpage\" title=\"Next page\" accesskey=\"n\" href=\"";
- resnav += (navurlbase + "&amp;startRecord=" + ((thispage + 1) * itemsperpage));
+ if (jsResort) {
+ resnav += ("javascript:numberedPage(" + (thispage + 1) + ");");
+ } else {
+ resnav += (navurlbase + "&amp;startRecord=" + ((thispage + 1) * itemsperpage));
+ }
resnav += "\">&raquo;</a>";
}
resnav += "</ul>";
@@ -95,7 +110,7 @@ function parseFormattedInt(strIntValue) {
return intValue;
}
-function statistics(offset, itemscount, itemsperpage, totalcount, localIndexCount, remoteIndexCount, remotePeerCount, navurlbase, localQuery, feedRunning) {
+function statistics(offset, itemscount, itemsperpage, totalcount, localIndexCount, remoteIndexCount, remotePeerCount, navurlbase, localQuery, feedRunning, jsResort) {
var totalcountIntValue = parseFormattedInt(totalcount);
var offsetIntValue = parseFormattedInt(offset);
var itemscountIntValue = parseFormattedInt(itemscount);
@@ -174,7 +189,7 @@ function statistics(offset, itemscount, itemsperpage, totalcount, localIndexCoun
}
var resnavElement = document.getElementById("resNav");
if (resnavElement != null) {
- resnavElement.innerHTML = renderPaginationButtons(offsetIntValue, itemsperpageIntValue, totalcountIntValue, navurlbase, localQuery);
+ resnavElement.innerHTML = renderPaginationButtons(offsetIntValue, itemsperpageIntValue, totalcountIntValue, navurlbase, localQuery, jsResort);
}
}
diff --git a/htroot/js/yacysort.js b/htroot/js/yacysort.js
index e4aad608b..048ee145d 100644
--- a/htroot/js/yacysort.js
+++ b/htroot/js/yacysort.js
@@ -28,8 +28,20 @@ var displayPage = function() {
}
});
- $("#offset").html($("#resultscontainer .searchresults.earlierpage").length + 1);
- $("#itemscount").html($("#resultscontainer .searchresults.earlierpage").length + $("#resultscontainer .searchresults.currentpage").length);
+ // TODO: The following statistical displays could maybe be moved to the latestinfo() call.
+
+ var offset = $("#resultscontainer .searchresults.earlierpage").length + 1;
+ var itemscount = $("#resultscontainer .searchresults.earlierpage").length + $("#resultscontainer .searchresults.currentpage").length;
+
+ // TODO: This seems to often be smaller than the "totalcount" that statistics() ends up with. Why is that?
+ var totalcount = $("#resultscontainer .searchresults").length;
+
+ $("#offset").html(offset);
+ $("#itemscount").html(itemscount);
+
+ $("#resNav").html(renderPaginationButtons(offset, requestedResults, totalcount, null, theLocalQuery, true));
+
+ //latestinfo();
console.log("Showing results " + ($("#resultscontainer .searchresults.earlierpage").length + 1) + " - " + ($("#resultscontainer .searchresults.earlierpage").length + requestedResults) + " out of " + $("#resultscontainer .searchresults").length + "; notEarlierPage = " + $("#resultscontainer .searchresults:not(.earlierpage)").length);
};
diff --git a/htroot/yacysearch.html b/htroot/yacysearch.html
index ba95d5c12..82aff1d50 100644
--- a/htroot/yacysearch.html
+++ b/htroot/yacysearch.html
@@ -16,6 +16,7 @@
<script type="text/javascript">
var requestedResults = #[results]#;
var theEventID = "#[eventID]#";
+ var theLocalQuery = #[localQuery]#;
</script>
<script type="text/javascript" src="js/yacysort.js"></script>
#(/jsResort)#
@@ -209,11 +210,7 @@ document.getElementById("Enter").innerHTML = "search again";
::
::
::
- #(jsResort)#
- <span id="resNav" class="col-sm-12 col-md-12" style="display: inline;"></span>
- ::
- <p><br><br><a href="javascript:earlierPage();">Prev Page</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:laterPage();">Next Page</a></p>
- #(/jsResort)#
+ <span id="resNav" class="col-sm-12 col-md-12" style="display: inline;"></span>
::
#(/num-results)#
@@ -254,9 +251,9 @@ function latestinfo() {
if(rsp && rsp.offset != null) {
#(jsResort)#
- statistics(rsp.offset, rsp.itemscount, rsp.itemsperpage, rsp.totalcount, rsp.localIndexCount, rsp.remoteIndexCount, rsp.remotePeerCount, rsp.navurlBase, #[localQuery]#, rsp.feedRunning);
+ statistics(rsp.offset, rsp.itemscount, rsp.itemsperpage, rsp.totalcount, rsp.localIndexCount, rsp.remoteIndexCount, rsp.remotePeerCount, rsp.navurlBase, #[localQuery]#, rsp.feedRunning, false);
::
- statistics($("#resultscontainer .searchresults.earlierpage").length + 1, $("#resultscontainer .searchresults.earlierpage").length + $("#resultscontainer .searchresults.currentpage").length, rsp.itemsperpage, rsp.totalcount, rsp.localIndexCount, rsp.remoteIndexCount, rsp.remotePeerCount, rsp.navurlBase, #[localQuery]#, rsp.feedRunning);
+ statistics($("#resultscontainer .searchresults.earlierpage").length + 1, $("#resultscontainer .searchresults.earlierpage").length + $("#resultscontainer .searchresults.currentpage").length, rsp.itemsperpage, rsp.totalcount, rsp.localIndexCount, rsp.remoteIndexCount, rsp.remotePeerCount, rsp.navurlBase, #[localQuery]#, rsp.feedRunning, true);
#(/jsResort)#
if(rsp.feedRunning) {
/* Refresh statistics while server feeders are still running */