@@ -23,38 +23,41 @@ function getElementIndex(el) {
23
23
24
24
var mappingTableInfos = [ ] ;
25
25
26
- function viewAsSingleTable ( mappingTableInfo ) {
27
- hideElement ( mappingTableInfo . detailsContainer ) ;
28
- // add <summary> @id to ids array and remove @id from summary
29
- queryAll ( 'summary' , mappingTableInfo . detailsContainer ) . forEach ( function (
26
+ function viewAsSingleTable ( tableContainer , detailsContainer ) {
27
+ hideElement ( detailsContainer ) ;
28
+ showElement ( tableContainer ) ;
29
+
30
+ // Remove ids from summary
31
+ queryAll ( 'summary' , detailsContainer ) . forEach ( function (
30
32
summary
31
33
) {
32
34
summary . dataset [ 'id' ] = summary . id ;
33
35
summary . removeAttribute ( 'id' ) ;
34
36
} ) ;
35
- showElement ( mappingTableInfo . tableContainer ) ;
36
37
37
- // add relevant @id to tr
38
- queryAll ( 'tbody tr' , mappingTableInfo . tableContainer ) . forEach ( function (
38
+ // Add ids to table
39
+ queryAll ( 'tbody tr' , tableContainer ) . forEach ( function (
39
40
tr
40
41
) {
41
42
tr . id = tr . dataset [ 'id' ] ;
42
43
tr . removeAttribute ( 'data-id' ) ;
43
44
} ) ;
44
45
}
45
46
46
- function viewAsDetails ( mappingTableInfo ) {
47
- hideElement ( mappingTableInfo . tableContainer ) ;
48
- // add tr @id to ids array and remove @id from tr
49
- queryAll ( 'tbody tr' , mappingTableInfo . tableContainer ) . forEach ( function (
47
+ function viewAsDetails ( tableContainer , detailsContainer ) {
48
+ hideElement ( tableContainer ) ;
49
+ showElement ( detailsContainer ) ;
50
+
51
+ // Remove ids from table
52
+ queryAll ( 'tbody tr' , tableContainer ) . forEach ( function (
50
53
tr
51
54
) {
52
55
tr . dataset [ 'id' ] = tr . id ;
53
56
tr . removeAttribute ( 'id' ) ;
54
57
} ) ;
55
- showElement ( mappingTableInfo . detailsContainer ) ;
56
- // add relevant @id to summary
57
- queryAll ( 'summary' , mappingTableInfo . detailsContainer ) . forEach ( function (
58
+
59
+ // Add ids to summary
60
+ queryAll ( 'summary' , detailsContainer ) . forEach ( function (
58
61
summary
59
62
) {
60
63
summary . id = summary . dataset [ 'id' ] ;
@@ -72,6 +75,7 @@ function expandReferredDetails(summaryFragId) {
72
75
73
76
function mappingTables ( ) {
74
77
queryAll ( '.table-container' ) . forEach ( function ( container ) {
78
+
75
79
// object to store information about a mapping table.
76
80
var tableInfo = { } ;
77
81
mappingTableInfos . push ( tableInfo ) ;
@@ -94,22 +98,8 @@ function mappingTables() {
94
98
95
99
// add switch to view as single table or details/summary
96
100
var viewSwitch = document . createElement ( 'button' ) ;
97
- viewSwitch . className = 'switch-view removeOnSave ' ;
101
+ viewSwitch . className = 'switch-view' ;
98
102
viewSwitch . innerHTML = mappingTableLabels . viewByTable ;
99
- viewSwitch . addEventListener ( 'click' , function ( ) {
100
- // if current view is details/summary
101
- if ( tableInfo . detailsContainer . style . display !== 'none' ) {
102
- viewAsSingleTable ( tableInfo ) ;
103
- // toggle the viewSwitch label from view-as-single-table to view-by-X
104
- viewSwitch . innerHTML =
105
- mappingTableLabels . viewByLabels [ tableInfo . table . id ] ;
106
- } else {
107
- viewAsDetails ( tableInfo ) ;
108
- // toggle the viewSwitch label from view-by-X to view-as-single-table.
109
- viewSwitch . innerHTML = mappingTableLabels . viewByTable ;
110
- }
111
- } ) ;
112
-
113
103
tableInfo . tableContainer . insertAdjacentElement ( 'beforebegin' , viewSwitch ) ;
114
104
115
105
// store the table's column headers in array colHeaders
@@ -127,7 +117,9 @@ function mappingTables() {
127
117
var caption = row . querySelector ( 'th' ) . innerHTML ;
128
118
var summary = caption . replace ( / < a [ ^ > ] + > | < \/ a > / g, '' ) ;
129
119
// get the tr's @id
130
- var id = row . dataset . id ;
120
+ var id = row . id ;
121
+ row . dataset . id = id ;
122
+
131
123
// remove the tr's @id since same id will be used in the relevant summary element
132
124
row . removeAttribute ( 'id' ) ;
133
125
// store the row's cells in array rowCells
@@ -187,12 +179,12 @@ function mappingTables() {
187
179
188
180
// add 'expand/collapse all' functionality
189
181
var expandAllButton = document . createElement ( 'button' ) ;
190
- expandAllButton . className = 'expand removeOnSave ' ;
182
+ expandAllButton . className = 'expand' ;
191
183
expandAllButton . innerHTML = mappingTableLabels . expand ;
192
184
193
185
var collapseAllButton = document . createElement ( 'button' ) ;
194
186
collapseAllButton . disabled = true ;
195
- collapseAllButton . className = 'collapse removeOnSave ' ;
187
+ collapseAllButton . className = 'collapse' ;
196
188
collapseAllButton . innerHTML = mappingTableLabels . collapse ;
197
189
198
190
tableInfo . detailsContainer . insertBefore (
@@ -203,97 +195,6 @@ function mappingTables() {
203
195
expandAllButton ,
204
196
tableInfo . detailsContainer . firstChild
205
197
) ;
206
-
207
- var expandCollapseDetails = function ( detCont , action ) {
208
- queryAll ( 'details' , detCont ) . forEach ( function ( details ) {
209
- details . open = action !== 'collapse'
210
- } ) ;
211
- } ;
212
-
213
- expandAllButton . addEventListener ( 'click' , function ( ) {
214
- expandCollapseDetails ( tableInfo . detailsContainer , 'expand' ) ;
215
- expandAllButton . disabled = true ;
216
- tableInfo . detailsContainer
217
- . querySelector ( 'button.collapse' )
218
- . removeAttribute ( 'disabled' ) ;
219
- } ) ;
220
-
221
- collapseAllButton . addEventListener ( 'click' , function ( ) {
222
- expandCollapseDetails ( tableInfo . detailsContainer , 'collapse' ) ;
223
- collapseAllButton . disabled = true ;
224
- tableInfo . detailsContainer
225
- . querySelector ( 'button.expand' )
226
- . removeAttribute ( 'disabled' ) ;
227
- } ) ;
228
-
229
- // add collapsible table columns functionality
230
- var showHideCols = document . createElement ( 'div' ) ;
231
- showHideCols . className = 'show-hide-cols removeOnSave' ;
232
- showHideCols . innerHTML =
233
- '<span>' + mappingTableLabels . showHideCols + '</span>' ;
234
-
235
- for ( var i = 0 , len = colHeaders . length ; i < len ; i ++ ) {
236
- ( function ( i ) {
237
- var toggleLabel = colHeaders [ i ]
238
- . replace ( / < a [ ^ < ] + > | < \/ a > / g, '' )
239
- . replace ( / < s u p > \[ N o t e [ 0 - 9 ] + \] < \/ s u p > / g, '' ) ;
240
-
241
- var showHideColButton = document . createElement ( 'button' ) ;
242
- showHideColButton . className = 'hide-col' ;
243
- showHideColButton . setAttribute ( 'aria-pressed' , false ) ;
244
- showHideColButton . setAttribute (
245
- 'title' ,
246
- mappingTableLabels . hideToolTipText
247
- ) ;
248
- showHideColButton . innerHTML =
249
- '<span class="action">' +
250
- mappingTableLabels . hideActionText +
251
- '</span>' +
252
- toggleLabel ;
253
-
254
- showHideColButton . addEventListener ( 'click' , function ( ) {
255
- var index = getElementIndex ( showHideColButton ) ;
256
- console . log ( "index?" , index ) ;
257
- var wasHidden = showHideColButton . className === 'hide-col' ;
258
-
259
- queryAll (
260
- 'tr>th:nth-child(' + index + '), tr>td:nth-child(' + index + ')' ,
261
- tableInfo . table
262
- ) . forEach ( function ( element ) {
263
- if ( wasHidden ) {
264
- hideElement ( element ) ;
265
- } else {
266
- showElement ( element ) ;
267
- }
268
- } ) ;
269
-
270
- showHideColButton . className = wasHidden ? 'show-col' : 'hide-col' ;
271
- showHideColButton . setAttribute ( 'aria-pressed' , wasHidden ) ;
272
- showHideColButton . setAttribute (
273
- 'title' ,
274
- wasHidden
275
- ? mappingTableLabels . showToolTipText
276
- : mappingTableLabels . hideToolTipText
277
- ) ;
278
- showHideColButton . querySelector ( 'span' ) . innerText = wasHidden
279
- ? mappingTableLabels . showActionText
280
- : mappingTableLabels . hideActionText ;
281
- } ) ;
282
- queryAll ( 'span' , showHideColButton )
283
- . filter ( function ( span ) {
284
- return ! span . classList . contains ( 'action' ) ;
285
- } )
286
- . forEach ( function ( span ) {
287
- span . parentNode . removeChild ( span ) ;
288
- } ) ;
289
- showHideCols . appendChild ( showHideColButton ) ;
290
- } ) ( i )
291
- }
292
-
293
- tableInfo . tableContainer . insertBefore (
294
- showHideCols ,
295
- tableInfo . tableContainer . firstChild
296
- ) ;
297
198
} ) ;
298
199
299
200
// if page URL links to frag id, reset location to frag id once details/summary view is set
@@ -318,3 +219,53 @@ function mappingTables() {
318
219
}
319
220
} ) ;
320
221
}
222
+
223
+ document . addEventListener ( "DOMContentLoaded" , ( ) => {
224
+
225
+ document . querySelectorAll ( 'button.switch-view' ) . forEach ( function ( b ) {
226
+ b . addEventListener ( 'click' , function ( ) {
227
+ tableContainer = b . parentElement . querySelector ( '.table-container' ) ;
228
+ table = tableContainer . querySelector ( 'table' ) ;
229
+ detailsContainer = b . parentElement . querySelector ( '.details' ) ;
230
+
231
+ if ( detailsContainer . style . display !== 'none' ) {
232
+ viewAsSingleTable ( tableContainer , detailsContainer ) ;
233
+ // toggle the viewSwitch label from view-as-single-table to view-by-X
234
+ b . innerHTML =
235
+ mappingTableLabels . viewByLabels [ table . id ] ;
236
+ } else {
237
+ viewAsDetails ( tableContainer , detailsContainer ) ;
238
+ // toggle the viewSwitch label from view-by-X to view-as-single-table.
239
+ b . innerHTML = mappingTableLabels . viewByTable ;
240
+ }
241
+ } ) ;
242
+ } ) ;
243
+
244
+ var expandCollapseDetails = function ( detCont , action ) {
245
+ queryAll ( 'details' , detCont ) . forEach ( function ( details ) {
246
+ details . open = action !== 'collapse'
247
+ } ) ;
248
+ } ;
249
+
250
+ document . querySelectorAll ( 'button.expand' ) . forEach ( function ( b ) {
251
+ b . addEventListener ( 'click' , function ( ) {
252
+ detailsContainer = b . parentElement . querySelector ( '.details' ) ;
253
+ expandCollapseDetails ( detailsContainer , 'expand' ) ;
254
+ b . disabled = true ;
255
+ b . parentElement
256
+ . querySelector ( 'button.collapse' )
257
+ . removeAttribute ( 'disabled' ) ;
258
+ } ) ;
259
+ } ) ;
260
+
261
+ document . querySelectorAll ( 'button.collapse' ) . forEach ( function ( b ) {
262
+ b . addEventListener ( 'click' , function ( ) {
263
+ detailsContainer = b . parentElement . querySelector ( '.details' ) ;
264
+ expandCollapseDetails ( detailsContainer , 'collapse' ) ;
265
+ b . disabled = true ;
266
+ b . parentElement
267
+ . querySelector ( 'button.expand' )
268
+ . removeAttribute ( 'disabled' ) ;
269
+ } ) ;
270
+ } ) ;
271
+ } ) ;
0 commit comments