FIX: use imports instead of Discourse global (#118)
Replaces `Discourse.Site` with the imported equivalent and `Discourse.SiteSettings` with `this.siteSettings`
This commit is contained in:
parent
a01058f041
commit
f2171a51c3
|
@ -2,14 +2,11 @@ import AdComponent from "discourse/plugins/discourse-adplugin/discourse/componen
|
|||
import discourseComputed, { observes } from "discourse-common/utils/decorators";
|
||||
import loadScript from "discourse/lib/load-script";
|
||||
|
||||
const publisherId = Discourse.SiteSettings.adbutler_publisher_id;
|
||||
const adserverHostname = Discourse.SiteSettings.adbutler_adserver_hostname;
|
||||
|
||||
let _loaded = false,
|
||||
_promise = null,
|
||||
_c = 0;
|
||||
|
||||
function loadAdbutler() {
|
||||
function loadAdbutler(adserverHostname) {
|
||||
if (_loaded) {
|
||||
return Ember.RSVP.resolve();
|
||||
}
|
||||
|
@ -29,6 +26,7 @@ function loadAdbutler() {
|
|||
|
||||
export default AdComponent.extend({
|
||||
divs: null,
|
||||
publisherId: null,
|
||||
|
||||
init() {
|
||||
let dimensions = [728, 90];
|
||||
|
@ -56,7 +54,12 @@ export default AdComponent.extend({
|
|||
|
||||
let divId = "placement-" + zoneId + "-" + _c;
|
||||
this.set("divId", divId);
|
||||
|
||||
let publisherId = this.siteSettings.adbutler_publisher_id;
|
||||
this.set("publisherId", publisherId);
|
||||
|
||||
_c++;
|
||||
|
||||
this.divs.push({
|
||||
divId: divId,
|
||||
publisherId: publisherId,
|
||||
|
@ -64,7 +67,6 @@ export default AdComponent.extend({
|
|||
dimensions: dimensions,
|
||||
});
|
||||
|
||||
this.set("publisherId", publisherId);
|
||||
this._super();
|
||||
},
|
||||
|
||||
|
@ -73,7 +75,9 @@ export default AdComponent.extend({
|
|||
return; // Don't load external JS during tests
|
||||
}
|
||||
|
||||
loadAdbutler().then(
|
||||
const adserverHostname = this.siteSettings.adbutler_adserver_hostname;
|
||||
|
||||
loadAdbutler(adserverHostname).then(
|
||||
function () {
|
||||
if (this.divs.length > 0) {
|
||||
let abkw = window.abkw || "";
|
||||
|
@ -117,18 +121,24 @@ export default AdComponent.extend({
|
|||
@discourseComputed("currentUser.trust_level")
|
||||
showToTrustLevel(trustLevel) {
|
||||
return !(
|
||||
trustLevel &&
|
||||
trustLevel > Discourse.SiteSettings.adbutler_through_trust_level
|
||||
trustLevel && trustLevel > this.siteSettings.adbutler_through_trust_level
|
||||
);
|
||||
},
|
||||
|
||||
@discourseComputed(
|
||||
"publisherId",
|
||||
"showToTrustLevel",
|
||||
"showToGroups",
|
||||
"showAfterPost",
|
||||
"showOnCurrentPage"
|
||||
)
|
||||
showAd(showToTrustLevel, showToGroups, showAfterPost, showOnCurrentPage) {
|
||||
showAd(
|
||||
publisherId,
|
||||
showToTrustLevel,
|
||||
showToGroups,
|
||||
showAfterPost,
|
||||
showOnCurrentPage
|
||||
) {
|
||||
return (
|
||||
publisherId &&
|
||||
showToTrustLevel &&
|
||||
|
|
|
@ -1,134 +1,6 @@
|
|||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
|
||||
const data = {
|
||||
"topic-list-top": {},
|
||||
"topic-above-post-stream": {},
|
||||
"topic-above-suggested": {},
|
||||
"post-bottom": {},
|
||||
};
|
||||
|
||||
let mobileView = Discourse.Site.currentProp("mobileView");
|
||||
|
||||
if (!mobileView && Discourse.SiteSettings.amazon_topic_list_top_src_code) {
|
||||
data["topic-list-top"]["user_input"] =
|
||||
Discourse.SiteSettings.amazon_topic_list_top_src_code;
|
||||
data["topic-list-top"]["amazon_width"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_topic_list_top_ad_width_code,
|
||||
10
|
||||
);
|
||||
data["topic-list-top"]["amazon_height"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_topic_list_top_ad_height_code,
|
||||
10
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
mobileView &&
|
||||
Discourse.SiteSettings.amazon_mobile_topic_list_top_src_code
|
||||
) {
|
||||
data["topic-list-top"]["user_input_mobile"] =
|
||||
Discourse.SiteSettings.amazon_mobile_topic_list_top_src_code;
|
||||
data["topic-list-top"]["mobile_amazon_width"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_mobile_topic_list_top_ad_width_code,
|
||||
10
|
||||
);
|
||||
data["topic-list-top"]["mobile_amazon_height"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_mobile_topic_list_top_ad_height_code,
|
||||
10
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
!mobileView &&
|
||||
Discourse.SiteSettings.amazon_topic_above_post_stream_src_code
|
||||
) {
|
||||
data["topic-above-post-stream"]["user_input"] =
|
||||
Discourse.SiteSettings.amazon_topic_above_post_stream_src_code;
|
||||
data["topic-above-post-stream"]["amazon_width"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_topic_above_post_stream_ad_width_code,
|
||||
10
|
||||
);
|
||||
data["topic-above-post-stream"]["amazon_height"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_topic_above_post_stream_ad_height_code,
|
||||
10
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
mobileView &&
|
||||
Discourse.SiteSettings.amazon_mobile_topic_above_post_stream_src_code
|
||||
) {
|
||||
data["topic-above-post-stream"]["user_input_mobile"] =
|
||||
Discourse.SiteSettings.amazon_mobile_topic_above_post_stream_src_code;
|
||||
data["topic-above-post-stream"]["mobile_amazon_width"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_mobile_topic_above_post_stream_ad_width_code,
|
||||
10
|
||||
);
|
||||
data["topic-above-post-stream"]["mobile_amazon_height"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_mobile_topic_above_post_stream_ad_height_code,
|
||||
10
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
!mobileView &&
|
||||
Discourse.SiteSettings.amazon_topic_above_suggested_src_code
|
||||
) {
|
||||
data["topic-above-suggested"]["user_input"] =
|
||||
Discourse.SiteSettings.amazon_topic_above_suggested_src_code;
|
||||
data["topic-above-suggested"]["amazon_width"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_topic_above_suggested_ad_width_code,
|
||||
10
|
||||
);
|
||||
data["topic-above-suggested"]["amazon_height"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_topic_above_suggested_ad_height_code,
|
||||
10
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
mobileView &&
|
||||
Discourse.SiteSettings.amazon_mobile_topic_above_suggested_src_code
|
||||
) {
|
||||
data["topic-above-suggested"]["user_input_mobile"] =
|
||||
Discourse.SiteSettings.amazon_mobile_topic_above_suggested_src_code;
|
||||
data["topic-above-suggested"]["mobile_amazon_width"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_mobile_topic_above_suggested_ad_width_code,
|
||||
10
|
||||
);
|
||||
data["topic-above-suggested"]["mobile_amazon_height"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_mobile_topic_above_suggested_ad_height_code,
|
||||
10
|
||||
);
|
||||
}
|
||||
|
||||
if (!mobileView && Discourse.SiteSettings.amazon_post_bottom_src_code) {
|
||||
data["post-bottom"]["user_input"] =
|
||||
Discourse.SiteSettings.amazon_post_bottom_src_code;
|
||||
data["post-bottom"]["amazon_width"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_post_bottom_ad_width_code,
|
||||
10
|
||||
);
|
||||
data["post-bottom"]["amazon_height"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_post_bottom_ad_height_code,
|
||||
10
|
||||
);
|
||||
}
|
||||
|
||||
if (mobileView && Discourse.SiteSettings.amazon_mobile_post_bottom_src_code) {
|
||||
data["post-bottom"]["user_input_mobile"] =
|
||||
Discourse.SiteSettings.amazon_mobile_post_bottom_src_code;
|
||||
data["post-bottom"]["mobile_amazon_width"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_mobile_post_bottom_ad_width_code,
|
||||
10
|
||||
);
|
||||
data["post-bottom"]["mobile_amazon_height"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_mobile_post_bottom_ad_height_code,
|
||||
10
|
||||
);
|
||||
}
|
||||
|
||||
export default AdComponent.extend({
|
||||
classNames: ["amazon-product-links"],
|
||||
|
||||
|
@ -140,7 +12,139 @@ export default AdComponent.extend({
|
|||
),
|
||||
|
||||
init() {
|
||||
let placement = this.get("placement");
|
||||
const data = {
|
||||
"topic-list-top": {},
|
||||
"topic-above-post-stream": {},
|
||||
"topic-above-suggested": {},
|
||||
"post-bottom": {},
|
||||
};
|
||||
const mobileView = this.site.get("mobileView");
|
||||
const placement = this.get("placement");
|
||||
|
||||
if (!mobileView && this.siteSettings.amazon_topic_list_top_src_code) {
|
||||
data["topic-list-top"][
|
||||
"user_input"
|
||||
] = this.siteSettings.amazon_topic_list_top_src_code;
|
||||
data["topic-list-top"]["amazon_width"] = parseInt(
|
||||
this.siteSettings.amazon_topic_list_top_ad_width_code,
|
||||
10
|
||||
);
|
||||
data["topic-list-top"]["amazon_height"] = parseInt(
|
||||
this.siteSettings.amazon_topic_list_top_ad_height_code,
|
||||
10
|
||||
);
|
||||
}
|
||||
|
||||
if (mobileView && this.siteSettings.amazon_mobile_topic_list_top_src_code) {
|
||||
data["topic-list-top"][
|
||||
"user_input_mobile"
|
||||
] = this.siteSettings.amazon_mobile_topic_list_top_src_code;
|
||||
data["topic-list-top"]["mobile_amazon_width"] = parseInt(
|
||||
this.siteSettings.amazon_mobile_topic_list_top_ad_width_code,
|
||||
10
|
||||
);
|
||||
data["topic-list-top"]["mobile_amazon_height"] = parseInt(
|
||||
this.siteSettings.amazon_mobile_topic_list_top_ad_height_code,
|
||||
10
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
!mobileView &&
|
||||
this.siteSettings.amazon_topic_above_post_stream_src_code
|
||||
) {
|
||||
data["topic-above-post-stream"][
|
||||
"user_input"
|
||||
] = this.siteSettings.amazon_topic_above_post_stream_src_code;
|
||||
data["topic-above-post-stream"]["amazon_width"] = parseInt(
|
||||
this.siteSettings.amazon_topic_above_post_stream_ad_width_code,
|
||||
10
|
||||
);
|
||||
data["topic-above-post-stream"]["amazon_height"] = parseInt(
|
||||
this.siteSettings.amazon_topic_above_post_stream_ad_height_code,
|
||||
10
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
mobileView &&
|
||||
this.siteSettings.amazon_mobile_topic_above_post_stream_src_code
|
||||
) {
|
||||
data["topic-above-post-stream"][
|
||||
"user_input_mobile"
|
||||
] = this.siteSettings.amazon_mobile_topic_above_post_stream_src_code;
|
||||
data["topic-above-post-stream"]["mobile_amazon_width"] = parseInt(
|
||||
this.siteSettings.amazon_mobile_topic_above_post_stream_ad_width_code,
|
||||
10
|
||||
);
|
||||
data["topic-above-post-stream"]["mobile_amazon_height"] = parseInt(
|
||||
this.siteSettings.amazon_mobile_topic_above_post_stream_ad_height_code,
|
||||
10
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
!mobileView &&
|
||||
this.siteSettings.amazon_topic_above_suggested_src_code
|
||||
) {
|
||||
data["topic-above-suggested"][
|
||||
"user_input"
|
||||
] = this.siteSettings.amazon_topic_above_suggested_src_code;
|
||||
data["topic-above-suggested"]["amazon_width"] = parseInt(
|
||||
this.siteSettings.amazon_topic_above_suggested_ad_width_code,
|
||||
10
|
||||
);
|
||||
data["topic-above-suggested"]["amazon_height"] = parseInt(
|
||||
this.siteSettings.amazon_topic_above_suggested_ad_height_code,
|
||||
10
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
mobileView &&
|
||||
this.siteSettings.amazon_mobile_topic_above_suggested_src_code
|
||||
) {
|
||||
data["topic-above-suggested"][
|
||||
"user_input_mobile"
|
||||
] = this.siteSettings.amazon_mobile_topic_above_suggested_src_code;
|
||||
data["topic-above-suggested"]["mobile_amazon_width"] = parseInt(
|
||||
this.siteSettings.amazon_mobile_topic_above_suggested_ad_width_code,
|
||||
10
|
||||
);
|
||||
data["topic-above-suggested"]["mobile_amazon_height"] = parseInt(
|
||||
this.siteSettings.amazon_mobile_topic_above_suggested_ad_height_code,
|
||||
10
|
||||
);
|
||||
}
|
||||
|
||||
if (!mobileView && this.siteSettings.amazon_post_bottom_src_code) {
|
||||
data["post-bottom"][
|
||||
"user_input"
|
||||
] = this.siteSettings.amazon_post_bottom_src_code;
|
||||
data["post-bottom"]["amazon_width"] = parseInt(
|
||||
this.siteSettings.amazon_post_bottom_ad_width_code,
|
||||
10
|
||||
);
|
||||
data["post-bottom"]["amazon_height"] = parseInt(
|
||||
this.siteSettings.amazon_post_bottom_ad_height_code,
|
||||
10
|
||||
);
|
||||
}
|
||||
|
||||
if (mobileView && this.siteSettings.amazon_mobile_post_bottom_src_code) {
|
||||
data["post-bottom"][
|
||||
"user_input_mobile"
|
||||
] = this.siteSettings.amazon_mobile_post_bottom_src_code;
|
||||
data["post-bottom"]["mobile_amazon_width"] = parseInt(
|
||||
this.siteSettings.amazon_mobile_post_bottom_ad_width_code,
|
||||
10
|
||||
);
|
||||
data["post-bottom"]["mobile_amazon_height"] = parseInt(
|
||||
this.siteSettings.amazon_mobile_post_bottom_ad_height_code,
|
||||
10
|
||||
);
|
||||
}
|
||||
|
||||
this.set("user_input", data[placement]["user_input"]);
|
||||
this.set("amazon_width", data[placement]["amazon_width"]);
|
||||
this.set("amazon_height", data[placement]["amazon_height"]);
|
||||
|
@ -178,8 +182,7 @@ export default AdComponent.extend({
|
|||
@discourseComputed("currentUser.trust_level")
|
||||
showToTrustLevel(trustLevel) {
|
||||
return !(
|
||||
trustLevel &&
|
||||
trustLevel > Discourse.SiteSettings.amazon_through_trust_level
|
||||
trustLevel && trustLevel > this.siteSettings.amazon_through_trust_level
|
||||
);
|
||||
},
|
||||
|
||||
|
|
|
@ -1,33 +1,45 @@
|
|||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
|
||||
const serve_id = Discourse.SiteSettings.carbonads_serve_id,
|
||||
placement = Discourse.SiteSettings.carbonads_placement;
|
||||
|
||||
export default AdComponent.extend({
|
||||
serve_id: null,
|
||||
placement: null,
|
||||
|
||||
init() {
|
||||
this.set("serve_id", serve_id);
|
||||
this.set("serve_id", this.siteSettings.carbonads_serve_id);
|
||||
this.set("placement", this.siteSettings.carbonads_placement);
|
||||
this._super();
|
||||
},
|
||||
|
||||
@discourseComputed("serve_id")
|
||||
url(serveId) {
|
||||
@discourseComputed("serve_id", "placement")
|
||||
url(serveId, placement) {
|
||||
return `//cdn.carbonads.com/carbon.js?serve=${serveId}&placement=${placement}`.htmlSafe();
|
||||
},
|
||||
|
||||
@discourseComputed("currentUser.trust_level")
|
||||
showToTrustLevel(trustLevel) {
|
||||
return !(
|
||||
trustLevel &&
|
||||
trustLevel > Discourse.SiteSettings.carbonads_through_trust_level
|
||||
trustLevel && trustLevel > this.siteSettings.carbonads_through_trust_level
|
||||
);
|
||||
},
|
||||
|
||||
@discourseComputed("showToTrustLevel", "showToGroups", "showOnCurrentPage")
|
||||
showAd(showToTrustLevel, showToGroups, showOnCurrentPage) {
|
||||
@discourseComputed(
|
||||
"placement",
|
||||
"serve_id",
|
||||
"showToTrustLevel",
|
||||
"showToGroups",
|
||||
"showOnCurrentPage"
|
||||
)
|
||||
showAd(
|
||||
placement,
|
||||
serveId,
|
||||
showToTrustLevel,
|
||||
showToGroups,
|
||||
showOnCurrentPage
|
||||
) {
|
||||
return (
|
||||
placement &&
|
||||
serve_id &&
|
||||
serveId &&
|
||||
showToTrustLevel &&
|
||||
showToGroups &&
|
||||
showOnCurrentPage
|
||||
|
|
|
@ -4,8 +4,7 @@ import loadScript from "discourse/lib/load-script";
|
|||
|
||||
let _loaded = false,
|
||||
_promise = null,
|
||||
renderCounts = {},
|
||||
publisher_id = Discourse.SiteSettings.adsense_publisher_code;
|
||||
renderCounts = {};
|
||||
|
||||
function parseAdWidth(value) {
|
||||
if (value === "responsive") {
|
||||
|
@ -102,7 +101,7 @@ export default AdComponent.extend({
|
|||
],
|
||||
loadedGoogletag: false,
|
||||
|
||||
publisher_id: publisher_id,
|
||||
publisher_id: null,
|
||||
ad_width: null,
|
||||
ad_height: null,
|
||||
|
||||
|
@ -134,6 +133,7 @@ export default AdComponent.extend({
|
|||
this.set("ad_width", parseAdWidth(size));
|
||||
this.set("ad_height", parseAdHeight(size));
|
||||
this.set("ad_code", this.siteSettings[config.code]);
|
||||
this.set("publisher_id", this.siteSettings.adsense_publisher_code);
|
||||
this._super();
|
||||
},
|
||||
|
||||
|
@ -220,14 +220,21 @@ export default AdComponent.extend({
|
|||
},
|
||||
|
||||
@discourseComputed(
|
||||
"publisher_id",
|
||||
"showToTrustLevel",
|
||||
"showToGroups",
|
||||
"showAfterPost",
|
||||
"showOnCurrentPage"
|
||||
)
|
||||
showAd(showToTrustLevel, showToGroups, showAfterPost, showOnCurrentPage) {
|
||||
showAd(
|
||||
publisherId,
|
||||
showToTrustLevel,
|
||||
showToGroups,
|
||||
showAfterPost,
|
||||
showOnCurrentPage
|
||||
) {
|
||||
return (
|
||||
this.siteSettings.adsense_publisher_code &&
|
||||
publisherId &&
|
||||
showToTrustLevel &&
|
||||
showToGroups &&
|
||||
showAfterPost &&
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
import Site from "discourse/models/site";
|
||||
|
||||
export default {
|
||||
name: "initialize-ad-plugin",
|
||||
|
@ -28,7 +29,7 @@ export default {
|
|||
}
|
||||
|
||||
messageBus.subscribe("/site/house-creatives", function (houseAdsSettings) {
|
||||
Discourse.Site.currentProp("house_creatives", houseAdsSettings);
|
||||
Site.currentProp("house_creatives", houseAdsSettings);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue