@@ -5,7 +5,8 @@ import bindEvent from './bind-event'
55const DEFAULT_OPTS = {
66 el : '#app' ,
77 repo : '' ,
8- 'max-level' : 6
8+ 'max-level' : 6 ,
9+ sidebar : ''
910}
1011
1112const script = document . currentScript || [ ] . slice . call ( document . getElementsByTagName ( 'script' ) ) . pop ( )
@@ -21,15 +22,17 @@ class Docsify {
2122 Docsify . installed = true
2223
2324 this . opts = Object . assign ( { } , opts , DEFAULT_OPTS )
24-
2525 this . replace = true
2626 this . dom = document . querySelector ( this . opts . el )
2727 if ( ! this . dom ) {
2828 this . dom = document . body
2929 this . replace = false
3030 }
31+ if ( this . opts . sidebar ) this . opts . sidebar = window [ this . opts . sidebar ]
32+
3133 this . loc = document . location . pathname
3234 if ( / \/ $ / . test ( this . loc ) ) this . loc += 'README'
35+
3336 this . load ( )
3437
3538 const nav = document . querySelector ( 'nav' )
@@ -43,7 +46,10 @@ class Docsify {
4346 this . render ( 'not found' )
4447 } else {
4548 this . render ( res . target . response )
46- bindEvent ( )
49+ bindEvent ( ! ! this . opts . sidebar )
50+ if ( this . opts . sidebar ) {
51+ this . activeNav ( document . querySelector ( 'aside.sidebar' ) , true )
52+ }
4753 }
4854 } )
4955 }
@@ -52,12 +58,14 @@ class Docsify {
5258 this . dom [ this . replace ? 'outerHTML' : 'innerHTML' ] = render ( content , this . opts )
5359 }
5460
55- activeNav ( elm ) {
61+ activeNav ( elm , activeParentNode ) {
5662 const host = document . location . origin + document . location . pathname
5763
5864 ; [ ] . slice . call ( elm . querySelectorAll ( 'a' ) ) . forEach ( node => {
5965 if ( node . href === host ) {
60- node . setAttribute ( 'class' , 'active' )
66+ activeParentNode
67+ ? node . parentNode . setAttribute ( 'class' , 'active' )
68+ : node . setAttribute ( 'class' , 'active' )
6169 }
6270 } )
6371 }
0 commit comments