Refactors per review
This commit is contained in:
parent
1b7f642da6
commit
9e84a89f76
|
@ -1,20 +1,22 @@
|
|||
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
|
||||
|
||||
var _loaded = false,
|
||||
_promise = null,
|
||||
currentUser = Discourse.User.current(),
|
||||
propertyId = Discourse.SiteSettings.codefund_property_code;
|
||||
propertyId = Discourse.SiteSettings.codefund_property_id;
|
||||
|
||||
function loadCodeFund() {
|
||||
if (_loaded) {
|
||||
return Ember.RSVP.resolve();
|
||||
}
|
||||
|
||||
|
||||
if (_promise) {
|
||||
return _promise;
|
||||
}
|
||||
|
||||
const url = 'https://codefund.io/t/s/' + propertyId + '/details.json';
|
||||
|
||||
_promise = new Promise(function(resolve, reject){
|
||||
_promise = new Promise(function(resolve, reject) {
|
||||
let xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.open('GET', url);
|
||||
|
@ -66,35 +68,41 @@ export default Ember.Component.extend({
|
|||
Ember.run.scheduleOnce('afterRender', this, this._triggerAds);
|
||||
},
|
||||
|
||||
@observes('listLoading')
|
||||
waitForLoad: function() {
|
||||
if (this.get('adRequested')) { return; } // already requested that this ad unit be populated
|
||||
if (!this.get('listLoading')) {
|
||||
Ember.run.scheduleOnce('afterRender', this, this._triggerAds);
|
||||
}
|
||||
}.observes('listLoading'),
|
||||
},
|
||||
|
||||
checkTrustLevels: function() {
|
||||
return !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.codefund_through_trust_level));
|
||||
}.property('trust_level'),
|
||||
|
||||
showAd: function() {
|
||||
return Discourse.SiteSettings.codefund_property_code && this.get('checkTrustLevels');
|
||||
}.property('checkTrustLevels'),
|
||||
@computed('checkTrustLevels')
|
||||
showAd: function(checkTrustLevels) {
|
||||
return Discourse.SiteSettings.codefund_property_id && checkTrustLevels;
|
||||
},
|
||||
|
||||
displayPostBottom: function() {
|
||||
return this.get('placement') === 'post-bottom';
|
||||
}.property('placement'),
|
||||
@computed('placement')
|
||||
displayPostBottom: function(placement) {
|
||||
return placement === 'post-bottom';
|
||||
},
|
||||
|
||||
@computed('placement')
|
||||
displayTopicAbovePostStream: function() {
|
||||
return this.get('placement') === 'topic-above-post-stream';
|
||||
}.property('placement'),
|
||||
},
|
||||
|
||||
@computed('placement')
|
||||
displayTopicAboveSuggested: function() {
|
||||
return this.get('placement') === 'topic-above-suggested';
|
||||
}.property('placement'),
|
||||
},
|
||||
|
||||
@computed('placement')
|
||||
displayTopicListTop: function() {
|
||||
return this.get('placement') === 'topic-list-top';
|
||||
}.property('placement'),
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -9,23 +9,23 @@ export default {
|
|||
const siteSettings = container.lookup('site-settings:main');
|
||||
|
||||
PostModel.reopen({
|
||||
postSpecificCountDFP: function () {
|
||||
postSpecificCountDFP: function() {
|
||||
return this.isNthPost(parseInt(siteSettings.dfp_nth_post_code));
|
||||
}.property('post_number'),
|
||||
|
||||
postSpecificCountAdsense: function () {
|
||||
postSpecificCountAdsense: function() {
|
||||
return this.isNthPost(parseInt(siteSettings.adsense_nth_post_code));
|
||||
}.property('post_number'),
|
||||
|
||||
postSpecificCountAmazon: function () {
|
||||
postSpecificCountAmazon: function() {
|
||||
return this.isNthPost(parseInt(siteSettings.amazon_nth_post_code));
|
||||
}.property('post_number'),
|
||||
|
||||
postSpecificCountCodeFund: function () {
|
||||
return this.isNthPost(parseInt(siteSettings.codefund_nth_post_code));
|
||||
postSpecificCountCodeFund: function() {
|
||||
return this.isNthPost(parseInt(siteSettings.codefund_nth_post));
|
||||
}.property('post_number'),
|
||||
|
||||
isNthPost: function (n) {
|
||||
isNthPost: function(n) {
|
||||
if (n && n > 0) {
|
||||
return (this.get('post_number') % n) === 0;
|
||||
} else {
|
||||
|
|
|
@ -79,12 +79,12 @@ en:
|
|||
amazon_mobile_post_bottom_ad_height_code: "Input your ad height (mobile)"
|
||||
amazon_nth_post_code: "Show an ad after every N posts, where N is this value."
|
||||
|
||||
codefund_property_code: "Your CodeFund property ID"
|
||||
codefund_property_id: "Your CodeFund property ID"
|
||||
codefund_advertiser_label: "Label that appears before the advertisement (e.g. Advertiser or Supporter)"
|
||||
codefund_advertiser_short_label: "Abbreviated label that appears before the advertisement (e.g. Ad)"
|
||||
codefund_display_advertiser_labels: "Show the advertiser label (e.g. 'Advertiser') on the ads"
|
||||
codefund_through_trust_level: "Show your ads to users based on trust levels. Users with trust level higher than this value will not see ads"
|
||||
codefund_nth_post_code: "Show an ad after every N posts, where N is this value"
|
||||
codefund_nth_post: "Show an ad after every N posts, where N is this value"
|
||||
codefund_below_post_enabled: "Show an ad below each blog post"
|
||||
codefund_above_post_stream_enabled: "Show an ad above the post stream"
|
||||
codefund_above_suggested_enabled: "Show an ad above the suggested topic list"
|
||||
|
|
|
@ -343,7 +343,7 @@ amazon_plugin:
|
|||
default: ''
|
||||
|
||||
codefund_plugin:
|
||||
codefund_property_code:
|
||||
codefund_property_id:
|
||||
client: true
|
||||
default: ''
|
||||
regex: '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'
|
||||
|
@ -357,7 +357,7 @@ codefund_plugin:
|
|||
client: true
|
||||
default: 2
|
||||
enum: 'TrustLevelSetting'
|
||||
codefund_nth_post_code:
|
||||
codefund_nth_post:
|
||||
client: true
|
||||
default: 4
|
||||
min: 1
|
||||
|
|
Loading…
Reference in New Issue