webpack-bootstrap-ui-kit/src/js/_components/_ui.header-footer.js

70 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-05-13 16:47:49 +02:00
'use strict';
import Events from '../_events';
const HeaderUI = (($) => {
const D = document;
const W = window;
const $Body = $('html,body');
const NAME = 'HeaderUI';
const CLASSNAME = `js${NAME}`;
class HeaderUI {
static init() {
const ui = this;
ui.dispose();
2020-05-13 18:05:34 +02:00
//console.log(`Initializing: ${NAME}`);
2020-05-13 16:47:49 +02:00
2020-05-13 18:05:34 +02:00
const $header = $(`#Header,.js${NAME}`);
2020-05-13 16:47:49 +02:00
const updateHeader = () => {
const h = $header.height();
const s = $Body.scrollTop();
if (s > h) {
$Body.addClass('shrink');
} else {
$Body.removeClass('shrink');
}
};
updateHeader();
const updateFooter = (i, el) => {
const $el = $(el);
const footerHeight = $el.height();
2020-05-24 08:58:18 +02:00
$el.css('height', footerHeight);
2020-05-13 16:47:49 +02:00
$el.css('margin-top', -footerHeight);
$el.siblings('.wrapper').css('padding-bottom', footerHeight);
};
2020-05-24 08:58:18 +02:00
$('.footer,.jsFooterUI').css('height', 'auto');
setTimeout(() => {
$('.footer,.jsFooterUI').each(updateFooter);
}, 500);
2020-05-13 16:47:49 +02:00
}
static dispose() {
2020-05-13 21:22:15 +02:00
$Body.removeClass('shrink');
2020-05-13 21:31:19 +02:00
$(`#Header,.js${NAME},.footer,.jsFooterUI,.wrapper`).attr('css', '');
2020-05-13 16:47:49 +02:00
}
}
$(W).on(`${Events.AJAX} ${Events.LOADED}`, () => {
HeaderUI.init();
});
// align event content
$(W).on(`${Events.RESIZE}`, () => {
setTimeout(() => {
HeaderUI.init();
}, 200);
});
2020-05-13 16:47:49 +02:00
W.HeaderUI = new HeaderUI();
return HeaderUI;
})($);
export default HeaderUI;