@@ -354,13 +354,54 @@ define([
354
354
355
355
NotebookList . prototype . load_list = function ( ) {
356
356
var that = this ;
357
+ // Add an event handler browser back and forward events
358
+ window . onpopstate = function ( e ) {
359
+ var path = window . history . state ? window . history . state . path : '' ;
360
+ that . update_location ( path ) ;
361
+ } ;
362
+ var breadcrumb = $ ( '.breadcrumb' ) ;
363
+ breadcrumb . empty ( ) ;
364
+ var list_item = $ ( '<li/>' ) ;
365
+ var root = $ ( '<li/>' ) . append ( '<a href="/tree"><i class="fa fa-folder"></i></a>' ) . click ( function ( e ) {
366
+ var path = '' ;
367
+ window . history . pushState ( {
368
+ path : path
369
+ } , 'Home' , utils . url_path_join ( that . base_url , 'tree' ) ) ;
370
+ that . update_location ( path ) ;
371
+ return false ;
372
+ } ) ;
373
+ breadcrumb . append ( root ) ;
374
+ var path_parts = [ ] ;
375
+ this . notebook_path . split ( '/' ) . forEach ( function ( path_part ) {
376
+ path_parts . push ( path_part )
377
+ var path = path_parts . join ( '/' )
378
+ var url = utils . url_path_join (
379
+ that . base_url ,
380
+ '/tree' ,
381
+ utils . encode_uri_components ( path )
382
+ ) ;
383
+ var crumb = $ ( '<li/>' ) . append ( '<a href="' + url + '">' + path_part + '</a>' ) . click ( function ( e ) {
384
+ window . history . pushState ( {
385
+ path : path
386
+ } , path , url ) ;
387
+ that . update_location ( path ) ;
388
+ return false ;
389
+ } ) ;
390
+ breadcrumb . append ( crumb ) ;
391
+ } ) ;
357
392
this . contents . list_contents ( that . notebook_path ) . then (
358
393
$ . proxy ( this . draw_notebook_list , this ) ,
359
394
function ( error ) {
360
395
that . draw_notebook_list ( { content : [ ] } , i18n . msg . _ ( "Server error: " ) + error . message ) ;
361
396
}
362
397
) ;
363
398
} ;
399
+
400
+ NotebookList . prototype . update_location = function ( path ) {
401
+ this . notebook_path = path ;
402
+ // Update the file tree list without reloading the page
403
+ this . load_list ( ) ;
404
+ } ;
364
405
365
406
/**
366
407
* Draw the list of notebooks
@@ -723,6 +764,7 @@ define([
723
764
} ;
724
765
725
766
NotebookList . prototype . add_link = function ( model , item ) {
767
+ var that = this ;
726
768
var running = ( model . type === 'notebook' && this . sessions [ model . path ] !== undefined ) ;
727
769
item . data ( 'name' , model . name ) ;
728
770
item . data ( 'path' , model . path ) ;
@@ -762,7 +804,21 @@ define([
762
804
// directory nav doesn't open new tabs
763
805
// files, notebooks do
764
806
if ( model . type !== "directory" ) {
765
- link . attr ( 'target' , IPython . _target ) ;
807
+ link . attr ( 'target' , IPython . _target ) ;
808
+ } else {
809
+ // Replace with a click handler that will use the History API to
810
+ // push a new route without reloading the page
811
+ link . click ( function ( e ) {
812
+ window . history . pushState ( {
813
+ path : model . path
814
+ } , model . path , utils . url_path_join (
815
+ that . base_url ,
816
+ 'tree' ,
817
+ utils . encode_uri_components ( model . path )
818
+ ) ) ;
819
+ that . update_location ( model . path ) ;
820
+ return false ;
821
+ } ) ;
766
822
}
767
823
768
824
// Add in the date that the file was last modified
0 commit comments