@@ -269,11 +269,6 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
269269 const lastChildEl = el . lastElementChild ;
270270
271271 if ( lastChildEl ) {
272- // Find the top and bottom o the element that is being managed
273- const elTop = el . offsetTop ;
274- const elBottom =
275- elTop + lastChildEl . offsetTop + lastChildEl . offsetHeight ;
276-
277272 // Converts the sidebar to a menu
278273 const convertToMenu = ( ) => {
279274 for ( const child of el . children ) {
@@ -299,7 +294,10 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
299294 placeholderDescriptor . titleSelector
300295 ) ;
301296 if ( titleEl ) {
302- toggleTitle . append ( titleEl . innerText , toggleIcon ) ;
297+ toggleTitle . append (
298+ titleEl . textContent || titleEl . innerText ,
299+ toggleIcon
300+ ) ;
303301 }
304302 toggleTitle . classList . add ( "zindex-over-content" ) ;
305303 toggleTitle . classList . add ( "quarto-sidebar-toggle-title" ) ;
@@ -321,6 +319,7 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
321319 }
322320 toggleContents . style . height = "0px" ;
323321 toggleContainer . append ( toggleContents ) ;
322+
324323 el . parentElement . prepend ( toggleContainer ) ;
325324
326325 // Process clicks
@@ -398,6 +397,11 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
398397 convertToMenu ( ) ;
399398 isVisible = false ;
400399 } else {
400+ // Find the top and bottom o the element that is being managed
401+ const elTop = el . offsetTop ;
402+ const elBottom =
403+ elTop + lastChildEl . offsetTop + lastChildEl . offsetHeight ;
404+
401405 if ( ! isVisible ) {
402406 // If the element is current not visible reveal if there are
403407 // no conflicts with overlay regions
@@ -506,8 +510,9 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
506510 const kOverlapPaddingSize = 10 ;
507511 function toRegions ( els ) {
508512 return els . map ( ( el ) => {
513+ const boundRect = el . getBoundingClientRect ( ) ;
509514 const top =
510- el . getBoundingClientRect ( ) . top +
515+ boundRect . top +
511516 document . documentElement . scrollTop -
512517 kOverlapPaddingSize ;
513518 return {
@@ -517,11 +522,45 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
517522 } ) ;
518523 }
519524
525+ const visibleItemObserver = ( els ) => {
526+ let visibleElements = [ ] ;
527+ const intersectionObserver = new IntersectionObserver (
528+ ( entries , _observer ) => {
529+ entries . forEach ( ( entry ) => {
530+ if ( entry . isIntersecting ) {
531+ if ( visibleElements . indexOf ( entry . target ) === - 1 ) {
532+ visibleElements . push ( entry . target ) ;
533+ }
534+ } else {
535+ visibleElements = visibleElements . filter ( ( visibleEntry ) => {
536+ return visibleEntry !== entry ;
537+ } ) ;
538+ }
539+ } ) ;
540+ } ,
541+ { }
542+ ) ;
543+ els . forEach ( ( el ) => {
544+ intersectionObserver . observe ( el ) ;
545+ } ) ;
546+
547+ return {
548+ getVisibleEntries : ( ) => {
549+ return visibleElements ;
550+ } ,
551+ } ;
552+ } ;
553+
554+ const rightElementObserver = visibleItemObserver ( rightSideConflictEls ) ;
555+ const leftElementObserver = visibleItemObserver ( leftSideConflictEls ) ;
556+
520557 const hideOverlappedSidebars = ( ) => {
521- marginScrollVisibility ( toRegions ( rightSideConflictEls ) ) ;
522- sidebarScrollVisiblity ( toRegions ( leftSideConflictEls ) ) ;
558+ marginScrollVisibility ( toRegions ( rightElementObserver . getVisibleEntries ( ) ) ) ;
559+ sidebarScrollVisiblity ( toRegions ( leftElementObserver . getVisibleEntries ( ) ) ) ;
523560 if ( tocLeftScrollVisibility ) {
524- tocLeftScrollVisibility ( toRegions ( leftSideConflictEls ) ) ;
561+ tocLeftScrollVisibility (
562+ toRegions ( leftElementObserver . getVisibleEntries ( ) )
563+ ) ;
525564 }
526565 } ;
527566
0 commit comments