mirror of
https://github.com/docsifyjs/docsify.git
synced 2025-12-08 19:55:52 +00:00
BREAKING: The new project layout might break in some tooling setups. We've added an exports field to `package.json` to specify where statements like `import ... from 'docsify'` will import from, and left the `main` and `unpkg` fields as-is for backwards compatibility with the global <script> import method. Most people who use a non-module `<script>` tag to import Docsify will not notice a difference. Anyone else who is importing Docsify into a specilized build setup using `import` statements has a chance of being broken, so we've marked this as BREAKING.
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
import { isMobile } from '../util/env.js';
|
|
import { body, on } from '../util/dom.js';
|
|
import * as sidebar from './sidebar.js';
|
|
import { scrollIntoView, scroll2Top } from './scroll.js';
|
|
|
|
/** @typedef {import('../Docsify').Constructor} Constructor */
|
|
|
|
/**
|
|
* @template {!Constructor} T
|
|
* @param {T} Base - The class to extend
|
|
*/
|
|
export function Events(Base) {
|
|
return class Events extends Base {
|
|
$resetEvents(source) {
|
|
const { auto2top } = this.config;
|
|
|
|
(() => {
|
|
// Rely on the browser's scroll auto-restoration when going back or forward
|
|
if (source === 'history') {
|
|
return;
|
|
}
|
|
// Scroll to ID if specified
|
|
if (this.route.query.id) {
|
|
scrollIntoView(this.route.path, this.route.query.id);
|
|
}
|
|
// Scroll to top if a link was clicked and auto2top is enabled
|
|
if (source === 'navigate') {
|
|
auto2top && scroll2Top(auto2top);
|
|
}
|
|
})();
|
|
|
|
if (this.config.loadNavbar) {
|
|
sidebar.getAndActive(this.router, 'nav');
|
|
}
|
|
}
|
|
|
|
initEvent() {
|
|
// Bind toggle button
|
|
sidebar.btn('button.sidebar-toggle', this.router);
|
|
sidebar.collapse('.sidebar', this.router);
|
|
// Bind sticky effect
|
|
if (this.config.coverpage) {
|
|
!isMobile && on('scroll', sidebar.sticky);
|
|
} else {
|
|
body.classList.add('sticky');
|
|
}
|
|
}
|
|
};
|
|
}
|