diff --git a/app/assets/javascripts/discourse/components/post-gutter.js.es6 b/app/assets/javascripts/discourse/components/post-gutter.js.es6
index 5b923febe33..f4ca4cac6f7 100644
--- a/app/assets/javascripts/discourse/components/post-gutter.js.es6
+++ b/app/assets/javascripts/discourse/components/post-gutter.js.es6
@@ -1,22 +1,25 @@
-var MAX_SHOWN = 5;
+const MAX_SHOWN = 5;
import StringBuffer from 'discourse/mixins/string-buffer';
import { iconHTML } from 'discourse/helpers/fa-icon';
+import property from 'ember-addons/ember-computed-decorators';
-export default Em.Component.extend(StringBuffer, {
+const { get, isEmpty, Component } = Ember;
+
+export default Component.extend(StringBuffer, {
classNameBindings: [':gutter'],
rerenderTriggers: ['expanded'],
// Roll up links to avoid duplicates
- collapsed: function() {
- var seen = {},
- result = [],
- links = this.get('links');
+ @property('links')
+ collapsed(links) {
+ const seen = {};
+ const result = [];
- if (!Em.isEmpty(links)) {
+ if (!isEmpty(links)) {
links.forEach(function(l) {
- var title = Em.get(l, 'title');
+ const title = get(l, 'title');
if (!seen[title]) {
result.pushObject(l);
seen[title] = true;
@@ -24,52 +27,52 @@ export default Em.Component.extend(StringBuffer, {
});
}
return result;
- }.property('links'),
+ },
- renderString: function(buffer) {
- var links = this.get('collapsed'),
- toRender = links,
- collapsed = !this.get('expanded');
+ renderString(buffer) {
+ const links = this.get('collapsed');
+ const collapsed = !this.get('expanded');
- if (!Em.isEmpty(links)) {
+ if (!isEmpty(links)) {
+ let toRender = links;
if (collapsed) {
toRender = toRender.slice(0, MAX_SHOWN);
}
buffer.push("
");
toRender.forEach(function(l) {
- var direction = Em.get(l, 'reflection') ? 'inbound' : 'outbound',
- clicks = Em.get(l, 'clicks');
+ const direction = get(l, 'reflection') ? 'inbound' : 'outbound',
+ clicks = get(l, 'clicks');
- buffer.push("- ");
+ buffer.push(`
- `);
- var title = Em.get(l, 'title');
- if (!Em.isEmpty(title)) {
+ let title = get(l, 'title');
+ if (!isEmpty(title)) {
title = Handlebars.Utils.escapeExpression(title);
buffer.push(Discourse.Emoji.unescape(title));
}
if (clicks) {
- buffer.push("" + clicks + "");
+ buffer.push(`${clicks}`);
}
buffer.push("
");
});
if (collapsed) {
- var remaining = links.length - MAX_SHOWN;
+ const remaining = links.length - MAX_SHOWN;
if (remaining > 0) {
- buffer.push("- " + I18n.t('post.more_links', {count: remaining}) + "
");
+ buffer.push(`- ${I18n.t('post.more_links', {count: remaining})}
`);
}
}
buffer.push('
');
}
if (this.get('canReplyAsNewTopic')) {
- buffer.push("" + iconHTML('plus') + I18n.t('post.reply_as_new_topic') + "");
+ buffer.push(`${iconHTML('plus')}${I18n.t('post.reply_as_new_topic')}`);
}
},
- click: function(e) {
- var $target = $(e.target);
+ click(e) {
+ const $target = $(e.target);
if ($target.hasClass('toggle-more')) {
this.toggleProperty('expanded');
return false;
diff --git a/app/assets/javascripts/discourse/controllers/quote-button.js.es6 b/app/assets/javascripts/discourse/controllers/quote-button.js.es6
index 8b416b6d505..729d5f7a925 100644
--- a/app/assets/javascripts/discourse/controllers/quote-button.js.es6
+++ b/app/assets/javascripts/discourse/controllers/quote-button.js.es6
@@ -1,5 +1,6 @@
import loadScript from 'discourse/lib/load-script';
import Quote from 'discourse/lib/quote';
+import property from 'ember-addons/ember-computed-decorators';
export default Ember.Controller.extend({
needs: ['topic', 'composer'],
@@ -8,10 +9,15 @@ export default Ember.Controller.extend({
loadScript('defer/html-sanitizer-bundle');
}.on('init'),
- // If the buffer is cleared, clear out other state (post)
- bufferChanged: function() {
- if (Ember.isEmpty(this.get('buffer'))) this.set('post', null);
- }.observes('buffer'),
+ @property('buffer', 'postId')
+ post(buffer, postId) {
+ if (!postId || Ember.isEmpty(buffer)) { return null; }
+
+ const postStream = this.get('controllers.topic.model.postStream');
+ const post = postStream.findLoadedPost(postId);
+
+ return post;
+ },
// Save the currently selected text and displays the
// "quote reply" button
@@ -85,16 +91,13 @@ export default Ember.Controller.extend({
},
quoteText() {
-
- const postStream = this.get('controllers.topic.model.postStream');
const postId = this.get('postId');
- const post = postStream.findLoadedPost(postId);
+ const post = this.get('post');
// defer load if needed, if in an expanded replies section
if (!post) {
- postStream.loadPost(postId).then(() => {
- this.quoteText();
- });
+ const postStream = this.get('controllers.topic.model.postStream');
+ postStream.loadPost(postId).then(() => this.quoteText());
return;
}
@@ -110,7 +113,7 @@ export default Ember.Controller.extend({
draftKey: post.get('topic.draft_key')
};
- if(post.get('post_number') === 1) {
+ if (post.get('post_number') === 1) {
composerOpts.topic = post.get("topic");
} else {
composerOpts.post = post;