1- var addSorting = ( function ( ) {
2- 'use strict' ;
3- var cols ,
4- currentSort = {
5- index : 0 ,
6- desc : false ,
7- } ;
1+ /* eslint-disable */
2+
3+ const addSorting = ( function ( ) {
4+ let cols ;
5+ const currentSort = {
6+ index : 0 ,
7+ desc : false ,
8+ } ;
89
910 // returns the summary table element
1011 function getTable ( ) {
@@ -38,19 +39,19 @@ var addSorting = (function () {
3839
3940 // loads the search box
4041 function addSearchBox ( ) {
41- var template = document . getElementById ( 'filterTemplate' ) ;
42- var templateClone = template . content . cloneNode ( true ) ;
42+ const template = document . getElementById ( 'filterTemplate' ) ;
43+ const templateClone = template . content . cloneNode ( true ) ;
4344 templateClone . getElementById ( 'fileSearch' ) . oninput = onFilterInput ;
4445 template . parentElement . appendChild ( templateClone ) ;
4546 }
4647
4748 // loads all columns
4849 function loadColumns ( ) {
49- var colNodes = getTableHeader ( ) . querySelectorAll ( 'th' ) ,
50- colNode ,
51- cols = [ ] ,
52- col ,
53- i ;
50+ const colNodes = getTableHeader ( ) . querySelectorAll ( 'th' ) ;
51+ let colNode ;
52+ const cols = [ ] ;
53+ let col ;
54+ let i ;
5455
5556 for ( i = 0 ; i < colNodes . length ; i += 1 ) {
5657 colNode = colNodes [ i ] ;
@@ -62,20 +63,20 @@ var addSorting = (function () {
6263 cols . push ( col ) ;
6364 if ( col . sortable ) {
6465 col . defaultDescSort = col . type === 'number' ;
65- colNode . innerHTML = colNode . innerHTML + '<span class="sorter"></span>' ;
66+ colNode . innerHTML += '<span class="sorter"></span>' ;
6667 }
6768 }
6869 return cols ;
6970 }
7071 // attaches a data attribute to every tr element with an object
7172 // of data values keyed by column name
7273 function loadRowData ( tableRow ) {
73- var tableCols = tableRow . querySelectorAll ( 'td' ) ,
74- colNode ,
75- col ,
76- data = { } ,
77- i ,
78- val ;
74+ const tableCols = tableRow . querySelectorAll ( 'td' ) ;
75+ let colNode ;
76+ let col ;
77+ const data = { } ;
78+ let i ;
79+ let val ;
7980 for ( i = 0 ; i < tableCols . length ; i += 1 ) {
8081 colNode = tableCols [ i ] ;
8182 col = cols [ i ] ;
@@ -89,26 +90,26 @@ var addSorting = (function () {
8990 }
9091 // loads all row data
9192 function loadData ( ) {
92- var rows = getTableBody ( ) . querySelectorAll ( 'tr' ) ,
93- i ;
93+ const rows = getTableBody ( ) . querySelectorAll ( 'tr' ) ;
94+ let i ;
9495
9596 for ( i = 0 ; i < rows . length ; i += 1 ) {
9697 rows [ i ] . data = loadRowData ( rows [ i ] ) ;
9798 }
9899 }
99100 // sorts the table using the data for the ith column
100101 function sortByIndex ( index , desc ) {
101- var key = cols [ index ] . key ,
102- sorter = function ( a , b ) {
103- a = a . data [ key ] ;
104- b = b . data [ key ] ;
105- return a < b ? - 1 : a > b ? 1 : 0 ;
106- } ,
107- finalSorter = sorter ,
108- tableBody = document . querySelector ( '.coverage-summary tbody' ) ,
109- rowNodes = tableBody . querySelectorAll ( 'tr' ) ,
110- rows = [ ] ,
111- i ;
102+ const { key } = cols [ index ] ;
103+ const sorter = function ( a , b ) {
104+ a = a . data [ key ] ;
105+ b = b . data [ key ] ;
106+ return a < b ? - 1 : a > b ? 1 : 0 ;
107+ } ;
108+ let finalSorter = sorter ;
109+ const tableBody = document . querySelector ( '.coverage-summary tbody' ) ;
110+ const rowNodes = tableBody . querySelectorAll ( 'tr' ) ;
111+ const rows = [ ] ;
112+ let i ;
112113
113114 if ( desc ) {
114115 finalSorter = function ( a , b ) {
@@ -129,8 +130,8 @@ var addSorting = (function () {
129130 }
130131 // removes sort indicators for current column being sorted
131132 function removeSortIndicators ( ) {
132- var col = getNthColumn ( currentSort . index ) ,
133- cls = col . className ;
133+ const col = getNthColumn ( currentSort . index ) ;
134+ let cls = col . className ;
134135
135136 cls = cls . replace ( / s o r t e d $ / , '' ) . replace ( / s o r t e d - d e s c $ / , '' ) ;
136137 col . className = cls ;
@@ -143,24 +144,24 @@ var addSorting = (function () {
143144 }
144145 // adds event listeners for all sorter widgets
145146 function enableUI ( ) {
146- var i ,
147- el ,
148- ithSorter = function ithSorter ( i ) {
149- var col = cols [ i ] ;
147+ let i ;
148+ let el ;
149+ const ithSorter = function ithSorter ( i ) {
150+ const col = cols [ i ] ;
150151
151- return function ( ) {
152- var desc = col . defaultDescSort ;
152+ return function ( ) {
153+ let desc = col . defaultDescSort ;
153154
154- if ( currentSort . index === i ) {
155- desc = ! currentSort . desc ;
156- }
157- sortByIndex ( i , desc ) ;
158- removeSortIndicators ( ) ;
159- currentSort . index = i ;
160- currentSort . desc = desc ;
161- addSortIndicators ( ) ;
162- } ;
155+ if ( currentSort . index === i ) {
156+ desc = ! currentSort . desc ;
157+ }
158+ sortByIndex ( i , desc ) ;
159+ removeSortIndicators ( ) ;
160+ currentSort . index = i ;
161+ currentSort . desc = desc ;
162+ addSortIndicators ( ) ;
163163 } ;
164+ } ;
164165 for ( i = 0 ; i < cols . length ; i += 1 ) {
165166 if ( cols [ i ] . sortable ) {
166167 // add the click event handler on the th so users
0 commit comments