|
@@ -1,226 +1,65 @@
|
|
|
// m-a stands for monthly-annual
|
|
// m-a stands for monthly-annual
|
|
|
|
|
|
|
|
-// We need this mutable variable because the group tab only have annual.
|
|
|
|
|
-// There's some difference between the monthly and annual UI
|
|
|
|
|
-// and since monthly-annual switch is disabled for the group tab,
|
|
|
|
|
-// we need to introduce a new variable to store the information
|
|
|
|
|
-let currentMonthlyAnnualSwitchValue = 'monthly'
|
|
|
|
|
-
|
|
|
|
|
-// only executed if switching to group tab
|
|
|
|
|
-export function disableMonthlyAnnualSwitching() {
|
|
|
|
|
|
|
+export function toggleMonthlyAnnualSwitching(
|
|
|
|
|
+ view,
|
|
|
|
|
+ currentMonthlyAnnualSwitchValue
|
|
|
|
|
+) {
|
|
|
const containerEl = document.querySelector(
|
|
const containerEl = document.querySelector(
|
|
|
'[data-ol-plans-v2-m-a-switch-container]'
|
|
'[data-ol-plans-v2-m-a-switch-container]'
|
|
|
)
|
|
)
|
|
|
const checkbox = containerEl.querySelector('input[type="checkbox"]')
|
|
const checkbox = containerEl.querySelector('input[type="checkbox"]')
|
|
|
|
|
|
|
|
- containerEl.classList.add('disabled')
|
|
|
|
|
-
|
|
|
|
|
- checkbox.disabled = true
|
|
|
|
|
- checkbox.checked = true
|
|
|
|
|
-
|
|
|
|
|
- document
|
|
|
|
|
- .querySelectorAll('[data-ol-plans-v2-table-container]')
|
|
|
|
|
- .forEach(el => {
|
|
|
|
|
- const period = el.getAttribute('data-ol-plans-v2-table-container')
|
|
|
|
|
- if (period === 'annual') {
|
|
|
|
|
- el.hidden = false
|
|
|
|
|
- } else {
|
|
|
|
|
- el.hidden = true
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- document
|
|
|
|
|
- .querySelectorAll('[data-ol-plans-v2-table-annual-price-before-discount]')
|
|
|
|
|
- .forEach(el => {
|
|
|
|
|
- el.classList.remove('hidden')
|
|
|
|
|
- })
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// executed if switching from group tab to individual and student tab
|
|
|
|
|
-export function enableMonthlyAnnualSwitching() {
|
|
|
|
|
- const containerEl = document.querySelector(
|
|
|
|
|
- '[data-ol-plans-v2-m-a-switch-container]'
|
|
|
|
|
- )
|
|
|
|
|
- const checkbox = containerEl.querySelector('input[type="checkbox"]')
|
|
|
|
|
- containerEl.classList.remove('disabled')
|
|
|
|
|
|
|
+ containerEl.classList.toggle('disabled', view === 'group')
|
|
|
|
|
|
|
|
- checkbox.disabled = false
|
|
|
|
|
|
|
+ checkbox.disabled = view === 'group'
|
|
|
|
|
+ checkbox.checked = currentMonthlyAnnualSwitchValue === 'annual'
|
|
|
|
|
|
|
|
- if (currentMonthlyAnnualSwitchValue === 'annual') {
|
|
|
|
|
- checkbox.checked = true
|
|
|
|
|
- } else {
|
|
|
|
|
- checkbox.checked = false
|
|
|
|
|
- document
|
|
|
|
|
- .querySelectorAll('[data-ol-plans-v2-table-container]')
|
|
|
|
|
- .forEach(el => {
|
|
|
|
|
- const period = el.getAttribute('data-ol-plans-v2-table-container')
|
|
|
|
|
- if (period === 'annual') {
|
|
|
|
|
- el.hidden = true
|
|
|
|
|
- } else {
|
|
|
|
|
- el.hidden = false
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- document
|
|
|
|
|
- .querySelectorAll('[data-ol-plans-v2-table-annual-price-before-discount]')
|
|
|
|
|
- .forEach(el => {
|
|
|
|
|
- el.classList.add('hidden')
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ switchMonthlyAnnual(currentMonthlyAnnualSwitchValue)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export function hideMonthlyAnnualSwitchOnSmallScreen() {
|
|
|
|
|
- const smallScreen = window.matchMedia('(max-width: 767px)').matches
|
|
|
|
|
-
|
|
|
|
|
- if (smallScreen) {
|
|
|
|
|
- const el = document.querySelector('[data-ol-plans-v2-m-a-switch-container]')
|
|
|
|
|
-
|
|
|
|
|
- el.hidden = true
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-export function showMonthlyAnnualSwitchOnSmallScreen() {
|
|
|
|
|
- const smallScreen = window.matchMedia('(max-width: 767px)').matches
|
|
|
|
|
-
|
|
|
|
|
- if (smallScreen) {
|
|
|
|
|
- const el = document.querySelector('[data-ol-plans-v2-m-a-switch-container]')
|
|
|
|
|
-
|
|
|
|
|
- el.hidden = false
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// in group tab, there are no "20% discount"
|
|
|
|
|
-// tooltip in the monthly-annual switch "annual" text.
|
|
|
|
|
-// so, we need to hide it
|
|
|
|
|
-export function showMonthlyAnnualTooltip() {
|
|
|
|
|
|
|
+export function switchMonthlyAnnual(currentMonthlyAnnualSwitchValue) {
|
|
|
const el = document.querySelector('[data-ol-plans-v2-m-a-tooltip]')
|
|
const el = document.querySelector('[data-ol-plans-v2-m-a-tooltip]')
|
|
|
-
|
|
|
|
|
- el.hidden = false
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-export function hideMonthlyAnnualTooltip() {
|
|
|
|
|
- const el = document.querySelector('[data-ol-plans-v2-m-a-tooltip]')
|
|
|
|
|
-
|
|
|
|
|
- el.hidden = true
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// "20% discount" tooltip in the monthly-annual switch will have a different
|
|
|
|
|
-// text and different colour, so we need to switch them accordingly
|
|
|
|
|
-function switchMonthlyAnnualTooltip() {
|
|
|
|
|
- const el = document.querySelector('[data-ol-plans-v2-m-a-tooltip]')
|
|
|
|
|
- if (currentMonthlyAnnualSwitchValue === 'annual') {
|
|
|
|
|
- el.classList.remove('plans-v2-m-a-tooltip-annual-selected')
|
|
|
|
|
- document.querySelectorAll('[data-ol-tooltip-period]').forEach(childEl => {
|
|
|
|
|
- const period = childEl.getAttribute('data-ol-tooltip-period')
|
|
|
|
|
- if (period === 'monthly') {
|
|
|
|
|
- childEl.hidden = false
|
|
|
|
|
- } else {
|
|
|
|
|
- childEl.hidden = true
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- } else {
|
|
|
|
|
- el.classList.add('plans-v2-m-a-tooltip-annual-selected')
|
|
|
|
|
- document.querySelectorAll('[data-ol-tooltip-period]').forEach(childEl => {
|
|
|
|
|
- const period = childEl.getAttribute('data-ol-tooltip-period')
|
|
|
|
|
- if (period === 'annual') {
|
|
|
|
|
- childEl.hidden = false
|
|
|
|
|
- } else {
|
|
|
|
|
- childEl.hidden = true
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-function changeMonthlyAnnualTooltipPosition() {
|
|
|
|
|
- const smallScreen = window.matchMedia('(max-width: 767px)').matches
|
|
|
|
|
- const el = document.querySelector('[data-ol-plans-v2-m-a-tooltip]')
|
|
|
|
|
-
|
|
|
|
|
- if (smallScreen) {
|
|
|
|
|
- el.classList.replace('right', 'bottom')
|
|
|
|
|
- } else {
|
|
|
|
|
- el.classList.replace('bottom', 'right')
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// month and annual value will each have its own set of tables that we need to
|
|
|
|
|
-// switch accordingly
|
|
|
|
|
-function switchMonthlyAnnualTable() {
|
|
|
|
|
- const isAnnualPricing = document.querySelector(
|
|
|
|
|
- '[data-ol-plans-v2-m-a-switch] input[type="checkbox"]'
|
|
|
|
|
- ).checked
|
|
|
|
|
-
|
|
|
|
|
- if (isAnnualPricing) {
|
|
|
|
|
- currentMonthlyAnnualSwitchValue = 'annual'
|
|
|
|
|
- } else {
|
|
|
|
|
- currentMonthlyAnnualSwitchValue = 'monthly'
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ el.classList.toggle(
|
|
|
|
|
+ 'plans-v2-m-a-tooltip-annual-selected',
|
|
|
|
|
+ currentMonthlyAnnualSwitchValue === 'annual'
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
document
|
|
document
|
|
|
.querySelectorAll('[data-ol-plans-v2-table-annual-price-before-discount]')
|
|
.querySelectorAll('[data-ol-plans-v2-table-annual-price-before-discount]')
|
|
|
.forEach(el => {
|
|
.forEach(el => {
|
|
|
- if (isAnnualPricing) {
|
|
|
|
|
- el.classList.remove('hidden')
|
|
|
|
|
- } else {
|
|
|
|
|
- el.classList.add('hidden')
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ el.classList.toggle(
|
|
|
|
|
+ 'hidden',
|
|
|
|
|
+ currentMonthlyAnnualSwitchValue === 'monthly'
|
|
|
|
|
+ )
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ document.querySelectorAll('[data-ol-plans-v2-period').forEach(el => {
|
|
|
|
|
+ const period = el.getAttribute('data-ol-plans-v2-period')
|
|
|
|
|
+
|
|
|
|
|
+ el.hidden = currentMonthlyAnnualSwitchValue !== period
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
document
|
|
document
|
|
|
- .querySelectorAll('[data-ol-plans-v2-table-container]')
|
|
|
|
|
|
|
+ .querySelectorAll('[data-ol-plans-v2-m-a-switch-text]')
|
|
|
.forEach(el => {
|
|
.forEach(el => {
|
|
|
- const period = el.getAttribute('data-ol-plans-v2-table-container')
|
|
|
|
|
- if (isAnnualPricing) {
|
|
|
|
|
- if (period === 'annual') {
|
|
|
|
|
- el.hidden = false
|
|
|
|
|
- } else {
|
|
|
|
|
- el.hidden = true
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- if (period === 'annual') {
|
|
|
|
|
- el.hidden = true
|
|
|
|
|
- } else {
|
|
|
|
|
- el.hidden = false
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ el.classList.toggle(
|
|
|
|
|
+ 'underline',
|
|
|
|
|
+ el.getAttribute('data-ol-plans-v2-m-a-switch-text') ===
|
|
|
|
|
+ currentMonthlyAnnualSwitchValue
|
|
|
|
|
+ )
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export function underlineAnnualText() {
|
|
|
|
|
- document
|
|
|
|
|
- .querySelector('[data-ol-plans-v2-m-a-switch-monthly-text]')
|
|
|
|
|
- .classList.remove('underline')
|
|
|
|
|
- document
|
|
|
|
|
- .querySelector('[data-ol-plans-v2-m-a-switch-annual-text]')
|
|
|
|
|
- .classList.add('underline')
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-function underlineMonthlyText() {
|
|
|
|
|
- document
|
|
|
|
|
- .querySelector('[data-ol-plans-v2-m-a-switch-monthly-text]')
|
|
|
|
|
- .classList.add('underline')
|
|
|
|
|
- document
|
|
|
|
|
- .querySelector('[data-ol-plans-v2-m-a-switch-annual-text]')
|
|
|
|
|
- .classList.remove('underline')
|
|
|
|
|
-}
|
|
|
|
|
|
|
+function changeMonthlyAnnualTooltipPosition() {
|
|
|
|
|
+ const smallScreen = window.matchMedia('(max-width: 767px)').matches
|
|
|
|
|
+ const el = document.querySelector('[data-ol-plans-v2-m-a-tooltip]')
|
|
|
|
|
|
|
|
-// if annual is active, we need to underline the "annual" text
|
|
|
|
|
-// if monthly is active, we need to underline the "monthly" text
|
|
|
|
|
-export function switchUnderlineText() {
|
|
|
|
|
- if (currentMonthlyAnnualSwitchValue === 'annual') {
|
|
|
|
|
- underlineAnnualText()
|
|
|
|
|
- } else {
|
|
|
|
|
- underlineMonthlyText()
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ el.classList.toggle('bottom', smallScreen)
|
|
|
|
|
+ el.classList.toggle('right', !smallScreen)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// click event listener for monthly-annual switch
|
|
// click event listener for monthly-annual switch
|
|
|
export function setUpMonthlyAnnualSwitching() {
|
|
export function setUpMonthlyAnnualSwitching() {
|
|
|
- document
|
|
|
|
|
- .querySelector('[data-ol-plans-v2-m-a-switch]')
|
|
|
|
|
- .addEventListener('click', () => {
|
|
|
|
|
- switchMonthlyAnnualTooltip()
|
|
|
|
|
- switchMonthlyAnnualTable()
|
|
|
|
|
- switchUnderlineText()
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
changeMonthlyAnnualTooltipPosition()
|
|
changeMonthlyAnnualTooltipPosition()
|
|
|
window.addEventListener('resize', changeMonthlyAnnualTooltipPosition)
|
|
window.addEventListener('resize', changeMonthlyAnnualTooltipPosition)
|
|
|
}
|
|
}
|