2022-01-09 14:09:29 +03:00
|
|
|
/**
|
|
|
|
* A tool for smooth scrolling and topbar switcher
|
|
|
|
*/
|
|
|
|
const ScrollHelper = (function () {
|
2022-10-25 14:26:44 +03:00
|
|
|
const $body = $("body");
|
|
|
|
const ATTR_TOPBAR_VISIBLE = "data-topbar-visible";
|
|
|
|
const topbarHeight = $("#topbar-wrapper").outerHeight();
|
2022-01-09 14:09:29 +03:00
|
|
|
|
2022-10-25 14:26:44 +03:00
|
|
|
let scrollUpCount = 0; // the number of times the scroll up was triggered by ToC or anchor
|
|
|
|
let topbarLocked = false;
|
|
|
|
let orientationLocked = false;
|
2022-01-09 14:09:29 +03:00
|
|
|
|
2022-10-25 14:26:44 +03:00
|
|
|
return {
|
2023-02-14 23:53:40 +03:00
|
|
|
hideTopbar: () => $body.attr(ATTR_TOPBAR_VISIBLE, 'false'),
|
|
|
|
showTopbar: () => $body.attr(ATTR_TOPBAR_VISIBLE, 'true'),
|
2022-01-09 14:09:29 +03:00
|
|
|
|
2022-10-25 14:26:44 +03:00
|
|
|
// scroll up
|
2022-01-09 14:09:29 +03:00
|
|
|
|
2022-10-25 14:26:44 +03:00
|
|
|
addScrollUpTask: () => {
|
|
|
|
scrollUpCount += 1;
|
|
|
|
if (!topbarLocked) {
|
|
|
|
topbarLocked = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
popScrollUpTask: () => scrollUpCount -= 1,
|
|
|
|
hasScrollUpTask: () => scrollUpCount > 0,
|
|
|
|
topbarLocked: () => topbarLocked === true,
|
|
|
|
unlockTopbar: () => topbarLocked = false,
|
|
|
|
getTopbarHeight: () => topbarHeight,
|
2022-01-09 14:09:29 +03:00
|
|
|
|
2022-10-25 14:26:44 +03:00
|
|
|
// orientation change
|
2022-01-09 14:09:29 +03:00
|
|
|
|
2022-10-25 14:26:44 +03:00
|
|
|
orientationLocked: () => orientationLocked === true,
|
|
|
|
lockOrientation: () => orientationLocked = true,
|
|
|
|
unLockOrientation: () => orientationLocked = false
|
|
|
|
};
|
2022-01-09 14:09:29 +03:00
|
|
|
|
|
|
|
}());
|