mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Add site setting to choose which share links to show and in what order
This commit is contained in:
parent
1b779e5e71
commit
5961ffc0e4
9 changed files with 102 additions and 30 deletions
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
});
|
68
app/assets/javascripts/discourse/models/share_link.js
Normal file
68
app/assets/javascripts/discourse/models/share_link.js
Normal file
|
@ -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);
|
||||
}
|
||||
});
|
|
@ -1,14 +1,10 @@
|
|||
<h3>{{view.title}}</h3>
|
||||
<div><input type='text' /></div>
|
||||
<div class="social-link">
|
||||
<a href="#" {{action sharePopup "twitter" view.twitterUrl}} title='{{i18n share.twitter}}'><i class="icon icon-twitter"></i></a>
|
||||
</div>
|
||||
<div class="social-link">
|
||||
<a href="#" {{action sharePopup "facebook" view.facebookUrl}} title='{{i18n share.facebook}}'><i class="icon icon-facebook-sign"></i></a>
|
||||
</div>
|
||||
<div class="social-link">
|
||||
<a href="#" {{action sharePopup "googlePlus" view.googlePlusUrl}} title='{{i18n share.google_plus}}'><i class="icon icon-google-plus"></i></a>
|
||||
</div>
|
||||
|
||||
{{#each controller.shareLinks}}
|
||||
{{view Discourse.ShareLinkView contentBinding="this"}}
|
||||
{{/each}}
|
||||
|
||||
<div class='link'>
|
||||
<a href='#' {{action close target="controller"}} title='{{i18n share.close}}'><i class="icon icon-remove-sign"></i></a>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<a href="#" {{action sharePopup target href}} {{bindAttr title="title"}}><i {{bindAttr class=":icon iconClass"}}></i></a>
|
14
app/assets/javascripts/discourse/views/share_link_view.js
Normal file
14
app/assets/javascripts/discourse/views/share_link_view.js
Normal file
|
@ -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']
|
||||
});
|
|
@ -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) {
|
||||
|
|
|
@ -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, "")
|
||||
|
|
|
@ -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!"
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue