@@ -7,51 +7,42 @@ var tables = document.querySelectorAll("table.configuration-reference");
7
7
var typingTimer ;
8
8
9
9
if ( tables ) {
10
- var idx = 0 ;
11
10
for ( var table of tables ) {
12
11
var caption = table . previousElementSibling ;
13
12
if ( table . classList . contains ( 'searchable' ) ) { // activate search engine only when needed
14
- var input = document . createElement ( "input" ) ;
15
- input . setAttribute ( "type" , "search" ) ;
16
- input . setAttribute ( "placeholder" , "FILTER CONFIGURATION" ) ;
17
- input . id = "config-search-" + ( idx ++ ) ;
18
- caption . children . item ( 0 ) . appendChild ( input ) ;
13
+ var input = caption . firstElementChild . lastElementChild ;
19
14
input . addEventListener ( "keyup" , initiateSearch ) ;
20
15
input . addEventListener ( "input" , initiateSearch ) ;
21
- var descriptions = table . querySelectorAll ( ".description" ) ;
22
- if ( descriptions ) {
23
- var heights = new Array ( descriptions . length ) ;
24
- var h = 0 ;
25
- for ( description of descriptions ) {
26
- heights [ h ++ ] = description . offsetHeight ;
27
- }
28
- var shadowTable = table . cloneNode ( true ) ;
29
- var shadowDescriptions = shadowTable . querySelectorAll ( ".description" ) ;
30
- h = 0 ;
31
- for ( shadowDescription of shadowDescriptions ) {
32
- makeCollapsible ( shadowDescription , heights [ h ++ ] ) ;
33
- }
34
- table . parentNode . replaceChild ( shadowTable , table ) ;
35
- table = shadowTable ;
36
- }
16
+ input . attributes . removeNamedItem ( 'disabled' ) ;
37
17
inputs [ input . id ] = { "table" : table } ;
38
18
}
39
19
40
- var rowIdx = 0 ;
41
- for ( var row of table . querySelectorAll ( "table.configuration-reference > tbody > tr" ) ) {
42
- var heads = row . querySelectorAll ( "table.configuration-reference > tbody > tr > th" ) ;
43
- if ( ! heads || heads . length == 0 ) {
44
- // mark even rows
45
- if ( ++ rowIdx % 2 ) {
46
- row . classList . add ( "odd" ) ;
47
- } else {
48
- row . classList . remove ( "odd" ) ;
49
- }
50
- } else {
51
- // reset count at each section
52
- rowIdx = 0 ;
20
+ const collapsibleRows = table . querySelectorAll ( 'tr.row-collapsible' ) ;
21
+ if ( collapsibleRows ) {
22
+ for ( let row of collapsibleRows ) {
23
+ const td = row . firstElementChild ;
24
+ const decoration = td . firstElementChild . lastElementChild . firstElementChild ;
25
+ const iconDecoration = decoration . children . item ( 0 ) ;
26
+ const collapsibleSpan = decoration . children . item ( 1 ) ;
27
+ const descDiv = td . firstElementChild . children . item ( 1 ) ;
28
+ const collapsibleHandler = makeCollapsibleHandler ( descDiv , td , row , collapsibleSpan , iconDecoration ) ;
29
+ row . addEventListener ( 'click' , collapsibleHandler ) ;
53
30
}
54
31
}
32
+
33
+ // render hidden rows asynchronously
34
+ setTimeout ( ( ) => renderHiddenRows ( ) ) ;
35
+ }
36
+ }
37
+
38
+ function renderHiddenRows ( ) {
39
+ // some rows are initially hidden so that user can hit the ground running
40
+ // we render them at this very moment, but when user can already use search function
41
+ const hiddenRows = document . querySelectorAll ( 'table.configuration-reference-all-rows.tableblock > tbody > tr.row-hidden' ) ;
42
+ if ( hiddenRows ) {
43
+ for ( row of hiddenRows ) {
44
+ row . classList . remove ( 'row-hidden' ) ;
45
+ }
55
46
}
56
47
}
57
48
@@ -164,8 +155,8 @@ function reinstallClickHandlers(table){
164
155
var td = getAncestor ( descDiv , "td" ) ;
165
156
var row = td . parentNode ;
166
157
var decoration = content . lastElementChild ;
167
- var iconDecoration = decoration . children . item ( 0 ) ;
168
- var collapsibleSpan = decoration . children . item ( 1 ) ;
158
+ var iconDecoration = decoration . firstElementChild . children . item ( 0 ) ;
159
+ var collapsibleSpan = decoration . firstElementChild . children . item ( 1 ) ;
169
160
var collapsibleHandler = makeCollapsibleHandler ( descDiv , td , row ,
170
161
collapsibleSpan ,
171
162
iconDecoration ) ;
@@ -178,6 +169,12 @@ function reinstallClickHandlers(table){
178
169
function swapShadowTable ( input ) {
179
170
var currentTable = inputs [ input . id ] . table ;
180
171
var shadowTable = inputs [ input . id ] . shadowTable ;
172
+
173
+ // makes sure hidden rows are always displayed when search term is defined
174
+ if ( shadowTable . classList . contains ( 'configuration-reference-all-rows' ) ) {
175
+ shadowTable . classList . remove ( 'configuration-reference-all-rows' ) ;
176
+ }
177
+
181
178
currentTable . parentNode . replaceChild ( shadowTable , currentTable ) ;
182
179
inputs [ input . id ] . table = shadowTable ;
183
180
inputs [ input . id ] . shadowTable = currentTable ;
@@ -254,41 +251,9 @@ function getAncestor(element, name){
254
251
return null ;
255
252
}
256
253
257
- /*
258
- * COLLAPSIBLE DESCRIPTION
259
- */
260
- function makeCollapsible ( descDiv , descHeightLong ) {
261
- if ( descHeightLong > 25 ) {
262
- var td = getAncestor ( descDiv , "td" ) ;
263
- var row = td . parentNode ;
264
- var iconDecoration = document . createElement ( "i" ) ;
265
- descDiv . classList . add ( 'description-collapsed' ) ;
266
- iconDecoration . classList . add ( 'fa' , 'fa-chevron-down' ) ;
267
-
268
- var descDecoration = document . createElement ( "div" ) ;
269
- descDecoration . classList . add ( 'description-decoration' ) ;
270
- descDecoration . appendChild ( iconDecoration ) ;
271
-
272
- var collapsibleSpan = document . createElement ( "span" ) ;
273
- collapsibleSpan . appendChild ( document . createTextNode ( "Show more" ) ) ;
274
- descDecoration . appendChild ( collapsibleSpan ) ;
275
-
276
- var collapsibleHandler = makeCollapsibleHandler ( descDiv , td , row ,
277
- collapsibleSpan ,
278
- iconDecoration ) ;
279
-
280
- var parent = descDiv . parentNode ;
281
-
282
- parent . appendChild ( descDecoration ) ;
283
- row . classList . add ( "row-collapsible" , "row-collapsed" ) ;
284
- row . addEventListener ( "click" , collapsibleHandler ) ;
285
- }
286
-
287
- } ;
288
-
289
254
function makeCollapsibleHandler ( descDiv , td , row ,
290
- collapsibleSpan ,
291
- iconDecoration ) {
255
+ collapsibleSpan ,
256
+ iconDecoration ) {
292
257
293
258
return function ( event ) {
294
259
var target = event . target ;
@@ -316,4 +281,4 @@ function makeCollapsibleHandler(descDiv, td, row,
316
281
} ;
317
282
}
318
283
319
- } ) ;
284
+ } ) ;
0 commit comments