@@ -36,12 +36,12 @@ function on_click(sel, fn) {
36
36
function getCellValue ( row , column = 0 ) {
37
37
const cell = row . cells [ column ] // nosemgrep: eslint.detect-object-injection
38
38
if ( cell . childElementCount == 1 ) {
39
- const child = cell . firstElementChild
40
- if ( child instanceof HTMLTimeElement && child . dateTime ) {
41
- return child . dateTime
42
- } else if ( child instanceof HTMLDataElement && child . value ) {
43
- console . log ( "child.value" , child . value ) ;
44
- return child . value
39
+ var child = cell . firstElementChild ;
40
+ if ( child . tagName === "A" ) {
41
+ child = child . firstElementChild ;
42
+ }
43
+ if ( child instanceof HTMLDataElement && child . value ) {
44
+ return child . value ;
45
45
}
46
46
}
47
47
return cell . innerText || cell . textContent ;
@@ -51,28 +51,37 @@ function rowComparator(rowA, rowB, column = 0) {
51
51
let valueA = getCellValue ( rowA , column ) ;
52
52
let valueB = getCellValue ( rowB , column ) ;
53
53
if ( ! isNaN ( valueA ) && ! isNaN ( valueB ) ) {
54
- return valueA - valueB
54
+ return valueA - valueB ;
55
55
}
56
56
return valueA . localeCompare ( valueB , undefined , { numeric : true } ) ;
57
57
}
58
58
59
59
function sortColumn ( th ) {
60
60
// Get the current sorting direction of the selected header,
61
- // clear state on other headers and then set the new sorting direction
61
+ // clear state on other headers and then set the new sorting direction.
62
62
const currentSortOrder = th . getAttribute ( "aria-sort" ) ;
63
63
[ ...th . parentElement . cells ] . forEach ( header => header . setAttribute ( "aria-sort" , "none" ) ) ;
64
+ var direction ;
64
65
if ( currentSortOrder === "none" ) {
65
- th . setAttribute ( "aria-sort" , th . dataset . defaultSortOrder || "ascending" ) ;
66
- } else {
67
- th . setAttribute ( "aria-sort" , currentSortOrder === "ascending" ? "descending" : "ascending" ) ;
66
+ direction = th . dataset . defaultSortOrder || "ascending" ;
67
+ }
68
+ else if ( currentSortOrder === "ascending" ) {
69
+ direction = "descending" ;
68
70
}
71
+ else {
72
+ direction = "ascending" ;
73
+ }
74
+ th . setAttribute ( "aria-sort" , direction ) ;
69
75
70
76
const column = [ ...th . parentElement . cells ] . indexOf ( th )
71
77
72
- // Sort all rows and afterwards append them in order to move them in the DOM
78
+ // Sort all rows and afterwards append them in order to move them in the DOM.
73
79
Array . from ( th . closest ( "table" ) . querySelectorAll ( "tbody tr" ) )
74
- . sort ( ( rowA , rowB ) => rowComparator ( rowA , rowB , column ) * ( th . getAttribute ( "aria-sort" ) === "ascending" ? 1 : - 1 ) )
75
- . forEach ( tr => tr . parentElement . appendChild ( tr ) ) ;
80
+ . sort ( ( rowA , rowB ) => rowComparator ( rowA , rowB , column ) * ( direction === "ascending" ? 1 : - 1 ) )
81
+ . forEach ( tr => tr . parentElement . appendChild ( tr ) ) ;
82
+
83
+ // Save the sort order for next time.
84
+ localStorage . setItem ( coverage . INDEX_SORT_STORAGE , JSON . stringify ( { column, direction} ) ) ;
76
85
}
77
86
78
87
// Find all the elements with data-shortcut attribute, and use them to assign a shortcut key.
@@ -105,11 +114,17 @@ coverage.wire_up_filter = function () {
105
114
106
115
// Hide / show elements.
107
116
table_body_rows . forEach ( row => {
108
- show = false ;
117
+ var show = false ;
118
+ var target = event . target . value ;
119
+ var casefold = ( target === target . toLowerCase ( ) ) ;
109
120
for ( let column = 0 ; column < totals . length ; column ++ ) {
110
121
cell = row . cells [ column ] ;
111
122
if ( cell . classList . contains ( "name" ) ) {
112
- if ( cell . textContent . includes ( event . target . value ) ) {
123
+ var celltext = cell . textContent ;
124
+ if ( casefold ) {
125
+ celltext = celltext . toLowerCase ( ) ;
126
+ }
127
+ if ( celltext . includes ( target ) ) {
113
128
show = true ;
114
129
}
115
130
}
@@ -136,7 +151,8 @@ coverage.wire_up_filter = function () {
136
151
const [ numer , denom ] = cell . dataset . ratio . split ( " " ) ;
137
152
totals [ column ] [ "numer" ] += parseInt ( numer , 10 ) ; // nosemgrep: eslint.detect-object-injection
138
153
totals [ column ] [ "denom" ] += parseInt ( denom , 10 ) ; // nosemgrep: eslint.detect-object-injection
139
- } else {
154
+ }
155
+ else {
140
156
totals [ column ] += parseInt ( cell . textContent , 10 ) ; // nosemgrep: eslint.detect-object-injection
141
157
}
142
158
}
@@ -175,7 +191,8 @@ coverage.wire_up_filter = function () {
175
191
cell . textContent = denom
176
192
? `${ ( numer * 100 / denom ) . toFixed ( places ) } %`
177
193
: `${ ( 100 ) . toFixed ( places ) } %` ;
178
- } else {
194
+ }
195
+ else {
179
196
cell . textContent = totals [ column ] ; // nosemgrep: eslint.detect-object-injection
180
197
}
181
198
}
@@ -186,37 +203,31 @@ coverage.wire_up_filter = function () {
186
203
document . getElementById ( "filter" ) . dispatchEvent ( new Event ( "input" ) ) ;
187
204
} ;
188
205
189
- coverage . INDEX_SORT_STORAGE = "COVERAGE_INDEX_SORT_2" ;
190
-
191
- // Loaded on index.html
192
- coverage . index_ready = function ( ) {
193
- coverage . assign_shortkeys ( ) ;
194
- coverage . wire_up_filter ( ) ;
206
+ // Set up the click-to-sort columns.
207
+ coverage . wire_up_sorting = function ( ) {
195
208
document . querySelectorAll ( "[data-sortable] th[aria-sort]" ) . forEach (
196
209
th => th . addEventListener ( "click" , e => sortColumn ( e . target ) )
197
210
) ;
198
211
199
212
// Look for a localStorage item containing previous sort settings:
213
+ var column = 0 , direction = "ascending" ;
200
214
const stored_list = localStorage . getItem ( coverage . INDEX_SORT_STORAGE ) ;
201
-
202
215
if ( stored_list ) {
203
- const { column, direction} = JSON . parse ( stored_list ) ;
204
- const th = document . querySelector ( "[data-sortable]" ) . tHead . rows [ 0 ] . cells [ column ] ; // nosemgrep: eslint.detect-object-injection
205
- th . setAttribute ( "aria-sort" , direction === "ascending" ? "descending" : "ascending" ) ;
206
- th . click ( )
216
+ ( { column, direction} = JSON . parse ( stored_list ) ) ;
207
217
}
208
218
209
- // Watch for page unload events so we can save the final sort settings:
210
- window . addEventListener ( "unload" , function ( ) {
211
- const th = document . querySelector ( '[data-sortable] th[aria-sort="ascending"], [data-sortable] [aria-sort="descending"]' ) ;
212
- if ( ! th ) {
213
- return ;
214
- }
215
- localStorage . setItem ( coverage . INDEX_SORT_STORAGE , JSON . stringify ( {
216
- column : [ ...th . parentElement . cells ] . indexOf ( th ) ,
217
- direction : th . getAttribute ( "aria-sort" ) ,
218
- } ) ) ;
219
- } ) ;
219
+ const th = document . querySelector ( "[data-sortable]" ) . tHead . rows [ 0 ] . cells [ column ] ; // nosemgrep: eslint.detect-object-injection
220
+ th . setAttribute ( "aria-sort" , direction === "ascending" ? "descending" : "ascending" ) ;
221
+ th . click ( )
222
+ } ;
223
+
224
+ coverage . INDEX_SORT_STORAGE = "COVERAGE_INDEX_SORT_2" ;
225
+
226
+ // Loaded on index.html
227
+ coverage . index_ready = function ( ) {
228
+ coverage . assign_shortkeys ( ) ;
229
+ coverage . wire_up_filter ( ) ;
230
+ coverage . wire_up_sorting ( ) ;
220
231
221
232
on_click ( ".button_prev_file" , coverage . to_prev_file ) ;
222
233
on_click ( ".button_next_file" , coverage . to_next_file ) ;
@@ -234,7 +245,8 @@ coverage.pyfile_ready = function () {
234
245
if ( frag . length > 2 && frag [ 1 ] === "t" ) {
235
246
document . querySelector ( frag ) . closest ( ".n" ) . classList . add ( "highlight" ) ;
236
247
coverage . set_sel ( parseInt ( frag . substr ( 2 ) , 10 ) ) ;
237
- } else {
248
+ }
249
+ else {
238
250
coverage . set_sel ( 0 ) ;
239
251
}
240
252
@@ -458,7 +470,8 @@ coverage.to_next_chunk_nicely = function () {
458
470
if ( line . parentElement !== document . getElementById ( "source" ) ) {
459
471
// The element is not a source line but the header or similar
460
472
coverage . select_line_or_chunk ( 1 ) ;
461
- } else {
473
+ }
474
+ else {
462
475
// We extract the line number from the id
463
476
coverage . select_line_or_chunk ( parseInt ( line . id . substring ( 1 ) , 10 ) ) ;
464
477
}
@@ -477,7 +490,8 @@ coverage.to_prev_chunk_nicely = function () {
477
490
if ( line . parentElement !== document . getElementById ( "source" ) ) {
478
491
// The element is not a source line but the header or similar
479
492
coverage . select_line_or_chunk ( coverage . lines_len ) ;
480
- } else {
493
+ }
494
+ else {
481
495
// We extract the line number from the id
482
496
coverage . select_line_or_chunk ( parseInt ( line . id . substring ( 1 ) , 10 ) ) ;
483
497
}
@@ -579,7 +593,8 @@ coverage.build_scroll_markers = function () {
579
593
if ( line_number === previous_line + 1 ) {
580
594
// If this solid missed block just make previous mark higher.
581
595
last_mark . style . height = `${ line_top + line_height - last_top } px` ;
582
- } else {
596
+ }
597
+ else {
583
598
// Add colored line in scroll_marker block.
584
599
last_mark = document . createElement ( "div" ) ;
585
600
last_mark . id = `m${ line_number } ` ;
@@ -607,7 +622,8 @@ coverage.wire_up_sticky_header = function () {
607
622
function updateHeader ( ) {
608
623
if ( window . scrollY > header_bottom ) {
609
624
header . classList . add ( "sticky" ) ;
610
- } else {
625
+ }
626
+ else {
611
627
header . classList . remove ( "sticky" ) ;
612
628
}
613
629
}
@@ -635,7 +651,8 @@ coverage.expand_contexts = function (e) {
635
651
document . addEventListener ( "DOMContentLoaded" , ( ) => {
636
652
if ( document . body . classList . contains ( "indexfile" ) ) {
637
653
coverage . index_ready ( ) ;
638
- } else {
654
+ }
655
+ else {
639
656
coverage . pyfile_ready ( ) ;
640
657
}
641
658
} ) ;
0 commit comments