mirror of
https://github.com/searxng/searxng.git
synced 2025-09-02 16:28:33 +02:00
[enh] simple theme: image detail
When an image is selected, the detail with the full size image is displayed on the right side of the screen (or full screen on tablet and phone). When Javascript is disabled, the thumbnail is a linked to the full size image, as it was before. When the image proxy is enabled, the full size image is also proxied, in consequence this commit increases the bandwidth usage of instances. The detail can be closed by the close button or the Esc key. It is possible to go to the next and previous images using the j and k keys or the button on the top right of the screen.
This commit is contained in:
parent
2624034cd6
commit
fd374d6322
8 changed files with 390 additions and 31 deletions
|
@ -4,7 +4,7 @@
|
|||
searxng.ready(function() {
|
||||
|
||||
searxng.on('.result', 'click', function() {
|
||||
highlightResult(this)(true);
|
||||
highlightResult(this)(true);
|
||||
});
|
||||
|
||||
searxng.on('.result a', 'focus', function(e) {
|
||||
|
@ -124,9 +124,7 @@ searxng.ready(function() {
|
|||
if (Object.prototype.hasOwnProperty.call(vimKeys, e.keyCode) && !e.ctrlKey && !e.altKey && !e.shiftKey && !e.metaKey) {
|
||||
var tagName = e.target.tagName.toLowerCase();
|
||||
if (e.keyCode === 27) {
|
||||
if (tagName === 'input' || tagName === 'select' || tagName === 'textarea') {
|
||||
vimKeys[e.keyCode].fun();
|
||||
}
|
||||
vimKeys[e.keyCode].fun(e);
|
||||
} else {
|
||||
if (e.target === document.body || tagName === 'a' || tagName === 'button') {
|
||||
e.preventDefault();
|
||||
|
@ -213,9 +211,12 @@ searxng.ready(function() {
|
|||
document.location.reload(true);
|
||||
}
|
||||
|
||||
function removeFocus() {
|
||||
if (document.activeElement) {
|
||||
function removeFocus(e) {
|
||||
const tagName = e.target.tagName.toLowerCase();
|
||||
if (document.activeElement && (tagName === 'input' || tagName === 'select' || tagName === 'textarea')) {
|
||||
document.activeElement.blur();
|
||||
} else {
|
||||
searxng.closeDetail();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -285,6 +286,9 @@ searxng.ready(function() {
|
|||
function openResult(newTab) {
|
||||
return function() {
|
||||
var link = document.querySelector('.result[data-vim-selected] h3 a');
|
||||
if (link === null) {
|
||||
link = document.querySelector('.result[data-vim-selected] > a');
|
||||
}
|
||||
if (link !== null) {
|
||||
var url = link.getAttribute('href');
|
||||
if (newTab) {
|
||||
|
@ -368,4 +372,8 @@ searxng.ready(function() {
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
searxng.scrollPageToSelected = scrollPageToSelected;
|
||||
searxng.selectNext = highlightResult('down');
|
||||
searxng.selectPrevious = highlightResult('up');
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
'use strict';
|
||||
|
||||
searxng.ready(function() {
|
||||
searxng.image_thumbnail_layout = new searxng.ImageLayout('#urls', '#urls .result-images', 'img.image_thumbnail', 10, 200);
|
||||
searxng.image_thumbnail_layout = new searxng.ImageLayout('#urls', '#urls .result-images', 'img.image_thumbnail', 14, 6, 200);
|
||||
searxng.image_thumbnail_layout.watch();
|
||||
|
||||
searxng.on('.btn-collapse', 'click', function() {
|
||||
|
@ -31,17 +31,74 @@
|
|||
}
|
||||
});
|
||||
|
||||
w.addEventListener('scroll', function() {
|
||||
var e = d.getElementById('backToTop'),
|
||||
scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
|
||||
if (e !== null) {
|
||||
if (scrollTop >= 200) {
|
||||
e.style.opacity = 1;
|
||||
} else {
|
||||
e.style.opacity = 0;
|
||||
function selectImage(e) {
|
||||
/*eslint no-unused-vars: 0*/
|
||||
let t = e.target;
|
||||
while (t && t.nodeName != 'ARTICLE') {
|
||||
t = t.parentNode;
|
||||
}
|
||||
if (t) {
|
||||
// load full size image in background
|
||||
const imgElement = t.querySelector('.result-images-source img');
|
||||
const thumbnailElement = t.querySelector('.image_thumbnail');
|
||||
const detailElement = t.querySelector('.detail');
|
||||
if (imgElement) {
|
||||
const imgSrc = imgElement.getAttribute('data-src');
|
||||
if (imgSrc) {
|
||||
const loader = d.createElement('div');
|
||||
const imgLoader = new Image();
|
||||
|
||||
loader.classList.add('loader');
|
||||
detailElement.appendChild(loader);
|
||||
|
||||
imgLoader.onload = e => {
|
||||
imgElement.src = imgSrc;
|
||||
loader.remove();
|
||||
};
|
||||
imgLoader.onerror = e => {
|
||||
loader.remove();
|
||||
};
|
||||
imgLoader.src = imgSrc;
|
||||
imgElement.src = thumbnailElement.src;
|
||||
imgElement.removeAttribute('data-src');
|
||||
}
|
||||
}
|
||||
}
|
||||
d.getElementById('results').classList.add('image-detail-open');
|
||||
searxng.image_thumbnail_layout.align();
|
||||
searxng.scrollPageToSelected();
|
||||
}
|
||||
|
||||
searxng.closeDetail = function(e) {
|
||||
d.getElementById('results').classList.remove('image-detail-open');
|
||||
searxng.image_thumbnail_layout.align();
|
||||
searxng.scrollPageToSelected();
|
||||
}
|
||||
|
||||
searxng.on('.result-images', 'click', e => {
|
||||
e.preventDefault();
|
||||
selectImage(e);
|
||||
});
|
||||
searxng.on('.result-images a', 'focus', selectImage, true);
|
||||
searxng.on('.result-detail-close', 'click', e => {
|
||||
e.preventDefault();
|
||||
searxng.closeDetail();
|
||||
});
|
||||
searxng.on('.result-detail-previous', 'click', e => searxng.selectPrevious(false));
|
||||
searxng.on('.result-detail-next', 'click', e => searxng.selectNext(false));
|
||||
|
||||
w.addEventListener('scroll', function() {
|
||||
var e = d.getElementById('backToTop'),
|
||||
scrollTop = document.documentElement.scrollTop || document.body.scrollTop,
|
||||
results = d.getElementById('results');
|
||||
if (e !== null) {
|
||||
if (scrollTop >= 100) {
|
||||
results.classList.add('scrolling');
|
||||
} else {
|
||||
results.classList.remove('scrolling');
|
||||
}
|
||||
}
|
||||
}, true);
|
||||
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue