Skip to content
Snippets Groups Projects

Issue #3526123: Fixed sticky table header issue when toolbar sticky disable,...

Files
4
+ 45
0
/**
* @file
* Admin Toolbar disable sticky behavior JS.
*/
(($, Drupal, once) => {
/**
* Implements the Admin Toolbar configured 'disabled sticky behavior'.
*
* @type {Drupal~behavior}
*
* @prop {Drupal~behaviorAttach} attach
* Attaches the behavior to remove reset top offset.
*/
Drupal.behaviors.adminToolbarDisableStickyBehavior = {
attach (context) {
if (context !== document) {
return;
}
// If toolbar 'stickyness' is disabled, the toolbar should not be
// included in the calculation of the top offset. Listen for the offset
// change event and remove data-offset-top attributes from toolbar-bar
// and any active toolbar-tray.
once('admin-toolbar-disable-sticky', 'body', context).forEach(() => {
$(document).on(
`drupalViewportOffsetChange`,
() => {
document.getElementById('toolbar-bar')
.removeAttribute('data-offset-top');
document.querySelector('.toolbar-tray.is-active')
?.removeAttribute('data-offset-top');
// Trigger a recalculation of viewport displacing elements.
// Use setTimeout to ensure this recalculation happens after
// changes to visual elements have processed.
setTimeout(() => {
Drupal.displace(false);
}, "500");
},
);
});
},
};
})(jQuery, Drupal, once);
Loading