var itemCount = 0; var highestRanking = Infinity; var displayPage = function() { // For every search item that has already been displayed... $("#resultscontainer .searchresults").each( function(i) { // Apply the "earlierpage" class IFF the item is from an earlier page. $(this).toggleClass("earlierpage", parseFloat($(this).data("ranking")) > highestRanking); }); // For every search item from an earlier page... $("#resultscontainer .searchresults.earlierpage").each( function(i) { // Hide the item $(this).removeClass("currentpage"); $(this).hide(1000); }); // For every search item from a current or later page... $("#resultscontainer .searchresults:not(.earlierpage)").each( function(i) { // If we now have too many results, hide the lowest-ranking ones. if (i >= requestedResults) { $(this).removeClass("currentpage"); $(this).hide(1000); } else { $(this).addClass("currentpage"); $(this).show(1000); } }); $("#offset").html($("#resultscontainer .searchresults.earlierpage").length + 1); $("#itemscount").html($("#resultscontainer .searchresults.earlierpage").length + $("#resultscontainer .searchresults.currentpage").length); 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); }; var earlierPage = function() { // Find all items that are on an earlier page. var allEarlierItems = $("#resultscontainer .searchresults.earlierpage"); // If going back one page would put us at the beginning... if (allEarlierItems.length <= requestedResults) { highestRanking = Infinity; } // If going back one page would still be in the middle of the results... else { var earlierItem = allEarlierItems.get().reverse()[ requestedResults - 1 ]; highestRanking = parseFloat($(earlierItem).data("ranking")); console.log("highestRanking is now " + highestRanking); } // Update the display to show the new page. displayPage(); }; var laterPage = function() { // Find all items that are on a later page. var allCurrentAndLaterItems = $("#resultscontainer .searchresults:not(.earlierpage)"); // If going forward one page would put us past the end... if (allCurrentAndLaterItems.length <= requestedResults) { return; } // If going forward one page would still be in the middle of the results... else { var laterItem = allCurrentAndLaterItems.get(requestedResults); highestRanking = parseFloat($(laterItem).data("ranking")); console.log("highestRanking is now " + highestRanking); } // Update the display to show the new page. displayPage(); }; 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) { 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