Skip to content

Commit

Permalink
Merge pull request #144 from hlxsites/feature/sidebar-sticky
Browse files Browse the repository at this point in the history
Added sidebar sticky to all the templates
  • Loading branch information
davenichols-DHLS authored Nov 20, 2023
2 parents f85122a + 8f2bd63 commit 8c7541f
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 2 deletions.
56 changes: 56 additions & 0 deletions styles/Typo.css
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,62 @@ body.purple input[type="submit"]:hover {
width: 100%
}

.text-left {
text-align: left;
}

.text-center {
text-align: center;
}

.text-right {
text-align: right;
}

.padding-1 {
padding: 1px;
}

.padding-2 {
padding: 2px
}

.padding-4 {
padding: 4px;
}

.padding-8 {
padding: 8px;
}

.padding-16 {
padding: 16px;
}

.margin-1 {
margin: 1px;
}

.margin-2 {
margin: 2px
}

.margin-4 {
margin: 4px;
}

.margin-8 {
margin: 8px;
}

.margin-16 {
margin: 16px;
}

.bg-grey {
background-color: #ededed;
}

.cols-row,
.cols2-row,
.cols3-row {
Expand Down
4 changes: 2 additions & 2 deletions styles/template.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ body {
box-sizing: border-box;
margin: 0 auto;
text-align: left;
width: 980px
width: 980px;
}

#header {
Expand Down Expand Up @@ -543,7 +543,7 @@ body.full-width #main {
float: right;
font-size: 16px;
line-height: normal;
width: 26%
width: 26%;
}

body.sidebar-50 #sidebar {
Expand Down
30 changes: 30 additions & 0 deletions templates/Blog/Blog.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,33 @@
.post-topics {
padding: 1em 0;
}

.outer {
display: flex;
justify-content: space-between;
}

#main {
float: none;
}

#sidebar {
position: sticky;
top: 130px;
float: none;
}

@media (max-width: 960px) {
#sidebar {
top: 80px;
}
}

@media (max-width: 860px) {
.outer {
flex-direction: column;
}
#sidebar {
max-height: none;
}
}
16 changes: 16 additions & 0 deletions templates/Blog/Blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,20 @@ function renderShareButtons(container, url, title) {
container.appendChild(list);
}

function setSidebarMaxHeight() {
let height = 0;
const sidebar = document.querySelector('#sidebar');
[...sidebar.children].forEach((element) => {
height += element.offsetHeight;
});
sidebar.style.maxHeight = `${height}px`;
}

function setSidebarHeight() {
window.addEventListener('resize', setSidebarMaxHeight);
window.addEventListener('click', setSidebarMaxHeight);
}

export default async function buildAutoBlocks(block) {
const searchParams = new URLSearchParams(window.location.search);
let pageNumber = 1; // Use let instead of const
Expand Down Expand Up @@ -340,4 +354,6 @@ export default async function buildAutoBlocks(block) {
content.appendChild(clearFix);
defaultTemplate.appendChild(content);
block.appendChild(defaultTemplate);
setSidebarMaxHeight();
setSidebarHeight();
}
30 changes: 30 additions & 0 deletions templates/Default/Default.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,34 @@

.default-content-wrapper h2:first-child {
margin-top: 0px!important;
}

.outer {
display: flex;
justify-content: space-between;
}

#main {
float: none;
}

#sidebar {
position: sticky;
top: 130px;
float: none;
}

@media (max-width: 960px) {
#sidebar {
top: 80px;
}
}

@media (max-width: 860px) {
.outer {
flex-direction: column;
}
#sidebar {
max-height: none;
}
}
16 changes: 16 additions & 0 deletions templates/Default/Default.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
function setSidebarMaxHeight() {
let height = 0;
const sidebar = document.querySelector('#sidebar');
[...sidebar.children].forEach((element) => {
height += element.offsetHeight;
});
sidebar.style.maxHeight = `${height}px`;
}

function setSidebarHeight() {
window.addEventListener('resize', setSidebarMaxHeight);
window.addEventListener('click', setSidebarMaxHeight);
}

export default function buildAutoBlocks(block) {
const blocks = block.querySelector('.section');
const sidebars = blocks.querySelectorAll('[data-block-name^="sidebar-"]');
Expand Down Expand Up @@ -50,4 +64,6 @@ export default function buildAutoBlocks(block) {
content.appendChild(clearFix);
defaultTemplate.appendChild(content);
block.appendChild(defaultTemplate);
setSidebarMaxHeight();
setSidebarHeight();
}
30 changes: 30 additions & 0 deletions templates/News/News.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,33 @@
.post-topics {
padding: 1em 0;
}

.outer {
display: flex;
justify-content: space-between;
}

#main {
float: none;
}

#sidebar {
position: sticky;
top: 130px;
float: none;
}

@media (max-width: 960px) {
#sidebar {
top: 80px;
}
}

@media (max-width: 860px) {
.outer {
flex-direction: column;
}
#sidebar {
max-height: none;
}
}
16 changes: 16 additions & 0 deletions templates/News/News.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,20 @@ function renderShareButtons(container, url, title) {
container.appendChild(list);
}

function setSidebarMaxHeight() {
let height = 0;
const sidebar = document.querySelector('#sidebar');
[...sidebar.children].forEach((element) => {
height += element.offsetHeight;
});
sidebar.style.maxHeight = `${height}px`;
}

function setSidebarHeight() {
window.addEventListener('resize', setSidebarMaxHeight);
window.addEventListener('click', setSidebarMaxHeight);
}

export default async function buildAutoBlocks(block) {
const searchParams = new URLSearchParams(window.location.search);
let pageNumber = 1; // Use let instead of const
Expand Down Expand Up @@ -339,4 +353,6 @@ export default async function buildAutoBlocks(block) {
content.appendChild(clearFix);
defaultTemplate.appendChild(content);
block.appendChild(defaultTemplate);
setSidebarMaxHeight();
setSidebarHeight();
}

0 comments on commit 8c7541f

Please sign in to comment.