From 50788a876e3699046df87d7bd87de86a72b096f3 Mon Sep 17 00:00:00 2001 From: Lawrence Thorpe Date: Fri, 21 Aug 2020 14:53:34 +0100 Subject: [PATCH] Add support for adsense fluid format for in-feed (#89) --- .../discourse/components/google-adsense.js.es6 | 15 +++++++++++++-- config/settings.yml | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/components/google-adsense.js.es6 b/assets/javascripts/discourse/components/google-adsense.js.es6 index c18ba2f..24257f0 100644 --- a/assets/javascripts/discourse/components/google-adsense.js.es6 +++ b/assets/javascripts/discourse/components/google-adsense.js.es6 @@ -11,6 +11,9 @@ function parseAdWidth(value) { if (value === "responsive") { return "auto"; } + if (value.startsWith("fluid")) { + return "fluid"; + } const w = parseInt(value.substring(0, 3).trim(), 10); if (isNaN(w)) { return "auto"; @@ -23,6 +26,9 @@ function parseAdHeight(value) { if (value === "responsive") { return "auto"; } + if (value.startsWith("fluid")) { + return "fluid"; + } const h = parseInt(value.substring(4, 7).trim(), 10); if (isNaN(h)) { return "auto"; @@ -172,7 +178,12 @@ export default AdComponent.extend({ @discourseComputed("ad_width") isResponsive(adWidth) { - return adWidth === "auto"; + return ["auto", "fluid"].includes(adWidth); + }, + + @discourseComputed("ad_width") + isFluid(adWidth) { + return adWidth === "fluid"; }, @discourseComputed("placement", "showAd") @@ -182,7 +193,7 @@ export default AdComponent.extend({ @discourseComputed("isResponsive") autoAdFormat(isResponsive) { - return isResponsive ? "auto".htmlSafe() : false; + return isResponsive ? (isFluid ? "fluid".htmlSafe() : "auto".htmlSafe()) : false; }, @discourseComputed("ad_width", "ad_height", "isResponsive") diff --git a/config/settings.yml b/config/settings.yml index 5c3abfd..a2cdd93 100755 --- a/config/settings.yml +++ b/config/settings.yml @@ -55,6 +55,7 @@ adsense_plugin: type: list choices: &adsense_choices - responsive + - fluid - for in-feed ad units - 728*90 - leaderboard - 336*280 - large rectangle - 300*250 - medium rectangle