summaryrefslogtreecommitdiff
path: root/coverage/htmlfiles/coverage_html.js
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-10-20 20:43:38 -0400
committerNed Batchelder <ned@nedbatchelder.com>2021-10-20 20:43:38 -0400
commite2281bc901150bafb6f64e62807b32abf22520a7 (patch)
treed897c559f570938d35720232f86a4cabd6286004 /coverage/htmlfiles/coverage_html.js
parentafe6cf34d022e8dbbaa47826c487a98ca6832721 (diff)
downloadpython-coveragepy-git-e2281bc901150bafb6f64e62807b32abf22520a7.tar.gz
fix(html): scrolling to an anchor ensures the line is visible
The sticky header was hiding the line scrolled to the top of the window. Along the way, also changed to use classes on <body> to control the sticky header, and moved the header code into a function.
Diffstat (limited to 'coverage/htmlfiles/coverage_html.js')
-rw-r--r--coverage/htmlfiles/coverage_html.js43
1 files changed, 24 insertions, 19 deletions
diff --git a/coverage/htmlfiles/coverage_html.js b/coverage/htmlfiles/coverage_html.js
index 514103c7..182e518c 100644
--- a/coverage/htmlfiles/coverage_html.js
+++ b/coverage/htmlfiles/coverage_html.js
@@ -277,25 +277,7 @@ coverage.pyfile_ready = function ($) {
coverage.assign_shortkeys();
coverage.wire_up_help_panel();
coverage.init_scroll_markers();
-
- const sticky = document.querySelector('#sticky_header');
- const header = document.querySelector('header');
- const header_bottom = document.querySelector('header .content .stats').getBoundingClientRect().top;
-
- function updateHeader() {
- if (window.scrollY > header_bottom) {
- sticky.classList.add('visible');
- header.classList.add('hidden');
- } else {
- sticky.classList.remove('visible');
- header.classList.remove('hidden');
- }
- }
-
- updateHeader();
- window.addEventListener('scroll', function() {
- updateHeader();
- });
+ coverage.wire_up_sticky_header();
// Rebuild scroll markers when the window height changes.
$(window).resize(coverage.build_scroll_markers);
@@ -627,3 +609,26 @@ coverage.build_scroll_markers = function () {
previous_line = line_number;
});
};
+
+coverage.wire_up_sticky_header = function () {
+ const body = document.querySelector('body');
+ const header_bottom = (
+ document.querySelector('header .content .stats').getBoundingClientRect().top -
+ document.querySelector('header').getBoundingClientRect().top
+ );
+
+ function updateHeader() {
+ if (window.scrollY > header_bottom) {
+ body.classList.remove('bighead');
+ body.classList.add('littlehead');
+ } else {
+ body.classList.add('bighead');
+ body.classList.remove('littlehead');
+ }
+ }
+
+ updateHeader();
+ window.addEventListener('scroll', function() {
+ updateHeader();
+ });
+};