Skip to content

EthicalAd: fixed footer placement for specific themes #618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions src/ethicalads.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ export class EthicalAdsAddon extends AddonBase {
placement.setAttribute("data-ea-type", "readthedocs-sidebar");
placement.setAttribute("id", "furo-sidebar-ad-placement");
knownPlacementFound = true;
} else {
// We know it's furo theme and the ad in the navbar is not above the fold at this point.
// Then, we render the ad as fixed footer.
selector = "div.page";
element = document.querySelector(selector);
element.style.setProperty("padding-bottom", "47.2px");
placement.setAttribute("data-ea-type", "text");
placement.setAttribute("data-ea-style", "fixedfooter");
placement.setAttribute("id", "furo-fixed-footer-ad-placement");
knownPlacementFound = true;
}
} else if (docTool.isSphinxBookThemeLikeTheme()) {
selector = ".sidebar-primary-items__start.sidebar-primary__section";
Expand Down Expand Up @@ -131,6 +141,20 @@ export class EthicalAdsAddon extends AddonBase {

placement.setAttribute("data-ea-type", "readthedocs-sidebar");
knownPlacementFound = true;
} else {
// We know it's Material for MkDocs theme and the ad in the navbar
// is not above the fold at this point. Then, we render the ad as
// fixed footer.
selector = "div.md-container";
element = document.querySelector(selector);
element.style.setProperty("padding-bottom", "47.2px");
placement.setAttribute("data-ea-type", "text");
placement.setAttribute("data-ea-style", "fixedfooter");
placement.setAttribute(
"id",
"mkdocs-material-fixed-footer-ad-placement",
);
knownPlacementFound = true;
}
} else if (docTool.isDocusaurusTheme()) {
selector = ".menu.thin-scrollbar.menu_SIkG";
Expand All @@ -145,6 +169,14 @@ export class EthicalAdsAddon extends AddonBase {
placement.setAttribute("data-ea-type", "readthedocs-sidebar");
placement.setAttribute("data-ea-style", "image");
knownPlacementFound = true;
} else {
selector = "div#__docusaurus";
element = document.querySelector(selector);
element.style.setProperty("padding-bottom", "47.2px");
placement.setAttribute("data-ea-type", "text");
placement.setAttribute("data-ea-style", "fixedfooter");
placement.setAttribute("id", "docusaurus-fixed-footer-ad-placement");
knownPlacementFound = true;
}
} else if (docTool.isDocsify()) {
selector = "main > aside > div.sidebar-nav";
Expand Down