@@ -9,6 +9,7 @@ import stylesheet from './stylesheet.css'
9
9
const DEFAULT_OPTIONS = {
10
10
previousText : 'PREVIOUS' ,
11
11
nextText : 'NEXT' ,
12
+ crossChapter : false ,
12
13
}
13
14
const CONTAINER_CLASSNAME = 'docsify-pagination-container'
14
15
@@ -18,8 +19,8 @@ const CONTAINER_CLASSNAME = 'docsify-pagination-container'
18
19
function toArray ( elements ) {
19
20
return Array . prototype . slice . call ( elements )
20
21
}
21
- function findHyperlink ( li ) {
22
- return query ( 'a' , li )
22
+ function findHyperlink ( element ) {
23
+ return element . href ? element : query ( 'a' , element )
23
24
}
24
25
function isALinkTo ( path , element ) {
25
26
if ( arguments . length === 1 ) {
@@ -50,20 +51,25 @@ class Link {
50
51
}
51
52
}
52
53
53
- function pagination ( vm ) {
54
+ function pagination ( vm , crossChapter ) {
54
55
try {
55
56
const path = vm . route . path
56
57
const all = toArray ( query . all ( '.sidebar li a' ) ) . filter ( ( element ) => ! matches ( element , '.section-link' ) )
57
58
const active = all . find ( isALinkTo ( path ) )
58
59
const group = toArray ( ( closest ( active , 'ul' ) || { } ) . children )
59
60
. filter ( ( element ) => element . tagName . toUpperCase ( ) === 'LI' )
60
- const index = group . findIndex ( ( item ) => {
61
- const hyperlink = findHyperlink ( item )
62
- return hyperlink && isALinkTo ( path , hyperlink )
63
- } )
61
+ const index = crossChapter
62
+ ? all . findIndex ( isALinkTo ( path ) )
63
+ : group . findIndex ( ( item ) => {
64
+ const hyperlink = findHyperlink ( item )
65
+ return hyperlink && isALinkTo ( path , hyperlink )
66
+ } )
67
+
68
+ const links = crossChapter ? all : group
69
+
64
70
return {
65
- prev : new Link ( group [ index - 1 ] ) . toJSON ( ) ,
66
- next : new Link ( group [ index + 1 ] ) . toJSON ( ) ,
71
+ prev : new Link ( links [ index - 1 ] ) . toJSON ( ) ,
72
+ next : new Link ( links [ index + 1 ] ) . toJSON ( ) ,
67
73
}
68
74
} catch ( error ) {
69
75
return { }
@@ -118,7 +124,7 @@ export function install (hook, vm) {
118
124
if ( ! container ) {
119
125
return
120
126
}
121
- container . innerHTML = template . inner ( pagination ( vm ) , options )
127
+ container . innerHTML = template . inner ( pagination ( vm , options . crossChapter ) , options )
122
128
}
123
129
124
130
hook . afterEach ( ( html ) => html + template . container ( ) )
0 commit comments