Skip to content

Commit

Permalink
Style: Allow tables to overflow for reponsiveness by wrapping w/JS
Browse files Browse the repository at this point in the history
  • Loading branch information
CAM-Gerlach committed Mar 21, 2022
1 parent cb01bd4 commit 8d2fcab
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
4 changes: 0 additions & 4 deletions pep_sphinx_extensions/pep_theme/static/mq.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
pre {
font-size: 0.75rem;
}
table th,
table td {
font-size: 3vw;
}
}

/* Reduce padding & margins for smaller screens */
Expand Down
5 changes: 5 additions & 0 deletions pep_sphinx_extensions/pep_theme/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ sup {top: -0.5em}
sub {bottom: -0.25em}

/* Table rules */
div.table-wrapper {
overflow-x: scroll;
scrollbar-width: thin; /* CSS Standards, not *yet* widely supported */
scrollbar-color: var(--colour-scrollbar) transparent;
}
table {
width: 100%;
border-collapse: collapse;
Expand Down
30 changes: 30 additions & 0 deletions pep_sphinx_extensions/pep_theme/static/wrap_tables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Wrap the tables in PEP bodies in a div, to allow for responsive scrolling

"use strict";

const pepContentId = "pep-content";


// Wrap passed table element in wrapper divs
function wrapTable (table) {
const wrapper = document.createElement("div");
wrapper.classList.add("table-wrapper");
table.parentNode.insertBefore(wrapper, table);
wrapper.appendChild(table);
}


// Wrap all tables in the PEP content in wrapper divs
function wrapPepContentTables () {
const pepContent = document.getElementById(pepContentId);
const bodyTables = pepContent.getElementsByTagName("table");
Array.from(bodyTables).forEach(wrapTable);
}


// Wrap the tables as soon as the DOM is loaded
document.addEventListener("DOMContentLoaded", () => {
if (document.getElementById(pepContentId)) {
wrapPepContentTables();
}
})
1 change: 1 addition & 0 deletions pep_sphinx_extensions/pep_theme/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ <h2>Contents</h2>
</nav>
</section>
<script src="{{ pathto('_static/colour_scheme.js', resource=True) }}"></script>
<script src="{{ pathto('_static/wrap_tables.js', resource=True) }}"></script>
</body>
</html>

0 comments on commit 8d2fcab

Please sign in to comment.