overleaf/services/web/frontend/js/pages/user/subscription/plans-v2/plans-v2-sticky-header.js
M Fahru 8157616f85 [web] New Plans Page for A/B Test (#7330)
GitOrigin-RevId: 4e4629583c6e86bd2bc6165d123224734c133df7
2022-05-13 08:03:30 +00:00

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)
}