diff options
| author | luccioman <luccioman@users.noreply.github.com> | 2018-08-24 09:13:12 +0200 |
|---|---|---|
| committer | luccioman <luccioman@users.noreply.github.com> | 2018-08-24 09:13:12 +0200 |
| commit | 1b866c60767e6a376e0c8a213054b41accf1c2bc (patch) | |
| tree | 44c5ac3a4869befab9c5260f5c616ddb819a1732 /htroot/js | |
| parent | d03c098b54704f1e64803ee6ff8f487af6c20d11 (diff) | |
Added possibility to hide or show image results with rendering errors
When searching images, thumbnails that could not be rendered (because of
a load error such as HTTP 404, networking issue or an internal error on
the rendering servlet) are now hidden as default. But can be revealed
with a button if desired.
Fix for issue #217
Diffstat (limited to 'htroot/js')
| -rw-r--r-- | htroot/js/yacysearch.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/htroot/js/yacysearch.js b/htroot/js/yacysearch.js index 16b80ff15..51eb81ea8 100644 --- a/htroot/js/yacysearch.js +++ b/htroot/js/yacysearch.js @@ -327,4 +327,65 @@ function handleAudioPlaying(event) { } } } +} + +/** + * Handle a rendering error on a result image thumbnail. + * @param imgElem {HTMLImageElement} the html img element that could not be rendered + */ +function handleResultThumbError(imgElem) { + if (imgElem.parentNode != null && imgElem.parentNode.parentNode != null + && imgElem.parentNode.parentNode.className == "thumbcontainer") { + /* Hide the thumbnail container */ + imgElem.parentNode.parentNode.className = "thumbcontainer thumbError hidden"; + var errorsInfoElem = document.getElementById("imageErrorsInfo"); + if (errorsInfoElem != null && errorsInfoElem.className.indexOf("hidden") >= 0) { + /* Show the image errors information block */ + errorsInfoElem.className = errorsInfoElem.className.replace("hidden", ""); + } + var errorsCountElem = document.getElementById("imageErrorsCount"); + if (errorsCountElem != null) { + /* Increase the count of thumbnails rendering errors */ + errorsCountElem.firstChild.nodeValue = parseInt(errorsCountElem.firstChild.nodeValue) + 1; + } + } +} + +/** + * Show result thumbnails that were hidden because a rendering error occurred. + */ +function showErrThumbnails() { + var thumbs = document.getElementsByClassName("thumbError hidden"); + var length = thumbs.length; + for (var i = 0; i < length && thumbs.length > 0; i++) { + thumbs[0].className = thumbs[0].className.replace("hidden", ""); // after that the element is removed from the thumbs live collection + } + var showBtn = document.getElementById("showErrorImagesBtn"); + if(showBtn != null) { + showBtn.className = showBtn.className + " hidden"; + } + var hideBtn = document.getElementById("hideErrorImagesBtn"); + if(hideBtn != null) { + hideBtn.className = hideBtn.className.replace("hidden", ""); + } +} + +/** + * Hide result thumbnails that had a rendering error. + */ +function hideErrThumbnails() { + var thumbs = document.getElementsByClassName("thumbError"); + for (var i = 0; i < thumbs.length; i++) { + if(thumbs[i].className.indexOf("hidden") < 0) { + thumbs[i].className = thumbs[i].className + " hidden"; + } + } + var showBtn = document.getElementById("showErrorImagesBtn"); + if(showBtn != null) { + showBtn.className = showBtn.className.replace("hidden", ""); + } + var hideBtn = document.getElementById("hideErrorImagesBtn"); + if(hideBtn != null) { + hideBtn.className = hideBtn.className + " hidden"; + } }
\ No newline at end of file |
