Skip to content

Commit f64e919

Browse files
committed
comment
1 parent ba709b1 commit f64e919

11 files changed

Lines changed: 267 additions & 368 deletions

File tree

‎theme/comment/comment.html‎

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,29 @@
88
<div class="pipe-comment__body">
99
<div class="fn-clear">
1010
<a href="{{.Item.Author.AvatarURL}}" class="ft-gray">{{.Item.Author.Name}}</a>
11-
<span class="ft-nowrap ft-12 ft-fade"> • {{.Item.CreatedAt}} •</span>
11+
<span class="ft-nowrap ft-12 ft-fade"> • {{.Item.CreatedAt}} • </span>
1212
<a class="ft-nowrap ft-12 ft-gray" href="#123">
13-
<svg><use xlink:href="#reply"></use></svg>{{.I18n.Reply}} Vanessa
13+
<svg><use xlink:href="#reply"></use></svg> {{.I18n.Reply}} Vanessa
1414
</a>
1515
<div class="fn-right">
16-
<button class="btn"
16+
<span class="pipe-comment__btn pipe-comment__btn--reply"
1717
data-title="{{.I18n.Reply}}{{.I18n.Colon}}{{.Item.Author.Name}}"
1818
data-id="{{.ArticleID}}"
1919
data-commentid="{{.Item.ID}}">
2020
{{.I18n.Reply}} <svg class="fn-right"><use xlink:href="#comment"></use></svg>
21-
</button>
22-
<button class="btn btn--danger btn--space"
21+
</span>
22+
<span class="pipe-comment__btn pipe-comment__btn--danger"
2323
data-id="{{.Item.ID}}"
2424
data-label="{{.I18n.ConfirmDelete}}"
2525
data-label2="{{.I18n.StayStep}}">
2626
{{.I18n.Delete}} <svg class="fn-right"><use xlink:href="#remove"></use></svg>
27-
</button>
27+
</span>
2828
{{if .Item.Removable}}
29-
<span class="btn"
30-
data-id="{{.Item.ID}}"
31-
data-label="{{.I18n.ConfirmDelete}}"
32-
data-label2="{{.I18n.StayStep}}">
33-
<svg><use xlink:href="#remove"></use></svg>
29+
<span class="pipe-comment__btn"
30+
data-id="{{.Item.ID}}"
31+
data-label="{{.I18n.ConfirmDelete}}"
32+
data-label2="{{.I18n.StayStep}}">
33+
{{.I18n.Delete}} <svg class="fn-right"><use xlink:href="#remove"></use></svg>
3434
</span>
3535
{{end}}
3636
</div>
@@ -39,21 +39,34 @@
3939
{{.Item.Content}}
4040
</div>
4141
<div>
42-
<span class="ft-gray ft-12 fn-pointer module__list-title comment__reply-btn" data-id="{{.Item.ID}}">
42+
<span class="ft-gray ft-12 fn-pointer" data-id="{{.Item.ID}}">
4343
2 {{.I18n.Reply}}
44-
<svg class="chevron-down"><use xlink:href="#chevron-up"></use></svg>
44+
<svg class="pipe-comment__chevron-down"><use xlink:href="#chevron-up"></use></svg>
4545
</span>
46-
<div class="comment__reply-panel fn-none">
47-
<section class="comment__reply-item">
46+
<div class="pipe-comment__reply fn-none">
47+
<section class="pipe-comment__item">
48+
<a rel="nofollow"
49+
class="pipe-comment__avatar"
50+
data-src="{{.Item.Author.AvatarURL}}"
51+
href="{{.Item.Author.URL}}">
52+
</a>
53+
<div class="pipe-comment__body">
54+
<a href="{{.Item.Author.AvatarURL}}" class="ft-gray">{{.Item.Author.Name}}</a>
55+
<span class="ft-nowrap ft-12 ft-gray"> • {{.Item.CreatedAt}}</span>
56+
<div class="content__reset">
57+
{{.Item.Content}}
58+
</div>
59+
</div>
60+
</section>
61+
<section class="pipe-comment__item">
4862
<a rel="nofollow"
49-
class="avatar fn-absolute"
63+
class="pipe-comment__avatar"
5064
data-src="{{.Item.Author.AvatarURL}}"
5165
href="{{.Item.Author.URL}}">
5266
</a>
53-
<div class="fn-padding60">
54-
<a href="{{.Item.Author.AvatarURL}}" class="module__list-title">{{.Item.Author.Name}}</a>
55-
<span class="ft-12 ft-gray"> • </span>
56-
<span class="ft-nowrap ft-12 ft-gray">{{.Item.CreatedAt}}</span>
67+
<div class="pipe-comment__body">
68+
<a href="{{.Item.Author.AvatarURL}}" class="ft-gray">{{.Item.Author.Name}}</a>
69+
<span class="ft-nowrap ft-12 ft-gray"> • {{.Item.CreatedAt}}</span>
5770
<div class="content__reset">
5871
{{.Item.Content}}
5972
</div>

