@@ -66,6 +66,8 @@ var DEFAULT_CONFIG = {
6666 'key_handler' : true ,
6767 // register hashchange handler, navigate to the location specified by the hash
6868 'hashchange_handler' : true ,
69+ // register view history handler, allowing going back to the previous location
70+ 'view_history_handler' : true ,
6971
7072 '__dummy__' : 'no comma'
7173} ;
@@ -313,6 +315,12 @@ Viewer.prototype = {
313315 } , false ) ;
314316 }
315317
318+ if ( this . config [ 'view_history_handler' ] ) {
319+ window . addEventListener ( 'popstate' , function ( e ) {
320+ if ( e . state ) self . navigate_to_dest ( e . state ) ;
321+ } , false ) ;
322+ }
323+
316324 // register schedule rendering
317325 // renew old schedules since scroll() may be called frequently
318326 this . container . addEventListener ( 'scroll' , function ( ) {
@@ -798,6 +806,13 @@ Viewer.prototype = {
798806 var detail_str = /** @type {string } */ ( target . getAttribute ( 'data-dest-detail' ) ) ;
799807 if ( ! detail_str ) return ;
800808
809+ if ( this . config [ 'view_history_handler' ] ) {
810+ try {
811+ var cur_hash = this . get_current_view_hash ( ) ;
812+ window . history . replaceState ( cur_hash , '' , '#' + cur_hash ) ;
813+ window . history . pushState ( detail_str , '' , '#' + detail_str ) ;
814+ } catch ( ex ) { }
815+ }
801816 this . navigate_to_dest ( detail_str , this . get_containing_page ( target ) ) ;
802817 e . preventDefault ( ) ;
803818 } ,
@@ -939,7 +954,7 @@ Viewer.prototype = {
939954 detail . push ( 'XYZ' ) ;
940955
941956 var cur_pos = cur_page . view_position ( ) ;
942- cur_pos [ 1 ] = cur_page . height ( ) - cur_pos [ 1 ] ;
957+ cur_pos = transform ( cur_page . ictm , [ cur_pos [ 0 ] , cur_page . height ( ) - cur_pos [ 1 ] ] ) ;
943958 detail . push ( cur_pos [ 0 ] / this . scale ) ;
944959 detail . push ( cur_pos [ 1 ] / this . scale ) ;
945960
0 commit comments