FIX: CodeFund is shutting down (#85)
This commit is contained in:
@@ -30,17 +30,6 @@ const adConfig = Ember.Object.create({
|
||||
"topic-above-suggested": "amazon_mobile_topic_above_suggested_src_code"
|
||||
}
|
||||
},
|
||||
"codefund-ad": {
|
||||
settingPrefix: "codefund",
|
||||
enabledSetting: "codefund_property_id",
|
||||
nthPost: "codefund_nth_post",
|
||||
desktop: {
|
||||
"topic-list-top": "codefund_top_of_topic_list_enabled",
|
||||
"post-bottom": "codefund_below_post_enabled",
|
||||
"topic-above-post-stream": "codefund_above_post_stream_enabled",
|
||||
"topic-above-suggested": "codefund_above_suggested_enabled"
|
||||
}
|
||||
},
|
||||
"carbonads-ad": {
|
||||
settingPrefix: "carbonads",
|
||||
enabledSetting: "carbonads_serve_id",
|
||||
|
||||
@@ -1,139 +0,0 @@
|
||||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
|
||||
import discourseComputed, { observes } from "discourse-common/utils/decorators";
|
||||
import { Promise } from "rsvp";
|
||||
|
||||
let _loaded = false,
|
||||
_promise = null;
|
||||
|
||||
const propertyId = Discourse.SiteSettings.codefund_property_id;
|
||||
|
||||
function loadCodeFund() {
|
||||
if (_loaded) {
|
||||
return Ember.RSVP.resolve();
|
||||
}
|
||||
|
||||
if (_promise) {
|
||||
return _promise;
|
||||
}
|
||||
|
||||
const url = "https://codefund.io/properties/" + propertyId + "/funder.json";
|
||||
|
||||
_promise = new Promise(function(resolve, reject) {
|
||||
let xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.open("GET", url);
|
||||
xhr.onreadystatechange = handler;
|
||||
xhr.responseType = "json";
|
||||
xhr.setRequestHeader("Accept", "application/json");
|
||||
xhr.send();
|
||||
|
||||
function handler() {
|
||||
if (this.readyState === this.DONE) {
|
||||
_loaded = true;
|
||||
|
||||
if (this.status === 200) {
|
||||
resolve(this.response);
|
||||
} else {
|
||||
reject(
|
||||
new Error(
|
||||
"getJSON: `" + url + "` failed with status: [" + this.status + "]"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return _promise;
|
||||
}
|
||||
|
||||
export default AdComponent.extend({
|
||||
classNameBindings: [":codefund-ad"],
|
||||
propertyId: propertyId,
|
||||
adRequested: false,
|
||||
adDetails: {},
|
||||
|
||||
displayPostBottom: Ember.computed.equal("placement", "post-bottom"),
|
||||
displayTopicAbovePostStream: Ember.computed.equal(
|
||||
"placement",
|
||||
"topic-above-post-stream"
|
||||
),
|
||||
displayTopicAboveSuggested: Ember.computed.equal(
|
||||
"placement",
|
||||
"topic-above-suggested"
|
||||
),
|
||||
displayTopicListTop: Ember.computed.equal("placement", "topic-list-top"),
|
||||
|
||||
_triggerAds() {
|
||||
if (!propertyId) return;
|
||||
|
||||
this.set("adRequested", true);
|
||||
loadCodeFund()
|
||||
.then(data => {
|
||||
_loaded = false;
|
||||
_promise = null;
|
||||
this.set("adDetails", data);
|
||||
this.set("adRequested", false);
|
||||
})
|
||||
.catch(error => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
|
||||
didInsertElement() {
|
||||
this._super();
|
||||
|
||||
if (!this.get("showAd")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.get("listLoading")) {
|
||||
return;
|
||||
}
|
||||
|
||||
Ember.run.scheduleOnce("afterRender", this, this._triggerAds);
|
||||
},
|
||||
|
||||
@observes("listLoading")
|
||||
waitForLoad() {
|
||||
if (this.get("adRequested")) {
|
||||
return;
|
||||
} // already requested that this ad unit be populated
|
||||
if (!this.get("listLoading")) {
|
||||
Ember.run.scheduleOnce("afterRender", this, this._triggerAds);
|
||||
}
|
||||
},
|
||||
|
||||
@discourseComputed("currentUser.trust_level")
|
||||
showToTrustLevel(trustLevel) {
|
||||
return !(
|
||||
trustLevel && trustLevel > this.siteSettings.codefund_through_trust_level
|
||||
);
|
||||
},
|
||||
|
||||
@discourseComputed(
|
||||
"showToTrustLevel",
|
||||
"showToGroups",
|
||||
"showAfterPost",
|
||||
"showOnCurrentPage"
|
||||
)
|
||||
showAd(showToTrustLevel, showToGroups, showAfterPost, showOnCurrentPage) {
|
||||
return (
|
||||
this.siteSettings.codefund_property_id &&
|
||||
showToTrustLevel &&
|
||||
showToGroups &&
|
||||
showAfterPost &&
|
||||
showOnCurrentPage
|
||||
);
|
||||
},
|
||||
|
||||
@discourseComputed("postNumber")
|
||||
showAfterPost(postNumber) {
|
||||
if (!postNumber) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return this.isNthPost(parseInt(this.siteSettings.codefund_nth_post, 10));
|
||||
}
|
||||
});
|
||||
@@ -1,29 +0,0 @@
|
||||
{{#if showAd}}
|
||||
{{#if site.mobileView}}
|
||||
{{#if displayPostBottom}}
|
||||
{{partial "components/codefund/post-bottom"}}
|
||||
{{/if}}
|
||||
{{#if displayTopicAbovePostStream}}
|
||||
{{partial "components/codefund/topic-above-post-stream"}}
|
||||
{{/if}}
|
||||
{{#if displayTopicAboveSuggested}}
|
||||
{{partial "components/codefund/topic-above-suggested"}}
|
||||
{{/if}}
|
||||
{{#if displayTopicListTop}}
|
||||
{{partial "components/codefund/topic-list-top"}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{#if displayPostBottom}}
|
||||
{{partial "components/codefund/post-bottom"}}
|
||||
{{/if}}
|
||||
{{#if displayTopicAbovePostStream}}
|
||||
{{partial "components/codefund/topic-above-post-stream"}}
|
||||
{{/if}}
|
||||
{{#if displayTopicAboveSuggested}}
|
||||
{{partial "components/codefund/topic-above-suggested"}}
|
||||
{{/if}}
|
||||
{{#if displayTopicListTop}}
|
||||
{{partial "components/codefund/topic-list-top"}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
@@ -1,9 +0,0 @@
|
||||
<span class="codefund-wrapper codefund-post-bottom">
|
||||
<a href="{{adDetails.campaignUrl}}" class="codefund-text" target="_blank" rel="noopener">
|
||||
{{#if siteSettings.codefund_display_advertiser_labels}}
|
||||
<span class="codefund-label">{{siteSettings.codefund_advertiser_short_label}}</span>
|
||||
{{/if}}
|
||||
<strong>{{adDetails.headline}}</strong> {{adDetails.body}}
|
||||
</a>
|
||||
<img src="{{adDetails.impressionUrl}}" class="codefund-pixel">
|
||||
</span>
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
<span class="codefund-wrapper codefund-topic-above-post-stream">
|
||||
<a href="{{adDetails.campaignUrl}}" class="codefund-text" target="_blank" rel="noopener">
|
||||
{{#if siteSettings.codefund_display_advertiser_labels}}
|
||||
<span class="codefund-label">{{siteSettings.codefund_advertiser_label}}</span>
|
||||
{{/if}}
|
||||
<strong>{{adDetails.headline}}</strong> {{adDetails.body}}
|
||||
</a>
|
||||
<a href={{adDetails.codefundUrl}} class="codefund-powered-by" target="_blank" rel="noopener">
|
||||
ads via codefund.io
|
||||
</a>
|
||||
<img src="{{adDetails.impressionUrl}}" class="codefund-pixel">
|
||||
</span>
|
||||
@@ -1,12 +0,0 @@
|
||||
<span class="codefund-wrapper codefund-topic-above-suggested">
|
||||
<a href="{{adDetails.campaignUrl}}" class="codefund-text" target="_blank" rel="noopener">
|
||||
{{#if siteSettings.codefund_display_advertiser_labels}}
|
||||
<span class="codefund-label">{{siteSettings.codefund_advertiser_label}}</span>
|
||||
{{/if}}
|
||||
<strong>{{adDetails.headline}}</strong> {{adDetails.body}}
|
||||
</a>
|
||||
<a href={{adDetails.codefundUrl}} class="codefund-powered-by" target="_blank" rel="noopener">
|
||||
ads via codefund.io
|
||||
</a>
|
||||
<img src="{{adDetails.impressionUrl}}" class="codefund-pixel">
|
||||
</span>
|
||||
@@ -1,12 +0,0 @@
|
||||
<span class="codefund-wrapper codefund-topic-list-top">
|
||||
<a href="{{adDetails.campaignUrl}}" class="codefund-text" target="_blank" rel="noopener">
|
||||
{{#if siteSettings.codefund_display_advertiser_labels}}
|
||||
<span class="codefund-label">{{siteSettings.codefund_advertiser_label}}</span>
|
||||
{{/if}}
|
||||
<strong>{{adDetails.headline}}</strong> {{adDetails.body}}
|
||||
</a>
|
||||
<a href={{adDetails.codefundUrl}} class="codefund-powered-by" target="_blank" rel="noopener">
|
||||
ads via codefund.io
|
||||
</a>
|
||||
<img src="{{adDetails.impressionUrl}}" class="codefund-pixel">
|
||||
</span>
|
||||
Reference in New Issue
Block a user