less code

This commit is contained in:
Régis Hanol 2016-06-08 11:57:33 +02:00
parent a1c875986a
commit 1ec25ba2a7

View file

@ -12,7 +12,8 @@ export default createWidget('post-links', {
},
linkHtml(link) {
const linkBody = [new RawHtml({html: `<span>${Discourse.Emoji.unescape(Handlebars.Utils.escapeExpression(link.title))}</span>`})];
const escapedTitle = Discourse.Emoji.unescape(Handlebars.Utils.escapeExpression(link.title));
const linkBody = [new RawHtml({ html: `<span>${escapedTitle}</span>` })];
if (link.clicks) {
linkBody.push(h('span.badge.badge-notification.clicks', link.clicks.toString()));
}
@ -20,7 +21,7 @@ export default createWidget('post-links', {
return h('li',
h('a.track-link', {
className: link.reflection ? 'inbound' : 'outbound',
attributes: {href: link.url}
attributes: { href: link.url }
}, [linkBody, iconNode(link.reflection ? 'arrow-left' : 'arrow-right')])
);
},
@ -35,28 +36,24 @@ export default createWidget('post-links', {
const result = [];
if (dedupedLinks.length <= 5) {
// show all links
// show all links
if (dedupedLinks.length <= 5 || !state.collapsed) {
_.each(dedupedLinks, l => result.push(this.linkHtml(l)));
} else {
// show up to 5 *incoming* links when collapsed
if (state.collapsed) {
const max = Math.min(5, incomingLinks.length);
for (let i = 0; i < max; i++) {
result.push(this.linkHtml(incomingLinks[i]));
}
// 'show more' link
if (dedupedLinks.length > 5) {
result.push(h('li', this.attach('link', {
labelCount: `post_links.title`,
title: "post_links.about",
count: links.length,
action: 'expandLinks',
className: 'expand-links'
})));
}
} else {
_.each(dedupedLinks, l => result.push(this.linkHtml(l)));
const max = Math.min(5, incomingLinks.length);
for (let i = 0; i < max; i++) {
result.push(this.linkHtml(incomingLinks[i]));
}
// 'show more' link
if (dedupedLinks.length > max) {
result.push(h('li', this.attach('link', {
labelCount: 'post_links.title',
title: 'post_links.about',
count: links.length,
action: 'expandLinks',
className: 'expand-links'
})));
}
}