$('body, html').animate({ scrollTop: 0 }, 600);
}
document.addEventListener('DOMContentLoaded', function() {
var container = document.getElementById('container');
if (!container) {
var path = window.location.pathname;
var origin = window.location.origin;
console.log('path:',path, '\norigin:',origin);
console.log('document:', document)
window.location.href = origin + '#' + path;
}
});
$(document).ready(function() {
if ($('#toggle-sidebar-btn').hasClass('fa-angle-right')) {
$('.page-indent').toggleClass('collapsed');
$('.article-meta').toggleClass('collapsed');
$('.article-more-link').toggleClass('collapsed');
}
const colorIndex = localStorage.getItem("ColorIndex");
// init color
changeBackgroundColor(BackColors[colorIndex]);
});
anchorComponentOnclick = function(event) {
// 文章的头链接 | 点击监听
$('.article-category-link').on('click', function(event) {
event.preventDefault();
const path = $(this).attr('href');
anchorInterceptor(path);
});
// 目录的跳转 | 点击监听
$('.toc-link').on('click', function(event) {
event.preventDefault();
const params = new URLSearchParams(window.location.search);
//const sectionId = $(this).attr('href').replace('?section=', '');
// 更新 URL,但不刷新页面
const idx = decodeURIComponent($(this).attr('href')).slice(1);
if (idx != 'ndefined') {
params.set('section', idx);
const curPath = window.location.pathname + window.location.hash.split('?section=')[0];
const newUrl = curPath + '?' + params.toString();
window.history.pushState({}, '', newUrl);
// 滚动到对应位置
scrollToSection(idx);
}
});
$('.tag-link-link').on('click', function(event) {
event.preventDefault();
const path = $(this).attr('href');
anchorInterceptor(path);
});
$('#page-nav').on('click', 'a', function(event) {
event.preventDefault();
const path = $(this).attr('href');
anchorInterceptor(path);
});
}