From 2d752d8b2f32243459d68b02ce9f4bfe48712990 Mon Sep 17 00:00:00 2001 From: Sarah Ni Date: Thu, 10 Sep 2015 22:48:14 +1000 Subject: [PATCH] basic amazon product link inputs added and works --- .../components/amazon-product-links.js.es6 | 56 +++++++++++++++++++ .../components/amazon-product-links.hbs | 12 ++++ .../discourse-adplugin.hbs | 3 + .../initializers/extend-post-model.js.es6 | 4 ++ ...bae62698596cbd1cca7ad6261ef903cf8fc2c.css} | 10 ++++ config/locales/client.en.yml | 3 +- config/locales/server.en.yml | 5 +- config/settings.yml | 6 ++ plugin.rb | 10 ++++ 9 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 assets/javascripts/discourse/components/amazon-product-links.js.es6 create mode 100644 assets/javascripts/discourse/templates/components/amazon-product-links.hbs rename auto_generated/{plugin_e37c3ee1ca7c7c4d4ef14a99312037cc7c47ecb5.css => plugin_954bae62698596cbd1cca7ad6261ef903cf8fc2c.css} (64%) diff --git a/assets/javascripts/discourse/components/amazon-product-links.js.es6 b/assets/javascripts/discourse/components/amazon-product-links.js.es6 new file mode 100644 index 0000000..e57a0fb --- /dev/null +++ b/assets/javascripts/discourse/components/amazon-product-links.js.es6 @@ -0,0 +1,56 @@ +var amazon_code = ''; +var amazon_width = ''; +var amazon_height = ''; +var amazon_mobile_width = 320; +var amazon_mobile_height = 50; +var user_input = Discourse.SiteSettings.amazon_topic_list_top_code; +var currentUser = Discourse.User.current(); + +function splitWidthInt(value) { + var str = value.substring(0, 3); + return str.trim(); +} + +function splitHeightInt(value) { + var str = value.substring(4, 7); + return str.trim(); +} + +if (Discourse.SiteSettings.amazon_topic_list_top_code) { + if (!((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.amazon_through_trust_level))) { + user_input = Discourse.SiteSettings.amazon_topic_list_top_code; + amazon_width = parseInt(splitWidthInt(Discourse.SiteSettings.amazon_topic_list_top_ad_sizes)); + amazon_height = parseInt(splitHeightInt(Discourse.SiteSettings.amazon_topic_list_top_ad_sizes)); + } + //if (Discourse.Mobile.mobileView && Discourse.SiteSettings.adsense_mobile_topic_list_top_code) { + // data["topic-list-top"]["ad_mobile_code"] = Discourse.SiteSettings.adsense_mobile_topic_list_top_code; + //} +} + +// Ember component - the class is the adblock and css +export default Ember.Component.extend({ + amazon_width: amazon_width, + amazon_height: amazon_height, + amazon_mobile_width: amazon_mobile_width, + amazon_mobile_height: amazon_mobile_height, + user_input: user_input, + + classNames: ['amazon-product-links'], + + adWrapperStyle: function() { + return `width: ${this.get('amazon_width')}px; height: ${this.get('amazon_height')}px;`.htmlSafe(); + }.property('amazon_width', 'amazon_height'), + + adWrapperStyleMobile: function() { + return `width: ${this.get('amazon_mobile_width')}px; height: ${this.get('amazon_mobile_height')}px;`.htmlSafe(); + }.property('amazon_mobile_width', 'amazon_mobile_height'), + + userInput: function() { + return `${this.get('user_input')}`.htmlSafe(); + }.property('user_input'), + + checkTrustLevels: function() { + return !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.amazon_through_trust_level)); + }.property('trust_level'), + +}); \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/components/amazon-product-links.hbs b/assets/javascripts/discourse/templates/components/amazon-product-links.hbs new file mode 100644 index 0000000..00dcc5f --- /dev/null +++ b/assets/javascripts/discourse/templates/components/amazon-product-links.hbs @@ -0,0 +1,12 @@ +{{#if site.mobileView}} + {{#if checkTrustLevels}} + + {{/if}} + +{{else}} + {{#if checkTrustLevels}} + + {{/if}} +{{/if}} \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs b/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs index 20b187d..723659e 100644 --- a/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs +++ b/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs @@ -4,3 +4,6 @@ {{#if siteSettings.dfp_topic_list_top_code}} {{google-dfp-ad placement="topic-list-top"}} {{/if}} +{{#if siteSettings.amazon_topic_list_top_code}} + {{amazon-product-links placement="topic-list-top"}} +{{/if}} \ No newline at end of file diff --git a/assets/javascripts/initializers/extend-post-model.js.es6 b/assets/javascripts/initializers/extend-post-model.js.es6 index 22f911d..534f642 100644 --- a/assets/javascripts/initializers/extend-post-model.js.es6 +++ b/assets/javascripts/initializers/extend-post-model.js.es6 @@ -11,6 +11,10 @@ export default { postSpecificCountAdsense: function() { return this.get('post_number') === parseInt(Discourse.SiteSettings.adsense_nth_post_code); }.property('post_number'), + + postSpecificCountAmazon: function() { + return this.get('post_number') === parseInt(Discourse.SiteSettings.amazon_nth_post_code); + }.property('post_number'), }); } }; diff --git a/auto_generated/plugin_e37c3ee1ca7c7c4d4ef14a99312037cc7c47ecb5.css b/auto_generated/plugin_954bae62698596cbd1cca7ad6261ef903cf8fc2c.css similarity index 64% rename from auto_generated/plugin_e37c3ee1ca7c7c4d4ef14a99312037cc7c47ecb5.css rename to auto_generated/plugin_954bae62698596cbd1cca7ad6261ef903cf8fc2c.css index a426f0c..ff9eb03 100644 --- a/auto_generated/plugin_e37c3ee1ca7c7c4d4ef14a99312037cc7c47ecb5.css +++ b/auto_generated/plugin_954bae62698596cbd1cca7ad6261ef903cf8fc2c.css @@ -19,3 +19,13 @@ margin: 0 auto; } +.amazon-product-links { + padding: 3px; + margin-bottom: 10px; + clear: both; +} + +.amazon-product-links .amazon-unit { + margin: 0 auto; +} + diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 1d8dc2f..191c522 100755 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -4,4 +4,5 @@ en: site_settings: categories: dfp_plugin: 'DFP Plugin' - adsense_plugin: 'Adsense Plugin' \ No newline at end of file + adsense_plugin: 'Adsense Plugin' + amazon_plugin: 'Amazon Plugin' \ No newline at end of file diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 2da21dd..6bcd6f2 100755 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -45,4 +45,7 @@ en: adsense_mobile_post_bottom_code: "Mobile - Show leaderboard ad post_bottom topics" adsense_show_post_bottom: "Disable post_bottom ad" adsense_post_bottom_ad_sizes: "Choose your ad sizes" - adsense_nth_post_code: "Choose the Nth position for your ad to show" \ No newline at end of file + adsense_nth_post_code: "Choose the Nth position for your ad to show" + amazon_topic_list_top_code: "Insert your src code here" + amazon_topic_list_top_ad_sizes: "Choose your ad sizes" + amazon_nth_post_code: "Choose the Nth position for your ad to show" \ No newline at end of file diff --git a/config/settings.yml b/config/settings.yml index 7e119dd..ef66d89 100755 --- a/config/settings.yml +++ b/config/settings.yml @@ -242,6 +242,12 @@ amazon_plugin: amazon_topic_list_top_code: client: true default: '' + amazon_through_trust_level: + client: true + default: 2 + amazon_nth_post_code: + client: true + default: '' amazon_topic_list_top_ad_sizes: client: true default: '728*90 - leaderboard' diff --git a/plugin.rb b/plugin.rb index 79d6be8..ecf23a5 100755 --- a/plugin.rb +++ b/plugin.rb @@ -25,4 +25,14 @@ register_css <