@@ -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-
238217export 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