‎theme/comment/comments.html‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{{define "comment/comments"}}
22
{{if gt (len .Comments) 0}}
3-
<div id="pipeComments" class="fn-clear">
3+
<div id="pipeComments" class="fn-clear"
4+
data-title="{{.I18n.Comment}}{{.I18n.Colon}}{{.Article.Title}}"
5+
data-id="{{.Article.ID}}">
46
<div class="pipe-comment__header">
57
<span id="pipeCommentsCnt">{{len $.Comments}}</span> {{$.I18n.Comment}}
68
</div>
@@ -13,11 +15,11 @@
1315
<nav class="pipe-comment__pagination fn-right">
1416
{{range $.Pagination.PageNums}}
1517
{{if eq . -1}}
16-
<a class="btn fn-left" href="{{$.Pagination.PageURL}}{{$.Pagination.PreviousPageNum}}">
18+
<a class="pipe-comment__btn" href="{{$.Pagination.PageURL}}{{$.Pagination.PreviousPageNum}}">
1719
<svg class="fn-left"><use xlink:href="#chevron-left"></use></svg> {{$.I18n.prePage}}
1820
</a>
1921
{{else if eq . -2}}
20-
<a class="btn btn--space fn-left" href="{{$.Pagination.PageURL}}{{$.Pagination.NextPageNum}}">
22+
<a class="pipe-comment__btn" href="{{$.Pagination.PageURL}}{{$.Pagination.NextPageNum}}">
2123
{{$.I18n.nextPage}} <svg class="fn-right"><use xlink:href="#chevron-right"></use></svg>
2224
</a>
2325
{{end}}

‎theme/js/common.js‎

Lines changed: 68 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -211,30 +211,9 @@ export const ShowEditor = (reply, id, commentId) => {
211211
$editor.css({'bottom': '0', 'opacity': 1}).data('id', id)
212212
$('body').css('padding-bottom', $editor.outerHeight() + 'px')
213213
$('#pipeEditorReplyTarget').text(reply)
214+
$('#pipeEditorComment').focus()
214215
};
215216

