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-above-post-stream": {},
"topic-above-suggested": {},
@ -119,10 +122,12 @@ if (
);
}
export default Ember.Component.extend({
export default AdComponent.extend({
classNames: ["amazon-product-links"],
init: function() {
showAd: Ember.computed.and("showToTrustLevel", "showToGroups"),
init() {
let placement = this.get("placement");
this.set("user_input", data[placement]["user_input"]);
this.set("amazon_width", data[placement]["amazon_width"]);
@ -133,35 +138,37 @@ export default Ember.Component.extend({
this._super();
},
adWrapperStyle: function() {
return `width: ${this.get("amazon_width")}px; height: ${this.get(
"amazon_height"
)}px;`.htmlSafe();
}.property("amazon_width", "amazon_height"),
@computed("amazon_width", "amazon_height")
adWrapperStyle(w, h) {
return `width: ${w}px; height: ${h}px;`.htmlSafe();
},
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"),
@computed("mobile_amazon_width", "mobile_amazon_height")
adWrapperStyleMobile(w, h) {
return `width: ${w}px; height: ${h}px;`.htmlSafe();
},
adTitleStyleMobile: function() {
return `width: ${this.get("mobile_amazon_width")}px;`.htmlSafe();
}.property("mobile_amazon_width"),
@computed("mobile_amazon_width")
adTitleStyleMobile(w) {
return `width: ${w}px;`.htmlSafe();
},
userInput: function() {
return `${this.get("user_input")}`.htmlSafe();
}.property("user_input"),
@computed("user_input")
userInput(userInput) {
return `${userInput}`.htmlSafe();
},
userInputMobile: function() {
return `${this.get("user_input_mobile")}`.htmlSafe();
}.property("user_input_mobile"),
@computed("user_input_mobile")
userInputMobile(userInput) {
return `${userInput}`.htmlSafe();
},
checkTrustLevels: function() {
@computed()
showToTrustLevel() {
return !(
currentUser &&
currentUser.get("trust_level") >
Discourse.SiteSettings.amazon_through_trust_level
);
}.property("trust_level")
}
});

View File

@ -1,4 +1,4 @@
{{#if checkTrustLevels}}
{{#if showAd}}
{{#if site.mobileView}}
<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}}>