forked from a64f7bb4-7358-4778-9fbe-3b882c34cc1d/v1
28 lines
935 B
JavaScript
28 lines
935 B
JavaScript
/* eslint-disable no-bitwise, no-nested-ternary, no-mutable-exports, comma-dangle, strict */
|
|
|
|
'use strict';
|
|
|
|
((Drupal) => {
|
|
Drupal.behaviors.ginSticky = {
|
|
attach: (context) => {
|
|
const ginSticky = once('ginSticky', document.querySelectorAll('.region-sticky-watcher'));
|
|
ginSticky.forEach(() => {
|
|
// Watch sticky header
|
|
const observer = new IntersectionObserver(
|
|
([e]) => {
|
|
const regionSticky = context.querySelector('.region-sticky');
|
|
regionSticky.classList.toggle('region-sticky--is-sticky', e.intersectionRatio < 1);
|
|
regionSticky.toggleAttribute('data-offset-top', e.intersectionRatio < 1);
|
|
Drupal.displace(true);
|
|
},
|
|
{ threshold: [1] }
|
|
);
|
|
const element = context.querySelector('.region-sticky-watcher');
|
|
if (element) {
|
|
observer.observe(element);
|
|
}
|
|
});
|
|
}
|
|
};
|
|
})(Drupal);
|