DEV: Apply prettier
This commit is contained in:
parent
2ed1d1c5d6
commit
2e36e2c656
|
@ -1,98 +1,167 @@
|
|||
var currentUser = Discourse.User.current();
|
||||
|
||||
var data = {
|
||||
"topic-list-top" : {},
|
||||
"topic-above-post-stream" : {},
|
||||
"topic-above-suggested" : {},
|
||||
"post-bottom" : {}
|
||||
"topic-list-top": {},
|
||||
"topic-above-post-stream": {},
|
||||
"topic-above-suggested": {},
|
||||
"post-bottom": {}
|
||||
};
|
||||
|
||||
|
||||
if (!Discourse.Mobile.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);
|
||||
data["topic-list-top"]["amazon_height"] = parseInt(Discourse.SiteSettings.amazon_topic_list_top_ad_height_code);
|
||||
if (
|
||||
!Discourse.Mobile.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
|
||||
);
|
||||
data["topic-list-top"]["amazon_height"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_topic_list_top_ad_height_code
|
||||
);
|
||||
}
|
||||
|
||||
if (Discourse.Mobile.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);
|
||||
data["topic-list-top"]["mobile_amazon_height"] = parseInt(Discourse.SiteSettings.amazon_mobile_topic_list_top_ad_height_code);
|
||||
if (
|
||||
Discourse.Mobile.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
|
||||
);
|
||||
data["topic-list-top"]["mobile_amazon_height"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_mobile_topic_list_top_ad_height_code
|
||||
);
|
||||
}
|
||||
|
||||
if (!Discourse.Mobile.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);
|
||||
data["topic-above-post-stream"]["amazon_height"] = parseInt(Discourse.SiteSettings.amazon_topic_above_post_stream_ad_height_code);
|
||||
if (
|
||||
!Discourse.Mobile.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
|
||||
);
|
||||
data["topic-above-post-stream"]["amazon_height"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_topic_above_post_stream_ad_height_code
|
||||
);
|
||||
}
|
||||
|
||||
if (Discourse.Mobile.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);
|
||||
data["topic-above-post-stream"]["mobile_amazon_height"] = parseInt(Discourse.SiteSettings.amazon_mobile_topic_above_post_stream_ad_height_code);
|
||||
if (
|
||||
Discourse.Mobile.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
|
||||
);
|
||||
data["topic-above-post-stream"]["mobile_amazon_height"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_mobile_topic_above_post_stream_ad_height_code
|
||||
);
|
||||
}
|
||||
|
||||
if (!Discourse.Mobile.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);
|
||||
data["topic-above-suggested"]["amazon_height"] = parseInt(Discourse.SiteSettings.amazon_topic_above_suggested_ad_height_code);
|
||||
if (
|
||||
!Discourse.Mobile.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
|
||||
);
|
||||
data["topic-above-suggested"]["amazon_height"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_topic_above_suggested_ad_height_code
|
||||
);
|
||||
}
|
||||
|
||||
if (Discourse.Mobile.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);
|
||||
data["topic-above-suggested"]["mobile_amazon_height"] = parseInt(Discourse.SiteSettings.amazon_mobile_topic_above_suggested_ad_height_code);
|
||||
if (
|
||||
Discourse.Mobile.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
|
||||
);
|
||||
data["topic-above-suggested"]["mobile_amazon_height"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_mobile_topic_above_suggested_ad_height_code
|
||||
);
|
||||
}
|
||||
|
||||
if (!Discourse.Mobile.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);
|
||||
data["post-bottom"]["amazon_height"] = parseInt(Discourse.SiteSettings.amazon_post_bottom_ad_height_code);
|
||||
if (
|
||||
!Discourse.Mobile.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
|
||||
);
|
||||
data["post-bottom"]["amazon_height"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_post_bottom_ad_height_code
|
||||
);
|
||||
}
|
||||
|
||||
if (Discourse.Mobile.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);
|
||||
data["post-bottom"]["mobile_amazon_height"] = parseInt(Discourse.SiteSettings.amazon_mobile_post_bottom_ad_height_code);
|
||||
if (
|
||||
Discourse.Mobile.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
|
||||
);
|
||||
data["post-bottom"]["mobile_amazon_height"] = parseInt(
|
||||
Discourse.SiteSettings.amazon_mobile_post_bottom_ad_height_code
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export default Ember.Component.extend({
|
||||
classNames: ['amazon-product-links'],
|
||||
classNames: ["amazon-product-links"],
|
||||
|
||||
init: function() {
|
||||
let placement = this.get('placement');
|
||||
this.set('user_input', data[placement]["user_input"] );
|
||||
this.set('amazon_width', data[placement]["amazon_width"] );
|
||||
this.set('amazon_height', data[placement]["amazon_height"] );
|
||||
this.set('user_input_mobile', data[placement]["user_input_mobile"] );
|
||||
this.set('mobile_amazon_height', data[placement]["mobile_amazon_height"] );
|
||||
this.set('mobile_amazon_width', data[placement]["mobile_amazon_width"] );
|
||||
let placement = this.get("placement");
|
||||
this.set("user_input", data[placement]["user_input"]);
|
||||
this.set("amazon_width", data[placement]["amazon_width"]);
|
||||
this.set("amazon_height", data[placement]["amazon_height"]);
|
||||
this.set("user_input_mobile", data[placement]["user_input_mobile"]);
|
||||
this.set("mobile_amazon_height", data[placement]["mobile_amazon_height"]);
|
||||
this.set("mobile_amazon_width", data[placement]["mobile_amazon_width"]);
|
||||
this._super();
|
||||
},
|
||||
|
||||
adWrapperStyle: function() {
|
||||
return `width: ${this.get('amazon_width')}px; height: ${this.get('amazon_height')}px;`.htmlSafe();
|
||||
}.property('amazon_width', 'amazon_height'),
|
||||
return `width: ${this.get("amazon_width")}px; height: ${this.get(
|
||||
"amazon_height"
|
||||
)}px;`.htmlSafe();
|
||||
}.property("amazon_width", "amazon_height"),
|
||||
|
||||
adWrapperStyleMobile: function() {
|
||||
return `width: ${this.get('mobile_amazon_width')}px; height: ${this.get('mobile_amazon_height')}px;`.htmlSafe();
|
||||
}.property('mobile_amazon_width', 'mobile_amazon_height'),
|
||||
return `width: ${this.get("mobile_amazon_width")}px; height: ${this.get(
|
||||
"mobile_amazon_height"
|
||||
)}px;`.htmlSafe();
|
||||
}.property("mobile_amazon_width", "mobile_amazon_height"),
|
||||
|
||||
adTitleStyleMobile: function() {
|
||||
return `width: ${this.get('mobile_amazon_width')}px;`.htmlSafe();
|
||||
}.property('mobile_amazon_width'),
|
||||
return `width: ${this.get("mobile_amazon_width")}px;`.htmlSafe();
|
||||
}.property("mobile_amazon_width"),
|
||||
|
||||
userInput: function() {
|
||||
return `${this.get('user_input')}`.htmlSafe();
|
||||
}.property('user_input'),
|
||||
return `${this.get("user_input")}`.htmlSafe();
|
||||
}.property("user_input"),
|
||||
|
||||
userInputMobile: function() {
|
||||
return `${this.get('user_input_mobile')}`.htmlSafe();
|
||||
}.property('user_input_mobile'),
|
||||
return `${this.get("user_input_mobile")}`.htmlSafe();
|
||||
}.property("user_input_mobile"),
|
||||
|
||||
checkTrustLevels: function() {
|
||||
return !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.amazon_through_trust_level));
|
||||
}.property('trust_level'),
|
||||
|
||||
return !(
|
||||
currentUser &&
|
||||
currentUser.get("trust_level") >
|
||||
Discourse.SiteSettings.amazon_through_trust_level
|
||||
);
|
||||
}.property("trust_level")
|
||||
});
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
|
||||
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_id;
|
||||
_promise = null,
|
||||
currentUser = Discourse.User.current(),
|
||||
propertyId = Discourse.SiteSettings.codefund_property_id;
|
||||
|
||||
function loadCodeFund() {
|
||||
if (_loaded) {
|
||||
|
@ -14,15 +17,15 @@ function loadCodeFund() {
|
|||
return _promise;
|
||||
}
|
||||
|
||||
const url = 'https://codefund.io/t/s/' + propertyId + '/details.json';
|
||||
const url = "https://codefund.io/t/s/" + propertyId + "/details.json";
|
||||
|
||||
_promise = new Promise(function(resolve, reject) {
|
||||
let xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.open('GET', url);
|
||||
xhr.open("GET", url);
|
||||
xhr.onreadystatechange = handler;
|
||||
xhr.responseType = 'json';
|
||||
xhr.setRequestHeader('Accept', 'application/json');
|
||||
xhr.responseType = "json";
|
||||
xhr.setRequestHeader("Accept", "application/json");
|
||||
xhr.send();
|
||||
|
||||
function handler() {
|
||||
|
@ -32,79 +35,97 @@ function loadCodeFund() {
|
|||
if (this.status === 200) {
|
||||
resolve(this.response);
|
||||
} else {
|
||||
reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
|
||||
reject(
|
||||
new Error(
|
||||
"getJSON: `" + url + "` failed with status: [" + this.status + "]"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
return _promise;
|
||||
}
|
||||
|
||||
|
||||
export default Ember.Component.extend({
|
||||
classNameBindings: [':codefund-ad', 'classForSlot', 'isResponsive:codefund-responsive'],
|
||||
classNameBindings: [
|
||||
":codefund-ad",
|
||||
"classForSlot",
|
||||
"isResponsive:codefund-responsive"
|
||||
],
|
||||
propertyId: propertyId,
|
||||
adRequested: false,
|
||||
adDetails: {},
|
||||
|
||||
_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 => console.log(error));
|
||||
|
||||
this.set("adRequested", true);
|
||||
loadCodeFund()
|
||||
.then(data => {
|
||||
_loaded = false;
|
||||
_promise = null;
|
||||
this.set("adDetails", data);
|
||||
this.set("adRequested", false);
|
||||
})
|
||||
.catch(error => console.log(error));
|
||||
},
|
||||
|
||||
didInsertElement() {
|
||||
this._super();
|
||||
|
||||
if (!this.get('showAd')) { return; }
|
||||
if (!this.get("showAd")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.get('listLoading')) { return; }
|
||||
if (this.get("listLoading")) {
|
||||
return;
|
||||
}
|
||||
|
||||
Ember.run.scheduleOnce('afterRender', this, this._triggerAds);
|
||||
Ember.run.scheduleOnce("afterRender", this, this._triggerAds);
|
||||
},
|
||||
|
||||
@observes('listLoading')
|
||||
@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);
|
||||
if (this.get("adRequested")) {
|
||||
return;
|
||||
} // already requested that this ad unit be populated
|
||||
if (!this.get("listLoading")) {
|
||||
Ember.run.scheduleOnce("afterRender", this, this._triggerAds);
|
||||
}
|
||||
},
|
||||
|
||||
checkTrustLevels: function() {
|
||||
return !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.codefund_through_trust_level));
|
||||
}.property('trust_level'),
|
||||
return !(
|
||||
currentUser &&
|
||||
currentUser.get("trust_level") >
|
||||
Discourse.SiteSettings.codefund_through_trust_level
|
||||
);
|
||||
}.property("trust_level"),
|
||||
|
||||
@computed('checkTrustLevels')
|
||||
@computed("checkTrustLevels")
|
||||
showAd: function(checkTrustLevels) {
|
||||
return Discourse.SiteSettings.codefund_property_id && checkTrustLevels;
|
||||
},
|
||||
|
||||
@computed('placement')
|
||||
@computed("placement")
|
||||
displayPostBottom: function(placement) {
|
||||
return placement === 'post-bottom';
|
||||
return placement === "post-bottom";
|
||||
},
|
||||
|
||||
@computed('placement')
|
||||
@computed("placement")
|
||||
displayTopicAbovePostStream: function() {
|
||||
return this.get('placement') === 'topic-above-post-stream';
|
||||
return this.get("placement") === "topic-above-post-stream";
|
||||
},
|
||||
|
||||
@computed('placement')
|
||||
@computed("placement")
|
||||
displayTopicAboveSuggested: function() {
|
||||
return this.get('placement') === 'topic-above-suggested';
|
||||
return this.get("placement") === "topic-above-suggested";
|
||||
},
|
||||
|
||||
@computed('placement')
|
||||
@computed("placement")
|
||||
displayTopicListTop: function() {
|
||||
return this.get('placement') === 'topic-list-top';
|
||||
return this.get("placement") === "topic-list-top";
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -1,20 +1,24 @@
|
|||
import loadScript from 'discourse/lib/load-script';
|
||||
import loadScript from "discourse/lib/load-script";
|
||||
|
||||
var _loaded = false,
|
||||
_promise = null,
|
||||
currentUser = Discourse.User.current(),
|
||||
publisher_id = Discourse.SiteSettings.adsense_publisher_code;
|
||||
_promise = null,
|
||||
currentUser = Discourse.User.current(),
|
||||
publisher_id = Discourse.SiteSettings.adsense_publisher_code;
|
||||
|
||||
const mobileView = Discourse.Site.currentProp('mobileView');
|
||||
const mobileView = Discourse.Site.currentProp("mobileView");
|
||||
|
||||
function parseAdWidth(value) {
|
||||
if (value === 'responsive') { return 'auto'; }
|
||||
return `${parseInt( value.substring(0, 3).trim() )}px`;
|
||||
if (value === "responsive") {
|
||||
return "auto";
|
||||
}
|
||||
return `${parseInt(value.substring(0, 3).trim())}px`;
|
||||
}
|
||||
|
||||
function parseAdHeight(value) {
|
||||
if (value === 'responsive') { return 'auto'; }
|
||||
return `${parseInt( value.substring(4, 7).trim() )}px`;
|
||||
if (value === "responsive") {
|
||||
return "auto";
|
||||
}
|
||||
return `${parseInt(value.substring(4, 7).trim())}px`;
|
||||
}
|
||||
|
||||
function loadAdsense() {
|
||||
|
@ -26,7 +30,9 @@ function loadAdsense() {
|
|||
return _promise;
|
||||
}
|
||||
|
||||
var adsenseSrc = (('https:' === document.location.protocol) ? 'https:' : 'http:') + '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
|
||||
var adsenseSrc =
|
||||
("https:" === document.location.protocol ? "https:" : "http:") +
|
||||
"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js";
|
||||
_promise = loadScript(adsenseSrc, { scriptTag: true }).then(function() {
|
||||
_loaded = true;
|
||||
});
|
||||
|
@ -35,57 +41,113 @@ function loadAdsense() {
|
|||
}
|
||||
|
||||
var data = {
|
||||
"topic-list-top" : {},
|
||||
"topic-above-post-stream" : {},
|
||||
"topic-above-suggested" : {},
|
||||
"post-bottom" : {}
|
||||
"topic-list-top": {},
|
||||
"topic-above-post-stream": {},
|
||||
"topic-above-suggested": {},
|
||||
"post-bottom": {}
|
||||
};
|
||||
|
||||
if (Discourse.SiteSettings.adsense_publisher_code) {
|
||||
if (!mobileView && Discourse.SiteSettings.adsense_topic_list_top_code) {
|
||||
data["topic-list-top"]["ad_code"] = Discourse.SiteSettings.adsense_topic_list_top_code;
|
||||
data["topic-list-top"]["ad_width"] = parseAdWidth(Discourse.SiteSettings.adsense_topic_list_top_ad_sizes);
|
||||
data["topic-list-top"]["ad_height"] = parseAdHeight(Discourse.SiteSettings.adsense_topic_list_top_ad_sizes);
|
||||
data["topic-list-top"]["ad_code"] =
|
||||
Discourse.SiteSettings.adsense_topic_list_top_code;
|
||||
data["topic-list-top"]["ad_width"] = parseAdWidth(
|
||||
Discourse.SiteSettings.adsense_topic_list_top_ad_sizes
|
||||
);
|
||||
data["topic-list-top"]["ad_height"] = parseAdHeight(
|
||||
Discourse.SiteSettings.adsense_topic_list_top_ad_sizes
|
||||
);
|
||||
}
|
||||
if (mobileView && Discourse.SiteSettings.adsense_mobile_topic_list_top_code) {
|
||||
data["topic-list-top"]["ad_code"] = Discourse.SiteSettings.adsense_mobile_topic_list_top_code;
|
||||
data["topic-list-top"]["ad_width"] = parseAdWidth(Discourse.SiteSettings.adsense_mobile_topic_list_top_ad_size);
|
||||
data["topic-list-top"]["ad_height"] = parseAdHeight(Discourse.SiteSettings.adsense_mobile_topic_list_top_ad_size);
|
||||
data["topic-list-top"]["ad_code"] =
|
||||
Discourse.SiteSettings.adsense_mobile_topic_list_top_code;
|
||||
data["topic-list-top"]["ad_width"] = parseAdWidth(
|
||||
Discourse.SiteSettings.adsense_mobile_topic_list_top_ad_size
|
||||
);
|
||||
data["topic-list-top"]["ad_height"] = parseAdHeight(
|
||||
Discourse.SiteSettings.adsense_mobile_topic_list_top_ad_size
|
||||
);
|
||||
}
|
||||
if (!mobileView && Discourse.SiteSettings.adsense_topic_above_post_stream_code) {
|
||||
data["topic-above-post-stream"]["ad_code"] = Discourse.SiteSettings.adsense_topic_above_post_stream_code;
|
||||
data["topic-above-post-stream"]["ad_width"] = parseAdWidth(Discourse.SiteSettings.adsense_topic_above_post_stream_ad_sizes);
|
||||
data["topic-above-post-stream"]["ad_height"] = parseAdHeight(Discourse.SiteSettings.adsense_topic_above_post_stream_ad_sizes);
|
||||
if (
|
||||
!mobileView &&
|
||||
Discourse.SiteSettings.adsense_topic_above_post_stream_code
|
||||
) {
|
||||
data["topic-above-post-stream"]["ad_code"] =
|
||||
Discourse.SiteSettings.adsense_topic_above_post_stream_code;
|
||||
data["topic-above-post-stream"]["ad_width"] = parseAdWidth(
|
||||
Discourse.SiteSettings.adsense_topic_above_post_stream_ad_sizes
|
||||
);
|
||||
data["topic-above-post-stream"]["ad_height"] = parseAdHeight(
|
||||
Discourse.SiteSettings.adsense_topic_above_post_stream_ad_sizes
|
||||
);
|
||||
}
|
||||
if (mobileView && Discourse.SiteSettings.adsense_mobile_topic_above_post_stream_code) {
|
||||
data["topic-above-post-stream"]["ad_code"] = Discourse.SiteSettings.adsense_mobile_topic_above_post_stream_code;
|
||||
data["topic-above-post-stream"]["ad_width"] = parseAdWidth(Discourse.SiteSettings.adsense_mobile_topic_above_post_stream_ad_size);
|
||||
data["topic-above-post-stream"]["ad_height"] = parseAdHeight(Discourse.SiteSettings.adsense_mobile_topic_above_post_stream_ad_size);
|
||||
if (
|
||||
mobileView &&
|
||||
Discourse.SiteSettings.adsense_mobile_topic_above_post_stream_code
|
||||
) {
|
||||
data["topic-above-post-stream"]["ad_code"] =
|
||||
Discourse.SiteSettings.adsense_mobile_topic_above_post_stream_code;
|
||||
data["topic-above-post-stream"]["ad_width"] = parseAdWidth(
|
||||
Discourse.SiteSettings.adsense_mobile_topic_above_post_stream_ad_size
|
||||
);
|
||||
data["topic-above-post-stream"]["ad_height"] = parseAdHeight(
|
||||
Discourse.SiteSettings.adsense_mobile_topic_above_post_stream_ad_size
|
||||
);
|
||||
}
|
||||
if (!mobileView && Discourse.SiteSettings.adsense_topic_above_suggested_code) {
|
||||
data["topic-above-suggested"]["ad_code"] = Discourse.SiteSettings.adsense_topic_above_suggested_code;
|
||||
data["topic-above-suggested"]["ad_width"] = parseAdWidth(Discourse.SiteSettings.adsense_topic_above_suggested_ad_sizes);
|
||||
data["topic-above-suggested"]["ad_height"] = parseAdHeight(Discourse.SiteSettings.adsense_topic_above_suggested_ad_sizes);
|
||||
if (
|
||||
!mobileView &&
|
||||
Discourse.SiteSettings.adsense_topic_above_suggested_code
|
||||
) {
|
||||
data["topic-above-suggested"]["ad_code"] =
|
||||
Discourse.SiteSettings.adsense_topic_above_suggested_code;
|
||||
data["topic-above-suggested"]["ad_width"] = parseAdWidth(
|
||||
Discourse.SiteSettings.adsense_topic_above_suggested_ad_sizes
|
||||
);
|
||||
data["topic-above-suggested"]["ad_height"] = parseAdHeight(
|
||||
Discourse.SiteSettings.adsense_topic_above_suggested_ad_sizes
|
||||
);
|
||||
}
|
||||
if (mobileView && Discourse.SiteSettings.adsense_mobile_topic_above_suggested_code) {
|
||||
data["topic-above-suggested"]["ad_code"] = Discourse.SiteSettings.adsense_mobile_topic_above_suggested_code;
|
||||
data["topic-above-suggested"]["ad_width"] = parseAdWidth(Discourse.SiteSettings.adsense_mobile_topic_above_suggested_ad_size);
|
||||
data["topic-above-suggested"]["ad_height"] = parseAdHeight(Discourse.SiteSettings.adsense_mobile_topic_above_suggested_ad_size);
|
||||
if (
|
||||
mobileView &&
|
||||
Discourse.SiteSettings.adsense_mobile_topic_above_suggested_code
|
||||
) {
|
||||
data["topic-above-suggested"]["ad_code"] =
|
||||
Discourse.SiteSettings.adsense_mobile_topic_above_suggested_code;
|
||||
data["topic-above-suggested"]["ad_width"] = parseAdWidth(
|
||||
Discourse.SiteSettings.adsense_mobile_topic_above_suggested_ad_size
|
||||
);
|
||||
data["topic-above-suggested"]["ad_height"] = parseAdHeight(
|
||||
Discourse.SiteSettings.adsense_mobile_topic_above_suggested_ad_size
|
||||
);
|
||||
}
|
||||
if (!mobileView && Discourse.SiteSettings.adsense_post_bottom_code) {
|
||||
data["post-bottom"]["ad_code"] = Discourse.SiteSettings.adsense_post_bottom_code;
|
||||
data["post-bottom"]["ad_width"] = parseAdWidth(Discourse.SiteSettings.adsense_post_bottom_ad_sizes);
|
||||
data["post-bottom"]["ad_height"] = parseAdHeight(Discourse.SiteSettings.adsense_post_bottom_ad_sizes);
|
||||
data["post-bottom"]["ad_code"] =
|
||||
Discourse.SiteSettings.adsense_post_bottom_code;
|
||||
data["post-bottom"]["ad_width"] = parseAdWidth(
|
||||
Discourse.SiteSettings.adsense_post_bottom_ad_sizes
|
||||
);
|
||||
data["post-bottom"]["ad_height"] = parseAdHeight(
|
||||
Discourse.SiteSettings.adsense_post_bottom_ad_sizes
|
||||
);
|
||||
}
|
||||
if (mobileView && Discourse.SiteSettings.adsense_mobile_post_bottom_code) {
|
||||
data["post-bottom"]["ad_code"] = Discourse.SiteSettings.adsense_mobile_post_bottom_code;
|
||||
data["post-bottom"]["ad_width"] = parseAdWidth(Discourse.SiteSettings.adsense_mobile_post_bottom_ad_size);
|
||||
data["post-bottom"]["ad_height"] = parseAdHeight(Discourse.SiteSettings.adsense_mobile_post_bottom_ad_size);
|
||||
data["post-bottom"]["ad_code"] =
|
||||
Discourse.SiteSettings.adsense_mobile_post_bottom_code;
|
||||
data["post-bottom"]["ad_width"] = parseAdWidth(
|
||||
Discourse.SiteSettings.adsense_mobile_post_bottom_ad_size
|
||||
);
|
||||
data["post-bottom"]["ad_height"] = parseAdHeight(
|
||||
Discourse.SiteSettings.adsense_mobile_post_bottom_ad_size
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default Ember.Component.extend({
|
||||
classNameBindings: [':google-adsense', 'classForSlot', 'isResponsive:adsense-responsive'],
|
||||
classNameBindings: [
|
||||
":google-adsense",
|
||||
"classForSlot",
|
||||
"isResponsive:adsense-responsive"
|
||||
],
|
||||
loadedGoogletag: false,
|
||||
|
||||
publisher_id: publisher_id,
|
||||
|
@ -95,14 +157,14 @@ export default Ember.Component.extend({
|
|||
adRequested: false,
|
||||
|
||||
init() {
|
||||
this.set('ad_width', data[this.placement]["ad_width"] );
|
||||
this.set('ad_height', data[this.placement]["ad_height"] );
|
||||
this.set('ad_code', data[this.placement]["ad_code"] );
|
||||
this.set("ad_width", data[this.placement]["ad_width"]);
|
||||
this.set("ad_height", data[this.placement]["ad_height"]);
|
||||
this.set("ad_code", data[this.placement]["ad_code"]);
|
||||
this._super();
|
||||
},
|
||||
|
||||
_triggerAds() {
|
||||
this.set('adRequested', true);
|
||||
this.set("adRequested", true);
|
||||
loadAdsense().then(function() {
|
||||
const adsbygoogle = window.adsbygoogle || [];
|
||||
|
||||
|
@ -115,45 +177,63 @@ export default Ember.Component.extend({
|
|||
didInsertElement() {
|
||||
this._super();
|
||||
|
||||
if (!this.get('showAd')) { return; }
|
||||
if (!this.get("showAd")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.get('listLoading')) { return; }
|
||||
if (this.get("listLoading")) {
|
||||
return;
|
||||
}
|
||||
|
||||
Ember.run.scheduleOnce('afterRender', this, this._triggerAds);
|
||||
Ember.run.scheduleOnce("afterRender", this, this._triggerAds);
|
||||
},
|
||||
|
||||
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);
|
||||
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'),
|
||||
}.observes("listLoading"),
|
||||
|
||||
isResponsive: function() {
|
||||
return this.get('ad_width') === 'auto';
|
||||
}.property('ad_width'),
|
||||
return this.get("ad_width") === "auto";
|
||||
}.property("ad_width"),
|
||||
|
||||
classForSlot: function() {
|
||||
return `adsense-${this.get('placement')}`.htmlSafe();
|
||||
}.property('placement'),
|
||||
return `adsense-${this.get("placement")}`.htmlSafe();
|
||||
}.property("placement"),
|
||||
|
||||
autoAdFormat: function() {
|
||||
return this.get('isResponsive') ? 'auto'.htmlSafe() : false;
|
||||
}.property('isResponsive'),
|
||||
return this.get("isResponsive") ? "auto".htmlSafe() : false;
|
||||
}.property("isResponsive"),
|
||||
|
||||
adWrapperStyle: function() {
|
||||
return (this.get('isResponsive') ? '' : `width: ${this.get('ad_width')}; height: ${this.get('ad_height')};`).htmlSafe();
|
||||
}.property('ad_width', 'ad_height'),
|
||||
return (this.get("isResponsive")
|
||||
? ""
|
||||
: `width: ${this.get("ad_width")}; height: ${this.get("ad_height")};`
|
||||
).htmlSafe();
|
||||
}.property("ad_width", "ad_height"),
|
||||
|
||||
adInsStyle: function() {
|
||||
return `display: ${this.get('isResponsive') ? 'block' : 'inline-block'}; ${this.get('adWrapperStyle')}`.htmlSafe();
|
||||
}.property('adWrapperStyle', 'isResponsive'),
|
||||
return `display: ${
|
||||
this.get("isResponsive") ? "block" : "inline-block"
|
||||
}; ${this.get("adWrapperStyle")}`.htmlSafe();
|
||||
}.property("adWrapperStyle", "isResponsive"),
|
||||
|
||||
checkTrustLevels: function() {
|
||||
return !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.adsense_through_trust_level));
|
||||
}.property('trust_level'),
|
||||
return !(
|
||||
currentUser &&
|
||||
currentUser.get("trust_level") >
|
||||
Discourse.SiteSettings.adsense_through_trust_level
|
||||
);
|
||||
}.property("trust_level"),
|
||||
|
||||
showAd: function() {
|
||||
return Discourse.SiteSettings.adsense_publisher_code && this.get('checkTrustLevels');
|
||||
}.property('checkTrustLevels')
|
||||
return (
|
||||
Discourse.SiteSettings.adsense_publisher_code &&
|
||||
this.get("checkTrustLevels")
|
||||
);
|
||||
}.property("checkTrustLevels")
|
||||
});
|
||||
|
|
|
@ -1,37 +1,36 @@
|
|||
import loadScript from 'discourse/lib/load-script';
|
||||
import loadScript from "discourse/lib/load-script";
|
||||
|
||||
var currentUser = Discourse.User.current(),
|
||||
_loaded = false,
|
||||
_promise = null,
|
||||
ads = {};
|
||||
_loaded = false,
|
||||
_promise = null,
|
||||
ads = {};
|
||||
|
||||
function splitWidthInt(value) {
|
||||
var str = value.substring(0, 3);
|
||||
return str.trim();
|
||||
var str = value.substring(0, 3);
|
||||
return str.trim();
|
||||
}
|
||||
|
||||
function splitHeightInt(value) {
|
||||
var str = value.substring(4, 7);
|
||||
return str.trim();
|
||||
var str = value.substring(4, 7);
|
||||
return str.trim();
|
||||
}
|
||||
|
||||
// This creates an array for the values of the custom targeting key
|
||||
function valueParse(value) {
|
||||
var final = value.replace(/ /g,'');
|
||||
final = final.replace(/['"]+/g, '');
|
||||
final = final.split(',');
|
||||
var final = value.replace(/ /g, "");
|
||||
final = final.replace(/['"]+/g, "");
|
||||
final = final.split(",");
|
||||
return final;
|
||||
}
|
||||
|
||||
// This creates an array for the key of the custom targeting key
|
||||
function keyParse(word) {
|
||||
var key = word;
|
||||
key = key.replace(/['"]+/g, '');
|
||||
key = key.replace(/['"]+/g, "");
|
||||
key = key.split("\n");
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
// This sets the key and value for custom targeting
|
||||
var Foo = function(key, value, adslot) {
|
||||
this.locationKey = key;
|
||||
|
@ -56,7 +55,6 @@ function custom_targeting(key_array, value_array, location) {
|
|||
}
|
||||
|
||||
function defineSlot(divId, placement, settings, isMobile) {
|
||||
|
||||
if (!settings.dfp_publisher_id) {
|
||||
return;
|
||||
}
|
||||
|
@ -67,65 +65,204 @@ function defineSlot(divId, placement, settings, isMobile) {
|
|||
return ads[divId];
|
||||
}
|
||||
|
||||
if (placement === "topic-list-top" && settings.dfp_topic_list_top_code && settings.dfp_topic_list_top_ad_sizes) {
|
||||
if (
|
||||
placement === "topic-list-top" &&
|
||||
settings.dfp_topic_list_top_code &&
|
||||
settings.dfp_topic_list_top_ad_sizes
|
||||
) {
|
||||
if (isMobile) {
|
||||
width = parseInt(splitWidthInt(settings.dfp_mobile_topic_list_top_ad_sizes));
|
||||
height = parseInt(splitHeightInt(settings.dfp_mobile_topic_list_top_ad_sizes));
|
||||
ad = window.googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_mobile_topic_list_top_code, [width,height], divId).addService(window.googletag.pubads());
|
||||
custom_targeting((keyParse(Discourse.SiteSettings.dfp_target_topic_list_top_key_code)), (keyParse(settings.dfp_target_topic_list_top_value_code)), ad);
|
||||
width = parseInt(
|
||||
splitWidthInt(settings.dfp_mobile_topic_list_top_ad_sizes)
|
||||
);
|
||||
height = parseInt(
|
||||
splitHeightInt(settings.dfp_mobile_topic_list_top_ad_sizes)
|
||||
);
|
||||
ad = window.googletag
|
||||
.defineSlot(
|
||||
"/" +
|
||||
settings.dfp_publisher_id +
|
||||
"/" +
|
||||
settings.dfp_mobile_topic_list_top_code,
|
||||
[width, height],
|
||||
divId
|
||||
)
|
||||
.addService(window.googletag.pubads());
|
||||
custom_targeting(
|
||||
keyParse(Discourse.SiteSettings.dfp_target_topic_list_top_key_code),
|
||||
keyParse(settings.dfp_target_topic_list_top_value_code),
|
||||
ad
|
||||
);
|
||||
} else {
|
||||
width = parseInt(splitWidthInt(settings.dfp_topic_list_top_ad_sizes));
|
||||
height = parseInt(splitHeightInt(settings.dfp_topic_list_top_ad_sizes));
|
||||
ad = window.googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_topic_list_top_code, [width, height], divId).addService(window.googletag.pubads());
|
||||
custom_targeting((keyParse(settings.dfp_target_topic_list_top_key_code)), (keyParse(settings.dfp_target_topic_list_top_value_code)), ad);
|
||||
ad = window.googletag
|
||||
.defineSlot(
|
||||
"/" +
|
||||
settings.dfp_publisher_id +
|
||||
"/" +
|
||||
settings.dfp_topic_list_top_code,
|
||||
[width, height],
|
||||
divId
|
||||
)
|
||||
.addService(window.googletag.pubads());
|
||||
custom_targeting(
|
||||
keyParse(settings.dfp_target_topic_list_top_key_code),
|
||||
keyParse(settings.dfp_target_topic_list_top_value_code),
|
||||
ad
|
||||
);
|
||||
}
|
||||
} else if (placement === "topic-above-post-stream" && settings.dfp_topic_above_post_stream_code && settings.dfp_topic_above_post_stream_ad_sizes) {
|
||||
} else if (
|
||||
placement === "topic-above-post-stream" &&
|
||||
settings.dfp_topic_above_post_stream_code &&
|
||||
settings.dfp_topic_above_post_stream_ad_sizes
|
||||
) {
|
||||
if (isMobile) {
|
||||
width = parseInt(splitWidthInt(settings.dfp_mobile_topic_above_post_stream_ad_sizes));
|
||||
height = parseInt(splitHeightInt(settings.dfp_mobile_topic_above_post_stream_ad_sizes));
|
||||
ad = window.googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_mobile_topic_above_post_stream_code, [width,height], divId).addService(window.googletag.pubads());
|
||||
custom_targeting((keyParse(settings.dfp_target_topic_above_post_stream_key_code)), (keyParse(settings.dfp_target_topic_above_post_stream_value_code)), ad);
|
||||
width = parseInt(
|
||||
splitWidthInt(settings.dfp_mobile_topic_above_post_stream_ad_sizes)
|
||||
);
|
||||
height = parseInt(
|
||||
splitHeightInt(settings.dfp_mobile_topic_above_post_stream_ad_sizes)
|
||||
);
|
||||
ad = window.googletag
|
||||
.defineSlot(
|
||||
"/" +
|
||||
settings.dfp_publisher_id +
|
||||
"/" +
|
||||
settings.dfp_mobile_topic_above_post_stream_code,
|
||||
[width, height],
|
||||
divId
|
||||
)
|
||||
.addService(window.googletag.pubads());
|
||||
custom_targeting(
|
||||
keyParse(settings.dfp_target_topic_above_post_stream_key_code),
|
||||
keyParse(settings.dfp_target_topic_above_post_stream_value_code),
|
||||
ad
|
||||
);
|
||||
} else {
|
||||
width = parseInt(splitWidthInt(settings.dfp_topic_above_post_stream_ad_sizes));
|
||||
height = parseInt(splitHeightInt(settings.dfp_topic_above_post_stream_ad_sizes));
|
||||
ad = window.googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_topic_above_post_stream_code, [width, height], divId).addService(window.googletag.pubads());
|
||||
custom_targeting((keyParse(settings.dfp_target_topic_above_post_stream_key_code)), (keyParse(settings.dfp_target_topic_above_post_stream_value_code)), ad);
|
||||
width = parseInt(
|
||||
splitWidthInt(settings.dfp_topic_above_post_stream_ad_sizes)
|
||||
);
|
||||
height = parseInt(
|
||||
splitHeightInt(settings.dfp_topic_above_post_stream_ad_sizes)
|
||||
);
|
||||
ad = window.googletag
|
||||
.defineSlot(
|
||||
"/" +
|
||||
settings.dfp_publisher_id +
|
||||
"/" +
|
||||
settings.dfp_topic_above_post_stream_code,
|
||||
[width, height],
|
||||
divId
|
||||
)
|
||||
.addService(window.googletag.pubads());
|
||||
custom_targeting(
|
||||
keyParse(settings.dfp_target_topic_above_post_stream_key_code),
|
||||
keyParse(settings.dfp_target_topic_above_post_stream_value_code),
|
||||
ad
|
||||
);
|
||||
}
|
||||
} else if (placement === "topic-above-suggested" && settings.dfp_topic_above_suggested_code && settings.dfp_topic_above_suggested_ad_sizes) {
|
||||
} else if (
|
||||
placement === "topic-above-suggested" &&
|
||||
settings.dfp_topic_above_suggested_code &&
|
||||
settings.dfp_topic_above_suggested_ad_sizes
|
||||
) {
|
||||
if (isMobile) {
|
||||
width = parseInt(splitWidthInt(settings.dfp_mobile_topic_above_suggested_ad_sizes));
|
||||
height = parseInt(splitHeightInt(settings.dfp_mobile_topic_above_suggested_ad_sizes));
|
||||
ad = window.googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_mobile_topic_above_suggested_code, [width,height], divId).addService(window.googletag.pubads());
|
||||
custom_targeting((keyParse(settings.dfp_target_topic_above_suggested_key_code)), (keyParse(settings.dfp_target_topic_above_suggested_value_code)), ad);
|
||||
width = parseInt(
|
||||
splitWidthInt(settings.dfp_mobile_topic_above_suggested_ad_sizes)
|
||||
);
|
||||
height = parseInt(
|
||||
splitHeightInt(settings.dfp_mobile_topic_above_suggested_ad_sizes)
|
||||
);
|
||||
ad = window.googletag
|
||||
.defineSlot(
|
||||
"/" +
|
||||
settings.dfp_publisher_id +
|
||||
"/" +
|
||||
settings.dfp_mobile_topic_above_suggested_code,
|
||||
[width, height],
|
||||
divId
|
||||
)
|
||||
.addService(window.googletag.pubads());
|
||||
custom_targeting(
|
||||
keyParse(settings.dfp_target_topic_above_suggested_key_code),
|
||||
keyParse(settings.dfp_target_topic_above_suggested_value_code),
|
||||
ad
|
||||
);
|
||||
} else {
|
||||
width = parseInt(splitWidthInt(settings.dfp_topic_above_suggested_ad_sizes));
|
||||
height = parseInt(splitHeightInt(settings.dfp_topic_above_suggested_ad_sizes));
|
||||
ad = window.googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_topic_above_suggested_code, [width, height], divId).addService(window.googletag.pubads());
|
||||
custom_targeting((keyParse(settings.dfp_target_topic_above_suggested_key_code)), (keyParse(settings.dfp_target_topic_above_suggested_value_code)), ad);
|
||||
width = parseInt(
|
||||
splitWidthInt(settings.dfp_topic_above_suggested_ad_sizes)
|
||||
);
|
||||
height = parseInt(
|
||||
splitHeightInt(settings.dfp_topic_above_suggested_ad_sizes)
|
||||
);
|
||||
ad = window.googletag
|
||||
.defineSlot(
|
||||
"/" +
|
||||
settings.dfp_publisher_id +
|
||||
"/" +
|
||||
settings.dfp_topic_above_suggested_code,
|
||||
[width, height],
|
||||
divId
|
||||
)
|
||||
.addService(window.googletag.pubads());
|
||||
custom_targeting(
|
||||
keyParse(settings.dfp_target_topic_above_suggested_key_code),
|
||||
keyParse(settings.dfp_target_topic_above_suggested_value_code),
|
||||
ad
|
||||
);
|
||||
}
|
||||
} else if (placement === "post-bottom" && settings.dfp_post_bottom_code && settings.dfp_post_bottom_ad_sizes) {
|
||||
} else if (
|
||||
placement === "post-bottom" &&
|
||||
settings.dfp_post_bottom_code &&
|
||||
settings.dfp_post_bottom_ad_sizes
|
||||
) {
|
||||
if (isMobile) {
|
||||
width = parseInt(splitWidthInt(settings.dfp_mobile_post_bottom_ad_sizes));
|
||||
height = parseInt(splitHeightInt(settings.dfp_mobile_post_bottom_ad_sizes));
|
||||
ad = window.googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_mobile_post_bottom_code, [width,height], divId).addService(window.googletag.pubads());
|
||||
custom_targeting((keyParse(settings.dfp_target_post_bottom_key_code)), (keyParse(settings.dfp_target_post_bottom_value_code)), ad);
|
||||
height = parseInt(
|
||||
splitHeightInt(settings.dfp_mobile_post_bottom_ad_sizes)
|
||||
);
|
||||
ad = window.googletag
|
||||
.defineSlot(
|
||||
"/" +
|
||||
settings.dfp_publisher_id +
|
||||
"/" +
|
||||
settings.dfp_mobile_post_bottom_code,
|
||||
[width, height],
|
||||
divId
|
||||
)
|
||||
.addService(window.googletag.pubads());
|
||||
custom_targeting(
|
||||
keyParse(settings.dfp_target_post_bottom_key_code),
|
||||
keyParse(settings.dfp_target_post_bottom_value_code),
|
||||
ad
|
||||
);
|
||||
} else {
|
||||
width = parseInt(splitWidthInt(settings.dfp_post_bottom_ad_sizes));
|
||||
height = parseInt(splitHeightInt(settings.dfp_post_bottom_ad_sizes));
|
||||
ad = window.googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_post_bottom_code, [width, height], divId).addService(window.googletag.pubads());
|
||||
custom_targeting((keyParse(settings.dfp_target_post_bottom_key_code)), (keyParse(settings.dfp_target_post_bottom_value_code)), ad);
|
||||
ad = window.googletag
|
||||
.defineSlot(
|
||||
"/" + settings.dfp_publisher_id + "/" + settings.dfp_post_bottom_code,
|
||||
[width, height],
|
||||
divId
|
||||
)
|
||||
.addService(window.googletag.pubads());
|
||||
custom_targeting(
|
||||
keyParse(settings.dfp_target_post_bottom_key_code),
|
||||
keyParse(settings.dfp_target_post_bottom_value_code),
|
||||
ad
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (ad) {
|
||||
ads[divId] = {ad: ad, width: width, height: height};
|
||||
ads[divId] = { ad: ad, width: width, height: height };
|
||||
return ads[divId];
|
||||
}
|
||||
}
|
||||
|
||||
function destroySlot(divId) {
|
||||
if (ads[divId] && window.googletag) {
|
||||
window.googletag.cmd.push(function(){
|
||||
window.googletag.cmd.push(function() {
|
||||
window.googletag.destroySlots([ads[divId].ad]);
|
||||
delete ads[divId];
|
||||
});
|
||||
|
@ -142,11 +279,13 @@ function loadGoogle() {
|
|||
}
|
||||
|
||||
// The boilerplate code
|
||||
var dfpSrc = (('https:' === document.location.protocol) ? 'https:' : 'http:') + '//www.googletagservices.com/tag/js/gpt.js';
|
||||
var dfpSrc =
|
||||
("https:" === document.location.protocol ? "https:" : "http:") +
|
||||
"//www.googletagservices.com/tag/js/gpt.js";
|
||||
_promise = loadScript(dfpSrc, { scriptTag: true }).then(function() {
|
||||
_loaded = true;
|
||||
if (window.googletag === undefined) {
|
||||
console.log('googletag is undefined!');
|
||||
console.log("googletag is undefined!");
|
||||
}
|
||||
|
||||
window.googletag.cmd.push(function() {
|
||||
|
@ -159,84 +298,110 @@ function loadGoogle() {
|
|||
return _promise;
|
||||
}
|
||||
|
||||
|
||||
// Ember component - the class is the adblock and css
|
||||
export default Ember.Component.extend({
|
||||
width: 728,
|
||||
height: 90,
|
||||
|
||||
classNameBindings: ['adUnitClass'],
|
||||
classNames: ['google-dfp-ad'],
|
||||
classNameBindings: ["adUnitClass"],
|
||||
classNames: ["google-dfp-ad"],
|
||||
loadedGoogletag: false,
|
||||
refreshOnChange: null,
|
||||
|
||||
divId: function() {
|
||||
if (this.get('postNumber')) {
|
||||
return "div-gpt-ad-" + this.get('placement') + '-' + this.get('postNumber');
|
||||
if (this.get("postNumber")) {
|
||||
return (
|
||||
"div-gpt-ad-" + this.get("placement") + "-" + this.get("postNumber")
|
||||
);
|
||||
} else {
|
||||
return "div-gpt-ad-" + this.get('placement');
|
||||
return "div-gpt-ad-" + this.get("placement");
|
||||
}
|
||||
}.property('placement', 'postNumber'),
|
||||
}.property("placement", "postNumber"),
|
||||
|
||||
adUnitClass: function() {
|
||||
return "dfp-ad-" + this.get("placement");
|
||||
}.property('placement'),
|
||||
}.property("placement"),
|
||||
|
||||
adWrapperStyle: function() {
|
||||
return `width: ${this.get('width')}px; height: ${this.get('height')}px;`.htmlSafe();
|
||||
}.property('width', 'height'),
|
||||
return `width: ${this.get("width")}px; height: ${this.get(
|
||||
"height"
|
||||
)}px;`.htmlSafe();
|
||||
}.property("width", "height"),
|
||||
|
||||
adTitleStyleMobile: function() {
|
||||
return `width: ${this.get('width')}px;`.htmlSafe();
|
||||
}.property('width'),
|
||||
return `width: ${this.get("width")}px;`.htmlSafe();
|
||||
}.property("width"),
|
||||
|
||||
showAd: function() {
|
||||
return Discourse.SiteSettings.dfp_publisher_id && this.get('checkTrustLevels');
|
||||
}.property('checkTrustLevels'),
|
||||
return (
|
||||
Discourse.SiteSettings.dfp_publisher_id && this.get("checkTrustLevels")
|
||||
);
|
||||
}.property("checkTrustLevels"),
|
||||
|
||||
checkTrustLevels: function() {
|
||||
return !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.dfp_through_trust_level));
|
||||
}.property('trust_level'),
|
||||
return !(
|
||||
currentUser &&
|
||||
currentUser.get("trust_level") >
|
||||
Discourse.SiteSettings.dfp_through_trust_level
|
||||
);
|
||||
}.property("trust_level"),
|
||||
|
||||
refreshAd: function() {
|
||||
var slot = ads[this.get('divId')];
|
||||
if (!(slot && slot.ad)) { return; }
|
||||
var slot = ads[this.get("divId")];
|
||||
if (!(slot && slot.ad)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var self = this,
|
||||
ad = slot.ad;
|
||||
ad = slot.ad;
|
||||
|
||||
if (this.get('loadedGoogletag') && this.get('refreshOnChange')) {
|
||||
if (this.get("loadedGoogletag") && this.get("refreshOnChange")) {
|
||||
window.googletag.cmd.push(function() {
|
||||
ad.setTargeting('discourse-category', self.get('category') ? self.get('category') : '0');
|
||||
ad.setTargeting(
|
||||
"discourse-category",
|
||||
self.get("category") ? self.get("category") : "0"
|
||||
);
|
||||
window.googletag.pubads().refresh([ad]);
|
||||
});
|
||||
}
|
||||
}.observes('refreshOnChange'),
|
||||
}.observes("refreshOnChange"),
|
||||
|
||||
_initGoogleDFP: function() {
|
||||
if (!this.get('showAd')) { return; }
|
||||
if (!this.get("showAd")) {
|
||||
return;
|
||||
}
|
||||
|
||||
const ember_w_function = String.prototype.w;
|
||||
String.prototype.w = null;
|
||||
var self = this;
|
||||
loadGoogle(this.siteSettings).then(function() {
|
||||
self.set('loadedGoogletag', true);
|
||||
window.googletag.cmd.push(function() {
|
||||
let slot = defineSlot(self.get('divId'), self.get('placement'), self.siteSettings, self.site.mobileView);
|
||||
if (slot && slot.ad) {
|
||||
slot.ad.setTargeting('discourse-category', self.get('category') ? self.get('category') : '0');
|
||||
self.set('width', slot.width);
|
||||
self.set('height', slot.height);
|
||||
window.googletag.display(self.get('divId'));
|
||||
window.googletag.pubads().refresh([slot.ad]);
|
||||
}
|
||||
loadGoogle(this.siteSettings)
|
||||
.then(function() {
|
||||
self.set("loadedGoogletag", true);
|
||||
window.googletag.cmd.push(function() {
|
||||
let slot = defineSlot(
|
||||
self.get("divId"),
|
||||
self.get("placement"),
|
||||
self.siteSettings,
|
||||
self.site.mobileView
|
||||
);
|
||||
if (slot && slot.ad) {
|
||||
slot.ad.setTargeting(
|
||||
"discourse-category",
|
||||
self.get("category") ? self.get("category") : "0"
|
||||
);
|
||||
self.set("width", slot.width);
|
||||
self.set("height", slot.height);
|
||||
window.googletag.display(self.get("divId"));
|
||||
window.googletag.pubads().refresh([slot.ad]);
|
||||
}
|
||||
});
|
||||
})
|
||||
.finally(function() {
|
||||
String.prototype.w = ember_w_function;
|
||||
});
|
||||
}).finally(function() {
|
||||
String.prototype.w = ember_w_function;
|
||||
});
|
||||
}.on('didInsertElement'),
|
||||
}.on("didInsertElement"),
|
||||
|
||||
cleanup: function() {
|
||||
destroySlot(this.get('divId'));
|
||||
}.on('willDestroyElement')
|
||||
destroySlot(this.get("divId"));
|
||||
}.on("willDestroyElement")
|
||||
});
|
||||
|
|
|
@ -1,53 +1,50 @@
|
|||
import PostModel from 'discourse/models/post';
|
||||
import {
|
||||
withPluginApi
|
||||
} from 'discourse/lib/plugin-api';
|
||||
import PostModel from "discourse/models/post";
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
|
||||
export default {
|
||||
name: 'initialize-ad-plugin',
|
||||
name: "initialize-ad-plugin",
|
||||
initialize(container) {
|
||||
const siteSettings = container.lookup('site-settings:main');
|
||||
const siteSettings = container.lookup("site-settings:main");
|
||||
|
||||
PostModel.reopen({
|
||||
postSpecificCountDFP: function() {
|
||||
return this.isNthPost(parseInt(siteSettings.dfp_nth_post_code));
|
||||
}.property('post_number'),
|
||||
}.property("post_number"),
|
||||
|
||||
postSpecificCountAdsense: function() {
|
||||
return this.isNthPost(parseInt(siteSettings.adsense_nth_post_code));
|
||||
}.property('post_number'),
|
||||
}.property("post_number"),
|
||||
|
||||
postSpecificCountAmazon: function() {
|
||||
return this.isNthPost(parseInt(siteSettings.amazon_nth_post_code));
|
||||
}.property('post_number'),
|
||||
}.property("post_number"),
|
||||
|
||||
postSpecificCountCodeFund: function() {
|
||||
return this.isNthPost(parseInt(siteSettings.codefund_nth_post));
|
||||
}.property('post_number'),
|
||||
}.property("post_number"),
|
||||
|
||||
isNthPost: function(n) {
|
||||
if (n && n > 0) {
|
||||
return (this.get('post_number') % n) === 0;
|
||||
return this.get("post_number") % n === 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
withPluginApi('0.1', api => {
|
||||
api.decorateWidget('post:after', dec => {
|
||||
|
||||
withPluginApi("0.1", api => {
|
||||
api.decorateWidget("post:after", dec => {
|
||||
if (dec.canConnectComponent) {
|
||||
return dec.connect({
|
||||
component: 'adplugin-container',
|
||||
context: 'model'
|
||||
component: "adplugin-container",
|
||||
context: "model"
|
||||
});
|
||||
}
|
||||
|
||||
// Old way for backwards compatibility
|
||||
return dec.connect({
|
||||
templateName: 'connectors/post-bottom/discourse-adplugin',
|
||||
context: 'model'
|
||||
templateName: "connectors/post-bottom/discourse-adplugin",
|
||||
context: "model"
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue