@@ -19,17 +19,13 @@ $(() => {
1919 return $tgt . closest ( '.js-comment-thread-wrapper' ) [ 0 ] ?? null ;
2020 } ;
2121
22- $ ( document ) . on ( 'click' , '.post--comments-thread.is-inline a' , async ( evt ) => {
23- if ( evt . ctrlKey ) { return ; }
24-
25- evt . preventDefault ( ) ;
26-
27- const $tgt = $ ( evt . target ) ;
28- const $threadId = $tgt . data ( 'thread' ) ;
29- const wrapper = getCommentThreadWrapper ( $tgt ) ;
30-
31- openThread ( wrapper , $threadId ) ;
32- } ) ;
22+ /**
23+ * @param {HTMLElement } wrapper
24+ * @returns {boolean }
25+ */
26+ const isInlineCommentThread = ( wrapper ) => {
27+ return ! ! wrapper . querySelector ( '[data-inline=true]' ) ;
28+ } ;
3329
3430 /**
3531 * @param {HTMLElement } wrapper
@@ -45,8 +41,24 @@ $(() => {
4541 window . hljs && hljs . highlightAll ( ) ;
4642 }
4743
44+ $ ( document ) . on ( 'click' , '.post--comments-thread.is-inline a' , async ( evt ) => {
45+ if ( evt . ctrlKey ) {
46+ return ; // TODO: do we need this early exit?
47+ }
48+
49+ evt . preventDefault ( ) ;
50+
51+ const $tgt = $ ( evt . target ) ;
52+ const $threadId = $tgt . data ( 'thread' ) ;
53+ const wrapper = getCommentThreadWrapper ( $tgt ) ;
54+
55+ openThread ( wrapper , $threadId ) ;
56+ } ) ;
57+
4858 $ ( document ) . on ( 'click' , '.js-show-deleted-comments' , ( ev ) => {
49- if ( ev . ctrlKey ) { return ; } // do we really need it?
59+ if ( ev . ctrlKey ) {
60+ return ;
61+ } // do we really need it?
5062
5163 ev . preventDefault ( ) ;
5264
@@ -80,7 +92,9 @@ $(() => {
8092 }
8193
8294 if ( isDeleted ) {
83- $container . append ( `<i class="fas fa-trash h-c-red-600 fa-fw" title="Deleted thread" aria-label="Deleted thread"></i>` ) ;
95+ $container . append (
96+ `<i class="fas fa-trash h-c-red-600 fa-fw" title="Deleted thread" aria-label="Deleted thread"></i>`
97+ ) ;
8498 $container . addClass ( 'is-deleted' ) ;
8599 }
86100
@@ -171,8 +185,7 @@ $(() => {
171185 if ( isDelete ) {
172186 $comment . addClass ( 'deleted-content' ) ;
173187 $tgt . removeClass ( 'js-comment-delete' ) . addClass ( 'js-comment-undelete' ) . val ( 'undelete' ) ;
174- }
175- else {
188+ } else {
176189 $comment . removeClass ( 'deleted-content' ) ;
177190 $tgt . removeClass ( 'js-comment-undelete' ) . addClass ( 'js-comment-delete' ) . val ( 'delete' ) ;
178191 }
@@ -189,7 +202,7 @@ $(() => {
189202 const $modal = $ ( $tgt . data ( 'modal' ) ) ;
190203
191204 const resp = await QPixel . fetch ( `/comments/thread/${ threadId } /followers` , {
192- headers : { ' Accept' : 'text/html' }
205+ headers : { Accept : 'text/html' }
193206 } ) ;
194207
195208 const data = await resp . text ( ) ;
@@ -201,49 +214,52 @@ $(() => {
201214 ev . preventDefault ( ) ;
202215
203216 const $tgt = $ ( ev . target ) ;
204- const threadID = $tgt . data ( " thread" ) ;
217+ const threadID = $tgt . data ( ' thread' ) ;
205218
206219 const data = await QPixel . archiveThread ( threadID ) ;
207220
208221 QPixel . handleJSONResponse ( data , ( ) => {
209222 const wrapper = getCommentThreadWrapper ( $tgt ) ;
210- openThread ( wrapper , threadID ) ;
223+ const inline = isInlineCommentThread ( wrapper ) ;
224+ openThread ( wrapper , threadID , { inline } ) ;
211225 } ) ;
212226 } ) ;
213227
214228 $ ( document ) . on ( 'click' , '.js-delete-thread' , async ( ev ) => {
215229 ev . preventDefault ( ) ;
216230
217231 const $tgt = $ ( ev . target ) ;
218- const threadID = $tgt . data ( " thread" ) ;
232+ const threadID = $tgt . data ( ' thread' ) ;
219233
220234 const data = await QPixel . deleteThread ( threadID ) ;
221235
222236 QPixel . handleJSONResponse ( data , ( ) => {
223237 const wrapper = getCommentThreadWrapper ( $tgt ) ;
224- openThread ( wrapper , threadID ) ;
238+ const inline = isInlineCommentThread ( wrapper ) ;
239+ openThread ( wrapper , threadID , { inline } ) ;
225240 } ) ;
226241 } ) ;
227242
228243 $ ( document ) . on ( 'click' , '.js-follow-thread' , async ( ev ) => {
229244 ev . preventDefault ( ) ;
230245
231246 const $tgt = $ ( ev . target ) ;
232- const threadID = $tgt . data ( " thread" ) ;
247+ const threadID = $tgt . data ( ' thread' ) ;
233248
234249 const data = await QPixel . followThread ( threadID ) ;
235250
236251 QPixel . handleJSONResponse ( data , ( ) => {
237252 const wrapper = getCommentThreadWrapper ( $tgt ) ;
238- openThread ( wrapper , threadID ) ;
253+ const inline = isInlineCommentThread ( wrapper ) ;
254+ openThread ( wrapper , threadID , { inline } ) ;
239255 } ) ;
240256 } ) ;
241257
242258 $ ( document ) . on ( 'click' , '.js-lock-thread' , async ( ev ) => {
243259 ev . preventDefault ( ) ;
244260
245261 const $tgt = $ ( ev . target ) ;
246- const threadID = $tgt . data ( " thread" ) ;
262+ const threadID = $tgt . data ( ' thread' ) ;
247263 const form = $tgt . closest ( `form[data-thread=${ threadID } ]` ) . get ( 0 ) ;
248264
249265 if ( form instanceof HTMLFormElement ) {
@@ -253,7 +269,8 @@ $(() => {
253269
254270 QPixel . handleJSONResponse ( data , ( ) => {
255271 const wrapper = getCommentThreadWrapper ( $tgt ) ;
256- openThread ( wrapper , threadID ) ;
272+ const inline = isInlineCommentThread ( wrapper ) ;
273+ openThread ( wrapper , threadID , { inline } ) ;
257274 } ) ;
258275 } else {
259276 QPixel . createNotification ( 'danger' , 'Failed to find thread to lock' ) ;
@@ -265,8 +282,8 @@ $(() => {
265282 evt . preventDefault ( ) ;
266283
267284 const $tgt = $ ( evt . target ) ;
268- const threadID = $tgt . data ( " thread" ) ;
269- const action = $tgt . data ( " action" ) ;
285+ const threadID = $tgt . data ( ' thread' ) ;
286+ const action = $tgt . data ( ' action' ) ;
270287
271288 const resp = await QPixel . fetchJSON ( `/comments/thread/${ threadID } /unrestrict` , { type : action } ) ;
272289
@@ -311,7 +328,7 @@ $(() => {
311328 const $item = $ ( ev . target ) . hasClass ( 'item' ) ? $ ( ev . target ) : $ ( ev . target ) . parents ( '.item' ) ;
312329 const id = $item . data ( 'user-id' ) ;
313330 $tgt [ 0 ] . selectionStart = caretPos - posInWord ;
314- $tgt [ 0 ] . selectionEnd = ( caretPos - posInWord ) + currentWord . length ;
331+ $tgt [ 0 ] . selectionEnd = caretPos - posInWord + currentWord . length ;
315332 QPixel . replaceSelection ( $tgt , `@#${ id } ` ) ;
316333 popup . destroy ( ) ;
317334 $tgt . focus ( ) ;
@@ -332,17 +349,20 @@ $(() => {
332349 pingable [ `${ threadId } -${ postId } ` ] = await resp . json ( ) ;
333350 }
334351
335- const items = Object . entries ( pingable [ `${ threadId } -${ postId } ` ] ) . filter ( ( e ) => {
336- return e [ 0 ] . toLowerCase ( ) . startsWith ( currentWord . substr ( 1 ) . toLowerCase ( ) ) ;
337- } ) . map ( ( e ) => {
338- const username = e [ 0 ] . replace ( / < / g, '<' ) . replace ( / > / g, '>' ) ;
339- const id = e [ 1 ] ;
340- return itemTemplate . clone ( ) . html ( `${ username } <span class="has-color-tertiary-600">#${ id } </span>` )
341- . attr ( 'data-user-id' , id ) ;
342- } ) ;
352+ const items = Object . entries ( pingable [ `${ threadId } -${ postId } ` ] )
353+ . filter ( ( e ) => {
354+ return e [ 0 ] . toLowerCase ( ) . startsWith ( currentWord . substr ( 1 ) . toLowerCase ( ) ) ;
355+ } )
356+ . map ( ( e ) => {
357+ const username = e [ 0 ] . replace ( / < / g, '<' ) . replace ( / > / g, '>' ) ;
358+ const id = e [ 1 ] ;
359+ return itemTemplate
360+ . clone ( )
361+ . html ( `${ username } <span class="has-color-tertiary-600">#${ id } </span>` )
362+ . attr ( 'data-user-id' , id ) ;
363+ } ) ;
343364 QPixel . Popup . getPopup ( items , $tgt [ 0 ] , callback ) ;
344- }
345- else {
365+ } else {
346366 QPixel . Popup . destroyAll ( ) ;
347367 }
348368 }
@@ -356,8 +376,7 @@ $(() => {
356376 if ( $thread . is ( ':hidden' ) ) {
357377 $thread . show ( ) ;
358378 $thread . find ( '.js-comment-field' ) . trigger ( 'focus' ) ;
359- }
360- else {
379+ } else {
361380 $thread . hide ( ) ;
362381 }
363382 } ) ;
@@ -372,8 +391,7 @@ $(() => {
372391 if ( $reply . is ( ':hidden' ) ) {
373392 $reply . show ( ) ;
374393 $reply . find ( '.js-comment-field' ) . trigger ( 'focus' ) ;
375- }
376- else {
394+ } else {
377395 $reply . hide ( ) ;
378396 }
379397 } ) ;
@@ -408,9 +426,7 @@ $(() => {
408426
409427 const shouldFollow = action === 'follow' ;
410428
411- const data = shouldFollow ?
412- await QPixel . followComments ( postId ) :
413- await QPixel . unfollowComments ( postId ) ;
429+ const data = shouldFollow ? await QPixel . followComments ( postId ) : await QPixel . unfollowComments ( postId ) ;
414430
415431 QPixel . handleJSONResponse ( data , ( ) => {
416432 target . dataset . action = shouldFollow ? 'unfollow' : 'follow' ;
0 commit comments