refactor(core): and sidebar event
This commit is contained in:
parent
fe88c154b0
commit
fbd51afdcb
6 changed files with 100 additions and 17 deletions
|
|
@ -1,4 +1,4 @@
|
|||
export function activeSidebar () {
|
||||
export function scrollActiveSidebar () {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { isMobile } from '../util/env'
|
||||
import { getNode, on, body } from '../util/dom'
|
||||
import { getNode, on, body, findAll, toggleClass } from '../util/dom'
|
||||
import { getHash } from '../route/hash'
|
||||
/**
|
||||
* Toggle button
|
||||
*/
|
||||
|
|
@ -14,7 +15,7 @@ export function btn (el) {
|
|||
|
||||
on(sidebar, 'click', () => {
|
||||
toggle()
|
||||
setTimeout(() => activeLink(sidebar, true), 0)
|
||||
setTimeout(() => getAndActive(true), 0)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +24,27 @@ export function sticky () {
|
|||
|
||||
}
|
||||
|
||||
export function activeLink () {
|
||||
export function getAndActive (el, isParent) {
|
||||
const dom = getNode(el)
|
||||
const links = findAll(dom, 'a')
|
||||
const hash = '#' + getHash()
|
||||
|
||||
let target
|
||||
|
||||
links
|
||||
.sort((a, b) => b.href.length - a.href.length)
|
||||
.forEach(a => {
|
||||
const href = a.getAttribute('href')
|
||||
const node = isParent ? a.parentNode : a
|
||||
|
||||
if (hash.indexOf(href) === 0 && !target) {
|
||||
target = a
|
||||
toggleClass(node, 'add', 'active')
|
||||
} else {
|
||||
toggleClass(node, 'remove', 'active')
|
||||
}
|
||||
})
|
||||
|
||||
// TODO FIXED
|
||||
return target
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue