Skip to content
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

Create an explicit ad placement #4647

Merged
merged 2 commits into from
Sep 20, 2018
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 media/css/readthedocs-doc-embed.css
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ div.ethical-footer {
.wy-nav-side .ethical-rtd {
/* RTD theme doesn't correctly set the sidebar width */
width: 300px;
padding: 1em;
padding: 0 1em;
}
.ethical-rtd .ethical-sidebar {
/* RTD theme doesn't set sidebar text color */
Expand Down
57 changes: 48 additions & 9 deletions readthedocs/core/static-src/core/js/doc-embed/sponsorship.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,35 @@ var bowser = require('bowser');

var rtd;

var EXPLICIT_PLACEMENT_SELECTOR = '#ethical-ad-placement';


/*
* Create an explicit placement if the project has specified one
*/
function create_explicit_placement() {
var element_id = 'rtd-' + (Math.random() + 1).toString(36).substring(4);
var display_type = constants.PROMO_TYPES.LEFTNAV;
var class_name; // Used for theme specific CSS customizations

if(rtd.is_rtd_like_theme()) {
class_name = 'ethical-rtd ethical-dark-theme';
} else {
class_name = 'ethical-alabaster';
}

if ($(EXPLICIT_PLACEMENT_SELECTOR).length > 0) {
$('<div />').attr('id', element_id)
.addClass(class_name).appendTo(EXPLICIT_PLACEMENT_SELECTOR);

return {
'div_id': element_id,
'display_type': display_type,
};
}
return null;
}

/*
* Creates a sidebar div where an ad could go
*/
Expand Down Expand Up @@ -230,16 +259,26 @@ function init() {

rtd = rtddata.get();

if (!rtd.show_promo()) {
return;
}
// Check if these docs have specified an explicit ad placement for us
placement = create_explicit_placement();

if (placement) {
div_ids.push(placement.div_id);
display_types.push(placement.display_type);
priorities.push(placement.priority || constants.DEFAULT_PROMO_PRIORITY);
} else {
// Standard placements
if (!rtd.show_promo()) {
return;
}

for (var i = 0; i < placement_funcs.length; i += 1) {
placement = placement_funcs[i]();
if (placement) {
div_ids.push(placement.div_id);
display_types.push(placement.display_type);
priorities.push(placement.priority || constants.DEFAULT_PROMO_PRIORITY);
for (var i = 0; i < placement_funcs.length; i += 1) {
placement = placement_funcs[i]();
if (placement) {
div_ids.push(placement.div_id);
display_types.push(placement.display_type);
priorities.push(placement.priority || constants.DEFAULT_PROMO_PRIORITY);
}
}
}

Expand Down