Skip to content

Commit 79be67b

Browse files
GKotfiszhhyu
andauthored
Make package body tabs linkable (#8860)
* replace history state on body tab show * restore body tab based on window hash * tweak Co-authored-by: zhhyu <[email protected]>
1 parent 986ad6e commit 79be67b

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

src/NuGetGallery/Scripts/gallery/page-display-package.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,19 @@
9393
var storage = window['localStorage'];
9494
var packageManagerStorageKey = 'preferred_package_manager';
9595
var bodyStorageKey = 'preferred_body_tab';
96-
97-
// The V3 registration API links to the display package page's README using
98-
// the 'show-readme-container' URL fragment.
9996
var restorePreferredBodyTab = true;
100-
if (window.location.hash === '#show-readme-container') {
101-
$('#readme-body-tab').focus();
97+
98+
var windowHash = window.location.hash;
99+
if (windowHash) {
100+
// The V3 registration API links to the display package page's README using
101+
// the 'show-readme-container' URL fragment.
102+
if (windowHash === '#show-readme-container') {
103+
windowHash = '#readme-body-tab';
104+
}
105+
106+
$(windowHash).focus();
107+
$(windowHash).tab('show');
108+
// don't restore body tab given the window hash
102109
restorePreferredBodyTab = false;
103110
}
104111

@@ -154,6 +161,8 @@
154161
storage.setItem(bodyStorageKey, e.target.id);
155162
}
156163

164+
window.history.replaceState("", "", "#" + e.target.id);
165+
157166
clampUsedByDescriptions();
158167

159168
window.nuget.sendMetric("ShowDisplayPackageTab", 1, {

0 commit comments

Comments
 (0)