@@ -51,7 +51,13 @@ $(document).ready(function () {
5151 . append ( $ ( '<i class="fa fa-github me-1"></i>' ) )
5252 . append ( $ ( '<span></span>' ) . text ( heading + ' (' + issues . length + ')' ) )
5353 ) ;
54- const list = $ ( '<ul class="list-unstyled m-0 d-flex flex-column gap-1"></ul>' ) ;
54+ const list = $ ( '<ul class="list-unstyled m-0 d-flex flex-column gap-1 pe-1"></ul>' ) . css ( {
55+ 'max-height' : 'calc(100vh - 350px)' ,
56+ 'overflow-y' : 'auto' ,
57+ 'overflow-x' : 'hidden' ,
58+ 'overscroll-behavior' : 'contain' ,
59+ 'scrollbar-width' : 'thin' ,
60+ } ) ;
5561 issues . forEach ( function ( issue ) {
5662 const label = '#' + issue . number + ( issue . title ? ' ' + issue . title : '' ) ;
5763 const link = $ ( '<a class="d-block text-truncate" target="_blank" rel="noopener noreferrer"></a>' )
@@ -195,25 +201,69 @@ $(document).ready(function () {
195201
196202 function placePanel ( panel ) {
197203 $ ( '.github-issue-topic-sidebar' ) . remove ( ) ;
204+ ensureScrollbarStyles ( ) ;
198205 // harmony's sticky topic sidebar column, hidden below lg
199206 const sticky = $ ( '.sticky-top .flex-column.align-items-end' ) . first ( ) ;
200207 if ( sticky . length ) {
201208 panel . addClass ( 'ps-2' ) . css ( { 'min-width' : '170px' , 'max-width' : '240px' } ) ;
202209 sticky . append ( $ ( '<hr class="my-0" style="min-width: 170px;" />' ) . addClass ( 'github-issue-topic-sidebar' ) )
203210 . append ( panel ) ;
211+ setTimeout ( function ( ) { adjustSidebarHeight ( panel ) ; } , 0 ) ;
204212 return ;
205213 }
206214 const widgetArea = $ ( '[data-widget-area="sidebar"]' ) . first ( ) ;
207215 if ( widgetArea . length ) {
208216 widgetArea . removeClass ( 'hidden' ) ;
209217 panel . addClass ( 'card card-body p-3 mb-3' ) ;
210218 widgetArea . prepend ( panel ) ;
219+ setTimeout ( function ( ) { adjustSidebarHeight ( panel ) ; } , 0 ) ;
211220 return ;
212221 }
213222 panel . addClass ( 'card card-body p-3 mb-3' ) ;
214223 $ ( '[component="topic"]' ) . first ( ) . before ( panel ) ;
224+ setTimeout ( function ( ) { adjustSidebarHeight ( panel ) ; } , 0 ) ;
225+ }
226+
227+ function adjustSidebarHeight ( panel ) {
228+ panel = panel || $ ( '.github-issue-topic-sidebar.d-flex' ) . first ( ) ;
229+ if ( ! panel || ! panel . length ) {
230+ return ;
231+ }
232+ const list = panel . find ( 'ul' ) ;
233+ if ( ! list . length ) {
234+ return ;
235+ }
236+ const stickyContainer = panel . closest ( '.sticky-top' ) ;
237+ if ( stickyContainer . length ) {
238+ const stickyTopPx = parseFloat ( stickyContainer . css ( 'top' ) ) || 32 ;
239+ const stickyOffset = stickyContainer . offset ( ) ? stickyContainer . offset ( ) . top : 0 ;
240+ const listOffset = list . offset ( ) ? list . offset ( ) . top : 0 ;
241+ const listOffsetInSticky = Math . max ( 0 , listOffset - stickyOffset ) ;
242+ const available = window . innerHeight - stickyTopPx - listOffsetInSticky - 24 ;
243+ const maxH = Math . max ( 140 , Math . floor ( available ) ) ;
244+ list . css ( 'max-height' , maxH + 'px' ) ;
245+ } else {
246+ list . css ( 'max-height' , '400px' ) ;
247+ }
215248 }
216249
250+ function ensureScrollbarStyles ( ) {
251+ if ( $ ( '#github-issue-sidebar-scrollbar-style' ) . length ) {
252+ return ;
253+ }
254+ $ ( 'head' ) . append (
255+ $ ( '<style id="github-issue-sidebar-scrollbar-style">' +
256+ '.github-issue-topic-sidebar ul::-webkit-scrollbar { width: 4px; }' +
257+ '.github-issue-topic-sidebar ul::-webkit-scrollbar-thumb { background: rgba(128, 128, 128, 0.4); border-radius: 2px; }' +
258+ '.github-issue-topic-sidebar ul::-webkit-scrollbar-thumb:hover { background: rgba(128, 128, 128, 0.7); }' +
259+ '</style>' )
260+ ) ;
261+ }
262+
263+ $ ( window ) . on ( 'resize' , function ( ) {
264+ adjustSidebarHeight ( ) ;
265+ } ) ;
266+
217267 $ ( document ) . on ( 'click' , '[component="post/github-issue-status"]' , function ( e ) {
218268 e . stopPropagation ( ) ;
219269 } ) ;
0 commit comments