mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
8157616f85
GitOrigin-RevId: 4e4629583c6e86bd2bc6165d123224734c133df7
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
// we have different sticky header according to plans (individual, group, and student)
|
|
// we need to show different sticky header based on active tab
|
|
// the value of attribute 'data-ol-plans-v2-table-sticky-header' can be individual, group, or student
|
|
export function switchStickyHeader(viewTab) {
|
|
document
|
|
.querySelectorAll('[data-ol-plans-v2-table-sticky-header]')
|
|
.forEach(el => {
|
|
const plan = el.getAttribute('data-ol-plans-v2-table-sticky-header')
|
|
|
|
if (plan === viewTab) {
|
|
el.hidden = false
|
|
} else {
|
|
el.hidden = true
|
|
}
|
|
})
|
|
}
|
|
|
|
function stickyHeaderObserverCallback(entry) {
|
|
const entryItem = entry[0]
|
|
|
|
if (entryItem.boundingClientRect.bottom <= 0) {
|
|
document
|
|
.querySelectorAll('[data-ol-plans-v2-table-sticky-header]')
|
|
.forEach(el => el.classList.remove('sticky'))
|
|
} else {
|
|
document
|
|
.querySelectorAll('[data-ol-plans-v2-table-sticky-header]')
|
|
.forEach(el => el.classList.add('sticky'))
|
|
}
|
|
}
|
|
|
|
export function setUpStickyHeaderObserver() {
|
|
const stickyHeaderStopEl = document.querySelector(
|
|
'[data-ol-plans-v2-table-sticky-header-stop]'
|
|
)
|
|
|
|
const observer = new IntersectionObserver(stickyHeaderObserverCallback)
|
|
|
|
observer.observe(stickyHeaderStopEl)
|
|
}
|