mirror of
https://github.com/discourse/discourse.git
synced 2025-09-07 12:02:53 +08:00
'Reply as new topic' link in the share dialog
This commit is contained in:
parent
bdd15d5452
commit
9588583244
7 changed files with 54 additions and 39 deletions
|
@ -29,6 +29,11 @@ export default Ember.Controller.extend({
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
replyAsNewTopic() {
|
||||||
|
this.get("controllers.topic").send("replyAsNewTopic");
|
||||||
|
this.send("close");
|
||||||
|
},
|
||||||
|
|
||||||
share(source) {
|
share(source) {
|
||||||
var url = source.generateUrl(this.get('link'), this.get('title'));
|
var url = source.generateUrl(this.get('link'), this.get('title'));
|
||||||
if (source.shouldOpenInPopup) {
|
if (source.shouldOpenInPopup) {
|
||||||
|
|
|
@ -586,10 +586,10 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
||||||
},
|
},
|
||||||
|
|
||||||
replyAsNewTopic(post) {
|
replyAsNewTopic(post) {
|
||||||
const composerController = this.get('controllers.composer'),
|
const composerController = this.get('controllers.composer');
|
||||||
quoteController = this.get('controllers.quote-button'),
|
const quoteController = this.get('controllers.quote-button');
|
||||||
quotedText = Quote.build(quoteController.get('post'), quoteController.get('buffer')),
|
post = post || quoteController.get('post');
|
||||||
self = this;
|
const quotedText = Quote.build(post, quoteController.get('buffer'));
|
||||||
|
|
||||||
quoteController.deselectText();
|
quoteController.deselectText();
|
||||||
|
|
||||||
|
@ -601,7 +601,7 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
||||||
return Em.isEmpty(quotedText) ? "" : quotedText;
|
return Em.isEmpty(quotedText) ? "" : quotedText;
|
||||||
}).then(q => {
|
}).then(q => {
|
||||||
const postUrl = `${location.protocol}//${location.host}${post.get('url')}`;
|
const postUrl = `${location.protocol}//${location.host}${post.get('url')}`;
|
||||||
const postLink = `[${Handlebars.escapeExpression(self.get('model.title'))}](${postUrl})`;
|
const postLink = `[${Handlebars.escapeExpression(this.get('model.title'))}](${postUrl})`;
|
||||||
composerController.get('model').prependText(`${I18n.t("post.continue_discussion", { postLink })}\n\n${q}`, {new_line: true});
|
composerController.get('model').prependText(`${I18n.t("post.continue_discussion", { postLink })}\n\n${q}`, {new_line: true});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -14,6 +14,10 @@
|
||||||
{{share-source source=s title=title action="share"}}
|
{{share-source source=s title=title action="share"}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
||||||
|
<div class='reply-as-new-topic'>
|
||||||
|
<a href {{action "replyAsNewTopic"}} aria-label='{{i18n 'post.reply_as_new_topic'}}' title='{{i18n 'post.reply_as_new_topic'}}'>{{fa-icon "plus"}}{{i18n 'topic.create'}}</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class='link'>
|
<div class='link'>
|
||||||
<a href {{action "close"}} aria-label='{{i18n 'share.close'}}' title='{{i18n 'share.close'}}'>{{fa-icon "close"}}</a>
|
<a href {{action "close"}} aria-label='{{i18n 'share.close'}}' title='{{i18n 'share.close'}}'>{{fa-icon "close"}}</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -3,7 +3,8 @@ function ignoreElements(e) {
|
||||||
const $target = $(e.target);
|
const $target = $(e.target);
|
||||||
return $target.hasClass('quote-button') ||
|
return $target.hasClass('quote-button') ||
|
||||||
$target.closest('.create').length ||
|
$target.closest('.create').length ||
|
||||||
$target.closest('.reply-new').length;
|
$target.closest('.reply-new').length ||
|
||||||
|
$target.closest('.share').length;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Ember.View.extend({
|
export default Ember.View.extend({
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import computed from 'ember-addons/ember-computed-decorators';
|
||||||
|
import { observes } from 'ember-addons/ember-computed-decorators';
|
||||||
import { wantsNewWindow } from 'discourse/lib/intercept-click';
|
import { wantsNewWindow } from 'discourse/lib/intercept-click';
|
||||||
|
|
||||||
export default Ember.View.extend({
|
export default Ember.View.extend({
|
||||||
|
@ -5,45 +7,43 @@ export default Ember.View.extend({
|
||||||
elementId: 'share-link',
|
elementId: 'share-link',
|
||||||
classNameBindings: ['hasLink'],
|
classNameBindings: ['hasLink'],
|
||||||
|
|
||||||
hasLink: function() {
|
@computed('controller.link')
|
||||||
if (!Ember.isEmpty(this.get('controller.link'))) return 'visible';
|
hasLink(link) {
|
||||||
return null;
|
return !Ember.isEmpty(link) ? 'visible' : null;
|
||||||
}.property('controller.link'),
|
},
|
||||||
|
|
||||||
linkChanged: function() {
|
@observes('controller.link')
|
||||||
const self = this;
|
linkChanged() {
|
||||||
if (!Ember.isEmpty(this.get('controller.link'))) {
|
const link = this.get('controller.link');
|
||||||
Em.run.next(function() {
|
if (!Ember.isEmpty(link)) {
|
||||||
if (!self.capabilities.touch) {
|
Ember.run.next(() => {
|
||||||
var $linkInput = $('#share-link input');
|
if (!this.capabilities.touch) {
|
||||||
$linkInput.val(self.get('controller.link'));
|
const $linkInput = $('#share-link input');
|
||||||
|
$linkInput.val(link);
|
||||||
|
|
||||||
// Wait for the fade-in transition to finish before selecting the link:
|
// Wait for the fade-in transition to finish before selecting the link:
|
||||||
window.setTimeout(function() {
|
window.setTimeout(() => $linkInput.select().focus(), 160);
|
||||||
$linkInput.select().focus();
|
|
||||||
}, 160);
|
|
||||||
} else {
|
} else {
|
||||||
var $linkForTouch = $('#share-link .share-for-touch a');
|
const $linkForTouch = $('#share-link .share-for-touch a');
|
||||||
$linkForTouch.attr('href',self.get('controller.link'));
|
$linkForTouch.attr('href', link);
|
||||||
$linkForTouch.html(self.get('controller.link'));
|
$linkForTouch.html(link);
|
||||||
var range = window.document.createRange();
|
const range = window.document.createRange();
|
||||||
range.selectNode($linkForTouch[0]);
|
range.selectNode($linkForTouch[0]);
|
||||||
window.getSelection().addRange(range);
|
window.getSelection().addRange(range);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}.observes('controller.link'),
|
},
|
||||||
|
|
||||||
didInsertElement: function() {
|
didInsertElement() {
|
||||||
var self = this,
|
const self = this;
|
||||||
$html = $('html');
|
const $html = $('html');
|
||||||
|
|
||||||
$html.on('mousedown.outside-share-link', function(e) {
|
$html.on('mousedown.outside-share-link', 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.
|
||||||
if (self.$().has(e.target).length !== 0) { return; }
|
if (this.$().has(e.target).length !== 0) { return; }
|
||||||
|
this.get('controller').send('close');
|
||||||
self.get('controller').send('close');
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -58,9 +58,7 @@ export default Ember.View.extend({
|
||||||
|
|
||||||
const shareLinkWidth = $shareLink.width();
|
const shareLinkWidth = $shareLink.width();
|
||||||
let x = $currentTargetOffset.left - (shareLinkWidth / 2);
|
let x = $currentTargetOffset.left - (shareLinkWidth / 2);
|
||||||
if (x < 25) {
|
if (x < 25) { x = 25; }
|
||||||
x = 25;
|
|
||||||
}
|
|
||||||
if (x + shareLinkWidth > $(window).width()) {
|
if (x + shareLinkWidth > $(window).width()) {
|
||||||
x -= shareLinkWidth / 2;
|
x -= shareLinkWidth / 2;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +82,7 @@ export default Ember.View.extend({
|
||||||
|
|
||||||
this.appEvents.on('share:url', (url, $target) => showPanel($target, url));
|
this.appEvents.on('share:url', (url, $target) => showPanel($target, url));
|
||||||
|
|
||||||
$html.on('click.discoure-share-link', '[data-share-url]', function(e) {
|
$html.on('click.discoure-share-link', '[data-share-url]', e => {
|
||||||
// if they want to open in a new tab, let it so
|
// if they want to open in a new tab, let it so
|
||||||
if (wantsNewWindow(e)) { return true; }
|
if (wantsNewWindow(e)) { return true; }
|
||||||
|
|
||||||
|
@ -98,14 +96,14 @@ export default Ember.View.extend({
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$html.on('keydown.share-view', function(e){
|
$html.on('keydown.share-view', e => {
|
||||||
if (e.keyCode === 27) {
|
if (e.keyCode === 27) {
|
||||||
self.get('controller').send('close');
|
this.get('controller').send('close');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
willDestroyElement: function() {
|
willDestroyElement() {
|
||||||
this.get('controller').send('close');
|
this.get('controller').send('close');
|
||||||
|
|
||||||
$('html').off('click.discoure-share-link')
|
$('html').off('click.discoure-share-link')
|
||||||
|
|
|
@ -114,6 +114,7 @@ registerButton('replies', (attrs, state, siteSettings) => {
|
||||||
registerButton('share', attrs => {
|
registerButton('share', attrs => {
|
||||||
return {
|
return {
|
||||||
action: 'share',
|
action: 'share',
|
||||||
|
className: 'share',
|
||||||
title: 'post.controls.share',
|
title: 'post.controls.share',
|
||||||
icon: 'link',
|
icon: 'link',
|
||||||
data: {
|
data: {
|
||||||
|
|
|
@ -42,6 +42,12 @@
|
||||||
float: left;
|
float: left;
|
||||||
font-size: 1.571em;
|
font-size: 1.571em;
|
||||||
}
|
}
|
||||||
|
.reply-as-new-topic {
|
||||||
|
float: left;
|
||||||
|
.fa {
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
}
|
||||||
.link {
|
.link {
|
||||||
margin-right: 2px;
|
margin-right: 2px;
|
||||||
float: right;
|
float: right;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue