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'
|
|
|
|
checkbox.checked = currentMonthlyAnnualSwitchValue === 'annual'
|
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(
|
|
|
|
'plans-v2-m-a-tooltip-annual-selected',
|
|
|
|
currentMonthlyAnnualSwitchValue === 'annual'
|
|
|
|
)
|
2022-05-12 07:38:02 -04:00
|
|
|
|
|
|
|
document
|
|
|
|
.querySelectorAll('[data-ol-plans-v2-table-annual-price-before-discount]')
|
|
|
|
.forEach(el => {
|
2022-06-22 08:22:11 -04:00
|
|
|
el.classList.toggle(
|
|
|
|
'hidden',
|
|
|
|
currentMonthlyAnnualSwitchValue === 'monthly'
|
|
|
|
)
|
2022-05-12 07:38:02 -04:00
|
|
|
})
|
|
|
|
|
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)
|
|
|
|
el.classList.toggle('right', !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
|
|
|
}
|