'Reply as new topic' link in the share dialog

This commit is contained in:
Régis Hanol 2016-06-14 20:01:21 +02:00
parent bdd15d5452
commit 9588583244
7 changed files with 54 additions and 39 deletions

View File

@ -29,6 +29,11 @@ export default Ember.Controller.extend({
return false;
},
replyAsNewTopic() {
this.get("controllers.topic").send("replyAsNewTopic");
this.send("close");
},
share(source) {
var url = source.generateUrl(this.get('link'), this.get('title'));
if (source.shouldOpenInPopup) {

View File

@ -586,10 +586,10 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
},
replyAsNewTopic(post) {
const composerController = this.get('controllers.composer'),
quoteController = this.get('controllers.quote-button'),
quotedText = Quote.build(quoteController.get('post'), quoteController.get('buffer')),
self = this;
const composerController = this.get('controllers.composer');
const quoteController = this.get('controllers.quote-button');
post = post || quoteController.get('post');
const quotedText = Quote.build(post, quoteController.get('buffer'));
quoteController.deselectText();
@ -601,7 +601,7 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
return Em.isEmpty(quotedText) ? "" : quotedText;
}).then(q => {
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});
});
},

View File

@ -14,6 +14,10 @@
{{share-source source=s title=title action="share"}}
{{/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'>
<a href {{action "close"}} aria-label='{{i18n 'share.close'}}' title='{{i18n 'share.close'}}'>{{fa-icon "close"}}</a>
</div>

View File

@ -3,7 +3,8 @@ function ignoreElements(e) {
const $target = $(e.target);
return $target.hasClass('quote-button') ||
$target.closest('.create').length ||
$target.closest('.reply-new').length;
$target.closest('.reply-new').length ||
$target.closest('.share').length;
}
export default Ember.View.extend({

View File

@ -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';
export default Ember.View.extend({
@ -5,45 +7,43 @@ export default Ember.View.extend({
elementId: 'share-link',
classNameBindings: ['hasLink'],
hasLink: function() {
if (!Ember.isEmpty(this.get('controller.link'))) return 'visible';
return null;
}.property('controller.link'),
@computed('controller.link')
hasLink(link) {
return !Ember.isEmpty(link) ? 'visible' : null;
},
linkChanged: function() {
const self = this;
if (!Ember.isEmpty(this.get('controller.link'))) {
Em.run.next(function() {
if (!self.capabilities.touch) {
var $linkInput = $('#share-link input');
$linkInput.val(self.get('controller.link'));
@observes('controller.link')
linkChanged() {
const link = this.get('controller.link');
if (!Ember.isEmpty(link)) {
Ember.run.next(() => {
if (!this.capabilities.touch) {
const $linkInput = $('#share-link input');
$linkInput.val(link);
// Wait for the fade-in transition to finish before selecting the link:
window.setTimeout(function() {
$linkInput.select().focus();
}, 160);
window.setTimeout(() => $linkInput.select().focus(), 160);
} else {
var $linkForTouch = $('#share-link .share-for-touch a');
$linkForTouch.attr('href',self.get('controller.link'));
$linkForTouch.html(self.get('controller.link'));
var range = window.document.createRange();
const $linkForTouch = $('#share-link .share-for-touch a');
$linkForTouch.attr('href', link);
$linkForTouch.html(link);
const range = window.document.createRange();
range.selectNode($linkForTouch[0]);
window.getSelection().addRange(range);
}
});
}
}.observes('controller.link'),
},
didInsertElement: function() {
var self = this,
$html = $('html');
didInsertElement() {
const self = this;
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
// link is clicked (which is a click event) while the share dialog is showing.
if (self.$().has(e.target).length !== 0) { return; }
self.get('controller').send('close');
if (this.$().has(e.target).length !== 0) { return; }
this.get('controller').send('close');
return true;
});
@ -58,9 +58,7 @@ export default Ember.View.extend({
const shareLinkWidth = $shareLink.width();
let x = $currentTargetOffset.left - (shareLinkWidth / 2);
if (x < 25) {
x = 25;
}
if (x < 25) { x = 25; }
if (x + shareLinkWidth > $(window).width()) {
x -= shareLinkWidth / 2;
}
@ -84,7 +82,7 @@ export default Ember.View.extend({
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 (wantsNewWindow(e)) { return true; }
@ -98,14 +96,14 @@ export default Ember.View.extend({
return false;
});
$html.on('keydown.share-view', function(e){
$html.on('keydown.share-view', e => {
if (e.keyCode === 27) {
self.get('controller').send('close');
this.get('controller').send('close');
}
});
},
willDestroyElement: function() {
willDestroyElement() {
this.get('controller').send('close');
$('html').off('click.discoure-share-link')

View File

@ -114,6 +114,7 @@ registerButton('replies', (attrs, state, siteSettings) => {
registerButton('share', attrs => {
return {
action: 'share',
className: 'share',
title: 'post.controls.share',
icon: 'link',
data: {

View File

@ -42,6 +42,12 @@
float: left;
font-size: 1.571em;
}
.reply-as-new-topic {
float: left;
.fa {
margin-right: 5px;
}
}
.link {
margin-right: 2px;
float: right;