Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/_includes/assets/css/screen.css
Original file line number Diff line number Diff line change
Expand Up @@ -2705,7 +2705,6 @@ a.banner:hover span {
}

.side-bar-ad-slot {
height: 600px;
width: 300px;
display: block;
}
Expand All @@ -2714,6 +2713,7 @@ a.banner:hover span {
/* ---------------------------------------------------------- */

.ad-wrapper {
width: 100%;
text-align: center;
height: auto;
}
Expand Down
2 changes: 1 addition & 1 deletion src/_includes/partials/ad.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="ad-text" data-test-label="ad-text">{{ localizedAdText | upper }}</div>
<ins
class="adsbygoogle"
style="display: block; height: 280px;"
style="display: block;"
data-ad-client="{{ secrets.googleAdsenseDataAdClient }}"
data-ad-slot="{{ secrets.googleAdsenseDataAdSlot }}"
data-ad-format="auto"
Expand Down
22 changes: 20 additions & 2 deletions src/_includes/partials/gam-lazy-loader.njk
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
<script>
document.addEventListener('DOMContentLoaded', function() {
var sidebar = document.querySelector('.sidebar');
var postContent = document.querySelector('.post-content');
var isSideBarDisplayed = window.getComputedStyle(sidebar).display !== 'none';

// Cap the sidebar height so it can never render taller than the main content
function capSidebarHeight() {
if (!isSideBarDisplayed || !postContent) return;
sidebar.style.maxHeight = postContent.offsetHeight + 'px';
sidebar.style.overflow = 'hidden';
}
capSidebarHeight();
window.addEventListener('load', capSidebarHeight);

function prepareAdSlot(elementId) {
// Get the element by ID
const targetElement = document.getElementById(elementId);
Expand Down Expand Up @@ -60,9 +71,16 @@ document.addEventListener('DOMContentLoaded', function() {
var sidebarHeight = sidebar.offsetHeight;
var adTextSideBarHeight = 0;
var sideBarAdContainert = 600 + 17;


// Since the sidebar contains content from multiple sources,
// account for its height so ads can fill leftover space
var existingContentHeight = 0;
for (var j = 0; j < sidebar.children.length; j++) {
existingContentHeight += sidebar.children[j].offsetHeight;
}

var styles = window.getComputedStyle(sidebar);
var avaiableSideAdSpace = sidebarHeight - adTextSideBarHeight - parseFloat(styles.paddingTop) - parseFloat(styles.paddingBottom);
var avaiableSideAdSpace = sidebarHeight - adTextSideBarHeight - existingContentHeight - parseFloat(styles.paddingTop) - parseFloat(styles.paddingBottom);
var numSideElements = Math.floor(avaiableSideAdSpace / sideBarAdContainert);
for (var i = 0; i < numSideElements; i++) {
// container element
Expand Down
Loading