Просмотр исходного кода

Port ability to set plans page tab view with URL hash

GitOrigin-RevId: 367829b46a1e984f19a131999938c554a960eccf
Thomas Mees 4 лет назад
Родитель
Сommit
b3d5a2c7f0

+ 20 - 0
services/web/frontend/js/pages/user/subscription/plans-v2/plans-v2-main.js

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