Skip to content

Node.js based forum software built for the modern web

moving social sharing parsing code from server side to client side & cleaned up templates

psychobunny98d42b0ade9c
diff --git a/public/src/forum/category.js b/public/src/forum/category.js
index 6eca83187a..3e2fe29b92 100644
--- a/public/src/forum/category.js
+++ b/public/src/forum/category.js
@@ -4,25 +4,27 @@ define(['composer'], function(composer) {
Category.init = function() {
var cid = templates.get('category_id'),
+ categoryName = templates.get('category_name'),
twitterEl = jQuery('#twitter-intent'),
facebookEl = jQuery('#facebook-share'),
googleEl = jQuery('#google-share'),
- twitter_url = templates.get('twitter-intent-url'),
- facebook_url = templates.get('facebook-share-url'),
- google_url = templates.get('google-share-url');
+ categoryUrl = encodeURIComponent(window.location.href),
+ twitterUrl = "https://twitter.com/intent/tweet?url=" + categoryUrl + "&text=" + encodeURIComponent(categoryName),
+ facebookUrl = "https://www.facebook.com/sharer/sharer.php?u=" + categoryUrl,
+ googleUrl = "https://plus.google.com/share?url=" + categoryUrl;
app.enterRoom('category_' + cid);
twitterEl.on('click', function () {
- window.open(twitter_url, '_blank', 'width=550,height=420,scrollbars=no,status=no');
+ window.open(twitterUrl, '_blank', 'width=550,height=420,scrollbars=no,status=no');
return false;
});
facebookEl.on('click', function () {
- window.open(facebook_url, '_blank', 'width=626,height=436,scrollbars=no,status=no');
+ window.open(facebookUrl, '_blank', 'width=626,height=436,scrollbars=no,status=no');
return false;
});
googleEl.on('click', function () {
- window.open(google_url, '_blank', 'width=500,height=570,scrollbars=no,status=no');
+ window.open(googleUrl, '_blank', 'width=500,height=570,scrollbars=no,status=no');
return false;
});
diff --git a/public/templates/category.tpl b/public/templates/category.tpl
index 79bbcd7412..849c042d9a 100644
--- a/public/templates/category.tpl
+++ b/public/templates/category.tpl
@@ -118,6 +118,4 @@
</div>
<input type="hidden" template-variable="category_id" value="{category_id}" />
-<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}" />
+<input type="hidden" template-variable="category_name" value="{category_name}" />
\ No newline at end of file
diff --git a/public/templates/topic.tpl b/public/templates/topic.tpl
index 5c05b35101..0ea7354ec0 100644
--- a/public/templates/topic.tpl
+++ b/public/templates/topic.tpl
@@ -5,9 +5,6 @@
<input type="hidden" template-variable="pinned" value="{pinned}" />
<input type="hidden" template-variable="topic_name" value="{topic_name}" />
<input 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">
diff --git a/src/categories.js b/src/categories.js
index a29b5ad357..939073ffcb 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -82,9 +82,6 @@ var db = require('./database.js'),
'active_users': [],
'topics': [],
'disableSocialButtons': meta.config.disableSocialButtons !== undefined ? parseInt(meta.config.disableSocialButtons, 10) !== 0 : false,
- 'twitter-intent-url': 'https://twitter.com/intent/tweet?url=' + encodeURIComponent(nconf.get('url') + 'category/' + categoryData.slug) + '&text=' + encodeURIComponent(categoryData.name),
- 'facebook-share-url': 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(nconf.get('url') + 'category/' + categoryData.slug),
- 'google-share-url': 'https://plus.google.com/share?url=' + encodeURIComponent(nconf.get('url') + 'category/' + categoryData.slug),
'sidebars': sidebars
};