mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-24 21:12:38 -04:00
69871fccbe
Example case: visit plans page via other pages, the hash will be empty initially, this commit will make sure hash is updated even though no initial hash exists. GitOrigin-RevId: 411585111e8cf1b3eb803059ad4cf98ae4e69b19
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
export function getViewInfoFromHash() {
|
|
const hash = window.location.hash.substring(1)
|
|
|
|
switch (hash) {
|
|
case 'individual-monthly':
|
|
return ['individual', 'monthly']
|
|
case 'individual-annual':
|
|
return ['individual', 'annual']
|
|
case 'group':
|
|
return ['group', 'annual']
|
|
case 'student-monthly':
|
|
return ['student', 'monthly']
|
|
case 'student-annual':
|
|
return ['student', 'annual']
|
|
default:
|
|
return ['individual', 'monthly']
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {individual | group | student} viewTab
|
|
* @param {monthly | annual} period
|
|
*/
|
|
export function setHashFromViewTab(viewTab, period) {
|
|
const newHash = viewTab === 'group' ? 'group' : `${viewTab}-${period}`
|
|
if (window.location.hash.substring(1) !== newHash) {
|
|
window.location.hash = newHash
|
|
}
|
|
}
|
|
|
|
// this is only for the students link in footer
|
|
export function handleForStudentsLinkInFooter() {
|
|
const links = document.querySelectorAll('[data-ol-for-students-link]')
|
|
|
|
links.forEach(function (link) {
|
|
link.addEventListener('click', function () {
|
|
if (window.location.pathname === '/user/subscription/plans') {
|
|
// reload location with the correct hash
|
|
const newURL =
|
|
'/user/subscription/plans?itm_referrer=footer-for-students#student-annual'
|
|
history.replaceState(null, '', newURL)
|
|
location.reload()
|
|
}
|
|
})
|
|
})
|
|
}
|