FIX: use imports instead of Discourse global (#118)

FIX: use imports instead of Discourse global (#118)

Replaces Discourse.Site with the imported equivalent and Discourse.SiteSettings with this.siteSettings

diff --git a/assets/javascripts/discourse/components/adbutler-ad.js.es6 b/assets/javascripts/discourse/components/adbutler-ad.js.es6
index fd468ac..ab3a0a3 100644
--- a/assets/javascripts/discourse/components/adbutler-ad.js.es6
+++ b/assets/javascripts/discourse/components/adbutler-ad.js.es6
@@ -2,14 +2,11 @@ import AdComponent from "discourse/plugins/discourse-adplugin/discourse/componen
 import discourseComputed, { observes } from "discourse-common/utils/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;
 
-function loadAdbutler() {
+function loadAdbutler(adserverHostname) {
   if (_loaded) {
     return Ember.RSVP.resolve();
   }
@@ -29,6 +26,7 @@ function loadAdbutler() {
 
 export default AdComponent.extend({
   divs: null,
+  publisherId: null,
 
   init() {
     let dimensions = [728, 90];
@@ -56,7 +54,12 @@ export default AdComponent.extend({
 
     let divId = "placement-" + zoneId + "-" + _c;
     this.set("divId", divId);
+
+    let publisherId = this.siteSettings.adbutler_publisher_id;
+    this.set("publisherId", publisherId);
+
     _c++;
+
     this.divs.push({
       divId: divId,
       publisherId: publisherId,
@@ -64,7 +67,6 @@ export default AdComponent.extend({
       dimensions: dimensions,
     });
 
-    this.set("publisherId", publisherId);
     this._super();
   },
 
@@ -73,7 +75,9 @@ export default AdComponent.extend({
       return; // Don't load external JS during tests
     }
 
-    loadAdbutler().then(
+    const adserverHostname = this.siteSettings.adbutler_adserver_hostname;
+
+    loadAdbutler(adserverHostname).then(
       function () {
         if (this.divs.length > 0) {
           let abkw = window.abkw || "";
@@ -117,18 +121,24 @@ export default AdComponent.extend({
   @discourseComputed("currentUser.trust_level")
   showToTrustLevel(trustLevel) {
     return !(
-      trustLevel &&
-      trustLevel > Discourse.SiteSettings.adbutler_through_trust_level
+      trustLevel && trustLevel > this.siteSettings.adbutler_through_trust_level
     );
   },
 
   @discourseComputed(
+    "publisherId",
     "showToTrustLevel",
     "showToGroups",
     "showAfterPost",
     "showOnCurrentPage"
   )
-  showAd(showToTrustLevel, showToGroups, showAfterPost, showOnCurrentPage) {
+  showAd(
+    publisherId,
+    showToTrustLevel,
+    showToGroups,
+    showAfterPost,
+    showOnCurrentPage
+  ) {
     return (
       publisherId &&
       showToTrustLevel &&
diff --git a/assets/javascripts/discourse/components/amazon-product-links.js.es6 b/assets/javascripts/discourse/components/amazon-product-links.js.es6
index cb0ec9c..fc4247d 100644
--- a/assets/javascripts/discourse/components/amazon-product-links.js.es6
+++ b/assets/javascripts/discourse/components/amazon-product-links.js.es6
@@ -1,134 +1,6 @@
 import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
 import discourseComputed from "discourse-common/utils/decorators";
 
-const data = {
-  "topic-list-top": {},
-  "topic-above-post-stream": {},
-  "topic-above-suggested": {},
-  "post-bottom": {},
-};
-
-let mobileView = Discourse.Site.currentProp("mobileView");
-
-if (!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,
-    10
-  );
-  data["topic-list-top"]["amazon_height"] = parseInt(
-    Discourse.SiteSettings.amazon_topic_list_top_ad_height_code,
-    10
-  );
-}
-
-if (
-  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,
-    10
-  );
-  data["topic-list-top"]["mobile_amazon_height"] = parseInt(
-    Discourse.SiteSettings.amazon_mobile_topic_list_top_ad_height_code,
-    10
-  );
-}
-
-if (
-  !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,
-    10
-  );
-  data["topic-above-post-stream"]["amazon_height"] = parseInt(
-    Discourse.SiteSettings.amazon_topic_above_post_stream_ad_height_code,
-    10
-  );
-}
-
-if (
-  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,
-    10
-  );
-  data["topic-above-post-stream"]["mobile_amazon_height"] = parseInt(
-    Discourse.SiteSettings.amazon_mobile_topic_above_post_stream_ad_height_code,
-    10
-  );
-}
-
-if (
-  !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,
-    10
-  );
-  data["topic-above-suggested"]["amazon_height"] = parseInt(
-    Discourse.SiteSettings.amazon_topic_above_suggested_ad_height_code,
-    10
-  );
-}
-
-if (
-  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,
-    10
-  );
-  data["topic-above-suggested"]["mobile_amazon_height"] = parseInt(
-    Discourse.SiteSettings.amazon_mobile_topic_above_suggested_ad_height_code,
-    10
-  );
-}
-
-if (!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,
-    10
-  );
-  data["post-bottom"]["amazon_height"] = parseInt(
-    Discourse.SiteSettings.amazon_post_bottom_ad_height_code,
-    10
-  );
-}
-
-if (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,
-    10
-  );
-  data["post-bottom"]["mobile_amazon_height"] = parseInt(
-    Discourse.SiteSettings.amazon_mobile_post_bottom_ad_height_code,
-    10
-  );
-}
-
 export default AdComponent.extend({
   classNames: ["amazon-product-links"],
 
@@ -140,7 +12,139 @@ export default AdComponent.extend({
   ),
 
   init() {
-    let placement = this.get("placement");
+    const data = {
+      "topic-list-top": {},
+      "topic-above-post-stream": {},
+      "topic-above-suggested": {},
+      "post-bottom": {},
+    };
+    const mobileView = this.site.get("mobileView");
+    const placement = this.get("placement");
+
+    if (!mobileView && this.siteSettings.amazon_topic_list_top_src_code) {
+      data["topic-list-top"][
+        "user_input"

[... diff too long, it was truncated ...]

GitHub sha: f2171a51c37f8fae701b4f4f1999b4bf23842f6f

This commit appears in #118 which was approved by CvX. It was merged by tshenry.