Problem:
- The height of a details/summary element pair is equal to the height of the summary element only when the details element is collapsed.
- The details/summary element must be expanded before its height can be calculated.
- Setting an equal height on a collapsed element makes it take up the space it would take up while expanded even though it is collapsed.
- The equal height should only apply when at least one more details/summary element pair is expanded on the same baseline.
Temporarily expanding a detail/summary element pair:
elm.setAttribute("open", "open")
elm.offsetHeight
elm.removeAttribute("open")
Determining if at least two expanded details/summary pairs exist on the same baseline:
function rowHasMultipleExpandedElements(row) {
var i,
count = 0;
for (i = row.length -1; row !== -1; i -= 1) {
if (row[i].hasAttribute("open")) {
count += 1;
}
if (count === 2) {
return true;
}
}
return false;
}
Storing the height to trigger when the detail/summary is expanded:
$elm.data("min-height", height);
Triggering the equal height:
var i;
if (rowHasMultipleExpandedElements(row)) {
for (i = row.length -1; i !== -1; i -= 1) {
row[i].style.minHeight = $(row[i]).data("min-height");
}
}