Skip to content

Commit 1ef2932

Browse files
committed
New Docs: Handle page properties/methods links.
1 parent 4b510df commit 1ef2932

File tree

1 file changed

+39
-0
lines changed
  • utils/docs/template/static/scripts

1 file changed

+39
-0
lines changed

utils/docs/template/static/scripts/page.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,45 @@ if ( typeof prettyPrint === 'function' ) {
55

66
}
77

8+
// Scroll to hash on page load
9+
( function () {
10+
11+
const hash = window.location.hash.substring( 1 );
12+
13+
if ( hash ) {
14+
15+
const element = document.getElementById( hash );
16+
17+
if ( element ) element.scrollIntoView();
18+
19+
}
20+
21+
} )();
22+
23+
// Update URL hash when clicking on method/property links
24+
( function () {
25+
26+
const h1 = document.querySelector( 'h1' );
27+
const className = h1 ? h1.textContent.trim() : null;
28+
29+
if ( ! className ) return;
30+
31+
document.addEventListener( 'click', function ( event ) {
32+
33+
const target = event.target.closest( 'a[href^="#"]' );
34+
35+
if ( ! target || ! target.hash ) return;
36+
37+
const hash = target.hash.substring( 1 );
38+
const newHash = ( hash !== className ) ? `#${className}.${hash}` : `#${hash}`;
39+
const targetWindow = ( window.parent !== window ) ? window.parent : window;
40+
41+
targetWindow.history.pushState( null, '', newHash );
42+
43+
} );
44+
45+
} )();
46+
847
// Add code copy buttons
948
( function addCopyButtons() {
1049

0 commit comments

Comments
 (0)