diff --git a/static/js/index.js b/static/js/index.js index 2c0cbfc..7936cdc 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -56,13 +56,20 @@ var searchResultsPage = 1; */ var previousResult = function(){ var currResult = $(".display-all"); - if(currResult.length) - currResult.closest(".result").prev(".result").each(function(){ - $('html,body').stop().animate({ - scrollTop: $(this).offset().top - ( - $(window).height() - $(this).outerHeight(true)) / 2 - }, 140); - }); + if(currResult.length) { + currResult.removeClass('display-all'); + currResult = currResult.closest(".result").prev(".result"); + } else { + currResult = $(document.querySelectorAll('.result')[0]); + } + + currResult.addClass('display-all'); + currResult.each(function(){ + $('html,body').stop().animate({ + scrollTop: $(this).offset().top - ( + $(window).height() - $(this).outerHeight(true)) / 2 + }, 140); + }); }; /* @@ -71,13 +78,20 @@ var searchResultsPage = 1; */ var nextResult = function(){ var currResult = $(".display-all"); - if(currResult.length) - currResult.closest(".result").next(".result").each(function(){ - $('html,body').stop().animate({ - scrollTop: $(this).offset().top - ( - $(window).height() - $(this).outerHeight(true)) / 2 - }, 140); - }); + if(currResult.length) { + currResult.removeClass('display-all'); + currResult = currResult.closest(".result").next(".result"); + } else { + currResult = $(document.querySelectorAll('.result')[0]); + } + + currResult.addClass('display-all'); + currResult.each(function(){ + $('html,body').stop().animate({ + scrollTop: $(this).offset().top - ( + $(window).height() - $(this).outerHeight(true)) / 2 + }, 140); + }); }; var hotkeyActions = { @@ -260,24 +274,26 @@ function createResult(codelet) { codeElt.innerHTML = '