2022-05-12 07:38:02 -04:00
|
|
|
import '../../../../marketing'
|
|
|
|
|
2022-05-19 05:13:25 -04:00
|
|
|
import * as eventTracking from '../../../../infrastructure/event-tracking'
|
2022-06-22 08:22:11 -04:00
|
|
|
import { setUpStickyHeaderObserver } from './plans-v2-sticky-header'
|
2022-05-12 07:38:02 -04:00
|
|
|
import {
|
|
|
|
setUpMonthlyAnnualSwitching,
|
2022-06-22 08:22:11 -04:00
|
|
|
switchMonthlyAnnual,
|
|
|
|
toggleMonthlyAnnualSwitching,
|
2022-05-12 07:38:02 -04:00
|
|
|
} from './plans-v2-m-a-switch'
|
|
|
|
import {
|
|
|
|
changeGroupPlanModalEducationalDiscount,
|
|
|
|
changeGroupPlanModalNumberOfLicenses,
|
2022-05-19 07:57:36 -04:00
|
|
|
updateMainGroupPlanPricing,
|
2022-05-12 07:38:02 -04:00
|
|
|
} from './plans-v2-group-plan'
|
|
|
|
import { setUpGroupSubscriptionButtonAction } from './plans-v2-subscription-button'
|
|
|
|
import { updateLinkTargets } from '../plans'
|
|
|
|
|
2022-06-22 08:22:11 -04:00
|
|
|
// 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'
|
|
|
|
|
2022-05-12 07:38:02 -04:00
|
|
|
function selectTab(viewTab) {
|
|
|
|
document.querySelectorAll('[data-ol-plans-v2-view-tab]').forEach(el => {
|
2022-06-22 08:22:11 -04:00
|
|
|
el.classList.toggle(
|
|
|
|
'active',
|
|
|
|
el.getAttribute('data-ol-plans-v2-view-tab') === viewTab
|
|
|
|
)
|
2022-05-12 07:38:02 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
document.querySelectorAll('[data-ol-plans-v2-view]').forEach(el => {
|
|
|
|
el.hidden = el.getAttribute('data-ol-plans-v2-view') !== viewTab
|
|
|
|
})
|
|
|
|
|
2022-06-22 08:22:11 -04:00
|
|
|
document.querySelector('[data-ol-plans-v2-m-a-tooltip]').hidden =
|
|
|
|
viewTab === 'group'
|
|
|
|
document.querySelector('[data-ol-plans-v2-license-picker-container]').hidden =
|
|
|
|
viewTab !== 'group'
|
|
|
|
|
|
|
|
document
|
|
|
|
.querySelector('[data-ol-plans-v2-m-a-switch-container]')
|
|
|
|
.setAttribute('data-ol-current-view', viewTab)
|
2022-05-12 07:38:02 -04:00
|
|
|
|
|
|
|
// group tab is special because group plan only has annual value
|
|
|
|
// so we need to perform some UI changes whenever user click the group tab
|
|
|
|
if (viewTab === 'group') {
|
2022-05-19 07:57:36 -04:00
|
|
|
updateMainGroupPlanPricing()
|
2022-06-22 08:22:11 -04:00
|
|
|
toggleMonthlyAnnualSwitching(viewTab, 'annual')
|
2022-05-12 07:38:02 -04:00
|
|
|
} else {
|
2022-06-22 08:22:11 -04:00
|
|
|
toggleMonthlyAnnualSwitching(viewTab, currentMonthlyAnnualSwitchValue)
|
2022-05-12 07:38:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setUpTabSwitching() {
|
|
|
|
document.querySelectorAll('[data-ol-plans-v2-view-tab]').forEach(el => {
|
|
|
|
const viewTab = el.getAttribute('data-ol-plans-v2-view-tab')
|
|
|
|
|
|
|
|
el.querySelector('a').addEventListener('click', function (e) {
|
|
|
|
e.preventDefault()
|
2022-05-19 05:13:25 -04:00
|
|
|
eventTracking.send(
|
|
|
|
'subscription-funnel',
|
|
|
|
'plans-page',
|
|
|
|
`${viewTab}-prices`
|
|
|
|
)
|
2022-05-12 07:38:02 -04:00
|
|
|
selectTab(viewTab)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function setUpGroupPlanPricingChange() {
|
|
|
|
document
|
|
|
|
.querySelectorAll('[data-ol-plans-v2-license-picker-select]')
|
|
|
|
.forEach(el => {
|
|
|
|
el.addEventListener('change', () => {
|
2022-05-19 07:57:36 -04:00
|
|
|
updateMainGroupPlanPricing()
|
|
|
|
changeGroupPlanModalNumberOfLicenses()
|
2022-05-12 07:38:02 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
document
|
|
|
|
.querySelectorAll(
|
|
|
|
'[data-ol-plans-v2-license-picker-educational-discount-input]'
|
|
|
|
)
|
|
|
|
.forEach(el =>
|
|
|
|
el.addEventListener('change', () => {
|
2022-05-19 07:57:36 -04:00
|
|
|
updateMainGroupPlanPricing()
|
|
|
|
changeGroupPlanModalEducationalDiscount()
|
2022-05-12 07:38:02 -04:00
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-06-23 05:22:04 -04:00
|
|
|
function selectViewFromHash() {
|
|
|
|
try {
|
|
|
|
const params = new URLSearchParams(window.location.hash.substring(1))
|
|
|
|
const view = params.get('view')
|
|
|
|
if (view) {
|
|
|
|
// make sure the selected view is valid
|
|
|
|
if (document.querySelector(`[data-ol-plans-v2-view-tab="${view}"]`)) {
|
|
|
|
selectTab(view)
|
|
|
|
// clear the hash so it doesn't persist when switching plans
|
|
|
|
window.location.hash = ''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-22 08:22:11 -04:00
|
|
|
document
|
|
|
|
.querySelector('[data-ol-plans-v2-m-a-switch]')
|
|
|
|
.addEventListener('click', () => {
|
|
|
|
const isAnnualPricing = document.querySelector(
|
|
|
|
'[data-ol-plans-v2-m-a-switch] input[type="checkbox"]'
|
|
|
|
).checked
|
|
|
|
|
|
|
|
if (isAnnualPricing) {
|
|
|
|
currentMonthlyAnnualSwitchValue = 'annual'
|
|
|
|
} else {
|
|
|
|
currentMonthlyAnnualSwitchValue = 'monthly'
|
|
|
|
}
|
|
|
|
|
|
|
|
switchMonthlyAnnual(currentMonthlyAnnualSwitchValue)
|
|
|
|
})
|
|
|
|
|
2022-05-12 07:38:02 -04:00
|
|
|
setUpTabSwitching()
|
|
|
|
setUpGroupPlanPricingChange()
|
|
|
|
setUpMonthlyAnnualSwitching()
|
|
|
|
setUpGroupSubscriptionButtonAction()
|
|
|
|
setUpStickyHeaderObserver()
|
|
|
|
updateLinkTargets()
|
2022-06-23 05:22:04 -04:00
|
|
|
|
|
|
|
selectViewFromHash()
|
|
|
|
window.addEventListener('hashchange', selectViewFromHash)
|