diff options
author | Oleh Krehel <ohwoeowho@gmail.com> | 2023-03-22 17:42:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-22 09:42:35 -0700 |
commit | d6cb1cdca6d15f5ec02eb6708314589290321faf (patch) | |
tree | 1cf7f910a9e9b1b1ad7f1a40dad59231da4e0d42 /coverage/htmlfiles/coverage_html.js | |
parent | 551522eb214ad0c3f1dc48cd112a4f0ba6ddc6b6 (diff) | |
download | python-coveragepy-git-d6cb1cdca6d15f5ec02eb6708314589290321faf.tar.gz |
fix: put contexts dict in <script> and reveal them using JavaScript (#1587)
* Put contexts dict in <script> and reveal them using JavaScript
Fixes #1584
* Address review comments
* coverage/htmlfiles/style.css: Align the contexts to the right
* coverage/htmlfiles/style.scss: Match style.css
* coverage/html.py: Fix linting and mypy errors
* two_tests_py.html: make update-gold
Diffstat (limited to 'coverage/htmlfiles/coverage_html.js')
-rw-r--r-- | coverage/htmlfiles/coverage_html.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/coverage/htmlfiles/coverage_html.js b/coverage/htmlfiles/coverage_html.js index 1c4eb988..8b7fb96f 100644 --- a/coverage/htmlfiles/coverage_html.js +++ b/coverage/htmlfiles/coverage_html.js @@ -212,6 +212,11 @@ coverage.index_ready = function () { coverage.LINE_FILTERS_STORAGE = "COVERAGE_LINE_FILTERS"; coverage.pyfile_ready = function () { + cboxes = document.querySelectorAll('[id^=ctxs]') + cboxes.forEach(function(cbox) { + cbox.addEventListener("click", coverage.showContexts) + }); + // If we're directed to a particular line number, highlight the line. var frag = location.hash; if (frag.length > 2 && frag[1] === 't') { @@ -595,10 +600,26 @@ coverage.wire_up_sticky_header = function () { updateHeader(); }; +coverage.showContexts = function (e) { + span = e.target.nextElementSibling.nextElementSibling; + span_text = span.textContent; + + if (/^[0-9,]+$/.test(span_text)) + { + span.textContent = ""; + span_text.split(",").forEach(function(s) { + ctx = contexts[s]; + span.appendChild(document.createTextNode(ctx)); + span.appendChild(document.createElement("br")); + }) + } +}; + document.addEventListener("DOMContentLoaded", () => { if (document.body.classList.contains("indexfile")) { coverage.index_ready(); } else { coverage.pyfile_ready(); } + }); |