logo

searx

My custom branche(s) on searx, a meta-search engine git clone https://hacktivis.me/git/searx.git
commit: 7b48a663503018dd47b81c94afd9c4df6d62467a
parent 0d6625e0703e3c4edfd0cdbca815795bb20c32b3
Author: Kirill Isakov <ukwt@ya.ru>
Date:   Sun, 24 Apr 2016 21:04:53 +0600

Add auto page scrolling to selected result

Diffstat:

Msearx/static/plugins/js/vim_hotkeys.js49+++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 45 insertions(+), 4 deletions(-)

diff --git a/searx/static/plugins/js/vim_hotkeys.js b/searx/static/plugins/js/vim_hotkeys.js @@ -140,8 +140,21 @@ $(document).ready(function() { next = which; } else { switch (which) { - // case 'visible': - // TODO + case 'visible': + var top = $(window).scrollTop(); + var bot = top + $(window).height(); + var results = $('.result'); + + for (var i = 0; i < results.length; i++) { + next = $(results[i]); + var etop = next.offset().top; + var ebot = etop + next.height(); + + if ((ebot <= bot) && (etop > top)) { + break; + } + } + break; case 'down': next = current.next('.result'); if (next.length === 0) { @@ -163,8 +176,11 @@ $(document).ready(function() { } } - current.removeAttr('data-vim-selected').removeClass('well well-sm'); - next.attr('data-vim-selected', 'true').addClass('well well-sm'); + if (next) { + current.removeAttr('data-vim-selected').removeClass('well well-sm'); + next.attr('data-vim-selected', 'true').addClass('well well-sm'); + scrollPageToSelected(); + } } } @@ -193,6 +209,31 @@ $(document).ready(function() { } } + function scrollPageToSelected() { + var sel = $('.result[data-vim-selected]'); + if (sel.length !== 1) { + return; + } + + var wnd = $(window); + + var wtop = wnd.scrollTop(); + var etop = sel.offset().top; + + var offset = 30; + + if (wtop > etop) { + wnd.scrollTop(etop - offset); + } else { + var ebot = etop + sel.height(); + var wbot = wtop + wnd.height(); + + if (wbot < ebot) { + wnd.scrollTop(ebot - wnd.height() + offset); + } + } + } + function scrollPage(amount) { return function() { window.scrollBy(0, amount);