Skip to content

Commit ac1ff1b

Browse files
committed
Refactor initial loading of config properties
1 parent 4df4d27 commit ac1ff1b

File tree

6 files changed

+256
-291
lines changed

6 files changed

+256
-291
lines changed

Diff for: _guides/javascript/config.js

+37-72
Original file line numberDiff line numberDiff line change
@@ -7,51 +7,42 @@ var tables = document.querySelectorAll("table.configuration-reference");
77
var typingTimer;
88

99
if(tables){
10-
var idx = 0;
1110
for (var table of tables) {
1211
var caption = table.previousElementSibling;
1312
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;
1914
input.addEventListener("keyup", initiateSearch);
2015
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');
3717
inputs[input.id] = {"table": table};
3818
}
3919

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);
5330
}
5431
}
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+
}
5546
}
5647
}
5748

@@ -164,8 +155,8 @@ function reinstallClickHandlers(table){
164155
var td = getAncestor(descDiv, "td");
165156
var row = td.parentNode;
166157
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);
169160
var collapsibleHandler = makeCollapsibleHandler(descDiv, td, row,
170161
collapsibleSpan,
171162
iconDecoration);
@@ -178,6 +169,12 @@ function reinstallClickHandlers(table){
178169
function swapShadowTable(input){
179170
var currentTable = inputs[input.id].table;
180171
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+
181178
currentTable.parentNode.replaceChild(shadowTable, currentTable);
182179
inputs[input.id].table = shadowTable;
183180
inputs[input.id].shadowTable = currentTable;
@@ -254,41 +251,9 @@ function getAncestor(element, name){
254251
return null;
255252
}
256253

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-
289254
function makeCollapsibleHandler(descDiv, td, row,
290-
collapsibleSpan,
291-
iconDecoration) {
255+
collapsibleSpan,
256+
iconDecoration) {
292257

293258
return function(event) {
294259
var target = event.target;
@@ -316,4 +281,4 @@ function makeCollapsibleHandler(descDiv, td, row,
316281
};
317282
}
318283

319-
});
284+
});

Diff for: _plugins/asciidoctor-extension.rb

+98-1
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,101 @@
5050
create_inline_pass parent, %(#{copy_btn})
5151
end
5252
end
53-
end
53+
end
54+
55+
56+
### ALL CONFIG page processors
57+
58+
# add show more 'button'
59+
doc_max_id = Array.new
60+
Extensions.register do
61+
tree_processor do
62+
process do |doc|
63+
# skip 2.7 branch as following code is not backwards compatible
64+
if !(doc.base_dir.include? '2.7')
65+
row_id = 0
66+
search_field_id = 0
67+
doc.find_by context: :table do |table|
68+
if (table.role && (table.role.include? 'configuration-reference'))
69+
table.add_role 'configuration-reference-all-rows'
70+
table.rows.body.each do |row|
71+
if (row && row.size > 0 && row[0].inner_document)
72+
row[0].inner_document.find_by role: 'description' do |desc|
73+
row_id += 1
74+
if (desc.blocks && desc.blocks.size && (desc.blocks.size > 1 || (desc.blocks.size == 1 && desc.blocks[0].content && !(desc.blocks[0].content.start_with? 'Environment variable: '))))
75+
# now we know description consist of more than one 'Environment variable' line
76+
desc.id = %(conf-collapsible-desc-#{row_id})
77+
desc.add_role 'description-collapsed'
78+
btnBlock = Block.new(desc.parent, :paragraph, source: %(<i class="fa fa-chevron-down"></i><span>Show more</span>))
79+
btnBlock.add_role 'description-decoration'
80+
# add show more 'button'
81+
row[0].inner_document.blocks.push(btnBlock)
82+
else
83+
desc.id = %(conf-non-collapsible-desc-#{row_id})
84+
end
85+
end
86+
end
87+
end
88+
if (table.role.include? 'searchable')
89+
caption = (children = table.parent.blocks)[(children.index table)-1]
90+
# create new caption with disabled search input
91+
new_caption = Block.new(caption.parent, :paragraph, source: %(#{caption.content} <input type="search" id="config-search-#{search_field_id}" placeholder="FILTER CONFIGURATION" disabled>))
92+
search_field_id += 1
93+
# replace original caption with enhanced one
94+
(children = caption.parent.blocks)[children.index caption] = new_caption
95+
end
96+
end
97+
end
98+
if row_id != 0
99+
# collect row ids per document
100+
doc_max_id.push(row_id)
101+
doc.id = %(page-with-config-#{doc_max_id.size - 1})
102+
end
103+
end
104+
end
105+
end
106+
end
107+
108+
# set CSS classes to rows with description
109+
Extensions.register do
110+
postprocessor do
111+
process do |doc, output|
112+
if doc.id && (doc.id.start_with? 'page-with-config-')
113+
doc_max_id_idx = doc.id.gsub('page-with-config-', '').to_i
114+
for id in 1..doc_max_id[doc_max_id_idx] do
115+
css_class = ''
116+
if (id > 30)
117+
css_class = ' row-hidden'
118+
end
119+
if (id.odd?)
120+
css_class += ' odd'
121+
end
122+
desc_idx = output.index(%(id="conf-collapsible-desc-#{id}"), 0)
123+
if (desc_idx)
124+
# collapsible description
125+
# set CSS classes for collapsible row
126+
row_idx = output.rindex('<tr>', desc_idx)
127+
if row_idx
128+
output[row_idx..(row_idx + 3)] = %(<tr class="row-collapsible row-collapsed row-with-desc#{css_class}">)
129+
else
130+
# illegal state - we don't expect this to happen unless there are breaking changes in Asciidoctor
131+
LoggerManager.logger.error(%(Failed to detect '<tr>' element on page #{doc.title}, show more button and config search won't work as expected))
132+
end
133+
else
134+
# odd non-collapsible row with description
135+
# add 'odd' CSS class
136+
desc_idx = output.index(%(id="conf-non-collapsible-desc-#{id}"), 0)
137+
row_idx = output.rindex('<tr>', desc_idx)
138+
if row_idx
139+
output[row_idx..(row_idx + 3)] = %(<tr class="#{css_class}">)
140+
else
141+
# illegal state - we don't expect this to happen unless there are breaking changes in Asciidoctor
142+
LoggerManager.logger.error(%(Failed to detect '<tr>' element on page #{doc.title}, row background color won't be correct))
143+
end
144+
end
145+
end
146+
end
147+
output
148+
end
149+
end
150+
end

Diff for: _sass/quarkus.scss

+10-2
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,19 @@ table.configuration-reference {
323323
}
324324

325325

326-
table.configuration-reference.tableblock > tbody {
327-
326+
table.configuration-reference-all-rows.tableblock > tbody {
327+
328+
> tr.row-hidden {
329+
display: none;
330+
}
331+
}
332+
333+
table.configuration-reference.tableblock > tbody {
334+
328335
> tr > th {
329336
color: $dark-blue;
330337
}
338+
331339
> tr {
332340
background: transparent;
333341
> th:nth-child(1) { width: 70%; }

0 commit comments

Comments
 (0)