Port ability to set plans page tab view with URL hash

GitOrigin-RevId: 367829b46a1e984f19a131999938c554a960eccf
This commit is contained in:
Thomas Mees 2022-06-23 11:22:04 +02:00 committed by Copybot
parent 0cb51a3d52
commit b3d5a2c7f0

View file

@ -90,6 +90,23 @@ function setUpGroupPlanPricingChange() {
) )
} }
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
}
}
document document
.querySelector('[data-ol-plans-v2-m-a-switch]') .querySelector('[data-ol-plans-v2-m-a-switch]')
.addEventListener('click', () => { .addEventListener('click', () => {
@ -112,3 +129,6 @@ setUpMonthlyAnnualSwitching()
setUpGroupSubscriptionButtonAction() setUpGroupSubscriptionButtonAction()
setUpStickyHeaderObserver() setUpStickyHeaderObserver()
updateLinkTargets() updateLinkTargets()
selectViewFromHash()
window.addEventListener('hashchange', selectViewFromHash)