216-
// TODO
217-
218-
/**
219-
* @description 删除评论
220-
* @param {string} id 评论 id
221-
* @param {function} succCB 成功回调
222-
* @param {function} errorCB 失败回调
223-
*/
224-
export const ReomveComment = (id, succCB, errorCB) => {
225-
$.ajax({
226-
url: `${location.origin}/api/console/comments/${id}`,
227-
type: 'DELETE',
228-
success: (result) => {
229-
if (result.code === 0) {
230-
succCB && succCB()
231-
} else {
232-
errorCB && errorCB(result.msg)
233-
}
234-
}
235-
})
236-
}
237-
238217
export const InitComment = () => {
239218
/**
240219
* @description 图片预览
@@ -322,6 +301,56 @@ export const InitComment = () => {
322301
ShowEditor($commentNull.data('title'), $commentNull.data('id'))
323302
})
324303

304+
// comment show reply
305+
$('body').on('click', '#pipeComments .fn-pointer', function () {
306+
const $it = $(this)
307+
const $svg = $it.find('svg')
308+
if ($svg.hasClass('pipe-comment__chevron-down')) {
309+
$svg.removeClass('pipe-comment__chevron-down')
310+
} else {
311+
$svg.addClass('pipe-comment__chevron-down')
312+
}
313+
$it.next().slideToggle({
314+
queue: false
315+
})
316+
});
317+
318+
// comment remove
319+
$('body').on('click', '#pipeComments .pipe-comment__btn--danger', function () {
320+
const $it = $(this)
321+
if (confirm($it.data('label'))) {
322+
$.ajax({
323+
url: `${location.origin}/api/console/comments/${$it.data('id')}`,
324+
type: 'DELETE',
325+
success: (result) => {
326+
if (result.code === 0) {
327+
const $commentsCnt = $('#pipeCommentsCnt')
328+
const $comments = $('#pipeComments')
329+
const $item = $(`#pipeComment${$it.data('id')}`)
330+
331+
if ($('#pipeComments > div > section').length === 1) {
332+
$comments.addClass('pipe-comment__null')
333+
.html(`${$it.data('label2')} <svg><use xlink:href="#comment"></use></svg>`).click(function () {
334+
ShowEditor($comments.data('title'), $comments.data('id'))
335+
})
336+
} else {
337+
$item.remove()
338+
$commentsCnt.text(parseInt($commentsCnt.text()) - 1)
339+
}
340+
} else {
341+
alert(result.msg)
342+
}
343+
}
344+
})
345+
}
346+
})
347+
348+
// comment remove
349+
$('body').on('click', '#pipeComments .pipe-comment__btn--reply', function () {
350+
const $it = $(this)
351+
ShowEditor($it.data('title'), $it.data('id'), $it.data('commentid'))
352+
})
353+
325354
// editor emoji
326355
$('.pipe-editor__emotion').find('span').click(function () {
327356
const comment = document.getElementById('pipeEditorComment')
@@ -332,6 +361,21 @@ export const InitComment = () => {
332361
comment.value = textValue
333362
})
334363

364+
// editor hot key
365+
$('#pipeEditorComment').keydown(function (event) {
366+
if (event.metaKey && 13 === event.keyCode) {
367+
$('#pipeEditorAdd').click()
368+
}
369+
370+
if (27 === event.keyCode) {
371+
_hideEditor()
372+
}
373+
}).keypress(function (event) {
374+
if (event.ctrlKey && 10 === event.charCode) {
375+
$('#pipeEditorAdd').click()
376+
}
377+
});
378+
335379
// editor cancel
336380
$('#pipeEditorCancel').click(function () {
337381
_hideEditor()
@@ -386,7 +430,7 @@ export const InitComment = () => {
386430
$comments.find('pre > code').each(function (i, block) {
387431
hljs.highlightBlock(block)
388432
})
389-
LazyLoadCSSImage('.avatar, .article__thumb')
433+
LazyLoadCSSImage('.avatar, .pipe-comment__avatar, .article__thumb')
390434
LazyLoadImage()
391435
$commentContent.val('')
392436
localStorage.removeItem('pipeEditorComment')
@@ -397,77 +441,4 @@ export const InitComment = () => {
397441
}
398442
})
399443
})
400-
}
401-
402-
/*
403-
(function () {
404-
405-
406-
_initShowReplyComment: () => {
407-
$('#comments').on('click', '.comment__item .fn-pointer', function () {
408-
const $it = $(this)
409-
const $svg = $it.find('svg')
410-
if ($svg.hasClass('chevron-down')) {
411-
$svg.removeClass('chevron-down')
412-
} else {
413-
$svg.addClass('chevron-down')
414-
}
415-
$it.next().slideToggle({
416-
queue: false
417-
})
418-
});
419-
},
420-
// comment
421-
422-
423-
removeComment: (id, label, label2) => {
424-
if (confirm(label)) {
425-
ReomveComment(id, () => {
426-
const $commentsCnt = $('#commentsCnt')
427-
const $comments = $('#comments')
428-
const $item = $('#comment' + id)
429-
430-
if ($comments.find('section').length === 1) {
431-
$comments.addClass('ft-center comment__null fn-bottom')
432-
.html(`${label2} <svg><use xlink:href="#comment"></use></svg>`).click(function () {
433-
const $itemReplyBtn = $item.find('.comment__btn:last')
434-
Article.showComment($itemReplyBtn.data('title'), $itemReplyBtn.data('id'))
435-
})
436-
} else {
437-
$item.remove()
438-
$commentsCnt.text(parseInt($commentsCnt.text()) - 1)
439-
}
440-
}, (msg) => {
441-
alert(msg)
442-
})
443-
}
444-
},
445-
446-
$('#comments').on('click', '.comment__btn', function () {
447-
const $this = $(this)
448-
if ($this.hasClass('commentDelete')) {
449-
// remove comment
450-
const $firstBtn = $(this)
451-
Article.removeComment($firstBtn.data('id'), $firstBtn.data('label'), $firstBtn.data('label2'))
452-
}
453-
454-
if ($this.hasClass('commentAdd')) {
455-
// add reply comment
456-
const $lastBtn = $(this)
457-
Article.showComment($lastBtn.data('title'), $lastBtn.data('id'), $lastBtn.data('commentid'))
458-
}
459-
})
460-
461-
462-
463-
464-
$('#commentContent').keydown(function (event) {
465-
if (event.metaKey && 13 === event.keyCode) {
466-
Article.addComment($('#editorAdd').data('label'), $('#editorAdd').data('label2'))
467-
}
468-
}).keypress(function (event) {
469-
if (event.ctrlKey && 10 === event.charCode) {
470-
Article.addComment($('#editorAdd').data('label'), $('#editorAdd').data('label2'))
471-
}
472-
});
473-
})();*/
444+
}

0 commit comments

Comments
 (0)