1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
/*
* Copyright (C) 2006 - 2014 Martin Thelian, Alexander Schier, Michael Hamann,
* Michael Peter Christen, Franz Brausse, fuchsi
*
* This file is part of YaCy.
*
* YaCy is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* YaCy is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with YaCy. If not, see <http://www.gnu.org/licenses/>.
*/
function addHover() {
if (document.all&&document.getElementById) {
var divs = document.getElementsByTagName("div");
for (i=0; i<divs.length; i++) {
var node = divs[i];
if (node.className=="searchresults") {
node.onmouseover=function() {
this.className+=" hover";
}
node.onmouseout=function() {
this.className=this.className.replace(" hover", "");
}
}
}
}
}
function fadeOutBar() {
document.getElementById("progressbar").setAttribute('style',"transition:transform 0s;-webkit-transition:-webkit-transform 0s;backgroundColor:transparent;");
/* Also ensure the accessibility property for progress current value is set to 100% */
document.getElementById("progressbar").setAttribute("aria-valuenow", 100);
}
/**
* @param buttonsList the DOM list element containing the pagination buttons
* @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
* @param navurlbase the search url without pagination parameters
* @param localQuery when true the search query is limited to the YaCy peer local data
* @param jsResort when true results resorting with JavaScript is enabled
*/
function renderPaginationButtons(buttonsList, offset, itemsperpage, totalcount,
navurlbase, localQuery, jsResort) {
var buttons = buttonsList.getElementsByTagName("li");
if (buttons.length < 2) {
/* At least prev and next page buttons are expected to be here */
return;
}
var thispage = Math.floor(offset / itemsperpage);
var firstPage = thispage - (thispage % 10);
var prevPageElement = buttons[0];
var prevPageLink = prevPageElement.firstChild;
if (thispage == 0) {
/* First page : the prev page button is disabled */
prevPageElement.className = "disabled";
if (prevPageLink != null) {
prevPageLink.accessKey = null;
prevPageLink.href = "#";
}
} else {
prevPageElement.className = "";
if (prevPageLink != null) {
prevPageLink.accessKey = "p";
if (jsResort) {
prevPageLink.href = "javascript:numberedPage(" + (thispage - 1)
+ ");";
} else {
prevPageLink.href = (navurlbase + "&startRecord=" + ((thispage - 1) * itemsperpage));
}
}
}
var nextPageElement = buttons[buttons.length - 1];
var totalPagesNb = Math.floor(1 + ((totalcount - 1) / itemsperpage));
var numberofpages = Math.min(10, totalPagesNb - firstPage);
if (!numberofpages) {
numberofpages = 10;
}
if(numberofpages > 1) {
buttonsList.className = "pagination";
} else {
/* Hide the pagination buttons when there is less than one page of results */
buttonsList.className = "pagination hidden";
}
var btnIndex = 1;
var btnElement, pageLink;
/* Update existing buttons or add new ones according to the new pagination */
for (var i = firstPage; i < (firstPage + numberofpages); i++) {
if (btnIndex < (buttons.length - 1)) {
btnElement = buttons[btnIndex];
pageLink = btnElement.firstChild;
} else {
btnElement = document.createElement("li");
btnElement.id = "pageBtn" + btnIndex;
pageLink = document.createElement("a");
btnElement.appendChild(pageLink);
}
if (pageLink != null) {
if (i == thispage) {
btnElement.className = "active";
pageLink.href = "#";
} else {
btnElement.className = "";
if (jsResort) {
pageLink.href = "javascript:numberedPage(" + (i) + ");";
} else {
pageLink.href = navurlbase + "&startRecord=" + (i * itemsperpage);
}
}
pageLink.innerText = (i + 1);
}
if (btnIndex >= (buttons.length - 1)) {
/*
* Insert the newly created button now that all its modifications
* are done
*/
buttonsList.insertBefore(btnElement, buttons[buttons.length - 1]);
}
btnIndex++;
}
/* Remove existing buttons now in excess */
while (btnIndex < (buttons.length - 1)) {
buttonsList.removeChild(buttons[buttons.length - 2]);
}
var nextPageLink = nextPageElement.firstChild;
if ((localQuery && thispage >= (totalPagesNb - 1))
|| (!localQuery && thispage >= (numberofpages - 1))) {
/* Last page on a local query, or last fetchable page in p2p mode : the next page button is disabled */
nextPageElement.className = "disabled";
if (nextPageLink != null) {
nextPageLink.accessKey = null;
nextPageLink.href = "#";
}
} else {
nextPageElement.className = "";
if (nextPageLink != null) {
nextPageLink.accessKey = "n";
if (jsResort) {
nextPageLink.href = "javascript:numberedPage(" + (thispage + 1)
+ ");";
} else {
nextPageLink.href = navurlbase + "&startRecord="
+ ((thispage + 1) * itemsperpage);
}
}
}
}
/**
* Parses a string representing an integer value
*
* @param strIntValue
* formatted string
* @returns the number value or undefined when the string is undefined, or NaN
* when the string is not a number
*/
function parseFormattedInt(strIntValue) {
var inValue;
if(strIntValue != null && strIntValue.replace != null) {
/* Remove thousands separator and try to parse as integer */
intValue = parseInt(strIntValue.replace(/[\.\,]/g,''))
}
return intValue;
}
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);
var itemsperpageIntValue = parseFormattedInt(itemsperpage);
var feedingStatusElement = document.getElementById("feedingStatus");
if(feedingStatusElement != null) {
if(feedRunning) {
feedingStatusElement.style.visibility = "visible";
} else {
feedingStatusElement.style.visibility = "hidden";
}
}
/* Display the eventual button allowing to refresh the sort of cached results
* only when all feeds are terminated and when there is more than one result */
var resortCachedElement = document.getElementById("resortCached");
if(resortCachedElement != null) {
if(feedRunning) {
resortCachedElement.style.visibility = "hidden";
} else if(totalcountIntValue > 1){
resortCachedElement.style.visibility = "visible";
}
}
if (totalcountIntValue == 0) {
return;
}
var elementToUpdate = document.getElementById("offset");
if (offsetIntValue >= 0 && elementToUpdate != null) {
elementToUpdate.innerHTML = offset;
}
elementToUpdate = document.getElementById("startRecord");
if (offsetIntValue >= 0 && elementToUpdate != null) {
elementToUpdate.setAttribute('value', offsetIntValue - 1);
}
elementToUpdate = document.getElementById("itemscount");
if (itemscountIntValue >= 0 && elementToUpdate != null) {
elementToUpdate.firstChild.nodeValue = itemscount;
}
elementToUpdate = document.getElementById("totalcount");
if(elementToUpdate != null) {
elementToUpdate.firstChild.nodeValue = totalcount;
}
elementToUpdate = document.getElementById("localIndexCount");
if (elementToUpdate != null) {
elementToUpdate.firstChild.nodeValue = localIndexCount;
}
elementToUpdate = document.getElementById("remoteIndexCount");
if (elementToUpdate != null) {
elementToUpdate.firstChild.nodeValue = remoteIndexCount;
}
elementToUpdate = document.getElementById("remotePeerCount");
if (elementToUpdate != null) {
elementToUpdate.firstChild.nodeValue = remotePeerCount;
}
// compose page navigation
var progresseBarElement = document.getElementById("progressbar");
if (progresseBarElement.getAttribute('class') != "progress-bar progress-bar-success") {
var percent = 100 * (itemscountIntValue - offsetIntValue + 1) / itemsperpageIntValue;
if (percent == 100) {
progresseBarElement.setAttribute('style',"transition:transform 0s;-webkit-transition:-webkit-transform 0s;");
progresseBarElement.setAttribute('class',"progress-bar progress-bar-success");
window.setTimeout(fadeOutBar, 500);
} else {
progresseBarElement.setAttribute('aria-valuenow', percent);
}
progresseBarElement.setAttribute('style',"width:" + percent + "%");
}
var buttonsList = document.getElementById("paginationButtons");
if (buttonsList != null && !jsResort) {
renderPaginationButtons(buttonsList, offsetIntValue, itemsperpageIntValue, totalcountIntValue, navurlbase, localQuery, jsResort);
}
}
|