@@ -3,39 +3,47 @@ import { body, on } from '../util/dom';
3
3
import * as sidebar from './sidebar' ;
4
4
import { scrollIntoView , scroll2Top } from './scroll' ;
5
5
6
- export function eventMixin ( proto ) {
7
- proto . $resetEvents = function ( source ) {
8
- const { auto2top } = this . config ;
6
+ /** @typedef {import('../Docsify').Constructor } Constructor */
9
7
10
- ( ( ) => {
11
- // Rely on the browser's scroll auto-restoration when going back or forward
12
- if ( source === 'history' ) {
13
- return ;
14
- }
15
- // Scroll to ID if specified
16
- if ( this . route . query . id ) {
17
- scrollIntoView ( this . route . path , this . route . query . id ) ;
18
- }
19
- // Scroll to top if a link was clicked and auto2top is enabled
20
- if ( source === 'navigate' ) {
21
- auto2top && scroll2Top ( auto2top ) ;
8
+ /**
9
+ * @template {!Constructor} T
10
+ * @param {T } Base - The class to extend
11
+ */
12
+ export function Events ( Base ) {
13
+ return class Events extends Base {
14
+ $resetEvents ( source ) {
15
+ const { auto2top } = this . config ;
16
+
17
+ ( ( ) => {
18
+ // Rely on the browser's scroll auto-restoration when going back or forward
19
+ if ( source === 'history' ) {
20
+ return ;
21
+ }
22
+ // Scroll to ID if specified
23
+ if ( this . route . query . id ) {
24
+ scrollIntoView ( this . route . path , this . route . query . id ) ;
25
+ }
26
+ // Scroll to top if a link was clicked and auto2top is enabled
27
+ if ( source === 'navigate' ) {
28
+ auto2top && scroll2Top ( auto2top ) ;
29
+ }
30
+ } ) ( ) ;
31
+
32
+ if ( this . config . loadNavbar ) {
33
+ sidebar . getAndActive ( this . router , 'nav' ) ;
22
34
}
23
- } ) ( ) ;
35
+ }
24
36
25
- if ( this . config . loadNavbar ) {
26
- sidebar . getAndActive ( this . router , 'nav' ) ;
37
+ initEvent ( ) {
38
+ // Bind toggle button
39
+ sidebar . btn ( 'button.sidebar-toggle' , this . router ) ;
40
+ sidebar . collapse ( '.sidebar' , this . router ) ;
41
+ // Bind sticky effect
42
+ if ( this . config . coverpage ) {
43
+ ! isMobile && on ( 'scroll' , sidebar . sticky ) ;
44
+ } else {
45
+ body . classList . add ( 'sticky' ) ;
46
+ }
27
47
}
28
48
} ;
29
49
}
30
-
31
- export function initEvent ( vm ) {
32
- // Bind toggle button
33
- sidebar . btn ( 'button.sidebar-toggle' , vm . router ) ;
34
- sidebar . collapse ( '.sidebar' , vm . router ) ;
35
- // Bind sticky effect
36
- if ( vm . config . coverpage ) {
37
- ! isMobile && on ( 'scroll' , sidebar . sticky ) ;
38
- } else {
39
- body . classList . add ( 'sticky' ) ;
40
- }
41
- }
0 commit comments