From: Vladimír Vondruš Date: Tue, 1 Jan 2019 23:42:43 +0000 (+0100) Subject: doxygen: if the URL already contains #search, hide scrollbar etc. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=6585ecd8f582b4cbed91792e1f4f9c6a07efef79;p=blog.git doxygen: if the URL already contains #search, hide scrollbar etc. For consistent experience compared to loading the docs without #search and then hitting Tab. --- diff --git a/doxygen/search.js b/doxygen/search.js index 3ec72455..05bda57f 100644 --- a/doxygen/search.js +++ b/doxygen/search.js @@ -494,10 +494,9 @@ function selectResult(event) { event.currentTarget.parentNode.id = 'search-current'; } -/* istanbul ignore next */ -function showSearch() { - window.location.hash = '#search'; - +/* This is separated from showSearch() because we need non-destructive behavior + when appearing directly on a URL with #search */ /* istanbul ignore next */ +function updateForSearchVisible() { /* Prevent accidental scrolling of the body, prevent page layout jumps */ let scrolledBodyWidth = document.body.offsetWidth; document.body.style.overflow = 'hidden'; @@ -508,6 +507,13 @@ function showSearch() { document.getElementById('search-results').style.display = 'none'; document.getElementById('search-notfound').style.display = 'none'; document.getElementById('search-help').style.display = 'block'; +} + +/* istanbul ignore next */ +function showSearch() { + window.location.hash = '#search'; + + updateForSearchVisible(); return false; } @@ -589,6 +595,10 @@ if(typeof document !== 'undefined') { document.getElementById('search-results').onmousemove = function() { Search.mouseMovedSinceLastRender = true; }; + + /* If #search is already present in the URL, hide the scrollbar etc. for a + consistent experience */ + if(window.location.hash == '#search') updateForSearchVisible(); } /* For Node.js testing */ /* istanbul ignore else */