From cd836e855af9a49f9363111343d23e9fe61ee65c Mon Sep 17 00:00:00 2001 From: Mark Conroy Date: Tue, 28 Jan 2025 12:07:31 +0000 Subject: [PATCH] Fixes eslint issues in sticky-header.js (#693) * fixes eslint issues in sticky-header.js * fix: change quotes to single --------- Co-authored-by: Lee Mills --- js/sticky-header.js | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/js/sticky-header.js b/js/sticky-header.js index 9ae05dba..3f333a41 100644 --- a/js/sticky-header.js +++ b/js/sticky-header.js @@ -1,22 +1,30 @@ (function stickyHeaderScript(Drupal) { Drupal.behaviors.stickyHeader = { - attach: function (context) { - const headers = once('allSticyHeaders', '.lgd-header', context); + attach(context) { + const headers = once('allStickyHeaders', '.lgd-header', context); if (!headers) { return; } - headers.forEach(header => { + headers.forEach((header) => { function calculatePositions() { let tabsHeight = 0; - const tabs = header.closest('body').querySelector('.lgd-region--tabs'); + const tabs = header + .closest('body') + .querySelector('.lgd-region--tabs'); if (tabs) { tabsHeight = tabs.offsetHeight; } let displaceOffsetTop = 0; - const displaceOffsetTopValue = parseInt(getComputedStyle(document.documentElement).getPropertyValue('--drupal-displace-offset-top').replace('px', '')); + const displaceOffsetTopValue = parseInt( + getComputedStyle(document.documentElement) + .getPropertyValue('--drupal-displace-offset-top') + .replace('px', ''), + 10, + ); + console.log('working'); if (displaceOffsetTopValue) { displaceOffsetTop = displaceOffsetTopValue; } @@ -25,11 +33,19 @@ const headerPosition = displaceOffsetTop + tabsHeight; if (header.closest('body').classList.contains('sticky-header')) { - document.documentElement.style.setProperty('--lgd-sticky-header-position', `${headerPosition}px`); - document.documentElement.style.setProperty('--lgd-sticky-header-height', `${headerHeight}px`); + document.documentElement.style.setProperty( + '--lgd-sticky-header-position', + `${headerPosition}px`, + ); + document.documentElement.style.setProperty( + '--lgd-sticky-header-height', + `${headerHeight}px`, + ); } - if (header.closest('body').classList.contains('sticky-header--sticky')) { + if ( + header.closest('body').classList.contains('sticky-header--sticky') + ) { header.style.position = 'fixed'; } } @@ -50,16 +66,16 @@ calculatePositions(); } - if (header.closest('body').classList.contains('sticky-header--scroll')) { + if ( + header.closest('body').classList.contains('sticky-header--scroll') + ) { window.addEventListener('scroll', handleScroll); } setTimeout(() => { calculatePositions(); }, 50); - }); - - } + }, }; -})(Drupal); \ No newline at end of file +})(Drupal);