Files
blog/themes/Ying/assets/js/modules/mypjax.js
T

171 lines
5.0 KiB
JavaScript
Raw Normal View History

2024-07-26 14:22:52 +08:00
// 定义pjax 预设pjax
2026-01-31 19:24:22 +08:00
(function() {
if (typeof Pjax === 'undefined') {
console.error('Pjax library is not loaded.');
return;
}
var pjax = new Pjax({
// 这里填写页面中改变的部分(和 CSS 选择器用法一样)
selectors: ["title", "#pjax-container"],
cacheBust: false,
elements: "a", // 拦截所有链接
switches: {
"#pjax-container": Pjax.switches.default
}
});
// 将 pjax 实例挂载到 window 以便调试或外部访问
window.pjax = pjax;
console.log("Pjax initialized:", pjax);
})();
2026-01-31 17:24:31 +08:00
// pjax预先加载代码
2024-07-26 14:22:52 +08:00
function pjax_reload() {
2026-01-31 19:24:22 +08:00
console.log("Pjax reload triggered");
2024-07-26 14:22:52 +08:00
// 给pjax容器加入css过渡动画
2026-01-31 19:24:22 +08:00
// var pjaxContainer = document.getElementById("pjax-container");
// if (pjaxContainer) pjaxContainer.classList.add("uk-animation-slide-bottom-small");
2024-07-26 14:22:52 +08:00
// 评论区过渡动画
2026-01-31 19:24:22 +08:00
var selectors = [
".comment-meta",
".comment-author vcard",
".comment-metadata",
".comment-content",
".reply"
];
selectors.forEach(function(selector) {
document.querySelectorAll(selector).forEach(function(el) {
el.setAttribute("uk-scrollspy", "cls: uk-animation-fade; delay: 100");
});
});
2024-07-26 14:22:52 +08:00
// 说说页面过渡动画
2026-01-31 19:24:22 +08:00
var shuoshuoBody = document.getElementById("shuoshuo_body");
if (shuoshuoBody) {
shuoshuoBody.setAttribute("uk-scrollspy", "target: > .shuoshuo; cls: uk-animation-fade; delay: 250");
}
2024-07-26 14:22:52 +08:00
}
2026-01-31 19:24:22 +08:00
2026-05-20 14:33:05 +08:00
function refreshHeatmap() {
if (typeof renderHeatmap === 'function') {
try {
renderHeatmap();
} catch (e) {
console.error('renderHeatmap error:', e);
}
}
}
2024-07-26 14:22:52 +08:00
// pjax发送时期
document.addEventListener("pjax:send", function () {
// pjax动画减少圆圈动画
NProgress.configure({
showSpinner: false
});
// pjax执行动画开始
NProgress.start(); //加载动画效果开始
});
2026-01-31 19:24:22 +08:00
2024-07-26 14:22:52 +08:00
// Pjax 成功后,重新加载下面的函数
document.addEventListener("pjax:success", function () {
// 重载图片懒加载插件的js
2026-01-31 19:24:22 +08:00
if (typeof lazyLoadInit === 'function') {
lazyLoadInit({
// coverColor: "white",
// coverDiv: "<div style='display: flex; justify-content: center; align-items: center; height: 200px; color: #000000;'><span>优世界·一个记录生活点滴的小站</span></div>",
2026-02-02 20:38:58 +08:00
offsetBottom: 50,
offsetTopm: 50,
showTime: 1100,
queueInterval: 100
2026-01-31 19:24:22 +08:00
});
}
2024-07-26 14:22:52 +08:00
// 激活文章图片灯箱
2026-01-31 19:24:22 +08:00
if (window.ViewImage) {
ViewImage.init('.post-content img');
}
2026-05-25 00:03:50 +08:00
if (typeof window.refreshFloatingTools === 'function') {
window.refreshFloatingTools();
}
2024-07-26 14:22:52 +08:00
});
2026-01-31 19:24:22 +08:00
2024-07-26 14:22:52 +08:00
// pjax加载完成
document.addEventListener("pjax:complete", function () {
// pjax完成动画
2026-01-31 19:24:22 +08:00
if (typeof NProgress !== 'undefined') {
NProgress.done();
}
2024-07-26 14:22:52 +08:00
// 重载一些js样式调整
2026-01-31 19:24:22 +08:00
pjax_reload();
2026-01-22 13:16:50 +08:00
// 初始化代码复制
2026-01-31 19:24:22 +08:00
if (typeof initCodeCopy === 'function') initCodeCopy();
2026-01-30 22:18:19 +08:00
// 初始化代码折叠
2026-01-31 19:24:22 +08:00
if (typeof initCodeFold === 'function') initCodeFold();
2026-01-31 21:27:06 +08:00
// 初始化段落评论
if (typeof window.initParagraphComments === 'function') {
2026-01-31 21:50:00 +08:00
try {
window.initParagraphComments();
2026-01-31 22:52:19 +08:00
} catch (e) {
console.error('initParagraphComments error:', e);
}
}
// 初始化无限加载
if (typeof window.initInfiniteScroll === 'function' && window.enableInfiniteScroll) {
window.initInfiniteScroll();
2026-01-31 21:27:06 +08:00
}
2026-01-30 23:07:58 +08:00
// 初始化友链状态
if (typeof window.initLinkStatus === 'function') {
2026-01-31 21:50:00 +08:00
try {
window.initLinkStatus();
} catch(e) { console.error('initLinkStatus error:', e); }
2026-01-30 23:07:58 +08:00
}
2026-01-31 19:24:22 +08:00
2024-07-26 14:22:52 +08:00
// 重载评论
2026-01-30 21:11:05 +08:00
if (typeof window.initArtalk === 'function') {
2026-01-31 21:50:00 +08:00
try {
window.initArtalk();
} catch(e) { console.error('initArtalk error:', e); }
2024-08-09 13:32:57 +08:00
}
2026-01-31 19:24:22 +08:00
2026-01-23 19:18:54 +08:00
// 重载不蒜子统计
if (typeof window.bsz_fetch === 'function') {
2026-01-31 21:50:00 +08:00
try {
window.bsz_fetch();
} catch(e) { console.error('bsz_fetch error:', e); }
2026-01-23 19:18:54 +08:00
}
2026-01-31 19:24:22 +08:00
// 重载 Search 和 Floating Tools (Moved from main.js)
2026-05-25 00:03:50 +08:00
if (typeof window.refreshFloatingTools === 'function') {
window.refreshFloatingTools();
} else if (typeof window.initFloatingTools === 'function') {
requestAnimationFrame(function() {
try {
window.initFloatingTools();
} catch(e) { console.error('initFloatingTools error:', e); }
});
2026-01-31 21:50:00 +08:00
}
if (typeof window.initSearch === 'function') {
try {
window.initSearch();
} catch(e) { console.error('initSearch error:', e); }
}
2026-05-20 14:33:05 +08:00
2026-05-24 12:17:43 +08:00
// 重载图片框架滚动显示
if (typeof window.initImageFrameReveal === 'function') {
try {
window.initImageFrameReveal();
} catch(e) { console.error('initImageFrameReveal error:', e); }
}
2026-05-20 14:33:05 +08:00
refreshHeatmap();
2024-07-26 14:22:52 +08:00
});