From 9588583244788c3c3a8695f016cc23b88df8dac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Tue, 14 Jun 2016 20:01:21 +0200 Subject: [PATCH] 'Reply as new topic' link in the share dialog --- .../discourse/controllers/share.js.es6 | 5 ++ .../discourse/controllers/topic.js.es6 | 10 +-- .../javascripts/discourse/templates/share.hbs | 4 ++ .../discourse/views/quote-button.js.es6 | 3 +- .../javascripts/discourse/views/share.js.es6 | 64 +++++++++---------- .../discourse/widgets/post-menu.js.es6 | 1 + .../stylesheets/common/base/share_link.scss | 6 ++ 7 files changed, 54 insertions(+), 39 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/share.js.es6 b/app/assets/javascripts/discourse/controllers/share.js.es6 index b276fcf590d..0fff3985221 100644 --- a/app/assets/javascripts/discourse/controllers/share.js.es6 +++ b/app/assets/javascripts/discourse/controllers/share.js.es6 @@ -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) { diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6 index a89f6927910..2c6d56a021f 100644 --- a/app/assets/javascripts/discourse/controllers/topic.js.es6 +++ b/app/assets/javascripts/discourse/controllers/topic.js.es6 @@ -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}); }); }, diff --git a/app/assets/javascripts/discourse/templates/share.hbs b/app/assets/javascripts/discourse/templates/share.hbs index c11aca002e4..71bf52b0040 100644 --- a/app/assets/javascripts/discourse/templates/share.hbs +++ b/app/assets/javascripts/discourse/templates/share.hbs @@ -14,6 +14,10 @@ {{share-source source=s title=title action="share"}} {{/each}} +
+ {{fa-icon "plus"}}{{i18n 'topic.create'}} +
+ diff --git a/app/assets/javascripts/discourse/views/quote-button.js.es6 b/app/assets/javascripts/discourse/views/quote-button.js.es6 index 681523377bc..e0b5e21434f 100644 --- a/app/assets/javascripts/discourse/views/quote-button.js.es6 +++ b/app/assets/javascripts/discourse/views/quote-button.js.es6 @@ -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({ diff --git a/app/assets/javascripts/discourse/views/share.js.es6 b/app/assets/javascripts/discourse/views/share.js.es6 index 96029481224..abaa6c82b78 100644 --- a/app/assets/javascripts/discourse/views/share.js.es6 +++ b/app/assets/javascripts/discourse/views/share.js.es6 @@ -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') diff --git a/app/assets/javascripts/discourse/widgets/post-menu.js.es6 b/app/assets/javascripts/discourse/widgets/post-menu.js.es6 index c2d474ae874..f8b6f6f40a3 100644 --- a/app/assets/javascripts/discourse/widgets/post-menu.js.es6 +++ b/app/assets/javascripts/discourse/widgets/post-menu.js.es6 @@ -114,6 +114,7 @@ registerButton('replies', (attrs, state, siteSettings) => { registerButton('share', attrs => { return { action: 'share', + className: 'share', title: 'post.controls.share', icon: 'link', data: { diff --git a/app/assets/stylesheets/common/base/share_link.scss b/app/assets/stylesheets/common/base/share_link.scss index 2b9b6b57157..33c39c86f86 100644 --- a/app/assets/stylesheets/common/base/share_link.scss +++ b/app/assets/stylesheets/common/base/share_link.scss @@ -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;