Skip to content

Commit 5a4e84e

Browse files
committed
Go to latest with path if exists
1 parent 86e0e6f commit 5a4e84e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

assets/js/sidebar/sidebar-version-select.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ if (!isEmbedded) {
3434
const select = qs(VERSIONS_DROPDOWN_SELECTOR)
3535
select.addEventListener('change', handleVersionSelected)
3636
adjustWidth(select)
37+
38+
const versionsGoToLatest = qs('.sidebar-staleVersion a')
39+
versionsGoToLatest.addEventListener('click', handleGoToLatestClicked)
3740
}
3841
}
3942

@@ -67,6 +70,22 @@ function handleVersionSelected (event) {
6770
})
6871
}
6972

73+
function handleGoToLatestClicked (event) {
74+
const url = this.href
75+
const pathSuffix = window.location.pathname.split('/').pop() + window.location.hash
76+
const otherVersionWithPath = `${url}/${pathSuffix}`
77+
event.preventDefault()
78+
79+
checkUrlExists(otherVersionWithPath)
80+
.then(exists => {
81+
if (exists) {
82+
window.location.href = otherVersionWithPath
83+
} else {
84+
window.location.href = url
85+
}
86+
})
87+
}
88+
7089
/**
7190
* Opens the version select if available.
7291
* Only focuses the version select if

0 commit comments

Comments
 (0)