From d1945057fde0f211985e1dd58a935deb47efcd69 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Wed, 27 Mar 2013 16:01:46 -0400 Subject: [PATCH] Include topic title in share links with third parties --- .../discourse/controllers/share_controller.js | 4 +++- .../discourse/models/share_link.js | 20 +++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/share_controller.js b/app/assets/javascripts/discourse/controllers/share_controller.js index d110d14cf87..1fda70b0d68 100644 --- a/app/assets/javascripts/discourse/controllers/share_controller.js +++ b/app/assets/javascripts/discourse/controllers/share_controller.js @@ -8,6 +8,8 @@ **/ Discourse.ShareController = Discourse.Controller.extend({ + needs: ['topic'], + // When the user clicks the post number, we pop up a share box shareLink: function(e, url) { var x; @@ -32,7 +34,7 @@ Discourse.ShareController = Discourse.Controller.extend({ 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')}); + return Discourse.ShareLink.create({target: i, link: this.get('link'), topicTitle: this.get('controllers.topic.title')}); } else { return null; } diff --git a/app/assets/javascripts/discourse/models/share_link.js b/app/assets/javascripts/discourse/models/share_link.js index 43454f79c4b..42970a6cef8 100644 --- a/app/assets/javascripts/discourse/models/share_link.js +++ b/app/assets/javascripts/discourse/models/share_link.js @@ -10,8 +10,8 @@ Discourse.ShareLink = Discourse.Model.extend({ href: function() { - return Discourse.ShareLink.urlFor(this.get('target'), this.get('link')); - }.property('target', 'link'), + return Discourse.ShareLink.urlFor(this.get('target'), this.get('link'), this.get('topicTitle')); + }.property('target', 'link', 'topicTitle'), title: function() { return Em.String.i18n("share." + this.get('target')); @@ -27,27 +27,27 @@ Discourse.ShareLink.reopenClass({ supportedTargets: ['twitter', 'facebook', 'google+'], - urlFor: function(target,link) { + urlFor: function(target,link,title) { switch(target) { case 'twitter': - return this.twitterUrl(link); + return this.twitterUrl(link,title); case 'facebook': - return this.facebookUrl(link); + return this.facebookUrl(link,title); case 'google+': return this.googlePlusUrl(link); } }, - twitterUrl: function(link) { - return ("http://twitter.com/home?status=" + link); + twitterUrl: function(link, title) { + return ("http://twitter.com/intent/tweet?url=" + encodeURIComponent(link) + "&text=" + encodeURIComponent(title) ); }, - facebookUrl: function(link) { - return ("http://www.facebook.com/sharer.php?u=" + link); + facebookUrl: function(link, title) { + return ("http://www.facebook.com/sharer.php?u=" + encodeURIComponent(link) + '&t=' + encodeURIComponent(title)); }, googlePlusUrl: function(link) { - return ("https://plus.google.com/share?url=" + link); + return ("https://plus.google.com/share?url=" + encodeURIComponent(link)); }, iconClasses: {