diff --git a/app/assets/javascripts/discourse/controllers/share_controller.js b/app/assets/javascripts/discourse/controllers/share_controller.js index 6dedc2e04..d110d14cf 100644 --- a/app/assets/javascripts/discourse/controllers/share_controller.js +++ b/app/assets/javascripts/discourse/controllers/share_controller.js @@ -29,16 +29,19 @@ Discourse.ShareController = Discourse.Controller.extend({ return false; }, - popupHeights: { - twitter: 265, - facebook: 315, - googlePlus: 600 - }, + shareLinks: function() { + return Discourse.SiteSettings.share_links.split('|').map(function(i) { + if( Discourse.ShareLink.supportedTargets.indexOf(i) >= 0 ) { + return Discourse.ShareLink.create({target: i, link: this.get('link')}); + } else { + return null; + } + }, this).compact(); + }.property('link'), sharePopup: function(target, url) { - window.open(url, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,width=600,height=' + this.popupHeights[target]); + window.open(url, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,width=600,height=' + Discourse.ShareLink.popupHeight(target)); return false; } -}); - +}); \ No newline at end of file diff --git a/app/assets/javascripts/discourse/models/share_link.js b/app/assets/javascripts/discourse/models/share_link.js new file mode 100644 index 000000000..43454f79c --- /dev/null +++ b/app/assets/javascripts/discourse/models/share_link.js @@ -0,0 +1,68 @@ +/** + A data model representing a link to share a post on a 3rd party site, + like Twitter, Facebook, and Google+. + + @class ShareLink + @extends Discourse.Model + @namespace Discourse + @module Discourse +**/ +Discourse.ShareLink = Discourse.Model.extend({ + + href: function() { + return Discourse.ShareLink.urlFor(this.get('target'), this.get('link')); + }.property('target', 'link'), + + title: function() { + return Em.String.i18n("share." + this.get('target')); + }.property('target'), + + iconClass: function() { + return Discourse.ShareLink.iconClasses[this.get('target')]; + }.property('target') + +}); + +Discourse.ShareLink.reopenClass({ + + supportedTargets: ['twitter', 'facebook', 'google+'], + + urlFor: function(target,link) { + switch(target) { + case 'twitter': + return this.twitterUrl(link); + case 'facebook': + return this.facebookUrl(link); + case 'google+': + return this.googlePlusUrl(link); + } + }, + + twitterUrl: function(link) { + return ("http://twitter.com/home?status=" + link); + }, + + facebookUrl: function(link) { + return ("http://www.facebook.com/sharer.php?u=" + link); + }, + + googlePlusUrl: function(link) { + return ("https://plus.google.com/share?url=" + link); + }, + + iconClasses: { + twitter: 'icon-twitter', + facebook: 'icon-facebook-sign', + 'google+': 'icon-google-plus' + }, + + popupHeights: { + twitter: 265, + facebook: 315, + 'google+': 600 + }, + + popupHeight: function(target) { + return (this.popupHeights[target] || 315); + } +}); \ No newline at end of file diff --git a/app/assets/javascripts/discourse/templates/share.js.handlebars b/app/assets/javascripts/discourse/templates/share.js.handlebars index 6a91d3552..ea1f4d127 100644 --- a/app/assets/javascripts/discourse/templates/share.js.handlebars +++ b/app/assets/javascripts/discourse/templates/share.js.handlebars @@ -1,14 +1,10 @@

{{view.title}}

- - - + +{{#each controller.shareLinks}} + {{view Discourse.ShareLinkView contentBinding="this"}} +{{/each}} + diff --git a/app/assets/javascripts/discourse/templates/share_link.js.handlebars b/app/assets/javascripts/discourse/templates/share_link.js.handlebars new file mode 100644 index 000000000..423d1d08c --- /dev/null +++ b/app/assets/javascripts/discourse/templates/share_link.js.handlebars @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/assets/javascripts/discourse/views/share_link_view.js b/app/assets/javascripts/discourse/views/share_link_view.js new file mode 100644 index 000000000..982e09c19 --- /dev/null +++ b/app/assets/javascripts/discourse/views/share_link_view.js @@ -0,0 +1,14 @@ +/** + This view handles rendering of a link to share something on a + third-party site. + + @class ShareLinkView + @extends Discourse.View + @namespace Discourse + @module Discourse +**/ +Discourse.ShareLinkView = Discourse.View.extend({ + templateName: 'share_link', + tagName: 'div', + classNameBindings: [':social-link'] +}); \ No newline at end of file diff --git a/app/assets/javascripts/discourse/views/share_view.js b/app/assets/javascripts/discourse/views/share_view.js index 30c5ea4f2..4f296c2e0 100644 --- a/app/assets/javascripts/discourse/views/share_view.js +++ b/app/assets/javascripts/discourse/views/share_view.js @@ -27,18 +27,6 @@ Discourse.ShareView = Discourse.View.extend({ } }).observes('controller.link'), - facebookUrl: function() { - return ("http://www.facebook.com/sharer.php?u=" + this.get('controller.link')); - }.property('controller.link'), - - twitterUrl: function() { - return ("http://twitter.com/home?status=" + this.get('controller.link')); - }.property('controller.link'), - - googlePlusUrl: function() { - return ("https://plus.google.com/share?url=" + this.get('controller.link')); - }.property('controller.link'), - didInsertElement: function() { var _this = this; $('html').on('click.outside-share-link', function(e) { diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb index ad5b58a89..80cf91a9c 100644 --- a/app/models/site_setting.rb +++ b/app/models/site_setting.rb @@ -19,6 +19,7 @@ class SiteSetting < ActiveRecord::Base client_setting(:traditional_markdown_linebreaks, false) client_setting(:top_menu, 'popular|new|unread|favorited|categories') client_setting(:post_menu, 'like|edit|flag|delete|share|bookmark|reply') + client_setting(:share_links, 'twitter|facebook|google+') client_setting(:track_external_right_clicks, false) client_setting(:must_approve_users, false) client_setting(:ga_tracking_code, "") diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index e231cb527..ab4eb1680 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -10,7 +10,7 @@ en: close: 'close' twitter: 'share this link on Twitter' facebook: 'share this link on Facebook' - google_plus: 'share this link on Google+' + google+: 'share this link on Google+' edit: 'edit the title and category of this topic' not_implemented: "That feature hasn't been implemented yet, sorry!" diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 271088f22..60a790b5f 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -362,6 +362,7 @@ en: ga_tracking_code: "Google analytics tracking code code, eg: UA-12345678-9; see http://google.com/analytics" top_menu: "Determine which items appear in the homepage navigation, and in what order. Example popular|read|favorited|unread|new|posted|categories" post_menu: "Determine which items appear on the post menu, and in what order. Example like|edit|flag|delete|share|bookmark|reply" + share_links: "Determine which items appear on the share dialog, and in what order. Example twitter|facebook|google+" track_external_right_clicks: "Track external links that are right clicked (eg: open in new tab) disabled by default because it rewrites URLs" topics_per_page: "How many topics are loaded by default on the topics list page" posts_per_page: "How many posts are returned on a topic page"