File tree 1 file changed +50
-0
lines changed
1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 35
35
}
36
36
}
37
37
38
+ function scrollToAnchorNestedInDetailsIfNeeded ( ) {
39
+ function scrollToElement ( ) {
40
+ const id = window . location . hash . substr ( 1 ) ;
41
+ if ( id === '' ) {
42
+ return ;
43
+ }
44
+
45
+ const element = document . getElementById ( id ) ;
46
+ if ( ! element ) {
47
+ return ;
48
+ }
49
+
50
+ const details = document . getElementsByTagName ( 'details' ) ;
51
+ for ( const element of details ) {
52
+ element . open = false ;
53
+ }
54
+
55
+ let temp = element ;
56
+ while ( temp && temp . tagName ) {
57
+ if ( temp . tagName . toLowerCase ( ) === 'details' ) {
58
+ temp . open = true ;
59
+ }
60
+
61
+ temp = temp . parentNode ;
62
+ }
63
+
64
+ element . scrollIntoView ( ) ;
65
+ }
66
+
67
+ function onReady ( callback ) {
68
+ if ( document . readyState !== 'loading' ) {
69
+ callback ( ) ;
70
+ } else if ( document . addEventListener ) {
71
+ document . addEventListener ( 'DOMContentLoaded' , callback ) ;
72
+ } else {
73
+ document . attachEvent ( 'onreadystatechange' , function ( ) {
74
+ if ( document . readyState === 'complete' ) {
75
+ callback ( ) ;
76
+ }
77
+ } ) ;
78
+ }
79
+ }
80
+
81
+ onReady ( function ( ) {
82
+ scrollToElement ( ) ;
83
+ window . addEventListener ( 'hashchange' , scrollToElement ) ;
84
+ } ) ;
85
+ }
86
+
38
87
ensureExternalLinksOpenInNewTab ( ) ;
88
+ scrollToAnchorNestedInDetailsIfNeeded ( ) ;
39
89
</ script >
You can’t perform that action at this time.
0 commit comments