2022-05-12 07:38:02 -04:00
|
|
|
// m-a stands for monthly-annual
|
|
|
|
|
2022-06-22 08:22:11 -04:00
|
|
|
export function toggleMonthlyAnnualSwitching(
|
|
|
|
view,
|
|
|
|
currentMonthlyAnnualSwitchValue
|
|
|
|
) {
|
2022-05-12 07:38:02 -04:00
|
|
|
const containerEl = document.querySelector(
|
|
|
|
'[data-ol-plans-v2-m-a-switch-container]'
|
|
|
|
)
|
|
|
|
const checkbox = containerEl.querySelector('input[type="checkbox"]')
|
|
|
|
|
2022-06-22 08:22:11 -04:00
|
|
|
containerEl.classList.toggle('disabled', view === 'group')
|
2022-05-12 07:38:02 -04:00
|
|
|
|
2022-06-22 08:22:11 -04:00
|
|
|
checkbox.disabled = view === 'group'
|
2023-01-27 10:04:33 -05:00
|
|
|
checkbox.checked = currentMonthlyAnnualSwitchValue === 'monthly'
|
2022-05-12 07:38:02 -04:00
|
|
|
|
2022-06-22 08:22:11 -04:00
|
|
|
switchMonthlyAnnual(currentMonthlyAnnualSwitchValue)
|
2022-05-12 07:38:02 -04:00
|
|
|
}
|
|
|
|
|
2022-06-22 08:22:11 -04:00
|
|
|
export function switchMonthlyAnnual(currentMonthlyAnnualSwitchValue) {
|
2022-05-12 07:38:02 -04:00
|
|
|
const el = document.querySelector('[data-ol-plans-v2-m-a-tooltip]')
|
2022-06-22 08:22:11 -04:00
|
|
|
el.classList.toggle(
|
2023-01-27 10:04:33 -05:00
|
|
|
'plans-v2-m-a-tooltip-monthly-selected',
|
|
|
|
currentMonthlyAnnualSwitchValue === 'monthly'
|
2022-06-22 08:22:11 -04:00
|
|
|
)
|
2022-05-12 07:38:02 -04:00
|
|
|
|
2022-06-28 09:36:35 -04:00
|
|
|
document.querySelectorAll('[data-ol-tooltip-period]').forEach(el => {
|
|
|
|
const period = el.getAttribute('data-ol-tooltip-period')
|
|
|
|
el.hidden = period !== currentMonthlyAnnualSwitchValue
|
|
|
|
})
|
|
|
|
|
2022-06-22 08:22:11 -04:00
|
|
|
document.querySelectorAll('[data-ol-plans-v2-period').forEach(el => {
|
|
|
|
const period = el.getAttribute('data-ol-plans-v2-period')
|
|
|
|
|
|
|
|
el.hidden = currentMonthlyAnnualSwitchValue !== period
|
|
|
|
})
|
|
|
|
|
2022-05-12 07:38:02 -04:00
|
|
|
document
|
2022-06-22 08:22:11 -04:00
|
|
|
.querySelectorAll('[data-ol-plans-v2-m-a-switch-text]')
|
2022-05-12 07:38:02 -04:00
|
|
|
.forEach(el => {
|
2022-06-22 08:22:11 -04:00
|
|
|
el.classList.toggle(
|
|
|
|
'underline',
|
|
|
|
el.getAttribute('data-ol-plans-v2-m-a-switch-text') ===
|
|
|
|
currentMonthlyAnnualSwitchValue
|
|
|
|
)
|
2022-05-12 07:38:02 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-06-22 08:22:11 -04:00
|
|
|
function changeMonthlyAnnualTooltipPosition() {
|
|
|
|
const smallScreen = window.matchMedia('(max-width: 767px)').matches
|
|
|
|
const el = document.querySelector('[data-ol-plans-v2-m-a-tooltip]')
|
2022-05-12 07:38:02 -04:00
|
|
|
|
2022-06-22 08:22:11 -04:00
|
|
|
el.classList.toggle('bottom', smallScreen)
|
2023-01-27 10:04:33 -05:00
|
|
|
el.classList.toggle('left', !smallScreen)
|
2022-05-12 07:38:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// click event listener for monthly-annual switch
|
|
|
|
export function setUpMonthlyAnnualSwitching() {
|
2022-05-17 04:32:01 -04:00
|
|
|
changeMonthlyAnnualTooltipPosition()
|
|
|
|
window.addEventListener('resize', changeMonthlyAnnualTooltipPosition)
|
2022-05-12 07:38:02 -04:00
|
|
|
}
|