@@ -3,39 +3,47 @@ import { body, on } from '../util/dom';
33import * as sidebar from './sidebar' ;
44import { scrollIntoView , scroll2Top } from './scroll' ;
55
6- export function eventMixin ( proto ) {
7- proto . $resetEvents = function ( source ) {
8- const { auto2top } = this . config ;
6+ /** @typedef {import('../Docsify').Constructor } Constructor */
97
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' ) ;
2234 }
23- } ) ( ) ;
35+ }
2436
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+ }
2747 }
2848 } ;
2949}
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