Files
.github
.husky
docs
scripts
assets
nodes
style
utils
anchorPoint.mjs
childs.mjs
darkMode.mjs
getSVGNode.mjs
getTocsTree.mjs
homeCardIcons.mjs
panelAddNumber.mjs
rehypePreviewHTML.mjs
rehypeTitle.mjs
rehypeUrls.mjs
tooltips.mjs
build.mjs
create.mjs
index.mjs
watch.mjs
.dockerignore
.editorconfig
.gitignore
.lintstagedrc
.markdownlint.json
.prettierignore
.prettierrc
CONTRIBUTING.md
Dockerfile
LICENSE
README.md
package.json
renovate.json
reference/scripts/utils/anchorPoint.mjs

50 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-10-16 02:22:53 +08:00
const scripts = `
if(('onhashchange' in window) && ((typeof document.documentMode==='undefined') || document.documentMode==8)) {
window.onhashchange = function () {
anchorPoint()
updateAnchor()
2022-10-16 02:22:53 +08:00
};
}
function anchorPoint() {
const hash = window.location.hash?.replace(/^#/, '') || '';
const elm = document.getElementById(decodeURIComponent(hash));
Array.from(document.querySelectorAll('.h2wrap-body .wrap')).forEach((elm) => elm.classList.remove('active'))
if (elm?.tagName === 'H3') {
elm?.parentElement?.parentElement?.classList.add('active');
}
}
anchorPoint();
function updateAnchor(element) {
const anchorContainer = document.querySelectorAll('.menu-tocs .menu-modal a.tocs-link');
anchorContainer.forEach((tocanchor) => {
tocanchor.classList.remove('is-active-link');
});
const anchor = element || document.querySelector(\`a.tocs-link[href='\${decodeURIComponent(window.location.hash)}']\`);
if (anchor) {
anchor.classList.add('is-active-link');
}
}
// toc 定位
updateAnchor()
const anchor = document.querySelectorAll('.menu-tocs .menu-modal a.tocs-link');
anchor.forEach((item) => {
item.addEventListener('click', (e) => {
updateAnchor()
})
})
2022-10-16 02:22:53 +08:00
`;
export function anchorPoint() {
return {
type: 'element',
tagName: 'script',
2022-10-29 00:24:39 +08:00
children: [
{
type: 'text',
value: scripts,
},
],
};
}