BUGFIX: share a link to a post instead of the topic

This commit is contained in:
Régis Hanol 2014-06-25 16:20:06 +02:00
parent bdb6032c11
commit 4b0eb0e159
2 changed files with 15 additions and 9 deletions
app/assets/javascripts/discourse/views

View file

@ -24,6 +24,7 @@ Button.prototype.render = function(buffer) {
buffer.push("<button title=\"" + I18n.t(this.label) + "\"");
if (this.opts.className) { buffer.push(" class=\"" + this.opts.className + "\""); }
if (this.opts.shareUrl) { buffer.push(" data-share-url=\"" + this.opts.shareUrl + "\""); }
if (this.opts.postNumber) { debugger; buffer.push(" data-post-number=\"" + this.opts.postNumber + "\""); }
buffer.push(" data-action=\"" + this.action + "\">");
if (this.icon) { buffer.push("<i class=\"fa fa-" + this.icon + "\"></i>"); }
if (this.opts.textLabel) { buffer.push(I18n.t(this.opts.textLabel)); }
@ -220,7 +221,11 @@ export default Discourse.View.extend({
// Share button
buttonForShare: function(post) {
return new Button('share', 'post.controls.share', 'link', {shareUrl: post.get('shareUrl')});
var options = {
shareUrl: post.get('shareUrl'),
postNumber: post.get('post_number')
};
return new Button('share', 'post.controls.share', 'link', options);
},
// Reply button

View file

@ -41,6 +41,7 @@ export default Discourse.View.extend({
didInsertElement: function() {
var shareView = this,
$html = $('html');
$html.on('mousedown.outside-share-link', function(e) {
// Use mousedown instead of click so this event is handled before routing occurs when a
// link is clicked (which is a click event) while the share dialog is showing.
@ -55,12 +56,13 @@ export default Discourse.View.extend({
if (e.shiftKey || e.metaKey || e.ctrlKey || e.which === 2) { return true; }
e.preventDefault();
var $currentTarget = $(e.currentTarget),
$currentTargetOffset = $currentTarget.offset(),
$shareLink = $('#share-link');
var url = $currentTarget.data('share-url');
var postNumber = $currentTarget.data('post-number');
var date = $currentTarget.children().data('time');
$shareLink = $('#share-link'),
url = $currentTarget.data('share-url'),
postNumber = $currentTarget.data('post-number'),
date = $currentTarget.children().data('time');
// Relative urls
if (url.indexOf("/") === 0) {
@ -102,10 +104,9 @@ export default Discourse.View.extend({
},
willDestroyElement: function() {
var $html = $('html');
$html.off('click.discoure-share-link');
$html.off('mousedown.outside-share-link');
$html.off('keydown.share-view');
$('html').off('click.discoure-share-link')
.off('mousedown.outside-share-link')
.off('keydown.share-view');
}
});