@@ -53,10 +53,41 @@ function attachAllListeners() {
53
53
}
54
54
}
55
55
}
56
-
57
- $ ( ".side-menu span" ) . on ( "click" , function ( ) {
58
- $ ( this ) . parent ( ) . toggleClass ( "expanded" ) ;
59
- } ) ;
56
+ $ ( ".side-menu span" ) . on ( "click" , function ( ) {
57
+ $ ( this ) . parent ( ) . toggleClass ( "expanded" ) ;
58
+ } ) ;
59
+ document . querySelectorAll ( 'a' ) . forEach ( el => {
60
+ const href = el . href
61
+ if ( href === "" ) { return }
62
+ const url = new URL ( href )
63
+ el . addEventListener ( 'click' , e => {
64
+ if ( url . href . replace ( "#" , "" ) === window . location . href . replace ( "#" , "" ) ) { return }
65
+ if ( url . origin !== window . location . origin ) { return }
66
+ if ( e . metaKey || e . ctrlKey || e . shiftKey || e . altKey || e . button !== 0 ) { return }
67
+ e . preventDefault ( )
68
+ e . stopPropagation ( )
69
+ $ . get ( href , function ( data ) {
70
+ const html = $ . parseHTML ( data )
71
+ const title = html . find ( node => node . nodeName === "TITLE" ) . innerText
72
+ const bodyDiv = html . find ( node => node . nodeName === "DIV" )
73
+ const { children } = document . body . firstChild
74
+ if ( window . history . state === null ) {
75
+ window . history . replaceState ( {
76
+ leftColumn : children [ 3 ] . innerHTML ,
77
+ mainDiv : children [ 6 ] . innerHTML ,
78
+ title : document . title ,
79
+ } , '' )
80
+ }
81
+ document . title = title
82
+ const leftColumn = bodyDiv . children [ 3 ] . innerHTML
83
+ const mainDiv = bodyDiv . children [ 6 ] . innerHTML
84
+ window . history . pushState ( { leftColumn, mainDiv, title } , '' , href )
85
+ children [ 3 ] . innerHTML = leftColumn
86
+ children [ 6 ] . innerHTML = mainDiv
87
+ attachAllListeners ( )
88
+ } )
89
+ } )
90
+ } )
60
91
61
92
document . querySelectorAll ( 'a' ) . forEach ( el => {
62
93
const href = el . href
0 commit comments