diff --git a/searx/static/themes/oscar/src/js/plugins/infinite_scroll.js b/searx/static/themes/oscar/src/js/plugins/infinite_scroll.js index f3b3767ff..3065d17c9 100644 --- a/searx/static/themes/oscar/src/js/plugins/infinite_scroll.js +++ b/searx/static/themes/oscar/src/js/plugins/infinite_scroll.js @@ -1,66 +1,66 @@ if (searxng.plugins['searx.plugins.infinite_scroll']) { -function hasScrollbar() { - var root = document.compatMode=='BackCompat'? document.body : document.documentElement; - return root.scrollHeight>root.clientHeight; -} + function hasScrollbar() { + var root = document.compatMode=='BackCompat'? document.body : document.documentElement; + return root.scrollHeight>root.clientHeight; + } -function loadNextPage() { - var formData = $('#pagination form:last').serialize(); - if (formData) { - $('#pagination').html('
'); - $.ajax({ - type: "POST", - url: $('#search_form').prop('action'), - data: formData, - dataType: 'html', - success: function(data) { - var body = $(data); - $('#pagination').remove(); - $('#main_results').append('
'); - $('#main_results').append(body.find('.result')); - $('#main_results').append(body.find('#pagination')); - if(!hasScrollbar()) { - loadNextPage(); + function loadNextPage() { + var formData = $('#pagination form:last').serialize(); + if (formData) { + $('#pagination').html('
'); + $.ajax({ + type: "POST", + url: $('#search_form').prop('action'), + data: formData, + dataType: 'html', + success: function(data) { + var body = $(data); + $('#pagination').remove(); + $('#main_results').append('
'); + $('#main_results').append(body.find('.result')); + $('#main_results').append(body.find('#pagination')); + if(!hasScrollbar()) { + loadNextPage(); + } } - } - }); + }); + } } -} -$(document).ready(function() { - var win = $(window); - if(!hasScrollbar()) { - loadNextPage(); - } - win.scroll(function() { - $("#pagination button").css("visibility", "hidden"); - if ($(document).height() - win.height() - win.scrollTop() < 150) { + $(document).ready(function() { + var win = $(window); + if(!hasScrollbar()) { loadNextPage(); } + win.scroll(function() { + $("#pagination button").css("visibility", "hidden"); + if ($(document).height() - win.height() - win.scrollTop() < 150) { + loadNextPage(); + } + }); }); -}); -const style = document.createElement('style'); -style.textContent = ` -@keyframes rotate-forever { - 0% { transform: rotate(0deg) } - 100% { transform: rotate(360deg) } -} -.loading-spinner { - animation-duration: 0.75s; - animation-iteration-count: infinite; - animation-name: rotate-forever; - animation-timing-function: linear; - height: 30px; - width: 30px; - border: 8px solid #666; - border-right-color: transparent; - border-radius: 50% !important; - margin: 0 auto; -} -#pagination button { - visibility: hidden; -} -`; -document.head.append(style); + const style = document.createElement('style'); + style.textContent = ` + @keyframes rotate-forever { + 0% { transform: rotate(0deg) } + 100% { transform: rotate(360deg) } + } + .loading-spinner { + animation-duration: 0.75s; + animation-iteration-count: infinite; + animation-name: rotate-forever; + animation-timing-function: linear; + height: 30px; + width: 30px; + border: 8px solid #666; + border-right-color: transparent; + border-radius: 50% !important; + margin: 0 auto; + } + #pagination button { + visibility: hidden; + } + `; + document.head.append(style); } diff --git a/searx/static/themes/oscar/src/js/plugins/search_on_category_select.js b/searx/static/themes/oscar/src/js/plugins/search_on_category_select.js index 80876606a..c270b8c11 100644 --- a/searx/static/themes/oscar/src/js/plugins/search_on_category_select.js +++ b/searx/static/themes/oscar/src/js/plugins/search_on_category_select.js @@ -1,44 +1,44 @@ if (searxng.plugins['searx.plugins.search_on_category_select']) { -$(document).ready(function() { - if($('#q').length) { - $('#categories label').click(function(e) { - $('#categories input[type="checkbox"]').each(function(i, checkbox) { - $(checkbox).prop('checked', false); + $(document).ready(function() { + if($('#q').length) { + $('#categories label').click(function(e) { + $('#categories input[type="checkbox"]').each(function(i, checkbox) { + $(checkbox).prop('checked', false); + }); + $(document.getElementById($(this).attr("for"))).prop('checked', true); + if($('#q').val()) { + if (getHttpRequest() == "GET") { + $('#search_form').attr('action', $('#search_form').serialize()); + } + $('#search_form').submit(); + } + return false; }); - $(document.getElementById($(this).attr("for"))).prop('checked', true); - if($('#q').val()) { - if (getHttpRequest() == "GET") { - $('#search_form').attr('action', $('#search_form').serialize()); + $('#time-range').change(function(e) { + if($('#q').val()) { + if (getHttpRequest() == "GET") { + $('#search_form').attr('action', $('#search_form').serialize()); + } + $('#search_form').submit(); } - $('#search_form').submit(); - } - return false; - }); - $('#time-range').change(function(e) { - if($('#q').val()) { - if (getHttpRequest() == "GET") { - $('#search_form').attr('action', $('#search_form').serialize()); + }); + $('#language').change(function(e) { + if($('#q').val()) { + if (getHttpRequest() == "GET") { + $('#search_form').attr('action', $('#search_form').serialize()); + } + $('#search_form').submit(); } - $('#search_form').submit(); - } - }); - $('#language').change(function(e) { - if($('#q').val()) { - if (getHttpRequest() == "GET") { - $('#search_form').attr('action', $('#search_form').serialize()); - } - $('#search_form').submit(); - } - }); - } -}); + }); + } + }); -function getHttpRequest() { - httpRequest = "POST"; - urlParams = new URLSearchParams(window.location.search); - if (urlParams.has('method')) { - httpRequest = urlParams.get('method'); + function getHttpRequest() { + httpRequest = "POST"; + urlParams = new URLSearchParams(window.location.search); + if (urlParams.has('method')) { + httpRequest = urlParams.get('method'); + } + return httpRequest; } - return httpRequest; -} } diff --git a/searx/static/themes/oscar/src/js/plugins/vim_hotkeys.js b/searx/static/themes/oscar/src/js/plugins/vim_hotkeys.js index 56b921ffa..35f351591 100644 --- a/searx/static/themes/oscar/src/js/plugins/vim_hotkeys.js +++ b/searx/static/themes/oscar/src/js/plugins/vim_hotkeys.js @@ -1,378 +1,378 @@ if (searxng.plugins['searx.plugins.vim_hotkeys']) { -$(document).ready(function() { - highlightResult('top')(); + $(document).ready(function() { + highlightResult('top')(); - $('.result').on('click', function() { - highlightResult($(this))(); - }); - - var vimKeys = { - 27: { - key: 'Escape', - fun: removeFocus, - des: 'remove focus from the focused input', - cat: 'Control' - }, - 73: { - key: 'i', - fun: searchInputFocus, - des: 'focus on the search input', - cat: 'Control' - }, - 66: { - key: 'b', - fun: scrollPage(-window.innerHeight), - des: 'scroll one page up', - cat: 'Navigation' - }, - 70: { - key: 'f', - fun: scrollPage(window.innerHeight), - des: 'scroll one page down', - cat: 'Navigation' - }, - 85: { - key: 'u', - fun: scrollPage(-window.innerHeight / 2), - des: 'scroll half a page up', - cat: 'Navigation' - }, - 68: { - key: 'd', - fun: scrollPage(window.innerHeight / 2), - des: 'scroll half a page down', - cat: 'Navigation' - }, - 71: { - key: 'g', - fun: scrollPageTo(-document.body.scrollHeight, 'top'), - des: 'scroll to the top of the page', - cat: 'Navigation' - }, - 86: { - key: 'v', - fun: scrollPageTo(document.body.scrollHeight, 'bottom'), - des: 'scroll to the bottom of the page', - cat: 'Navigation' - }, - 75: { - key: 'k', - fun: highlightResult('up'), - des: 'select previous search result', - cat: 'Results' - }, - 74: { - key: 'j', - fun: highlightResult('down'), - des: 'select next search result', - cat: 'Results' - }, - 80: { - key: 'p', - fun: pageButtonClick(0), - des: 'go to previous page', - cat: 'Results' - }, - 78: { - key: 'n', - fun: pageButtonClick(1), - des: 'go to next page', - cat: 'Results' - }, - 79: { - key: 'o', - fun: openResult(false), - des: 'open search result', - cat: 'Results' - }, - 84: { - key: 't', - fun: openResult(true), - des: 'open the result in a new tab', - cat: 'Results' - }, - 82: { - key: 'r', - fun: reloadPage, - des: 'reload page from the server', - cat: 'Control' - }, - 72: { - key: 'h', - fun: toggleHelp, - des: 'toggle help window', - cat: 'Other' - } - }; - - $(document).keydown(function(e) { - // check for modifiers so we don't break browser's hotkeys - if (vimKeys.hasOwnProperty(e.keyCode) - && !e.ctrlKey - && !e.altKey - && !e.shiftKey - && !e.metaKey) - { - if (e.keyCode === 27) { - if (e.target.tagName.toLowerCase() === 'input') { - vimKeys[e.keyCode].fun(); - } - } else { - if (e.target === document.body) { - e.preventDefault(); - vimKeys[e.keyCode].fun(); - } - } - } - }); - - function nextResult(current, direction) { - var next = current[direction](); - while (!next.is('.result') && next.length !== 0) { - next = next[direction](); - } - return next - } - - function highlightResult(which) { - return function() { - var current = $('.result[data-vim-selected]'); - if (current.length === 0) { - current = $('.result:first'); - if (current.length === 0) { - return; - } - } - - var next; - - if (typeof which !== 'string') { - next = which; - } else { - switch (which) { - 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 = nextResult(current, 'next'); - if (next.length === 0) { - next = $('.result:first'); - } - break; - case 'up': - next = nextResult(current, 'prev'); - if (next.length === 0) { - next = $('.result:last'); - } - break; - case 'bottom': - next = $('.result:last'); - break; - case 'top': - default: - next = $('.result:first'); - } - } - - if (next) { - current.removeAttr('data-vim-selected').removeClass('well well-sm'); - next.attr('data-vim-selected', 'true').addClass('well well-sm'); - scrollPageToSelected(); - } - } - } - - function reloadPage() { - document.location.reload(false); - } - - function removeFocus() { - if (document.activeElement) { - document.activeElement.blur(); - } - } - - function pageButtonClick(num) { - return function() { - var buttons = $('div#pagination button[type="submit"]'); - if (buttons.length !== 2) { - console.log('page navigation with this theme is not supported'); - return; - } - if (num >= 0 && num < buttons.length) { - buttons[num].click(); - } else { - console.log('pageButtonClick(): invalid argument'); - } - } - } - - 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); - highlightResult('visible')(); - } - } - - function scrollPageTo(position, nav) { - return function() { - window.scrollTo(0, position); - highlightResult(nav)(); - } - } - - function searchInputFocus() { - $('input#q').focus(); - } - - function openResult(newTab) { - return function() { - var link = $('.result[data-vim-selected] .result_header a'); - if (link.length) { - var url = link.attr('href'); - if (newTab) { - window.open(url); - } else { - window.location.href = url; - } - } - }; - } - - function toggleHelp() { - var helpPanel = $('#vim-hotkeys-help'); - if (helpPanel.length) { - helpPanel.toggleClass('hidden'); - return; - } - - var categories = {}; - - for (var k in vimKeys) { - var key = vimKeys[k]; - categories[key.cat] = categories[key.cat] || []; - categories[key.cat].push(key); - } - - var sorted = Object.keys(categories).sort(function(a, b) { - return categories[b].length - categories[a].length; + $('.result').on('click', function() { + highlightResult($(this))(); }); - if (sorted.length === 0) { - return; + var vimKeys = { + 27: { + key: 'Escape', + fun: removeFocus, + des: 'remove focus from the focused input', + cat: 'Control' + }, + 73: { + key: 'i', + fun: searchInputFocus, + des: 'focus on the search input', + cat: 'Control' + }, + 66: { + key: 'b', + fun: scrollPage(-window.innerHeight), + des: 'scroll one page up', + cat: 'Navigation' + }, + 70: { + key: 'f', + fun: scrollPage(window.innerHeight), + des: 'scroll one page down', + cat: 'Navigation' + }, + 85: { + key: 'u', + fun: scrollPage(-window.innerHeight / 2), + des: 'scroll half a page up', + cat: 'Navigation' + }, + 68: { + key: 'd', + fun: scrollPage(window.innerHeight / 2), + des: 'scroll half a page down', + cat: 'Navigation' + }, + 71: { + key: 'g', + fun: scrollPageTo(-document.body.scrollHeight, 'top'), + des: 'scroll to the top of the page', + cat: 'Navigation' + }, + 86: { + key: 'v', + fun: scrollPageTo(document.body.scrollHeight, 'bottom'), + des: 'scroll to the bottom of the page', + cat: 'Navigation' + }, + 75: { + key: 'k', + fun: highlightResult('up'), + des: 'select previous search result', + cat: 'Results' + }, + 74: { + key: 'j', + fun: highlightResult('down'), + des: 'select next search result', + cat: 'Results' + }, + 80: { + key: 'p', + fun: pageButtonClick(0), + des: 'go to previous page', + cat: 'Results' + }, + 78: { + key: 'n', + fun: pageButtonClick(1), + des: 'go to next page', + cat: 'Results' + }, + 79: { + key: 'o', + fun: openResult(false), + des: 'open search result', + cat: 'Results' + }, + 84: { + key: 't', + fun: openResult(true), + des: 'open the result in a new tab', + cat: 'Results' + }, + 82: { + key: 'r', + fun: reloadPage, + des: 'reload page from the server', + cat: 'Control' + }, + 72: { + key: 'h', + fun: toggleHelp, + des: 'toggle help window', + cat: 'Other' + } + }; + + $(document).keydown(function(e) { + // check for modifiers so we don't break browser's hotkeys + if (vimKeys.hasOwnProperty(e.keyCode) + && !e.ctrlKey + && !e.altKey + && !e.shiftKey + && !e.metaKey) + { + if (e.keyCode === 27) { + if (e.target.tagName.toLowerCase() === 'input') { + vimKeys[e.keyCode].fun(); + } + } else { + if (e.target === document.body) { + e.preventDefault(); + vimKeys[e.keyCode].fun(); + } + } + } + }); + + function nextResult(current, direction) { + var next = current[direction](); + while (!next.is('.result') && next.length !== 0) { + next = next[direction](); + } + return next } - var html = '
'; - html += '
'; + function highlightResult(which) { + return function() { + var current = $('.result[data-vim-selected]'); + if (current.length === 0) { + current = $('.result:first'); + if (current.length === 0) { + return; + } + } - html += '
'; - html += '
'; - html += '

How to navigate searx with Vim-like hotkeys

'; - html += '
'; // col-sm-12 - html += '
'; // row + var next; - for (var i = 0; i < sorted.length; i++) { - var cat = categories[sorted[i]]; + if (typeof which !== 'string') { + next = which; + } else { + switch (which) { + case 'visible': + var top = $(window).scrollTop(); + var bot = top + $(window).height(); + var results = $('.result'); - var lastCategory = i === (sorted.length - 1); - var first = i % 2 === 0; + for (var i = 0; i < results.length; i++) { + next = $(results[i]); + var etop = next.offset().top; + var ebot = etop + next.height(); - if (first) { - html += '
'; - } - html += '
'; + if ((ebot <= bot) && (etop > top)) { + break; + } + } + break; + case 'down': + next = nextResult(current, 'next'); + if (next.length === 0) { + next = $('.result:first'); + } + break; + case 'up': + next = nextResult(current, 'prev'); + if (next.length === 0) { + next = $('.result:last'); + } + break; + case 'bottom': + next = $('.result:last'); + break; + case 'top': + default: + next = $('.result:first'); + } + } - html += '
'; - html += '
' + cat[0].cat + '
'; - html += '
'; - html += '
    '; - - for (var cj in cat) { - html += '
  • ' + cat[cj].key + ' ' + cat[cj].des + '
  • '; - } - - html += '
'; - html += '
'; // panel-body - html += '
'; // panel - html += '
'; // col-sm-* - - if (!first || lastCategory) { - html += '
'; // row + if (next) { + current.removeAttr('data-vim-selected').removeClass('well well-sm'); + next.attr('data-vim-selected', 'true').addClass('well well-sm'); + scrollPageToSelected(); + } } } - html += '
'; // container-fluid - html += '
'; // vim-hotkeys-help + function reloadPage() { + document.location.reload(false); + } - $('body').append(html); + function removeFocus() { + if (document.activeElement) { + document.activeElement.blur(); + } + } + + function pageButtonClick(num) { + return function() { + var buttons = $('div#pagination button[type="submit"]'); + if (buttons.length !== 2) { + console.log('page navigation with this theme is not supported'); + return; + } + if (num >= 0 && num < buttons.length) { + buttons[num].click(); + } else { + console.log('pageButtonClick(): invalid argument'); + } + } + } + + 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); + highlightResult('visible')(); + } + } + + function scrollPageTo(position, nav) { + return function() { + window.scrollTo(0, position); + highlightResult(nav)(); + } + } + + function searchInputFocus() { + $('input#q').focus(); + } + + function openResult(newTab) { + return function() { + var link = $('.result[data-vim-selected] .result_header a'); + if (link.length) { + var url = link.attr('href'); + if (newTab) { + window.open(url); + } else { + window.location.href = url; + } + } + }; + } + + function toggleHelp() { + var helpPanel = $('#vim-hotkeys-help'); + if (helpPanel.length) { + helpPanel.toggleClass('hidden'); + return; + } + + var categories = {}; + + for (var k in vimKeys) { + var key = vimKeys[k]; + categories[key.cat] = categories[key.cat] || []; + categories[key.cat].push(key); + } + + var sorted = Object.keys(categories).sort(function(a, b) { + return categories[b].length - categories[a].length; + }); + + if (sorted.length === 0) { + return; + } + + var html = '
'; + html += '
'; + + html += '
'; + html += '
'; + html += '

How to navigate searx with Vim-like hotkeys

'; + html += '
'; // col-sm-12 + html += '
'; // row + + for (var i = 0; i < sorted.length; i++) { + var cat = categories[sorted[i]]; + + var lastCategory = i === (sorted.length - 1); + var first = i % 2 === 0; + + if (first) { + html += '
'; + } + html += '
'; + + html += '
'; + html += '
' + cat[0].cat + '
'; + html += '
'; + html += '
    '; + + for (var cj in cat) { + html += '
  • ' + cat[cj].key + ' ' + cat[cj].des + '
  • '; + } + + html += '
'; + html += '
'; // panel-body + html += '
'; // panel + html += '
'; // col-sm-* + + if (!first || lastCategory) { + html += '
'; // row + } + } + + html += '
'; // container-fluid + html += '
'; // vim-hotkeys-help + + $('body').append(html); + } + }); + + const style = document.createElement('style'); + style.textContent = ` + .vim-hotkeys-help { + position: fixed; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + z-index: 9999999; + overflow-y: auto; + max-height: 80%; + box-shadow: 0 0 1em; } -}); -const style = document.createElement('style'); -style.textContent = ` -.vim-hotkeys-help { - position: fixed; - top: 50%; - left: 50%; - transform: translate(-50%, -50%); - z-index: 9999999; - overflow-y: auto; - max-height: 80%; - box-shadow: 0 0 1em; -} + .dflex { + display: -webkit-box; /* OLD - iOS 6-, Safari 3.1-6 */ + display: -moz-box; /* OLD - Firefox 19- (buggy but mostly works) */ + display: -ms-flexbox; /* TWEENER - IE 10 */ + display: -webkit-flex; /* NEW - Chrome */ + display: flex; /* NEW, Spec - Opera 12.1, Firefox 20+ */ + } -.dflex { - display: -webkit-box; /* OLD - iOS 6-, Safari 3.1-6 */ - display: -moz-box; /* OLD - Firefox 19- (buggy but mostly works) */ - display: -ms-flexbox; /* TWEENER - IE 10 */ - display: -webkit-flex; /* NEW - Chrome */ - display: flex; /* NEW, Spec - Opera 12.1, Firefox 20+ */ -} - -.iflex { - -webkit-box-flex: 1; /* OLD - iOS 6-, Safari 3.1-6 */ - -moz-box-flex: 1; /* OLD - Firefox 19- */ - -webkit-flex: 1; /* Chrome */ - -ms-flex: 1; /* IE 10 */ - flex: 1; /* NEW, Spec - Opera 12.1, Firefox 20+ */ -} -`; -document.head.append(style); + .iflex { + -webkit-box-flex: 1; /* OLD - iOS 6-, Safari 3.1-6 */ + -moz-box-flex: 1; /* OLD - Firefox 19- */ + -webkit-flex: 1; /* Chrome */ + -ms-flex: 1; /* IE 10 */ + flex: 1; /* NEW, Spec - Opera 12.1, Firefox 20+ */ + } + `; + document.head.append(style); }