@@ -212,14 +212,9 @@ coverage.index_ready = function () {
212212coverage . LINE_FILTERS_STORAGE = "COVERAGE_LINE_FILTERS" ;
213213
214214coverage . pyfile_ready = function ( ) {
215- cboxes = document . querySelectorAll ( '[id^=ctxs]' )
216- cboxes . forEach ( function ( cbox ) {
217- cbox . addEventListener ( "click" , coverage . showContexts )
218- } ) ;
219-
220215 // If we're directed to a particular line number, highlight the line.
221216 var frag = location . hash ;
222- if ( frag . length > 2 && frag [ 1 ] === 't' ) {
217+ if ( frag . length > 2 && frag [ 1 ] === "t" ) {
223218 document . querySelector ( frag ) . closest ( ".n" ) . classList . add ( "highlight" ) ;
224219 coverage . set_sel ( parseInt ( frag . substr ( 2 ) , 10 ) ) ;
225220 } else {
@@ -262,6 +257,10 @@ coverage.pyfile_ready = function () {
262257 coverage . init_scroll_markers ( ) ;
263258 coverage . wire_up_sticky_header ( ) ;
264259
260+ document . querySelectorAll ( "[id^=ctxs]" ) . forEach (
261+ cbox => cbox . addEventListener ( "click" , coverage . expand_contexts )
262+ ) ;
263+
265264 // Rebuild scroll markers when the window height changes.
266265 window . addEventListener ( "resize" , coverage . build_scroll_markers ) ;
267266} ;
@@ -533,14 +532,14 @@ coverage.scroll_window = function (to_pos) {
533532
534533coverage . init_scroll_markers = function ( ) {
535534 // Init some variables
536- coverage . lines_len = document . querySelectorAll ( ' #source > p' ) . length ;
535+ coverage . lines_len = document . querySelectorAll ( " #source > p" ) . length ;
537536
538537 // Build html
539538 coverage . build_scroll_markers ( ) ;
540539} ;
541540
542541coverage . build_scroll_markers = function ( ) {
543- const temp_scroll_marker = document . getElementById ( ' scroll_marker' )
542+ const temp_scroll_marker = document . getElementById ( " scroll_marker" )
544543 if ( temp_scroll_marker ) temp_scroll_marker . remove ( ) ;
545544 // Don't build markers if the window has no scroll bar.
546545 if ( document . body . scrollHeight <= window . innerHeight ) {
@@ -554,8 +553,8 @@ coverage.build_scroll_markers = function () {
554553
555554 const scroll_marker = document . createElement ( "div" ) ;
556555 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"
559558 ) . forEach ( element => {
560559 const line_top = Math . floor ( element . offsetTop * marker_scale ) ;
561560 const line_number = parseInt ( element . querySelector ( ".n a" ) . id . substr ( 1 ) ) ;
@@ -582,35 +581,37 @@ coverage.build_scroll_markers = function () {
582581} ;
583582
584583coverage . wire_up_sticky_header = function ( ) {
585- const header = document . querySelector ( ' header' ) ;
584+ const header = document . querySelector ( " header" ) ;
586585 const header_bottom = (
587- header . querySelector ( ' .content h2' ) . getBoundingClientRect ( ) . top -
586+ header . querySelector ( " .content h2" ) . getBoundingClientRect ( ) . top -
588587 header . getBoundingClientRect ( ) . top
589588 ) ;
590589
591590 function updateHeader ( ) {
592591 if ( window . scrollY > header_bottom ) {
593- header . classList . add ( ' sticky' ) ;
592+ header . classList . add ( " sticky" ) ;
594593 } else {
595- header . classList . remove ( ' sticky' ) ;
594+ header . classList . remove ( " sticky" ) ;
596595 }
597596 }
598597
599- window . addEventListener ( ' scroll' , updateHeader ) ;
598+ window . addEventListener ( " scroll" , updateHeader ) ;
600599 updateHeader ( ) ;
601600} ;
602601
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" ) ;
614615 }
615616} ;
616617
@@ -620,5 +621,4 @@ document.addEventListener("DOMContentLoaded", () => {
620621 } else {
621622 coverage . pyfile_ready ( ) ;
622623 }
623-
624624} ) ;
0 commit comments