Skip to content

Commit

Permalink
Sidebar Container: Run the fixed sidebar check after setting up the t…
Browse files Browse the repository at this point in the history
…able of contents (#410)

Fixes #409
  • Loading branch information
ryelle committed Jun 23, 2023
1 parent fa41a30 commit b6b919e
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions mu-plugins/blocks/sidebar-container/src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,6 @@ function isSidebarWithinViewport( container ) {

function init() {
const container = document.querySelector( '.wp-block-wporg-sidebar-container' );

if ( container ) {
if ( isSidebarWithinViewport( container ) ) {
container.classList.add( 'is-fixed-sidebar' );
onScroll(); // Run once to avoid footer collisions on load (ex, when linked to #reply-title).
window.addEventListener( 'scroll', onScroll );
}
}

const toggleButton = container?.querySelector( '.wporg-table-of-contents__toggle' );
const list = container?.querySelector( '.wporg-table-of-contents__list' );

Expand Down Expand Up @@ -146,6 +137,14 @@ function init() {
} );
}

if ( container ) {
if ( isSidebarWithinViewport( container ) ) {
container.classList.add( 'is-fixed-sidebar' );
onScroll(); // Run once to avoid footer collisions on load (ex, when linked to #reply-title).
window.addEventListener( 'scroll', onScroll );
}
}

// If there is no table of contents, hide the heading.
if ( ! document.querySelector( '.wp-block-wporg-table-of-contents' ) ) {
const heading = document.querySelector( '.wp-block-wporg-sidebar-container h2' );
Expand Down

0 comments on commit b6b919e

Please sign in to comment.