Node.js based forum software built for the modern web
added share buttons to main post
Baris Soner Usakli1af98835b16e
diff --git a/public/src/forum/topic.js b/public/src/forum/topic.jsindex 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 stateif (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.tplindex e09d94f9d0..d5c3309234 100644--- a/public/templates/topic.tpl+++ b/public/templates/topic.tpl@@ -6,6 +6,9 @@<input class="test1" type="hidden" template-variable="pinned" value="{pinned}" /><input class="test1" type="hidden" template-variable="topic_name" value="{topic_name}" /><input class="test1" type="hidden" template-variable="postcount" value="{postcount}" />+<input type="hidden" template-variable="twitter-intent-url" value="{twitter-intent-url}" />+<input type="hidden" template-variable="facebook-share-url" value="{facebook-share-url}" />+<input type="hidden" template-variable="google-share-url" value="{google-share-url}" /><div class="topic"><ol class="breadcrumb">@@ -60,12 +63,18 @@<button class="btn btn-sm btn-default quote" type="button" title="[[topic:quote]]"><i class="icon-quote-left"></i></button><button class="btn btn-sm btn-primary btn post_reply" type="button">[[topic:reply]] <i class="icon-reply"></i></button></div>+<div class="btn-group pull-right post-tools">- <button class="btn btn-sm btn-default link" type="button" title="[[topic:link]]"><i class="icon-link"></i></button><button class="btn btn-sm btn-default edit {main_posts.display_moderator_tools}" type="button" title="[[topic:edit]]"><i class="icon-pencil"></i></button><button class="btn btn-sm btn-default delete {main_posts.display_moderator_tools}" type="button" title="[[topic:delete]]"><i class="icon-trash"></i></button>+ </div>+ <div class="btn-group pull-right post-tools">+ <button class="btn btn-sm btn-default link" type="button" title="[[topic:link]]"><i class="icon-link"></i></button>+ <button class="btn btn-sm btn-default facebook-share" type="button" title=""><i class="icon-facebook"></i></button>+ <button class="btn btn-sm btn-default twitter-share" type="button" title=""><i class="icon-twitter"></i></button>+ <button class="btn btn-sm btn-default google-share" type="button" title=""><i class="icon-google-plus"></i></button></div><input id="post_{main_posts.pid}_link" value="" class="pull-right" style="display:none;"></input>diff --git a/src/topics.js b/src/topics.jsindex 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)});});});