File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
src/jupyter_contrib_nbextensions/nbextensions/toc2 Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 134
134
$ . ajax ( )
135
135
} , 100 ) ;
136
136
evt . preventDefault ( ) ;
137
+ // Each time a link is clicked in the toc, save the current position and target in the history
138
+ var currentSection = $ ( '#toc .highlight_on_scroll a' ) . data ( 'tocModifiedId' )
139
+ if ( window . history . state != null ) {
140
+ if ( window . history . state . back != currentSection ) {
141
+ window . history . pushState ( { 'back' :currentSection } , "" , '' )
142
+ }
143
+ }
137
144
var trg_id = $ ( evt . currentTarget ) . attr ( 'data-toc-modified-id' ) ;
145
+ window . history . pushState ( { 'back' :trg_id } , "" , '' ) ;
146
+ window . history . lastjump = trg_id ;
147
+
138
148
// use native scrollIntoView method with semi-unique id
139
149
// ! browser native click does't follow links on all browsers
140
150
document . getElementById ( trg_id ) . scrollIntoView ( true )
149
159
}
150
160
} ;
151
161
162
+ //
163
+ window . addEventListener ( 'popstate' ,
164
+ function ( e ) {
165
+ if ( e . state != null && e . state . back != null ) {
166
+ var back_id = e . state . back ;
167
+ document . getElementById ( back_id ) . scrollIntoView ( true )
168
+ if ( liveNotebook ) {
169
+ var cell = $ ( document . getElementById ( back_id ) ) . closest ( '.cell' ) . data ( 'cell' ) ;
170
+ Jupyter . notebook . select ( Jupyter . notebook . find_cell_index ( cell ) ) ;
171
+ highlight_toc_item ( "toc_link_click" , {
172
+ cell : cell
173
+ } ) ;
174
+ }
175
+ }
176
+ } ) ;
177
+
152
178
var make_link = function ( h , toc_mod_id ) {
153
179
var a = $ ( '<a>' )
154
180
. attr ( {
You can’t perform that action at this time.
0 commit comments