mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Roll up gutter links, don't show reply as new topic unless expanded.
This commit is contained in:
parent
63a1f87806
commit
76cb4bf0a5
3 changed files with 74 additions and 55 deletions
73
app/assets/javascripts/discourse/components/post-gutter.js
Normal file
73
app/assets/javascripts/discourse/components/post-gutter.js
Normal file
|
@ -0,0 +1,73 @@
|
|||
var MAX_SHOWN = 5;
|
||||
|
||||
Discourse.PostGutterComponent = Em.Component.extend({
|
||||
classNameBindings: [':span5', ':gutter'],
|
||||
|
||||
// Roll up links to avoid duplicates
|
||||
collapsed: function() {
|
||||
var seen = {},
|
||||
result = [],
|
||||
links = this.get('links');
|
||||
|
||||
if (!Em.isEmpty(links)) {
|
||||
links.forEach(function(l) {
|
||||
var title = Em.get(l, 'title');
|
||||
if (!seen[title]) {
|
||||
result.pushObject(l);
|
||||
seen[title] = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}.property('links'),
|
||||
|
||||
render: function(buffer) {
|
||||
var links = this.get('collapsed'),
|
||||
toRender = links,
|
||||
collapsed = !this.get('expanded');
|
||||
|
||||
if (!Em.isEmpty(links)) {
|
||||
if (collapsed) {
|
||||
toRender = toRender.slice(0, MAX_SHOWN);
|
||||
}
|
||||
|
||||
buffer.push("<ul class='post-links'>");
|
||||
toRender.forEach(function(l) {
|
||||
var direction = Em.get(l, 'reflection') ? 'left' : 'right',
|
||||
clicks = Em.get(l, 'clicks');
|
||||
|
||||
buffer.push("<li><a href='" + Em.get(l, 'url') + "' class='track-link'>");
|
||||
buffer.push("<i class='fa fa-arrow-" + direction + "'></i>");
|
||||
buffer.push(Em.get(l, 'title'));
|
||||
if (clicks) {
|
||||
buffer.push("<span class='badge badge-notification clicks'>" + clicks + "</span>");
|
||||
}
|
||||
buffer.push("</a></li>");
|
||||
});
|
||||
|
||||
if (collapsed) {
|
||||
var remaining = links.length - MAX_SHOWN;
|
||||
if (remaining > 0) {
|
||||
buffer.push("<li><a href='#' class='toggle-more'>" + I18n.t('post.more_links', {count: remaining}) + "</a></li>");
|
||||
}
|
||||
}
|
||||
buffer.push('</ul>');
|
||||
}
|
||||
|
||||
if ((links.length <= MAX_SHOWN || !collapsed) && this.get('canReplyAsNewTopic')) {
|
||||
buffer.push("<a href='#' class='reply-new'><i class='fa fa-plus'></i>" + I18n.t('post.reply_as_new_topic') + "</a>");
|
||||
}
|
||||
},
|
||||
|
||||
_rerenderIfNeeded: function() {
|
||||
this.rerender();
|
||||
}.observes('expanded'),
|
||||
|
||||
click: function(e) {
|
||||
if ($(e.target).hasClass('toggle-more')) {
|
||||
this.toggleProperty('expanded');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
|
@ -1,49 +0,0 @@
|
|||
var MAX_SHOWN = 5;
|
||||
|
||||
Discourse.PostLinksComponent = Em.Component.extend({
|
||||
tagName: 'ul',
|
||||
classNameBindings: [':post-links'],
|
||||
|
||||
render: function(buffer) {
|
||||
var links = this.get('links'),
|
||||
toRender = links;
|
||||
|
||||
if (Em.isEmpty(links)) { return; }
|
||||
|
||||
if (!this.get('expanded')) {
|
||||
toRender = toRender.slice(0, MAX_SHOWN);
|
||||
}
|
||||
|
||||
toRender.forEach(function(l) {
|
||||
var direction = Em.get(l, 'reflection') ? 'left' : 'right',
|
||||
clicks = Em.get(l, 'clicks');
|
||||
|
||||
buffer.push("<li><a href='" + Em.get(l, 'url') + "' class='track-link'>");
|
||||
buffer.push("<i class='fa fa-arrow-" + direction + "'></i>");
|
||||
buffer.push(Em.get(l, 'title'));
|
||||
if (clicks) {
|
||||
buffer.push("<span class='badge badge-notification clicks'>" + clicks + "</span>");
|
||||
}
|
||||
buffer.push("</a></li>");
|
||||
});
|
||||
|
||||
if (!this.get('expanded')) {
|
||||
var remaining = links.length - MAX_SHOWN;
|
||||
if (remaining > 0) {
|
||||
buffer.push("<li><a href='#' class='toggle-more'>" + I18n.t('post.more_links', {count: remaining}) + "</a></li>");
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_rerenderIfNeeded: function() {
|
||||
this.rerender();
|
||||
}.observes('expanded'),
|
||||
|
||||
click: function(e) {
|
||||
if ($(e.target).hasClass('toggle-more')) {
|
||||
this.toggleProperty('expanded');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
|
@ -92,12 +92,7 @@
|
|||
{{view Discourse.TopicMapContainerView post=this topic=controller.model}}
|
||||
</div>
|
||||
|
||||
<div class='span5 gutter'>
|
||||
{{post-links links=internalLinks}}
|
||||
{{#if topic.details.can_reply_as_new_topic}}
|
||||
<a href='#' class='reply-new' {{action replyAsNewTopic this}}><i class='fa fa-plus'></i>{{i18n post.reply_as_new_topic}}</a>
|
||||
{{/if}}
|
||||
</div>
|
||||
{{post-gutter links=internalLinks canReplyAsNewTopic=topic.details.can_reply_as_new_topic}}
|
||||
</div>
|
||||
|
||||
</article>
|
||||
|
|
Loading…
Reference in a new issue