@@ -209,15 +209,21 @@ coverage.pyfile_ready = function () {
209
209
coverage . set_sel ( 0 ) ;
210
210
}
211
211
212
- document . querySelector ( ".button_toggle_run" ) . addEventListener ( "click" , coverage . toggle_lines ) ;
213
- document . querySelector ( ".button_toggle_mis" ) . addEventListener ( "click" , coverage . toggle_lines ) ;
214
- document . querySelector ( ".button_toggle_exc" ) . addEventListener ( "click" , coverage . toggle_lines ) ;
215
- document . querySelector ( ".button_toggle_par" ) . addEventListener ( "click" , coverage . toggle_lines ) ;
212
+ const on_click = function ( sel , fn ) {
213
+ const elt = document . querySelector ( sel ) ;
214
+ if ( elt ) {
215
+ elt . addEventListener ( "click" , fn ) ;
216
+ }
217
+ }
218
+ on_click ( ".button_toggle_run" , coverage . toggle_lines ) ;
219
+ on_click ( ".button_toggle_mis" , coverage . toggle_lines ) ;
220
+ on_click ( ".button_toggle_exc" , coverage . toggle_lines ) ;
221
+ on_click ( ".button_toggle_par" , coverage . toggle_lines ) ;
216
222
217
- document . querySelector ( ".button_next_chunk" ) . addEventListener ( "click ", coverage . to_next_chunk_nicely ) ;
218
- document . querySelector ( ".button_prev_chunk" ) . addEventListener ( "click ", coverage . to_prev_chunk_nicely ) ;
219
- document . querySelector ( ".button_top_of_page" ) . addEventListener ( "click ", coverage . to_top ) ;
220
- document . querySelector ( ".button_first_chunk" ) . addEventListener ( "click ", coverage . to_first_chunk ) ;
223
+ on_click ( ".button_next_chunk" , coverage . to_next_chunk_nicely ) ;
224
+ on_click ( ".button_prev_chunk" , coverage . to_prev_chunk_nicely ) ;
225
+ on_click ( ".button_top_of_page" , coverage . to_top ) ;
226
+ on_click ( ".button_first_chunk" , coverage . to_first_chunk ) ;
221
227
222
228
coverage . filters = undefined ;
223
229
try {
@@ -258,13 +264,15 @@ coverage.toggle_lines = function (event) {
258
264
coverage . set_line_visibilty = function ( category , should_show ) {
259
265
const cls = "show_" + category ;
260
266
const btn = document . querySelector ( ".button_toggle_" + category ) ;
261
- if ( should_show ) {
262
- document . querySelectorAll ( "#source ." + category ) . forEach ( e => e . classList . add ( cls ) ) ;
263
- btn . classList . add ( cls ) ;
264
- }
265
- else {
266
- document . querySelectorAll ( "#source ." + category ) . forEach ( e => e . classList . remove ( cls ) ) ;
267
- btn . classList . remove ( cls ) ;
267
+ if ( btn ) {
268
+ if ( should_show ) {
269
+ document . querySelectorAll ( "#source ." + category ) . forEach ( e => e . classList . add ( cls ) ) ;
270
+ btn . classList . add ( cls ) ;
271
+ }
272
+ else {
273
+ document . querySelectorAll ( "#source ." + category ) . forEach ( e => e . classList . remove ( cls ) ) ;
274
+ btn . classList . remove ( cls ) ;
275
+ }
268
276
}
269
277
} ;
270
278
0 commit comments