From 70f2df906138f210c15eaffba75f6edb696a68b7 Mon Sep 17 00:00:00 2001 From: David Fischer Date: Tue, 18 Sep 2018 16:53:07 -0700 Subject: [PATCH 1/2] Create an explicit ad placement --- media/css/readthedocs-doc-embed.css | 2 +- .../core/js/doc-embed/sponsorship.js | 57 ++++++++++++++++--- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/media/css/readthedocs-doc-embed.css b/media/css/readthedocs-doc-embed.css index f306f2d6489..c030e1607c3 100644 --- a/media/css/readthedocs-doc-embed.css +++ b/media/css/readthedocs-doc-embed.css @@ -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 */ diff --git a/readthedocs/core/static-src/core/js/doc-embed/sponsorship.js b/readthedocs/core/static-src/core/js/doc-embed/sponsorship.js index f4cbd456ba7..f80d1666be0 100644 --- a/readthedocs/core/static-src/core/js/doc-embed/sponsorship.js +++ b/readthedocs/core/static-src/core/js/doc-embed/sponsorship.js @@ -7,6 +7,35 @@ var bowser = require('bowser'); var rtd; +var EXPLICIT_PLACEMENT_SELECTOR = '#ethical-ad-placement'; + + +/* + * Create an explicit placement if the + */ +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) { + $('
').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 */ @@ -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); + } } } From 6e778a1de8dc59d68dc615dfc0eedaad078af77b Mon Sep 17 00:00:00 2001 From: David Fischer Date: Tue, 18 Sep 2018 17:00:36 -0700 Subject: [PATCH 2/2] Complete the comment I didn't finish --- readthedocs/core/static-src/core/js/doc-embed/sponsorship.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readthedocs/core/static-src/core/js/doc-embed/sponsorship.js b/readthedocs/core/static-src/core/js/doc-embed/sponsorship.js index f80d1666be0..b49eb2ab8dc 100644 --- a/readthedocs/core/static-src/core/js/doc-embed/sponsorship.js +++ b/readthedocs/core/static-src/core/js/doc-embed/sponsorship.js @@ -11,7 +11,7 @@ var EXPLICIT_PLACEMENT_SELECTOR = '#ethical-ad-placement'; /* - * Create an explicit placement if the + * 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);