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