fix(header): non-sticky header touches the top of the page (body padding-top 0px)

The parent vanilla theme.css statically sets body { padding-top: 90px } and
theme.js fixBodyPadding() always sets the inline padding to the header height.
Our fixBodyPaddingSticky() correction cleared the inline style when the header
was not fixed, so the stylesheet's 90px applied and a non-sticky header sat
~90px below the top. Now it sets padding-top: 0px explicitly when the computed
position is not 'fixed' (custom.js loads after theme.js, so this correction
runs last on ready/pjax:scriptcomplete/resize). Regression test
variants/tests/custom_js_sticky.test.js (jsdom): fails on the old code
(padding cleared to ''), passes now; suite 8/8.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Tammo ter Hark 2026-11-29 12:59:11 +01:00
commit 4d5f66e1f5

View file

@ -43,9 +43,12 @@ $(document).on('ready pjax:scriptcomplete',function(){
* screen sizes (theme options headersticky + headersticky{computer,tablet,
* mobile}, applied as media queries in custom_header.twig). The parent
* theme.js fixBodyPadding() assumes a permanently fixed header and always
* sets body padding-top to the header height; this correction runs after it
* and removes that padding when the header is NOT fixed at the current
* viewport width (computed position != 'fixed').
* sets body padding-top to the header height (and the parent theme.css
* statically sets body { padding-top: 90px }); this correction runs after
* it (custom.js loads after theme.js) and sets the padding to the header
* height when the header IS fixed at the current viewport width, or to 0
* when it is NOT (computed position != 'fixed') — so a non-sticky header
* sits at the very top of the page.
*/
var fixBodyPaddingSticky = function () {
var nav = $('#survey-nav');
@ -53,7 +56,10 @@ $(document).on('ready pjax:scriptcomplete',function(){
if (nav.css('position') === 'fixed') {
$('body').css('padding-top', Math.round(nav.height()) + 'px');
} else {
$('body').css('padding-top', '');
/* NOT '' (clearing the inline style): that would fall back to the
parent theme.css rule body { padding-top: 90px } and push the
static header 90px down. Set 0 explicitly. */
$('body').css('padding-top', '0px');
}
};
// namespaced so re-running on pjax:scriptcomplete never stacks duplicate handlers