mirror of
https://github.com/discourse/discourse.git
synced 2025-06-20 16:41:32 +08:00
BUGFIX: share a link to a post instead of the topic
This commit is contained in:
@ -24,6 +24,7 @@ Button.prototype.render = function(buffer) {
|
|||||||
buffer.push("<button title=\"" + I18n.t(this.label) + "\"");
|
buffer.push("<button title=\"" + I18n.t(this.label) + "\"");
|
||||||
if (this.opts.className) { buffer.push(" class=\"" + this.opts.className + "\""); }
|
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.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 + "\">");
|
buffer.push(" data-action=\"" + this.action + "\">");
|
||||||
if (this.icon) { buffer.push("<i class=\"fa fa-" + this.icon + "\"></i>"); }
|
if (this.icon) { buffer.push("<i class=\"fa fa-" + this.icon + "\"></i>"); }
|
||||||
if (this.opts.textLabel) { buffer.push(I18n.t(this.opts.textLabel)); }
|
if (this.opts.textLabel) { buffer.push(I18n.t(this.opts.textLabel)); }
|
||||||
@ -220,7 +221,11 @@ export default Discourse.View.extend({
|
|||||||
|
|
||||||
// Share button
|
// Share button
|
||||||
buttonForShare: function(post) {
|
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
|
// Reply button
|
||||||
|
@ -41,6 +41,7 @@ export default Discourse.View.extend({
|
|||||||
didInsertElement: function() {
|
didInsertElement: function() {
|
||||||
var shareView = this,
|
var shareView = this,
|
||||||
$html = $('html');
|
$html = $('html');
|
||||||
|
|
||||||
$html.on('mousedown.outside-share-link', function(e) {
|
$html.on('mousedown.outside-share-link', function(e) {
|
||||||
// Use mousedown instead of click so this event is handled before routing occurs when a
|
// 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.
|
// 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; }
|
if (e.shiftKey || e.metaKey || e.ctrlKey || e.which === 2) { return true; }
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
var $currentTarget = $(e.currentTarget),
|
var $currentTarget = $(e.currentTarget),
|
||||||
$currentTargetOffset = $currentTarget.offset(),
|
$currentTargetOffset = $currentTarget.offset(),
|
||||||
$shareLink = $('#share-link');
|
$shareLink = $('#share-link'),
|
||||||
var url = $currentTarget.data('share-url');
|
url = $currentTarget.data('share-url'),
|
||||||
var postNumber = $currentTarget.data('post-number');
|
postNumber = $currentTarget.data('post-number'),
|
||||||
var date = $currentTarget.children().data('time');
|
date = $currentTarget.children().data('time');
|
||||||
|
|
||||||
// Relative urls
|
// Relative urls
|
||||||
if (url.indexOf("/") === 0) {
|
if (url.indexOf("/") === 0) {
|
||||||
@ -102,10 +104,9 @@ export default Discourse.View.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
willDestroyElement: function() {
|
willDestroyElement: function() {
|
||||||
var $html = $('html');
|
$('html').off('click.discoure-share-link')
|
||||||
$html.off('click.discoure-share-link');
|
.off('mousedown.outside-share-link')
|
||||||
$html.off('mousedown.outside-share-link');
|
.off('keydown.share-view');
|
||||||
$html.off('keydown.share-view');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user