1- import { isMobile } from '../util/env'
1+ import { isMobile } from '../util/env'
22import * as dom from '../util/dom'
33
44const title = dom . $ . title
55/**
66 * Toggle button
7+ * @param {Element } el Button to be toggled
8+ * @void
79 */
810export function btn ( el ) {
911 const toggle = _ => dom . body . classList . toggle ( 'close' )
1012
1113 el = dom . getNode ( el )
12- if ( el == null ) {
14+ if ( el === null || el === undefined ) {
1315 return
1416 }
17+
1518 dom . on ( el , 'click' , e => {
1619 e . stopPropagation ( )
1720 toggle ( )
@@ -27,10 +30,11 @@ export function btn(el) {
2730
2831export function collapse ( el ) {
2932 el = dom . getNode ( el )
30- if ( el == null ) {
33+ if ( el === null || el === undefined ) {
3134 return
3235 }
33- dom . on ( el , 'click' , ( { target} ) => {
36+
37+ dom . on ( el , 'click' , ( { target } ) => {
3438 if (
3539 target . nodeName === 'A' &&
3640 target . nextSibling &&
@@ -46,6 +50,7 @@ export function sticky() {
4650 if ( ! cover ) {
4751 return
4852 }
53+
4954 const coverHeight = cover . getBoundingClientRect ( ) . height
5055
5156 if ( window . pageYOffset >= coverHeight || cover . classList . contains ( 'hidden' ) ) {
@@ -57,18 +62,19 @@ export function sticky() {
5762
5863/**
5964 * Get and active link
60- * @param {object } router
61- * @param {string|element } el
62- * @param {Boolean } isParent acitve parent
63- * @param {Boolean } autoTitle auto set title
64- * @return {element }
65+ * @param {Object } router Router
66+ * @param {String|Element } el Target element
67+ * @param {Boolean } isParent Active parent
68+ * @param {Boolean } autoTitle Automatically set title
69+ * @return {Element } Active element
6570 */
6671export function getAndActive ( router , el , isParent , autoTitle ) {
6772 el = dom . getNode ( el )
6873 let links = [ ]
69- if ( el != null ) {
74+ if ( el !== null && el !== undefined ) {
7075 links = dom . findAll ( el , 'a' )
7176 }
77+
7278 const hash = decodeURI ( router . toURL ( router . getCurrentPath ( ) ) )
7379 let target
7480
0 commit comments