Skip to content

Commit

Permalink
Hide empty elements (containing no text or other elements)
Browse files Browse the repository at this point in the history
  • Loading branch information
tverbeiren committed Sep 28, 2023
1 parent 300ade3 commit 1f92e79
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
14 changes: 14 additions & 0 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ format:
function virusFormatter(value, row) {
return value
};
// Rewrite the DOM by adding a .blank class to all 'empty' div elements
// The :empty CSS attribute does not work on DIV elements containing a newline
// The below checks if a node contains only whitespace AND has no children
function cleanUpMyDOM(){
var nodes = document.querySelectorAll("div");
for(var i = 0; i < nodes.length; i++) {
const content = nodes[i].innerHTML.replace(/^[\s\n]+|[\s\n]+$/, '');
if(!content && ( nodes[i].children.length == 0) ) {
nodes[i].className += " blank";
}
}
}
window.addEventListener("load", cleanUpMyDOM);
</script>
Expand Down
36 changes: 25 additions & 11 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,37 @@ table {
}

/* Virus pages */
/* .temp:empty { */
/* width: 90%; */
/* margin: auto; */
/* padding: 10px; */
/* border: 1px solid #9095A8; */
/* background: yellow !important; */
/* } */

/* Virus pages */
.blank {
display: none;
}

.virus-figure {
width: 90%;
margin: auto;
padding: 10px;
border: 1px solid #9095A8;
}

/* Add an indicator that text can be found below the figure */
.virus-figure::before {
font-weight: 300;
font-size: 1em;
float: right;
vertical-align: top;
color: #9095A8;
font-style: italic;
content: "text under figure(s)";
}

.virus-toolbox {
font-weight: 500;
font-size: 1.2em;
Expand All @@ -364,19 +388,9 @@ table {
width: 80%;
margin: auto;
text-align: left;
border-top: 4px solid #9095A8;
border-left: 4px solid #9095A8;
border-right: 4px solid #9095A8;
border-bottom: 4px solid #9095A8;
padding: 10px;
}

.virus-figure::before {
font-weight: 300;
font-size: 1em;
float: right;
vertical-align: top;
color: #9095A8;
font-style: italic;
content: "text under figure(s)";
}

0 comments on commit 1f92e79

Please sign in to comment.