Skip to content

Commit

Permalink
Use JS to only resize overflowing code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
RagnarGrootKoerkamp committed Jul 27, 2024
1 parent c985c98 commit bf27fc1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
10 changes: 1 addition & 9 deletions assets/css/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ h6 {
left: 50%;
transform: translateX(-50%);
position: relative;
@media only screen and (max-width: 920px) {
&.scroll {
left: 50%;
transform: translateX(-50vw);
border-radius: 0;
Expand All @@ -544,9 +544,6 @@ h6 {
padding-right: 1rem;
max-width: initial;
width: 100vw;
tr td:first-child {
display: none;
}
}
}

Expand All @@ -558,11 +555,6 @@ ol > li > .highlight > div {
}
}

.highlight {
// display: flex;
// justify-content: center;
}

pre {
display: block;
font-size: 1.6rem;
Expand Down
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ params:

# customCSS: []
customSCSS: ["css/style.scss", "css/syntax.css"]
customJS: ["js/toc.js", "js/footnote.js"]
customJS: ["js/toc.js", "js/footnote.js", "js/code.js"]
customHtml:

googleTagManager:
Expand Down
25 changes: 25 additions & 0 deletions static/js/code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var codescroll = function () {
console.log("codescroll");
var elements = document.querySelectorAll(".highlight > div.chroma");
for (element of elements) {
// Get the width of the screen
let screenWidth = window.innerWidth;
let threshold = screenWidth - 110;
let firstChild = element.firstElementChild;
console.log(
screenWidth,
threshold,
firstChild.offsetWidth,
element,
firstChild,
);
if (firstChild.offsetWidth > threshold) {
element.classList.add("scroll");
} else {
element.classList.remove("scroll");
}
}
};

codescroll();
window.onresize = codescroll;

0 comments on commit bf27fc1

Please sign in to comment.