From 1af98835b16e6c08ce30e92008874ebf1682fa0f Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Fri, 25 Oct 2013 18:00:08 -0400 Subject: [PATCH] added share buttons to main post --- public/src/forum/topic.js | 22 +++++++++++++++++++++- public/templates/topic.tpl | 11 ++++++++++- src/topics.js | 6 +++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index a9b70c7966..d464c7e985 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -11,18 +11,38 @@ define(function() { deleted: templates.get('deleted'), pinned: templates.get('pinned') }, - topic_name = templates.get('topic_name'); + topic_name = templates.get('topic_name'), + twitter_url = templates.get('twitter-intent-url'), + facebook_url = templates.get('facebook-share-url'), + google_url = templates.get('google-share-url'); jQuery('document').ready(function() { app.addCommasToNumbers(); + var room = 'topic_' + tid, adminTools = document.getElementById('thread-tools'); app.enter_room(room); + + $('.twitter-share').on('click', function () { + window.open(twitter_url, '_blank', 'width=550,height=420,scrollbars=no,status=no'); + return false; + }); + + $('.facebook-share').on('click', function () { + window.open(facebook_url, '_blank', 'width=626,height=436,scrollbars=no,status=no'); + return false; + }); + + $('.google-share').on('click', function () { + window.open(google_url, '_blank', 'width=500,height=570,scrollbars=no,status=no'); + return false; + }); + // Resetting thread state if (thread_state.locked === '1') set_locked_state(true); if (thread_state.deleted === '1') set_delete_state(true); diff --git a/public/templates/topic.tpl b/public/templates/topic.tpl index e09d94f9d0..d5c3309234 100644 --- a/public/templates/topic.tpl +++ b/public/templates/topic.tpl @@ -6,6 +6,9 @@ + + +
+
- +
+
+ + + +
diff --git a/src/topics.js b/src/topics.js index 6095a70ca1..f436776335 100644 --- a/src/topics.js +++ b/src/topics.js @@ -14,6 +14,7 @@ var RDB = require('./redis.js'), meta = require('./meta.js'), reds = require('reds'), topicSearch = reds.createSearch('nodebbtopicsearch'), + nconf = require('nconf'), validator = require('validator'); (function(Topics) { @@ -404,7 +405,10 @@ var RDB = require('./redis.js'), 'topic_id': tid, 'expose_tools': privileges.editable ? 1 : 0, 'posts': topicPosts, - 'main_posts': main_posts + 'main_posts': main_posts, + 'twitter-intent-url': 'https://twitter.com/intent/tweet?url=' + encodeURIComponent(nconf.get('url') + 'topic/' + topicData.slug) + '&text=' + encodeURIComponent(topicData.title), + 'facebook-share-url': 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(nconf.get('url') + 'topic/' + topicData.slug), + 'google-share-url': 'https://plus.google.com/share?url=' + encodeURIComponent(nconf.get('url') + 'topic/' + topicData.slug) }); }); });