Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/toc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
function pageToC (headings, path) {
let toc = ['<div class="page_toc">']
const list = []
headings = document.querySelectorAll(`#main ${window.$docsify.toc.target}`)
headings = findTitles()

if (headings) {
headings.forEach(function (heading) {
Expand Down Expand Up @@ -33,7 +33,7 @@ function generateToC (level, html) {
// scroll listener
const scrollHandler = () => {
const clientHeight = window.innerHeight
const titleBlocks = document.querySelectorAll(`#main ${window.$docsify.toc.target}`)
const titleBlocks = findTitles()
let insightBlocks = []
titleBlocks.forEach((titleBlock, index) => {
const rect = titleBlock.getBoundingClientRect()
Expand Down Expand Up @@ -62,6 +62,14 @@ const scrollHandler = () => {
})
}
}
// find toc titles
function findTitles() {
const targets = window.$docsify.toc.target.split(',')
const selectors = targets.map(item => {
return `#main ${item}`
}).join(',')
return document.querySelectorAll(selectors)
}

export function install (hook, vm) {
hook.mounted(function () {
Expand Down