@@ -212,14 +212,9 @@ coverage.index_ready = function () {
212
212
coverage . LINE_FILTERS_STORAGE = "COVERAGE_LINE_FILTERS" ;
213
213
214
214
coverage . pyfile_ready = function ( ) {
215
- cboxes = document . querySelectorAll ( '[id^=ctxs]' )
216
- cboxes . forEach ( function ( cbox ) {
217
- cbox . addEventListener ( "click" , coverage . showContexts )
218
- } ) ;
219
-
220
215
// If we're directed to a particular line number, highlight the line.
221
216
var frag = location . hash ;
222
- if ( frag . length > 2 && frag [ 1 ] === 't' ) {
217
+ if ( frag . length > 2 && frag [ 1 ] === "t" ) {
223
218
document . querySelector ( frag ) . closest ( ".n" ) . classList . add ( "highlight" ) ;
224
219
coverage . set_sel ( parseInt ( frag . substr ( 2 ) , 10 ) ) ;
225
220
} else {
@@ -262,6 +257,10 @@ coverage.pyfile_ready = function () {
262
257
coverage . init_scroll_markers ( ) ;
263
258
coverage . wire_up_sticky_header ( ) ;
264
259
260
+ document . querySelectorAll ( "[id^=ctxs]" ) . forEach (
261
+ cbox => cbox . addEventListener ( "click" , coverage . expand_contexts )
262
+ ) ;
263
+
265
264
// Rebuild scroll markers when the window height changes.
266
265
window . addEventListener ( "resize" , coverage . build_scroll_markers ) ;
267
266
} ;
@@ -533,14 +532,14 @@ coverage.scroll_window = function (to_pos) {
533
532
534
533
coverage . init_scroll_markers = function ( ) {
535
534
// Init some variables
536
- coverage . lines_len = document . querySelectorAll ( ' #source > p' ) . length ;
535
+ coverage . lines_len = document . querySelectorAll ( " #source > p" ) . length ;
537
536
538
537
// Build html
539
538
coverage . build_scroll_markers ( ) ;
540
539
} ;
541
540
542
541
coverage . build_scroll_markers = function ( ) {
543
- const temp_scroll_marker = document . getElementById ( ' scroll_marker' )
542
+ const temp_scroll_marker = document . getElementById ( " scroll_marker" )
544
543
if ( temp_scroll_marker ) temp_scroll_marker . remove ( ) ;
545
544
// Don't build markers if the window has no scroll bar.
546
545
if ( document . body . scrollHeight <= window . innerHeight ) {
@@ -554,8 +553,8 @@ coverage.build_scroll_markers = function () {
554
553
555
554
const scroll_marker = document . createElement ( "div" ) ;
556
555
scroll_marker . id = "scroll_marker" ;
557
- document . getElementById ( ' source' ) . querySelectorAll (
558
- ' p.show_run, p.show_mis, p.show_exc, p.show_exc, p.show_par'
556
+ document . getElementById ( " source" ) . querySelectorAll (
557
+ " p.show_run, p.show_mis, p.show_exc, p.show_exc, p.show_par"
559
558
) . forEach ( element => {
560
559
const line_top = Math . floor ( element . offsetTop * marker_scale ) ;
561
560
const line_number = parseInt ( element . querySelector ( ".n a" ) . id . substr ( 1 ) ) ;
@@ -582,35 +581,37 @@ coverage.build_scroll_markers = function () {
582
581
} ;
583
582
584
583
coverage . wire_up_sticky_header = function ( ) {
585
- const header = document . querySelector ( ' header' ) ;
584
+ const header = document . querySelector ( " header" ) ;
586
585
const header_bottom = (
587
- header . querySelector ( ' .content h2' ) . getBoundingClientRect ( ) . top -
586
+ header . querySelector ( " .content h2" ) . getBoundingClientRect ( ) . top -
588
587
header . getBoundingClientRect ( ) . top
589
588
) ;
590
589
591
590
function updateHeader ( ) {
592
591
if ( window . scrollY > header_bottom ) {
593
- header . classList . add ( ' sticky' ) ;
592
+ header . classList . add ( " sticky" ) ;
594
593
} else {
595
- header . classList . remove ( ' sticky' ) ;
594
+ header . classList . remove ( " sticky" ) ;
596
595
}
597
596
}
598
597
599
- window . addEventListener ( ' scroll' , updateHeader ) ;
598
+ window . addEventListener ( " scroll" , updateHeader ) ;
600
599
updateHeader ( ) ;
601
600
} ;
602
601
603
- coverage . showContexts = function ( e ) {
604
- span = e . target . nextElementSibling . nextElementSibling ;
605
- span_text = span . textContent ;
606
-
607
- if ( / ^ [ 0 - 9 , ] + $ / . test ( span_text ) ) {
608
- span . textContent = "" ;
609
- span_text . split ( "," ) . forEach ( function ( s ) {
610
- ctx = contexts [ s ] ;
611
- span . appendChild ( document . createTextNode ( ctx ) ) ;
612
- span . appendChild ( document . createElement ( "br" ) ) ;
613
- } )
602
+ coverage . expand_contexts = function ( e ) {
603
+ var ctxs = e . target . parentNode . querySelector ( ".ctxs" ) ;
604
+
605
+ if ( ! ctxs . classList . contains ( "expanded" ) ) {
606
+ var ctxs_text = ctxs . textContent ;
607
+ var width = Number ( ctxs_text [ 0 ] ) ;
608
+ ctxs . textContent = "" ;
609
+ for ( var i = 1 ; i < ctxs_text . length ; i += width ) {
610
+ key = ctxs_text . substring ( i , i + width ) . trim ( ) ;
611
+ ctxs . appendChild ( document . createTextNode ( contexts [ key ] ) ) ;
612
+ ctxs . appendChild ( document . createElement ( "br" ) ) ;
613
+ }
614
+ ctxs . classList . add ( "expanded" ) ;
614
615
}
615
616
} ;
616
617
@@ -620,5 +621,4 @@ document.addEventListener("DOMContentLoaded", () => {
620
621
} else {
621
622
coverage . pyfile_ready ( ) ;
622
623
}
623
-
624
624
} ) ;
0 commit comments