@@ -486,7 +486,7 @@ function initNavTree(toroot,relpath,allMembersFile) {
486486 $ ( window ) . resize ( function ( ) { adjustSyncIconPosition ( ) ; } ) ;
487487
488488 let navtree_trampoline = {
489- updateContentTop : function ( c ) { }
489+ updateContentTop : function ( ) { }
490490 }
491491
492492 function initResizable ( ) {
@@ -646,7 +646,7 @@ function initNavTree(toroot,relpath,allMembersFile) {
646646 const newWidth = $ ( this ) . width ( ) , newHeight = $ ( this ) . height ( ) ;
647647 if ( newWidth != lastWidth || newHeight != lastHeight ) {
648648 resizeHeight ( ) ;
649- navtree_trampoline . updateContentTop ( content ) ;
649+ navtree_trampoline . updateContentTop ( ) ;
650650 lastWidth = newWidth ;
651651 lastHeight = newHeight ;
652652 }
@@ -655,7 +655,7 @@ function initNavTree(toroot,relpath,allMembersFile) {
655655 lastWidth = $ ( window ) . width ( ) ;
656656 lastHeight = $ ( window ) . height ( ) ;
657657 content . scroll ( function ( ) {
658- navtree_trampoline . updateContentTop ( content ) ;
658+ navtree_trampoline . updateContentTop ( ) ;
659659 } ) ;
660660 } ) ;
661661 }
@@ -790,29 +790,27 @@ function initNavTree(toroot,relpath,allMembersFile) {
790790 // for PageDef
791791 const sectionTree = [ ] , sectionStack = [ ] ;
792792 $ ( 'h1.doxsection, h2.doxsection, h3.doxsection, h4.doxsection, h5.doxsection, h6.doxsection' ) . each ( function ( ) {
793- const level = parseInt ( this . tagName [ 1 ] ) ;
794- const anchor = $ ( this ) . find ( 'a.anchor' ) . attr ( 'id' ) ;
795- const node = { text : $ ( this ) . text ( ) , id : anchor , children : [ ] } ;
796- while ( sectionStack . length && sectionStack [ sectionStack . length - 1 ] . level >= level ) sectionStack . pop ( ) ;
797- ( sectionStack . length ? sectionStack [ sectionStack . length - 1 ] . children : sectionTree ) . push ( node ) ;
798- sectionStack . push ( { ...node , level } ) ;
793+ const level = parseInt ( this . tagName [ 1 ] ) ;
794+ const anchor = $ ( this ) . find ( 'a.anchor' ) . attr ( 'id' ) ;
795+ const node = { text : $ ( this ) . text ( ) , id : anchor , children : [ ] } ;
796+ while ( sectionStack . length && sectionStack [ sectionStack . length - 1 ] . level >= level ) sectionStack . pop ( ) ;
797+ ( sectionStack . length ? sectionStack [ sectionStack . length - 1 ] . children : sectionTree ) . push ( node ) ;
798+ sectionStack . push ( { ...node , level } ) ;
799799 } ) ;
800800 if ( sectionTree . length > 0 ) {
801801 function render ( nodes , level = 0 ) {
802- return $ ( '<ul>' ) . addClass ( 'nested' ) . append ( nodes . map ( n => {
803- const li = $ ( '<li>' ) . attr ( 'id' , 'nav-' + n . id ) ;
804- const div = $ ( '<div>' ) . addClass ( 'item' ) ;
805- const span = $ ( '<span>' ) . addClass ( 'arrow' ) . attr ( 'style' , 'padding-left:' + parseInt ( level * 16 ) + 'px;' ) ;
806- if ( n . children . length > 0 ) { span . append ( $ ( '<span>' ) . addClass ( 'arrowhead opened' ) ) ; }
807- const url = $ ( '<a>' ) . attr ( 'href' , '#' + n . id ) ;
808- url . append ( escapeHtml ( n . text ) )
809- div . append ( span ) . append ( url )
810- li . append ( div , render ( n . children , level + 1 ) ) ;
811- topMapping . push ( n . id ) ;
812- return li ;
813- } ) ) ;
802+ nodes . map ( n => {
803+ const li = $ ( '<li>' ) . attr ( 'id' , 'nav-' + n . id ) ;
804+ const div = $ ( '<div>' ) . addClass ( 'item' ) ;
805+ const span = $ ( '<span>' ) . addClass ( 'arrow' ) . attr ( 'style' , 'padding-left:' + parseInt ( level * 16 ) + 'px;' ) ;
806+ if ( n . children . length > 0 ) { span . append ( $ ( '<span>' ) . addClass ( 'arrowhead opened' ) ) ; }
807+ const url = $ ( '<a>' ) . attr ( 'href' , '#' + n . id ) ;
808+ content . append ( li . append ( div . append ( span ) . append ( url . append ( escapeHtml ( n . text ) ) ) ) ) ;
809+ topMapping . push ( n . id ) ;
810+ render ( n . children , level + 1 ) ;
811+ } ) ;
814812 }
815- content . append ( render ( sectionTree ) ) ;
813+ render ( sectionTree ) ;
816814 }
817815 }
818816
@@ -824,18 +822,20 @@ function initNavTree(toroot,relpath,allMembersFile) {
824822 gotoAnchor ( $ ( aname ) , aname ) ;
825823 } ) ;
826824
827- navtree_trampoline . updateContentTop = function ( c ) {
825+ navtree_trampoline . updateContentTop = function ( ) {
828826 const pagenavcontents = $ ( "#page-nav-contents" ) ;
829827 if ( pagenavcontents . length ) {
830- const height = $ ( '#doc-content' ) . height ( ) ;
828+ const content = $ ( "#doc-content" ) ;
829+ const height = content . height ( ) ;
831830 const navy = pagenavcontents . offset ( ) . top ;
832- const yc = $ ( c ) . offset ( ) . top ;
831+ const yc = content . offset ( ) . top ;
833832 let offsets = [ ]
834833 for ( let i = 0 ; i < topMapping . length ; i ++ ) {
835- offsets . push ( { id :topMapping [ i ] , y :$ ( '#' + topMapping [ i ] ) . offset ( ) . top - yc } ) ;
834+ const heading = $ ( '#' + topMapping [ i ] ) ;
835+ offsets . push ( { id :topMapping [ i ] , y :heading . offset ( ) . top - yc } ) ;
836836 }
837- offsets . push ( { id :'' , y :1000000 } ) ;
838- let scrollTarget = undefined , minNavY = 100000 , maxNavY = 0 ;
837+ offsets . push ( { id :'' , y :1e10 } ) ;
838+ let scrollTarget = undefined , minNavY = 1e10 , maxNavY = 0 ;
839839 for ( let i = 0 ; i < topMapping . length ; i ++ ) {
840840 const ys = offsets [ i ] . y ;
841841 const ye = offsets [ i + 1 ] . y ;
@@ -853,13 +853,18 @@ function initNavTree(toroot,relpath,allMembersFile) {
853853 }
854854 if ( scrollTarget ) {
855855 const my = ( maxNavY - minNavY ) / 2 ;
856- pagenavcontents . scrollTo ( scrollTarget , { offset :- height / 2 + my } ) ;
856+ pagenavcontents . stop ( ) ;
857+ pagenavcontents . scrollTo ( scrollTarget , {
858+ duration : 100 ,
859+ interrupt : true ,
860+ offset :- height / 2 + my
861+ } ) ;
857862 }
858863 }
859864 }
860865 // TODO: find out how to avoid a timeout
861866 setTimeout ( ( ) => {
862- navtree_trampoline . updateContentTop ( content ) ;
867+ navtree_trampoline . updateContentTop ( ) ;
863868 } , 200 ) ;
864869 }
865870 $ ( document ) . ready ( function ( ) { initPageToc ( ) ; initResizable ( ) ; } ) ;
0 commit comments