Skip to content

Reintroduce the stickybox on wide screens #604

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

Merged
Merged
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
15 changes: 13 additions & 2 deletions src/ethicalads.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,22 @@ export class EthicalAdsAddon extends AddonBase {
if (elementToAppend) {
elementToAppend.append(placement);
}
} else if (window.innerWidth > 1300 && Math.random() > 0.5) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be another place to eventually use media query events, so that we can re-evaluate this logic if the view port size changes. This will just execute once on page load.

Noting for later, I don't think we are using this type of logic anywhere else yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to avoid the randomness here. I think a better approach is using the same logic for each user, so it doesn't change randomly on refresh.

// https://ethical-ad-client.readthedocs.io/en/latest/#stickybox
placement.setAttribute("data-ea-type", "image");
placement.setAttribute("data-ea-style", "stickybox");
placement.setAttribute("id", "readthedocs-ea-image-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 {
// Default to a text ad appended to the root selector when no known placement found
placement.setAttribute("data-ea-type", "text");
// TODO: Check this placement on the dashboard,
// and see how this is performing.
const docToolName = docTool.getDocumentationTool();
const idSuffix = docToolName ? `-${docToolName}` : "";
placement.setAttribute("id", `readthedocs-ea-text-footer${idSuffix}`);
Expand Down