on master help sign in
Add search result navigation support
commit0d6625e0703e3c4edfd0cdbca815795bb20c32b3 authorKirill Isakov <ukwt@ya.ru> dateSun 24 Apr 2016, 18:01 (10 years ago) parent1faf1b6
2 files changed+67−9
searx/static/plugins/css/vim_hotkeys.css+1 searx/static/plugins/js/vim_hotkeys.js+66−9
searx/static/plugins/css/vim_hotkeys.css+1
@@ -6,6 +6,7 @@
66 z-index: 9999999;
77 overflow-y: auto;
88 max-height: 80%;
9+ box-shadow: 0 0 1em;
910}
1011
1112.dflex {
searx/static/plugins/js/vim_hotkeys.js+66−9
@@ -1,4 +1,10 @@
11$(document).ready(function() {
2+ highlightResult('top')();
3+
4+ $('.result').on('click', function() {
5+ highlightResult($(this))();
6+ });
7+
28 var vimKeys = {
39 27: {
410 key: 'Escape',
@@ -50,13 +56,13 @@ $(document).ready(function() {
5056 },
5157 75: {
5258 key: 'k',
53− fun: previousResult,
59+ fun: highlightResult('up'),
5460 des: 'select previous search result',
5561 cat: 'Results'
5662 },
5763 74: {
5864 key: 'j',
59− fun: nextResult,
65+ fun: highlightResult('down'),
6066 des: 'select next search result',
6167 cat: 'Results'
6268 },
@@ -75,7 +81,7 @@ $(document).ready(function() {
7581 79: {
7682 key: 'o',
7783 fun: openResult(false),
78− des: 'open search result',
84+ des: 'open search result',
7985 cat: 'Results'
8086 },
8187 84: {
@@ -118,6 +124,50 @@ $(document).ready(function() {
118124 }
119125 });
120126
127+ function highlightResult(which) {
128+ return function() {
129+ var current = $('.result[data-vim-selected]');
130+ if (current.length === 0) {
131+ current = $('.result:first');
132+ if (current.length === 0) {
133+ return;
134+ }
135+ }
136+
137+ var next;
138+
139+ if (typeof which !== 'string') {
140+ next = which;
141+ } else {
142+ switch (which) {
143+ // case 'visible':
144+ // TODO
145+ case 'down':
146+ next = current.next('.result');
147+ if (next.length === 0) {
148+ next = $('.result:first');
149+ }
150+ break;
151+ case 'up':
152+ next = current.prev('.result');
153+ if (next.length === 0) {
154+ next = $('.result:last');
155+ }
156+ break;
157+ case 'bottom':
158+ next = $('.result:last');
159+ break;
160+ case 'top':
161+ default:
162+ next = $('.result:first');
163+ }
164+ }
165+
166+ current.removeAttr('data-vim-selected').removeClass('well well-sm');
167+ next.attr('data-vim-selected', 'true').addClass('well well-sm');
168+ }
169+ }
170+
121171 function reloadPage() {
122172 document.location.reload(false);
123173 }
@@ -146,12 +196,14 @@ $(document).ready(function() {
146196 function scrollPage(amount) {
147197 return function() {
148198 window.scrollBy(0, amount);
199+ highlightResult('visible')();
149200 }
150201 }
151202
152203 function scrollPageTo(position) {
153204 return function() {
154205 window.scrollTo(0, position);
206+ highlightResult('visible')();
155207 }
156208 }
157209
@@ -159,13 +211,18 @@ $(document).ready(function() {
159211 $('input#q').focus();
160212 }
161213
162− function previousResult() {
163− }
164−
165− function nextResult() {
166− }
167−
168214 function openResult(newTab) {
215+ return function() {
216+ var link = $('.result[data-vim-selected] .result_header a');
217+ if (link.length) {
218+ var url = link.attr('href');
219+ if (newTab) {
220+ window.open(url);
221+ } else {
222+ window.location.href = url;
223+ }
224+ }
225+ };
169226 }
170227
171228 function toggleHelp() {