chiark / gitweb /
doxygen: if the URL already contains #search, hide scrollbar etc.
authorVladimír Vondruš <mosra@centrum.cz>
Tue, 1 Jan 2019 23:42:43 +0000 (00:42 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Wed, 2 Jan 2019 21:07:12 +0000 (22:07 +0100)
For consistent experience compared to loading the docs without #search
and then hitting Tab.

doxygen/search.js

index 3ec72455b14e804e52d4f79e7354539fa38a4e7f..05bda57f710d644e808581487cae1b2f8ef268a5 100644 (file)
@@ -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 */