less code
This commit is contained in:
parent
a1c875986a
commit
1ec25ba2a7
|
@ -12,7 +12,8 @@ export default createWidget('post-links', {
|
||||||
},
|
},
|
||||||
|
|
||||||
linkHtml(link) {
|
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) {
|
if (link.clicks) {
|
||||||
linkBody.push(h('span.badge.badge-notification.clicks', link.clicks.toString()));
|
linkBody.push(h('span.badge.badge-notification.clicks', link.clicks.toString()));
|
||||||
}
|
}
|
||||||
|
@ -20,7 +21,7 @@ export default createWidget('post-links', {
|
||||||
return h('li',
|
return h('li',
|
||||||
h('a.track-link', {
|
h('a.track-link', {
|
||||||
className: link.reflection ? 'inbound' : 'outbound',
|
className: link.reflection ? 'inbound' : 'outbound',
|
||||||
attributes: {href: link.url}
|
attributes: { href: link.url }
|
||||||
}, [linkBody, iconNode(link.reflection ? 'arrow-left' : 'arrow-right')])
|
}, [linkBody, iconNode(link.reflection ? 'arrow-left' : 'arrow-right')])
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -35,28 +36,24 @@ export default createWidget('post-links', {
|
||||||
|
|
||||||
const result = [];
|
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)));
|
_.each(dedupedLinks, l => result.push(this.linkHtml(l)));
|
||||||
} else {
|
} else {
|
||||||
// show up to 5 *incoming* links when collapsed
|
// show up to 5 *incoming* links when collapsed
|
||||||
if (state.collapsed) {
|
const max = Math.min(5, incomingLinks.length);
|
||||||
const max = Math.min(5, incomingLinks.length);
|
for (let i = 0; i < max; i++) {
|
||||||
for (let i = 0; i < max; i++) {
|
result.push(this.linkHtml(incomingLinks[i]));
|
||||||
result.push(this.linkHtml(incomingLinks[i]));
|
}
|
||||||
}
|
// 'show more' link
|
||||||
// 'show more' link
|
if (dedupedLinks.length > max) {
|
||||||
if (dedupedLinks.length > 5) {
|
result.push(h('li', this.attach('link', {
|
||||||
result.push(h('li', this.attach('link', {
|
labelCount: 'post_links.title',
|
||||||
labelCount: `post_links.title`,
|
title: 'post_links.about',
|
||||||
title: "post_links.about",
|
count: links.length,
|
||||||
count: links.length,
|
action: 'expandLinks',
|
||||||
action: 'expandLinks',
|
className: 'expand-links'
|
||||||
className: 'expand-links'
|
})));
|
||||||
})));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
_.each(dedupedLinks, l => result.push(this.linkHtml(l)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue