MDL-75762 theme_boost: fix sticky footer page scroll

This commit is contained in:
Ferran Recio 2023-05-25 17:20:06 +02:00 committed by Laurent David
parent 310122010e
commit c7e9af30df
6 changed files with 7 additions and 21 deletions

View File

@ -5,6 +5,6 @@ define("theme_boost/sticky-footer",["exports","core/pending","core/sticky-footer
* @module theme_boost/sticky-footer
* @copyright 2022 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=_exports.enableStickyFooter=_exports.disableStickyFooter=void 0,_pending=(obj=_pending)&&obj.__esModule?obj:{default:obj};const SELECTORS_STICKYFOOTER=".stickyfooter",SELECTORS_PAGE="#page",CLASSES_HASSTICKYFOOTER="hasstickyfooter";let initialized=!1,previousScrollPosition=0,enabled=!1;const scrollSpy=()=>{if(!enabled)return;if(document.body.clientWidth>=768)return;let scrollPosition=(()=>{const page=document.querySelector(SELECTORS_PAGE);return page?page.scrollTop:window.pageYOffset})();scrollPosition>previousScrollPosition?hideStickyFooter():showStickyFooter(),previousScrollPosition=scrollPosition},showStickyFooter=()=>{const pendingPromise=new _pending.default("theme_boost/sticky-footer:enabling"),footer=document.querySelector(SELECTORS_STICKYFOOTER),page=document.querySelector(SELECTORS_PAGE);footer&&page&&(document.body.classList.add(CLASSES_HASSTICKYFOOTER),page.classList.add(CLASSES_HASSTICKYFOOTER)),setTimeout((()=>pendingPromise.resolve()),1e3)},hideStickyFooter=()=>{document.body.classList.remove(CLASSES_HASSTICKYFOOTER);const page=document.querySelector(SELECTORS_PAGE);null==page||page.classList.remove(CLASSES_HASSTICKYFOOTER)},enableStickyFooter=()=>{enabled=!0,showStickyFooter()};_exports.enableStickyFooter=enableStickyFooter;const disableStickyFooter=()=>{enabled=!1,hideStickyFooter()};_exports.disableStickyFooter=disableStickyFooter;_exports.init=()=>{var _document$querySelect;if(initialized||document.body.classList.contains("behat-site"))return void(0,_stickyFooter.init)();initialized=!0,(()=>{const footer=document.querySelector(SELECTORS_STICKYFOOTER);return!!footer&&!!footer.dataset.disable})()||enableStickyFooter();(null!==(_document$querySelect=document.querySelector(SELECTORS_PAGE))&&void 0!==_document$querySelect?_document$querySelect:document.body).addEventListener("scroll",scrollSpy),(0,_stickyFooter.registerManager)({enableStickyFooter:enableStickyFooter,disableStickyFooter:disableStickyFooter})}}));
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=_exports.enableStickyFooter=_exports.disableStickyFooter=void 0,_pending=(obj=_pending)&&obj.__esModule?obj:{default:obj};const SELECTORS_STICKYFOOTER=".stickyfooter",SELECTORS_PAGE="#page",CLASSES_HASSTICKYFOOTER="hasstickyfooter";let initialized=!1,previousScrollPosition=0,enabled=!1;const scrollSpy=()=>{if(!enabled)return;if(document.body.clientWidth>=768)return;let scrollPosition=window.scrollY;scrollPosition>previousScrollPosition?hideStickyFooter():showStickyFooter(),previousScrollPosition=scrollPosition},showStickyFooter=()=>{const pendingPromise=new _pending.default("theme_boost/sticky-footer:enabling"),footer=document.querySelector(SELECTORS_STICKYFOOTER),page=document.querySelector(SELECTORS_PAGE);footer&&page&&(document.body.classList.add(CLASSES_HASSTICKYFOOTER),page.classList.add(CLASSES_HASSTICKYFOOTER)),setTimeout((()=>pendingPromise.resolve()),1e3)},hideStickyFooter=()=>{document.body.classList.remove(CLASSES_HASSTICKYFOOTER);const page=document.querySelector(SELECTORS_PAGE);null==page||page.classList.remove(CLASSES_HASSTICKYFOOTER)},enableStickyFooter=()=>{enabled=!0,showStickyFooter()};_exports.enableStickyFooter=enableStickyFooter;const disableStickyFooter=()=>{enabled=!1,hideStickyFooter()};_exports.disableStickyFooter=disableStickyFooter;_exports.init=()=>{initialized||document.body.classList.contains("behat-site")?(0,_stickyFooter.init)():(initialized=!0,(()=>{const footer=document.querySelector(SELECTORS_STICKYFOOTER);return!!footer&&!!footer.dataset.disable})()||enableStickyFooter(),document.addEventListener("scroll",scrollSpy),(0,_stickyFooter.registerManager)({enableStickyFooter:enableStickyFooter,disableStickyFooter:disableStickyFooter}))}}));
//# sourceMappingURL=sticky-footer.min.js.map

File diff suppressed because one or more lines are too long

View File

@ -39,19 +39,6 @@ let previousScrollPosition = 0;
let enabled = false;
/**
* Return the current page scroll position.
* @package
* @returns {number} the current scroll position
*/
const getScrollPosition = () => {
const page = document.querySelector(SELECTORS.PAGE);
if (page) {
return page.scrollTop;
}
return window.pageYOffset;
};
/**
* Scroll handler.
* @package
@ -65,7 +52,7 @@ const scrollSpy = () => {
return;
}
// Detect if scroll is going down.
let scrollPosition = getScrollPosition();
let scrollPosition = window.scrollY;
if (scrollPosition > previousScrollPosition) {
hideStickyFooter();
} else {
@ -139,9 +126,8 @@ export const init = () => {
if (!isDisabledByDefault()) {
enableStickyFooter();
}
const content = document.querySelector(SELECTORS.PAGE) ?? document.body;
content.addEventListener("scroll", scrollSpy);
document.addEventListener("scroll", scrollSpy);
registerManager({
enableStickyFooter,

View File

@ -14,7 +14,7 @@ body {
height: $stickyfooter-height;
bottom: calc(#{$stickyfooter-height} * -1);
transition: bottom .5s;
z-index: $zindex-dropdown;
z-index: $zindex-fixed;
overflow: hidden;
box-shadow: 0 0 1rem rgba($black, .15);
font-size: calc(#{$font-size-base} * 1.10);

View File

@ -35845,7 +35845,7 @@ body {
height: max(96px, 0.9375rem * 3);
bottom: calc(max(96px, 0.9375rem * 3) * -1);
transition: bottom 0.5s;
z-index: 1000;
z-index: 1030;
overflow: hidden;
box-shadow: 0 0 1rem rgba(0, 0, 0, 0.15);
font-size: calc(0.9375rem * 1.10);

View File

@ -35779,7 +35779,7 @@ body {
height: max(96px, 0.9375rem * 3);
bottom: calc(max(96px, 0.9375rem * 3) * -1);
transition: bottom 0.5s;
z-index: 1000;
z-index: 1030;
overflow: hidden;
box-shadow: 0 0 1rem rgba(0, 0, 0, 0.15);
font-size: calc(0.9375rem * 1.10);