mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 00:32:52 +08:00
FEATURE: auto expand incoming/outgoing links
This commit is contained in:
@ -16,20 +16,14 @@ export default createWidget('post-links', {
|
|||||||
|
|
||||||
const result = [];
|
const result = [];
|
||||||
if (links.length) {
|
if (links.length) {
|
||||||
if (state.collapsed) {
|
|
||||||
return this.attach('link', {
|
|
||||||
labelCount: `post_links.title`,
|
|
||||||
title: "post_links.about",
|
|
||||||
count: links.length,
|
|
||||||
action: 'expandLinks',
|
|
||||||
className: 'expand-links'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const seenTitles = {};
|
const seenTitles = {};
|
||||||
|
|
||||||
let titleCount = 0;
|
let titleCount = 0;
|
||||||
links.forEach(function(l) {
|
|
||||||
|
let hasMore = links.any((l) => {
|
||||||
|
if (this.state.collapsed && titleCount === 5) { return true; }
|
||||||
|
|
||||||
let title = l.title;
|
let title = l.title;
|
||||||
if (title && !seenTitles[title]) {
|
if (title && !seenTitles[title]) {
|
||||||
seenTitles[title] = true;
|
seenTitles[title] = true;
|
||||||
@ -47,9 +41,21 @@ export default createWidget('post-links', {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (hasMore) {
|
||||||
|
result.push(h('li', this.attach('link', {
|
||||||
|
labelCount: `post_links.title`,
|
||||||
|
title: "post_links.about",
|
||||||
|
count: links.length,
|
||||||
|
action: 'expandLinks',
|
||||||
|
className: 'expand-links'
|
||||||
|
})));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result.length) {
|
||||||
return h('ul.post-links', result);
|
return h('ul.post-links', result);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
expandLinks() {
|
expandLinks() {
|
||||||
|
@ -82,26 +82,35 @@
|
|||||||
.post-links-container {
|
.post-links-container {
|
||||||
@include unselectable;
|
@include unselectable;
|
||||||
clear: both;
|
clear: both;
|
||||||
text-align: right;
|
|
||||||
|
.post-links {
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
|
padding: 1em 1em 0;
|
||||||
|
background: blend-primary-secondary(4%);
|
||||||
|
border: 1px solid dark-light-diff($primary, $secondary, 90%, -65%);
|
||||||
|
}
|
||||||
|
|
||||||
.expand-links {
|
.expand-links {
|
||||||
color: dark-light-choose(scale-color($primary, $lightness: 50%), scale-color($secondary, $lightness: 50%));
|
color: dark-light-choose(scale-color($primary, $lightness: 40%), scale-color($secondary, $lightness: 60%));
|
||||||
}
|
}
|
||||||
|
|
||||||
.track-link {
|
.track-link {
|
||||||
padding-left: 10px;
|
padding-left: 0;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
ul {
|
ul {
|
||||||
|
margin: 0;
|
||||||
list-style: none;
|
list-style: none;
|
||||||
|
|
||||||
li {
|
li {
|
||||||
margin-bottom: 0.5em;
|
margin-bottom: 0.5em;
|
||||||
a[href] {
|
a[href] {
|
||||||
color: dark-light-choose(scale-color($primary, $lightness: 50%), scale-color($secondary, $lightness: 50%));
|
color: dark-light-choose(scale-color($primary, $lightness: 40%), scale-color($secondary, $lightness: 60%));
|
||||||
|
}
|
||||||
|
.clicks {
|
||||||
|
margin-left: 0.5em;
|
||||||
}
|
}
|
||||||
i {
|
i {
|
||||||
font-size: 0.857em;
|
font-size: 0.857em;
|
||||||
|
@ -273,9 +273,9 @@
|
|||||||
|
|
||||||
&.clicks {
|
&.clicks {
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
background-color: dark-light-diff($primary, $secondary, 85%, -60%);
|
background-color: dark-light-diff($primary, $secondary, 88%, -60%);
|
||||||
top: -1px;
|
top: -1px;
|
||||||
color: dark-light-diff($primary, $secondary, 50%, -20%);
|
color: dark-light-diff($primary, $secondary, 40%, -20%);
|
||||||
position: relative;
|
position: relative;
|
||||||
margin-left: 2px;
|
margin-left: 2px;
|
||||||
border: none;
|
border: none;
|
||||||
|
@ -1832,10 +1832,10 @@ en:
|
|||||||
one: "1 click"
|
one: "1 click"
|
||||||
other: "%{count} clicks"
|
other: "%{count} clicks"
|
||||||
post_links:
|
post_links:
|
||||||
about: "expand the links for this post"
|
about: "expand more links for this post"
|
||||||
title:
|
title:
|
||||||
one: "1 post link"
|
one: "1 more"
|
||||||
other: "%{count} post links"
|
other: "%{count} more"
|
||||||
|
|
||||||
topic_statuses:
|
topic_statuses:
|
||||||
warning:
|
warning:
|
||||||
|
@ -14,10 +14,7 @@ widgetTest("duplicate links", {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
test(assert) {
|
test(assert) {
|
||||||
click('.expand-links');
|
|
||||||
andThen(() => {
|
|
||||||
assert.equal(this.$('.post-links a.track-link').length, 1, 'it hides the dupe link');
|
assert.equal(this.$('.post-links a.track-link').length, 1, 'it hides the dupe link');
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -38,7 +35,7 @@ widgetTest("collapsed links", {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
test(assert) {
|
test(assert) {
|
||||||
assert.ok(this.$('.expand-links').length, 'collapsed by default');
|
assert.ok(this.$('.expand-links').length === 1, 'collapsed by default');
|
||||||
click('a.expand-links');
|
click('a.expand-links');
|
||||||
andThen(() => {
|
andThen(() => {
|
||||||
assert.equal(this.$('.post-links a.track-link').length, 7);
|
assert.equal(this.$('.post-links a.track-link').length, 7);
|
||||||
|
Reference in New Issue
Block a user