webpack-bootstrap-ui-kit/src/js/_components/_ui.shrink.js

42 lines
759 B
JavaScript
Raw Normal View History

2020-08-03 23:15:00 +02:00
'use strict';
2019-06-08 17:20:51 +02:00
import $ from 'jquery';
2020-08-03 23:15:00 +02:00
import Events from '../_events';
2019-06-08 17:20:51 +02:00
const ShrinkUI = (($) => {
// Constants
2020-08-03 23:15:00 +02:00
const W = window;
2019-06-08 17:20:51 +02:00
const D = document;
2020-08-03 23:15:00 +02:00
const NAME = 'ShrinkUI';
2019-06-08 17:20:51 +02:00
2020-08-03 23:15:00 +02:00
console.log(`${NAME}: init`);
$(W).on(`${Events.LOADED} ${Events.SCROLL} ${Events.RESIZE}`, () => {
let h1 = $('#SiteWideMessage').height();
if (!h1) {
h1 = 0;
}
let h2 = $('#SiteWideOffline').height();
if (!h2) {
h2 = 0;
}
let h3 = $('#Header').height();
if (!h3) {
h3 = 0;
}
const headerHeight = h1 + h2 + h3;
if ($(D).scrollTop() > headerHeight) {
2019-06-08 17:20:51 +02:00
$('body').addClass('shrink');
} else {
$('body').removeClass('shrink');
}
});
return ShrinkUI;
})($);
export default ShrinkUI;