chiark / gitweb /
doxygen: prevent page scroll (and layout jumps) on showing search.
authorVladimír Vondruš <mosra@centrum.cz>
Mon, 29 Jan 2018 12:45:09 +0000 (13:45 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Sat, 3 Feb 2018 09:51:55 +0000 (10:51 +0100)
doxygen/search.js

index 064028ac606b5e100498c35f95aa838bcd87251b..66da5acc42775899a2b2dc689fe8a3e8a04c60a5 100644 (file)
@@ -346,6 +346,12 @@ function selectResult(event) {
 /* istanbul ignore next */
 function showSearch() {
     window.location.hash = '#search';
+
+    /* Prevent accidental scrolling of the body, prevent page layout jumps */
+    let scrolledBodyWidth = document.body.offsetWidth;
+    document.body.style.overflow = 'hidden';
+    document.body.style.paddingRight = (document.body.offsetWidth - scrolledBodyWidth) + 'px';
+
     document.getElementById('search-input').value = '';
     document.getElementById('search-input').focus();
     document.getElementById('search-results').style.display = 'none';
@@ -358,6 +364,11 @@ function showSearch() {
 function hideSearch() {
     window.location.hash = '#!';
     window.history.pushState('', '', window.location.pathname);
+
+    /* Restore scrollbar, prevent page layout jumps */
+    document.body.style.overflow = 'auto';
+    document.body.style.paddingRight = '0';
+
     return false;
 }