From 6585ecd8f582b4cbed91792e1f4f9c6a07efef79 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 2 Jan 2019 00:42:43 +0100 Subject: [PATCH] doxygen: if the URL already contains #search, hide scrollbar etc. For consistent experience compared to loading the docs without #search and then hitting Tab. --- doxygen/search.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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 */ -- 2.30.2