refactor(stickyHeader): ♻️ create sticky sentinel in JS instead

It is only used for sticky header which requires JS, we should just create it in JS
This commit is contained in:
alistair3149 2024-07-02 19:20:17 -04:00
parent d71ee758f4
commit 7ec0ae5b8e
No known key found for this signature in database
2 changed files with 6 additions and 5 deletions

View file

@ -1,6 +1,5 @@
const SCROLL_DOWN_CLASS = 'citizen-scroll--down';
const SCROLL_UP_CLASS = 'citizen-scroll--up';
const STICKY_SENTINEL_ID = 'citizen-page-header-sticky-sentinel';
const STICKY_CLASS = 'citizen-page-header--sticky';
const { initDirectionObserver, initIntersectionObserver } = require( './scrollObserver.js' );
@ -28,11 +27,14 @@ function observeScrollDirection() {
* @return {void}
*/
function init() {
const sentinel = document.getElementById( STICKY_SENTINEL_ID );
const shouldStickyHeader = sentinel && getComputedStyle( sentinel ).getPropertyValue( 'display' ) !== 'none';
observeScrollDirection();
const header = document.querySelector( '.citizen-page-header' );
const sentinel = document.createElement( 'div' );
sentinel.id = 'citizen-page-header-sticky-sentinel';
header.insertAdjacentElement( 'afterend', sentinel );
const shouldStickyHeader = getComputedStyle( sentinel ).getPropertyValue( 'display' ) !== 'none';
if ( !shouldStickyHeader ) {
return;
}

View file

@ -2,4 +2,3 @@
{{#data-page-heading}}{{>PageHeading}}{{/data-page-heading}}
{{>PageTools}}
</header>
<div id="citizen-page-header-sticky-sentinel"></div>