Updates to amazon-product-links

This commit is contained in:
Neil Lalonde 2019-04-17 11:08:11 -04:00
parent 4fd7caffd6
commit 881a8e5d4c
2 changed files with 33 additions and 26 deletions

View File

@ -1,6 +1,9 @@
var currentUser = Discourse.User.current(); import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad_component";
import computed from "ember-addons/ember-computed-decorators";
var data = { const currentUser = Discourse.User.current();
const data = {
"topic-list-top": {}, "topic-list-top": {},
"topic-above-post-stream": {}, "topic-above-post-stream": {},
"topic-above-suggested": {}, "topic-above-suggested": {},
@ -119,10 +122,12 @@ if (
); );
} }
export default Ember.Component.extend({ export default AdComponent.extend({
classNames: ["amazon-product-links"], classNames: ["amazon-product-links"],
init: function() { showAd: Ember.computed.and("showToTrustLevel", "showToGroups"),
init() {
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"]);
@ -133,35 +138,37 @@ export default Ember.Component.extend({
this._super(); this._super();
}, },
adWrapperStyle: function() { @computed("amazon_width", "amazon_height")
return `width: ${this.get("amazon_width")}px; height: ${this.get( adWrapperStyle(w, h) {
"amazon_height" return `width: ${w}px; height: ${h}px;`.htmlSafe();
)}px;`.htmlSafe(); },
}.property("amazon_width", "amazon_height"),
adWrapperStyleMobile: function() { @computed("mobile_amazon_width", "mobile_amazon_height")
return `width: ${this.get("mobile_amazon_width")}px; height: ${this.get( adWrapperStyleMobile(w, h) {
"mobile_amazon_height" return `width: ${w}px; height: ${h}px;`.htmlSafe();
)}px;`.htmlSafe(); },
}.property("mobile_amazon_width", "mobile_amazon_height"),
adTitleStyleMobile: function() { @computed("mobile_amazon_width")
return `width: ${this.get("mobile_amazon_width")}px;`.htmlSafe(); adTitleStyleMobile(w) {
}.property("mobile_amazon_width"), return `width: ${w}px;`.htmlSafe();
},
userInput: function() { @computed("user_input")
return `${this.get("user_input")}`.htmlSafe(); userInput(userInput) {
}.property("user_input"), return `${userInput}`.htmlSafe();
},
userInputMobile: function() { @computed("user_input_mobile")
return `${this.get("user_input_mobile")}`.htmlSafe(); userInputMobile(userInput) {
}.property("user_input_mobile"), return `${userInput}`.htmlSafe();
},
checkTrustLevels: function() { @computed()
showToTrustLevel() {
return !( return !(
currentUser && currentUser &&
currentUser.get("trust_level") > currentUser.get("trust_level") >
Discourse.SiteSettings.amazon_through_trust_level Discourse.SiteSettings.amazon_through_trust_level
); );
}.property("trust_level") }
}); });

View File

@ -1,4 +1,4 @@
{{#if checkTrustLevels}} {{#if showAd}}
{{#if site.mobileView}} {{#if site.mobileView}}
<div class="amazon-product-links-label" style={{adTitleStyleMobile}}><h2>{{i18n 'adplugin.advertisement_label'}}</h2></div> <div class="amazon-product-links-label" style={{adTitleStyleMobile}}><h2>{{i18n 'adplugin.advertisement_label'}}</h2></div>
<iframe style={{adWrapperStyleMobile}} marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src={{userInputMobile}}> <iframe style={{adWrapperStyleMobile}} marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src={{userInputMobile}}>