2019-09-30 15:38:41 +03:00
|
|
|
/*
|
|
|
|
* Hide Header on scroll down
|
|
|
|
*/
|
2020-05-29 19:48:10 +03:00
|
|
|
|
2019-09-30 15:38:41 +03:00
|
|
|
$(function() {
|
2021-12-08 12:07:18 +03:00
|
|
|
const $topbarWrapper = $("#topbar-wrapper");
|
2022-01-06 12:42:08 +03:00
|
|
|
const $topbarTitle = $("#topbar-title");
|
2021-12-08 12:07:18 +03:00
|
|
|
const $panel = $("#panel-wrapper");
|
|
|
|
const $searchInput = $("#search-input");
|
2019-09-30 15:38:41 +03:00
|
|
|
|
2021-12-08 12:07:18 +03:00
|
|
|
const CLASS_TOPBAR_UP = "topbar-up";
|
|
|
|
const CLASS_TOPBAR_DOWN = "topbar-down";
|
|
|
|
const ATTR_TOC_SCROLLING_UP = "toc-scrolling-up"; // topbar locked
|
2021-01-23 10:07:18 +03:00
|
|
|
|
|
|
|
let didScroll;
|
|
|
|
let lastScrollTop = 0;
|
|
|
|
|
2021-12-08 12:07:18 +03:00
|
|
|
const delta = $topbarWrapper.outerHeight();
|
|
|
|
const topbarHeight = $topbarWrapper.outerHeight();
|
2019-09-30 15:38:41 +03:00
|
|
|
|
|
|
|
function hasScrolled() {
|
2021-12-08 12:07:18 +03:00
|
|
|
let st = $(this).scrollTop();
|
2019-09-30 15:38:41 +03:00
|
|
|
|
2020-05-29 19:48:10 +03:00
|
|
|
/* Make sure they scroll more than delta */
|
2020-08-19 07:26:45 +03:00
|
|
|
if (Math.abs(lastScrollTop - st) <= delta) {
|
2019-09-30 15:38:41 +03:00
|
|
|
return;
|
2020-08-19 07:26:45 +03:00
|
|
|
}
|
2019-09-30 15:38:41 +03:00
|
|
|
|
2021-12-08 12:07:18 +03:00
|
|
|
if (st > lastScrollTop ) { // Scroll Down
|
|
|
|
if (st > topbarHeight) {
|
|
|
|
$topbarWrapper.removeClass(CLASS_TOPBAR_DOWN).addClass(CLASS_TOPBAR_UP);
|
|
|
|
$panel.removeClass(CLASS_TOPBAR_DOWN);
|
2019-09-30 15:38:41 +03:00
|
|
|
|
2021-12-08 12:07:18 +03:00
|
|
|
if ($searchInput.is(":focus")) {
|
|
|
|
$searchInput.blur(); /* remove focus */
|
|
|
|
}
|
2019-09-30 15:38:41 +03:00
|
|
|
}
|
2021-12-08 12:07:18 +03:00
|
|
|
} else {// Scroll up
|
|
|
|
// did not reach the bottom of the document, i.e., still have space to scroll up
|
|
|
|
if (st + $(window).height() < $(document).height()) {
|
|
|
|
let tocScrollingUp = $topbarWrapper.attr(ATTR_TOC_SCROLLING_UP);
|
|
|
|
if (typeof tocScrollingUp !== "undefined") {
|
|
|
|
if (tocScrollingUp === "false") {
|
|
|
|
$topbarWrapper.removeAttr(ATTR_TOC_SCROLLING_UP);
|
|
|
|
}
|
2019-09-30 15:38:41 +03:00
|
|
|
|
2021-12-08 12:07:18 +03:00
|
|
|
} else {
|
|
|
|
$topbarWrapper.removeClass(CLASS_TOPBAR_UP).addClass(CLASS_TOPBAR_DOWN);
|
|
|
|
$panel.addClass(CLASS_TOPBAR_DOWN);
|
|
|
|
}
|
2019-09-30 15:38:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lastScrollTop = st;
|
|
|
|
}
|
2020-08-19 07:26:45 +03:00
|
|
|
|
|
|
|
$(window).scroll(function(event) {
|
2022-01-06 12:42:08 +03:00
|
|
|
if ($topbarTitle.is(":hidden")) {
|
2020-08-19 07:26:45 +03:00
|
|
|
didScroll = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
setInterval(function() {
|
|
|
|
if (didScroll) {
|
|
|
|
hasScrolled();
|
|
|
|
didScroll = false;
|
|
|
|
}
|
|
|
|
}, 250);
|
|
|
|
|
2021-01-23 10:07:18 +03:00
|
|
|
});
|