@@ -27,6 +27,11 @@ $(() => {
2727 return ! ! wrapper . querySelector ( '[data-inline=true]' ) ;
2828 } ;
2929
30+ const afterThreadRender = ( ) => {
31+ window . MathJax && MathJax . typeset ( ) ;
32+ window . hljs && hljs . highlightAll ( ) ;
33+ } ;
34+
3035 /**
3136 * @param {HTMLElement } wrapper
3237 * @param {string } threadId
@@ -35,20 +40,32 @@ $(() => {
3540 async function openThread ( wrapper , threadId , options ) {
3641 const data = await QPixel . getThreadContent ( threadId , options ) ;
3742
43+ if ( ! data ) {
44+ QPixel . createNotification ( 'danger' , 'Failed to open thread' ) ;
45+ return ;
46+ }
47+
3848 wrapper . innerHTML = data ;
3949
40- window . MathJax && MathJax . typeset ( ) ;
41- window . hljs && hljs . highlightAll ( ) ;
50+ if ( window . MathJax ) {
51+ const titleElem = wrapper . querySelector ( '.js-thread-title' ) ;
52+
53+ if ( titleElem && QPixel . DOM . isHTMLElement ( titleElem ) ) {
54+ titleElem . dataset . title = titleElem . textContent ;
55+ }
56+ }
57+
58+ afterThreadRender ( ) ;
4259 }
4360
44- $ ( document ) . on ( 'click' , '.post--comments-thread.is-inline a ' , async ( ev ) => {
61+ $ ( document ) . on ( 'click' , '.js--comment-link ' , async ( ev ) => {
4562 if ( ev . ctrlKey || ev . metaKey ) {
4663 return ;
4764 }
4865
4966 ev . preventDefault ( ) ;
5067
51- const $tgt = $ ( ev . target ) ;
68+ const $tgt = $ ( ev . currentTarget ) ;
5269 const $threadId = $tgt . data ( 'thread' ) ;
5370 const wrapper = getCommentThreadWrapper ( $tgt ) ;
5471
@@ -73,13 +90,14 @@ $(() => {
7390 $ ( document ) . on ( 'click' , '.js-collapse-thread' , async ( ev ) => {
7491 const $tgt = $ ( ev . target ) ;
7592 const $widget = $tgt . parents ( '.widget' ) ;
93+ const $title = $widget . find ( '.js-thread-title' ) ;
7694 const $embed = $tgt . parents ( '.post--comments-thread' ) ;
7795
7896 const threadId = $widget . data ( 'thread' ) ;
7997 const isLocked = $widget . data ( 'locked' ) ;
8098 const isDeleted = $widget . data ( 'deleted' ) ;
8199 const isArchived = $widget . data ( 'archived' ) ;
82- const threadTitle = $widget . find ( '.js-thread- title') . text ( ) ;
100+ const threadTitle = $title . data ( ' title') || $title . text ( ) ;
83101 const replyCount = $widget . data ( 'comments' ) ;
84102
85103 const $container = $ ( `<div class="post--comments-thread is-inline"></div>` ) ;
@@ -93,7 +111,7 @@ $(() => {
93111
94112 if ( isDeleted ) {
95113 $container . append (
96- `<i class="fas fa-trash h-c-red-600 fa-fw" title="Deleted thread" aria-label="Deleted thread"></i>`
114+ `<i class="fas fa-trash h-c-red-600 fa-fw" title="Deleted thread" aria-label="Deleted thread"></i>` ,
97115 ) ;
98116 $container . addClass ( 'is-deleted' ) ;
99117 }
@@ -106,6 +124,8 @@ $(() => {
106124 $container . append ( $link ) ;
107125 $container . append ( `(${ replyCount } comment${ replyCount !== 1 ? 's' : '' } )` ) ;
108126 $embed [ 0 ] . outerHTML = $container [ 0 ] . outerHTML ;
127+
128+ afterThreadRender ( ) ;
109129 } ) ;
110130
111131 $ ( document ) . on ( 'click' , '.js-comment-edit' , async ( evt ) => {
@@ -185,7 +205,8 @@ $(() => {
185205 if ( isDelete ) {
186206 $comment . addClass ( 'deleted-content' ) ;
187207 $tgt . removeClass ( 'js-comment-delete' ) . addClass ( 'js-comment-undelete' ) . val ( 'undelete' ) ;
188- } else {
208+ }
209+ else {
189210 $comment . removeClass ( 'deleted-content' ) ;
190211 $tgt . removeClass ( 'js-comment-undelete' ) . addClass ( 'js-comment-delete' ) . val ( 'delete' ) ;
191212 }
@@ -202,7 +223,7 @@ $(() => {
202223 const $modal = $ ( $tgt . data ( 'modal' ) ) ;
203224
204225 const resp = await QPixel . fetch ( `/comments/thread/${ threadId } /followers` , {
205- headers : { Accept : 'text/html' }
226+ headers : { Accept : 'text/html' } ,
206227 } ) ;
207228
208229 const data = await resp . text ( ) ;
@@ -274,7 +295,7 @@ $(() => {
274295 openThread ( wrapper , threadID , { inline } ) ;
275296 }
276297 } ) ;
277- } )
298+ } ) ;
278299
279300 /**
280301 * @param {Element } target
@@ -287,7 +308,7 @@ $(() => {
287308 const $submitter = $form . find ( '.js-rename-thread' ) ;
288309
289310 const newStripped = QPixel . MD . stripMarkdown ( $tgt . val ( ) , {
290- removeLeadingQuote : true
311+ removeLeadingQuote : true ,
291312 } ) ;
292313
293314 if ( newStripped === $tgt . data ( 'old' ) ) {
@@ -316,7 +337,7 @@ $(() => {
316337 const { old } = dataset ;
317338
318339 const newStripped = QPixel . MD . stripMarkdown ( newTitle , {
319- removeLeadingQuote : true
340+ removeLeadingQuote : true ,
320341 } ) ;
321342
322343 if ( newStripped === old ) {
@@ -344,7 +365,8 @@ $(() => {
344365 const inline = isInlineCommentThread ( wrapper ) ;
345366 openThread ( wrapper , threadID , { inline } ) ;
346367 } ) ;
347- } else {
368+ }
369+ else {
348370 QPixel . createNotification ( 'danger' , 'Failed to find thread to lock' ) ;
349371 }
350372 } ) ;
@@ -434,7 +456,8 @@ $(() => {
434456 . attr ( 'data-user-id' , id ) ;
435457 } ) ;
436458 QPixel . Popup . getPopup ( items , $tgt [ 0 ] , callback ) ;
437- } else {
459+ }
460+ else {
438461 QPixel . Popup . destroyAll ( ) ;
439462 }
440463 }
@@ -448,7 +471,8 @@ $(() => {
448471 if ( $thread . is ( ':hidden' ) ) {
449472 $thread . show ( ) ;
450473 $thread . find ( '.js-comment-field' ) . trigger ( 'focus' ) ;
451- } else {
474+ }
475+ else {
452476 $thread . hide ( ) ;
453477 }
454478 } ) ;
@@ -463,7 +487,8 @@ $(() => {
463487 if ( $reply . is ( ':hidden' ) ) {
464488 $reply . show ( ) ;
465489 $reply . find ( '.js-comment-field' ) . trigger ( 'focus' ) ;
466- } else {
490+ }
491+ else {
467492 $reply . hide ( ) ;
468493 }
469494 } ) ;
0 commit comments