/* * Copyright (C) 2017 Jeremy Rand, Ryszard Goń, luccioman * * 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 . */ /* Functions dedicated to (re)sort YaCy search results in the browser (configuration setting : search.jsresort=true) * See related style sheet env/yacysort.css */ var itemCount = 0; var highestRanking = Infinity; /* Set to true to enable browser console log traces */ var logEnabled = false; /* Indicates if the results feeders are running on the server */ var feedRunning = true; /** * Refresh the results page, checking each result CSS class depending on its position and ranking. * @param isPageChange when true this refresh is done in response to a page change */ var displayPage = function(isPageChange) { var offset = 1; var totalcount = 0; var itemscount = 0; // For every search item that has already been displayed and sorted ... $("#resultscontainer").find(".searchresults").each(function(i) { var item = $(this); var isFresh = item.hasClass("fresh"); if(isPageChange && isFresh) { /* When changing page, remove the 'fresh' mark from all results, * so that the related insertion/removal animations are not performed */ item.removeClass("fresh"); } totalcount++; var earlierPage = parseFloat(item.data("ranking")) > highestRanking; // Apply the "earlierpage" class IFF the item is from an earlier page. item.toggleClass("earlierpage", earlierPage); if (earlierPage) { item.removeClass("currentpage"); if(!isFresh) { /* Use the "hidden" CSS class when this item has not been recently inserted to hide it without unnecessary animation */ item.addClass("hidden"); } offset++; itemscount++; } else { var laterPage = ((i - offset + 1) >= requestedResults); item.toggleClass("laterpage", laterPage); // If we now have too many results, hide the lowest-ranking ones. if (laterPage) { item.removeClass("currentpage"); if(!isFresh) { /* Use the "hidden" CSS class when this item has not been recently inserted to hide it without unnecessary animation */ item.addClass("hidden"); } } else { item.removeClass("hidden"); item.addClass("currentpage"); itemscount++; } } }); // TODO: collected totalcount here seems to often be smaller than the "totalcount" that statistics() ends up with. Why is that? // TODO: The following statistical displays could maybe be moved to the // latestinfo() call. $("#offset").html(offset); $("#itemscount").html(itemscount); $("#resNav").html(renderPaginationButtons(offset, requestedResults, totalcount, null, theLocalQuery, true)); //latestinfo(); if(logEnabled) { console.log("Showing results " + ($("#resultscontainer").find(".searchresults.earlierpage").length + 1) + " - " + ($("#resultscontainer").find(".searchresults.earlierpage").length + requestedResults) + " out of " + $("#resultscontainer").find(".searchresults").length + "; notEarlierPage = " + $("#resultscontainer").find(".searchresults:not(.earlierpage)").length); } }; // pageNumber starts at 0. var numberedPage = function(pageNumber) { // Find all items. var allItems = $("#resultscontainer").find(".searchresults"); var itemNumber = pageNumber * requestedResults; // Check if the item number is too high. while ( allItems.length - 1 < itemNumber) { itemNumber = itemNumber - requestedResults; } // If the beginning of results is requested, set highestRanking to Infinity. if ( itemNumber <= 0 ) { highestRanking = Infinity; } else { var item = allItems.get(itemNumber); highestRanking = parseFloat($(item).data("ranking")); } if(logEnabled) { console.log("highestRanking is now " + highestRanking); } // Update the display to show the new page. displayPage(true); }; var processSidebarNavProtocols = function(navProtocolsOld, navProtocolsNew) { navProtocolsOld.find(".btn-group-xs").each( function(index, oldProtocol) { var protocolId = $(oldProtocol).attr("id"); var newProtocol = navProtocolsNew.find("#" + protocolId); // Check whether the protocol has been removed in the new sidebar. if (newProtocol.length === 0) { if(logEnabled) { console.log("Deleting nav-protocol..."); } $(oldProtocol).hide(1000); } } ); navProtocolsNew.find(".btn-group-xs").each( function(index, newProtocol) { var protocolId = $(newProtocol).attr("id"); var oldProtocol = navProtocolsOld.find("#" + protocolId); // Check whether the protocol exists in both the new and old sidebar if (oldProtocol.length === 1) { // Replace the HTML. // TODO: Look into smoother animations. $(oldProtocol).html($(newProtocol).html()).show(1000); } // Check whether the protocol has been added in the new sidebar. if (oldProtocol.length === 0) { // We need to insert the protocol in the right position. // TODO: Insert in the correct position instead of the end. $(newProtocol).hide(); $(navProtocolsOld).append($(newProtocol)); $(newProtocol).show(1000); } } ); }; // TODO: test this function // This is for sidebar items that are