File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
src/jupyter_contrib_nbextensions/nbextensions/toc2 Expand file tree Collapse file tree 1 file changed +24
-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 . back != currentSection ) {
140
+ window . history . pushState ( { 'back' :currentSection } , "" , '' )
141
+ }
137
142
var trg_id = $ ( evt . currentTarget ) . attr ( 'data-toc-modified-id' ) ;
143
+ window . history . pushState ( { 'back' :trg_id } , "" , '' ) ;
144
+ window . history . lastjump = trg_id ;
145
+
138
146
// use native scrollIntoView method with semi-unique id
139
147
// ! browser native click does't follow links on all browsers
140
148
document . getElementById ( trg_id ) . scrollIntoView ( true )
149
157
}
150
158
} ;
151
159
160
+ //
161
+ window . addEventListener ( 'popstate' ,
162
+ function ( e ) {
163
+ if ( e . state != null && e . state . back != null ) {
164
+ var back_id = e . state . back ;
165
+ document . getElementById ( back_id ) . scrollIntoView ( true )
166
+ if ( liveNotebook ) {
167
+ var cell = $ ( document . getElementById ( back_id ) ) . closest ( '.cell' ) . data ( 'cell' ) ;
168
+ Jupyter . notebook . select ( Jupyter . notebook . find_cell_index ( cell ) ) ;
169
+ highlight_toc_item ( "toc_link_click" , {
170
+ cell : cell
171
+ } ) ;
172
+ }
173
+ }
174
+ } ) ;
175
+
152
176
var make_link = function ( h , toc_mod_id ) {
153
177
var a = $ ( '<a>' )
154
178
. attr ( {
You can’t perform that action at this time.
0 commit comments