Skip to content

Commit f689df6

Browse files
committed
support auto folding
1 parent db6780c commit f689df6

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

src/gitment.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class Gitment {
5757
theme: defaultTheme,
5858
oauth: {},
5959
perPage: 30,
60+
maxCommentHeight: 250,
6061
}, options)
6162

6263
this.useTheme(this.theme)

src/theme/default.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,28 @@ function renderComments({ meta, comments, commentReactions, currentPage, user, e
119119
likeButton.classList.remove('liked')
120120
likeButton.onclick = () => instance.likeAComment(comment.id)
121121
}
122+
123+
// dirty
124+
// use a blank image to trigger height calculating when element rendered
125+
const imgTrigger = document.createElement('img')
126+
const markdownBody = commentItem.querySelector('.gitment-comment-body')
127+
imgTrigger.className = 'gitment-hidden'
128+
imgTrigger.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
129+
imgTrigger.onload = () => {
130+
if (markdownBody.clientHeight > instance.maxCommentHeight) {
131+
markdownBody.classList.add('gitment-comment-body-folded')
132+
markdownBody.style.maxHeight = instance.maxCommentHeight + 'px'
133+
markdownBody.title = 'Click to Expand'
134+
markdownBody.onclick = () => {
135+
markdownBody.classList.remove('gitment-comment-body-folded')
136+
markdownBody.style.maxHeight = ''
137+
markdownBody.title = ''
138+
markdownBody.onclick = null
139+
}
140+
}
141+
}
142+
commentItem.appendChild(imgTrigger)
143+
122144
commentsList.appendChild(commentItem)
123145
})
124146

style/default.css

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ a.gitment-header-issue-link:hover {
173173
width: 0;
174174
height: 0;
175175
pointer-events: none;
176-
content: " ";
176+
content: "";
177177
border-color: transparent;
178178
border-style: solid solid outset;
179179
}
@@ -264,7 +264,41 @@ a.gitment-editor-logout-link:hover {
264264

265265

266266
.gitment-comment-body {
267+
position: relative;
267268
padding: 15px;
269+
overflow: hidden;
270+
}
271+
272+
.gitment-comment-body-folded {
273+
cursor: pointer;
274+
}
275+
276+
.gitment-comment-body-folded::before {
277+
display: block !important;
278+
content: "";
279+
position: absolute;
280+
width: 100%;
281+
left: 0;
282+
top: 0;
283+
bottom: 50px;
284+
pointer-events: none;
285+
background: -webkit-linear-gradient(top, rgba(0, 0, 0, 0), rgba(255, 255, 255, .9));
286+
background: linear-gradient(180deg, rgba(0, 0, 0, 0), rgba(255, 255, 255, .9));
287+
}
288+
289+
.gitment-comment-body-folded::after {
290+
display: block !important;
291+
content: "Click to Expand" !important;
292+
text-align: center;
293+
color: #586069;
294+
position: absolute;
295+
width: 100%;
296+
height: 50px;
297+
line-height: 50px;
298+
left: 0;
299+
bottom: 0;
300+
pointer-events: none;
301+
background: rgba(255, 255, 255, .9);
268302
}
269303

270304
.gitment-editor-body {
@@ -331,7 +365,7 @@ a.gitment-editor-logout-link:hover {
331365
.gitment-editor-footer::after {
332366
display: table;
333367
clear: both;
334-
content: " ";
368+
content: "";
335369
}
336370

337371
a.gitment-editor-footer-tip {

0 commit comments

Comments
 (0)