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

49 lines
892 B
JavaScript
Raw Normal View History

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