This commit is contained in:
Neil Lalonde 2019-09-16 14:35:58 -04:00
parent 19f0457e8c
commit 51c1b89a62
2 changed files with 51 additions and 35 deletions

View File

@ -1,13 +1,16 @@
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
import { default as computed, observes } from "ember-addons/ember-computed-decorators";
import {
default as computed,
observes
} from "ember-addons/ember-computed-decorators";
import loadScript from "discourse/lib/load-script";
const publisherId = Discourse.SiteSettings.adbutler_publisher_id;
const adserverHostname = Discourse.SiteSettings.adbutler_adserver_hostname;
let _loaded = false,
_promise = null,
_c = 0;
_promise = null,
_c = 0;
function loadAdbutler() {
if (_loaded) {
@ -18,7 +21,9 @@ function loadAdbutler() {
return _promise;
}
_promise = loadScript('https://' + adserverHostname + '/app.js', { scriptTag: true }).then(function() {
_promise = loadScript("https://" + adserverHostname + "/app.js", {
scriptTag: true
}).then(function() {
_loaded = true;
});
@ -26,34 +31,33 @@ function loadAdbutler() {
}
export default AdComponent.extend({
divs: null,
init() {
let dimensions = [728,90];
let configKey = 'adbutler_';
let className = 'adbutler-';
let dimClassName = 'adbutler-ad';
let dimensions = [728, 90];
let configKey = "adbutler_";
let className = "adbutler-";
let dimClassName = "adbutler-ad";
this.set('divs', []);
this.set("divs", []);
if (this.site.mobileView) {
dimensions = [320,50];
configKey += 'mobile_';
className += 'mobile-';
dimClassName = 'adbutler-mobile-ad';
dimensions = [320, 50];
configKey += "mobile_";
className += "mobile-";
dimClassName = "adbutler-mobile-ad";
}
configKey += this.get("placement").replace(/-/g, '_') + '_zone_id';
configKey += this.get("placement").replace(/-/g, "_") + "_zone_id";
this.set("configKey", configKey);
className += this.get("placement");
this.set("className", className + ' ' + dimClassName);
this.set("className", className + " " + dimClassName);
let zoneId = this.siteSettings[configKey];
this.set("zoneId", zoneId);
let divId = 'placement-' + zoneId + '-' + _c;
let divId = "placement-" + zoneId + "-" + _c;
this.set("divId", divId);
_c++;
this.divs.push({
@ -68,17 +72,30 @@ export default AdComponent.extend({
},
_triggerAds() {
loadAdbutler().then(function() {
if(this.divs.length > 0) {
let abkw = window.abkw || '';
AdButler.ads.push({
handler: function(opt){
AdButler.register(opt.place.publisherId, opt.place.zoneId, opt.place.dimensions, opt.place.divId, opt);
},
opt: { place: this.divs.pop(), keywords: abkw, domain: adserverHostname, click:'CLICK_MACRO_PLACEHOLDER' }
});
}
}.bind(this));
loadAdbutler().then(
function() {
if (this.divs.length > 0) {
let abkw = window.abkw || "";
AdButler.ads.push({
handler: function(opt) {
AdButler.register(
opt.place.publisherId,
opt.place.zoneId,
opt.place.dimensions,
opt.place.divId,
opt
);
},
opt: {
place: this.divs.pop(),
keywords: abkw,
domain: adserverHostname,
click: "CLICK_MACRO_PLACEHOLDER"
}
});
}
}.bind(this)
);
},
didInsertElement() {
@ -105,10 +122,10 @@ export default AdComponent.extend({
},
@computed(
"showToTrustLevel",
"showToGroups",
"showToTrustLevel",
"showToGroups",
"showAfterPost",
"showOnCurrentPage",
"showOnCurrentPage"
)
showAd(showToTrustLevel, showToGroups, showAfterPost, showOnCurrentPage) {
return (
@ -127,5 +144,4 @@ export default AdComponent.extend({
}
return this.isNthPost(parseInt(this.siteSettings.adbutler_nth_post));
}
});

View File

@ -248,7 +248,8 @@
height: 50px;
}
.adbutler-topic-list-top, .adbutler-topic-above-suggested {
.adbutler-topic-list-top,
.adbutler-topic-above-suggested {
margin: 10px;
text-align: center;
}
@ -259,8 +260,7 @@
.adbutler-post-bottom {
margin: 10px 0px 10px 56px;
}
}
.adplugin-mgmt {
.house-ads-actions {