Skip to content

Commit

Permalink
Header UI fixes (#2371)
Browse files Browse the repository at this point in the history
* Revert "Fix header contents moving when opening modal (#2131)"
* Fix header contents moving when modal opened/closed.

Conditionally apply the navbar-fixed-top class only when needed, so that we can take advantage of it without always having the navbar in position:fixed, as was done in the previous solution. That resulted in a clash with custom headers.

* Show header on refresh of scrolled page

Due to some magic in Mithril 0.1's context:retain flag, some DOM elements were cached across page reloads. Since that has been eliminated, if we refresh the page and we are scrolled down, the "affix" class which makes the header fixed (and as a result, visible) isn't applied until the first scroll. We fix this by running ScrollListener.update() immediately to set initial navbar state.
  • Loading branch information
askvortsov1 authored Oct 9, 2020
1 parent bb69c3b commit 1d2f0ca
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
12 changes: 9 additions & 3 deletions js/src/common/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,19 @@ export default class Application {
m.route(document.getElementById('content'), basePath + '/', mapRoutes(this.routes, basePath));

// Add a class to the body which indicates that the page has been scrolled
// down.
new ScrollListener((top) => {
// down. When this happens, we'll add classes to the header and app body
// which will set the navbar's position to fixed. We don't want to always
// have it fixed, as that could overlap with custom headers.
const scrollListener = new ScrollListener((top) => {
const $app = $('#app');
const offset = $app.offset().top;

$app.toggleClass('affix', top >= offset).toggleClass('scrolled', top > offset);
}).start();
$('.App-header').toggleClass('navbar-fixed-top', top >= offset);
});

scrollListener.start();
scrollListener.update();

$(() => {
$('body').addClass('ontouchstart' in window ? 'touch' : 'no-touch');
Expand Down
6 changes: 5 additions & 1 deletion less/common/App.less
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,16 @@
.App-header {
padding: 8px;
height: @header-height;
position: fixed;
position: absolute;
top: 0;
left: 0;
right: 0;
z-index: @zindex-header;

.affix & {
position: fixed;
}

& when (@config-colored-header = true) {
.light-contents(@header-color, @header-control-bg, @header-control-color);
}
Expand Down
2 changes: 1 addition & 1 deletion views/frontend/admin.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<div id="drawer" class="App-drawer">

<header id="header" class="App-header navbar-fixed-top">
<header id="header" class="App-header">
<div id="header-navigation" class="Header-navigation"></div>
<div class="container">
<h1 class="Header-title">
Expand Down
2 changes: 1 addition & 1 deletion views/frontend/forum.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<div id="drawer" class="App-drawer">

<header id="header" class="App-header navbar-fixed-top">
<header id="header" class="App-header">
<div id="header-navigation" class="Header-navigation"></div>
<div class="container">
<h1 class="Header-title">
Expand Down

0 comments on commit 1d2f0ca

Please sign in to comment.