-
Notifications
You must be signed in to change notification settings - Fork 12
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
EthicalAds: Default to fixedfooter for smaller screens #447
base: main
Are you sure you want to change the base?
Changes from all commits
a831f71
3b7e92e
a4ef3ab
0f36172
3848033
0ec38cf
f6d18e0
9929bc2
cd25c99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,13 +158,41 @@ export class EthicalAdsAddon extends AddonBase { | |
if (elementToAppend) { | ||
elementToAppend.append(placement); | ||
} | ||
} else if (window.innerWidth > 1300) { | ||
// https://ethical-ad-client.readthedocs.io/en/latest/#stickybox | ||
placement.setAttribute("data-ea-type", "image"); | ||
placement.setAttribute("data-ea-style", "stickybox"); | ||
this.addEaPlacementToElement(placement); | ||
// `document.body` here is not too much relevant, since we are going to | ||
// use this selector only for a floating stickybox ad | ||
|
||
// Try fixed footer instead of stickybox as a default experience | ||
|
||
// } else if (window.innerWidth > 1300) { | ||
// // https://ethical-ad-client.readthedocs.io/en/latest/#stickybox | ||
// placement.setAttribute("data-ea-type", "image"); | ||
// placement.setAttribute("data-ea-style", "stickybox"); | ||
// this.addEaPlacementToElement(placement); | ||
// // `document.body` here is not too much relevant, since we are going to | ||
// // use this selector only for a floating stickybox ad | ||
// const elementInsertBefore = document.body; | ||
// elementInsertBefore.insertBefore( | ||
// placement, | ||
// elementInsertBefore.lastChild, | ||
// ); | ||
} else if (window.innerWidth > 768) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a case for Noted earlier that this check isn't dynamic currently, it's only evaluated once. Using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't easily reconfigure the ad without doing another API call, so we don't want it to be dynamic. We want to have a single ad load on page load, and stick with that, otherwise it will get weird. |
||
// Use fixed footer for smaller widths, but not mobile | ||
// https://ethical-ad-client.readthedocs.io/en/latest/#fixedfooter | ||
placement.setAttribute("data-ea-type", "text"); | ||
placement.setAttribute("data-ea-style", "fixedfooter"); | ||
placement.classList.add("ethical-fixedfooter"); | ||
|
||
// Add margin to content and footers to avoid hiding content | ||
const root_node = document.querySelector(docTool.getRootSelector()); | ||
const footers = document.querySelectorAll("footer, .footer"); | ||
|
||
if (root_node) { | ||
root_node.classList.add("ethical-fixedfooter-margin"); | ||
} | ||
|
||
footers.forEach((footer) => { | ||
footer.classList.add("ethical-fixedfooter-margin"); | ||
}); | ||
Comment on lines
+183
to
+193
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'd need to be a lot more precise adding margins into user content like this. Adding margin into the main document content is probably not what we want either, as there isn't a direct link between the main document content and the bottom of the frame. I suppose I'm not convinced we should be adding margins into nested elements yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we just not try and just the bottom margins at all? The issue is that it covers up fixed position content on other themes (eg. mkdocs-material), so I wasn't sure what the right approach was. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I had to choose, I would prefer to cover footer content than breaking layout (adding weird margins). In either case, we can work on "better placement for that particular doctool" when we see it or when users complain 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, I was trying to build a better placement for mkdocs-material specifically, because I know that's one we want to support, so understanding the "right" way to bump the ad above the footer is still useful. I agree maybe we just add that to the theme-specific support? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have a specific positioning for Material for MkDocs that's working already: https://docs.pypi.org/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, but not for smaller screen sizes, like we are discussing? |
||
|
||
// Inject the actual ad | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, my comment above was about not adding the fixed footer to document.body, but this feels like we should be adding the fixed footer placement to document.body. Do we want it full width of the frame or not? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think it should be full width, yes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It shouldn't be showing on the RTD theme, since that has a custom placement. I'm not really sure what the change being suggested here is -- isn't the ad getting injected into the document.body? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ad is being injected on RTD theme here. I think that happens because of the current logic: "if the specific placement it not above the fold, we show the default placement". The "default placement" now is fixedfooter, and that's why it's being shown. |
||
const elementInsertBefore = document.body; | ||
elementInsertBefore.insertBefore( | ||
placement, | ||
|
@@ -201,6 +229,11 @@ export class EthicalAdsAddon extends AddonBase { | |
} | ||
|
||
elementAboveTheFold(element) { | ||
// Return false if element doesn't exist | ||
if (!element) { | ||
return false; | ||
} | ||
|
||
// Determine if this element would be above the fold. | ||
// If this is off screen, instead create an ad in the footer. | ||
// Assumes the ad would be AD_SIZE pixels high. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@agjohnson Is there a way to have this match the height of the ad instead of a random height?
Seems like you could hack it with something like:
but I don't think there's a way to do it non-dynamically, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even calculating the margin at load time, it will break when resizing the window.
I think the problem here is
position: fixed
(that comes from EthicalAd client CSS). Using a more selector with more specificity (😉 @agjohnson ) we can override it. Example showing how it works:With this, we don't need to add the extra class
.ethical-fixedfooter-margin
to all the elements as you are doing in https://github.com/readthedocs/addons/pull/447/files#diff-10e47ee23788d0e8d3d4e13cee726fd04c8fe035922a74ac1c7d432db1dfb9faR191I understand this works because we are adding this element as the last one in the
document.body
.However, it does not work well in all the documentation tools because the ad may end behind a scroll 😞
Demo
Material for MkDocs
Sphinx Furo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There isn't pure CSS solution here given the fixed footer is a separate element from the elements you're adding classes to for the margin -- there isn't a way to reference between elements like this unless one element is a direct descendant. In this case you have more options and
calc()
might be able to get there.I'd avoid a JS solution here especially using
Element.style
-- my note above applies here.It feels like we should have multiple explicit styles by viewport size, not necessarily try to do this dynamically -- that is we'd have explicit heights for mobile, table, desktop widths.