mirror of
https://github.com/jkjoy/typecho-theme-farallon.git
synced 2026-06-27 20:34:30 +00:00
0.7.1
修复了一个<div>未闭合的bug 优化分页和加载更多逻辑
This commit is contained in:
+2
-2
@@ -17,7 +17,7 @@
|
||||
is_single = false;
|
||||
post_id = 0;
|
||||
is_archive = false;
|
||||
VERSION = "0.7.0";
|
||||
VERSION = "0.7.1";
|
||||
constructor() {
|
||||
super();
|
||||
this.initCopyright();
|
||||
@@ -46,7 +46,7 @@
|
||||
}
|
||||
initCopyright() {
|
||||
const copyright = `<div class="site--footer__info">由<a href="https://www.typecho.org" target="_blank">Typecho</a> 驱动 <br>
|
||||
Theme <a href="https://fatesinger.com/101971" target="_blank">farallon</a> by bigfa <br>Made with<a href="https://www.imsun.org" target="_blank"> Sun</a> / version ${this.VERSION}
|
||||
Theme <a href="https://fatesinger.com/101971" target="_blank">farallon</a> by bigfa <br>Made with<a href="https://www.imsun.org" target="_blank">jkjoy</a> / version ${this.VERSION}
|
||||
</div>`;
|
||||
document.querySelector(".site--footer__content").insertAdjacentHTML("afterend", copyright);
|
||||
document.querySelector(".icon--copryrights").addEventListener("click", () => {
|
||||
|
||||
@@ -5,7 +5,6 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
const methodBtns = document.querySelectorAll('.donate-method-btn');
|
||||
const qrImages = document.querySelectorAll('.qr-image');
|
||||
let isVisible = false;
|
||||
|
||||
// 切换支付方式
|
||||
function switchPayMethod(method) {
|
||||
// 更新按钮状态
|
||||
@@ -15,7 +14,6 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
btn.classList.add('active');
|
||||
}
|
||||
});
|
||||
|
||||
// 更新二维码显示
|
||||
qrImages.forEach(img => {
|
||||
img.classList.remove('active');
|
||||
@@ -24,21 +22,18 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 点击打赏按钮切换二维码显示状态
|
||||
function toggleQRCode(event) {
|
||||
event.stopPropagation();
|
||||
isVisible = !isVisible;
|
||||
qrcodePanel.style.display = isVisible ? 'block' : 'none';
|
||||
}
|
||||
|
||||
// 点击关闭按钮隐藏二维码
|
||||
function hideQRCode(event) {
|
||||
event.stopPropagation();
|
||||
isVisible = false;
|
||||
qrcodePanel.style.display = 'none';
|
||||
}
|
||||
|
||||
// 点击二维码面板之外的地方隐藏二维码
|
||||
function handleDocumentClick(event) {
|
||||
if (isVisible && !qrcodePanel.contains(event.target) && !donateBtn.contains(event.target)) {
|
||||
@@ -46,12 +41,10 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
qrcodePanel.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
// 绑定事件监听器
|
||||
donateBtn.addEventListener('click', toggleQRCode);
|
||||
donateClose.addEventListener('click', hideQRCode);
|
||||
document.addEventListener('click', handleDocumentClick);
|
||||
|
||||
// 绑定支付方式切换按钮事件
|
||||
methodBtns.forEach(btn => {
|
||||
btn.addEventListener('click', (e) => {
|
||||
@@ -59,7 +52,6 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
switchPayMethod(method);
|
||||
});
|
||||
});
|
||||
|
||||
// 初始化显示第一个支付方式
|
||||
switchPayMethod('wechat');
|
||||
});
|
||||
+19
-14
@@ -1,13 +1,13 @@
|
||||
document.addEventListener('click', function (e) {
|
||||
// 检查点击的元素是否是 .post-read-more a
|
||||
// 检查点击的元素是否是 .loadmore a
|
||||
if (e.target.closest('.loadmore a')) {
|
||||
e.preventDefault();
|
||||
var btn = e.target.closest('.loadmore a');
|
||||
var nextPage = btn.getAttribute('href');
|
||||
var nextPage = btn.getAttribute('href');
|
||||
// 防止重复点击
|
||||
if (btn.classList.contains('loading')) return false;
|
||||
btn.classList.add('loading');
|
||||
btn.textContent = '加载中...';
|
||||
btn.textContent = '加载中...';
|
||||
// 发起 AJAX 请求
|
||||
fetch(nextPage)
|
||||
.then(response => {
|
||||
@@ -19,18 +19,23 @@ document.addEventListener('click', function (e) {
|
||||
.then(data => {
|
||||
// 创建一个临时的 DOM 元素来解析返回的 HTML
|
||||
var parser = new DOMParser();
|
||||
var htmlDoc = parser.parseFromString(data, 'text/html');
|
||||
// 找到新的文章
|
||||
var newPosts = htmlDoc.querySelectorAll('.post--item');
|
||||
// 找到新的"加载更多"按钮
|
||||
var newBtn = htmlDoc.querySelector('.nav-links a');
|
||||
// 获取文章列表容器和加载更多按钮
|
||||
var postReadMore = document.querySelector('.nav-links');
|
||||
var articleList = document.querySelector('.articleList');
|
||||
var htmlDoc = parser.parseFromString(data, 'text/html');
|
||||
// 调试代码:检查选择器
|
||||
console.log('Searching for #loadpost:', htmlDoc.querySelectorAll('#loadpost'));
|
||||
console.log('Searching for .nav-links:', htmlDoc.querySelector('.nav-links'));
|
||||
// 找到新的文章和按钮
|
||||
var newPosts = htmlDoc.querySelectorAll('#loadpost');
|
||||
var newBtn = htmlDoc.querySelector('.nav-links a');
|
||||
// 更健壮的元素选择
|
||||
var articleList = document.querySelector('#loadposts') ||
|
||||
document.querySelector('.posts-container') ||
|
||||
document.body;
|
||||
var postReadMore = document.querySelector('.nav-links');
|
||||
if (newPosts.length > 0) {
|
||||
newPosts.forEach(post => {
|
||||
articleList.insertBefore(post, postReadMore);
|
||||
});
|
||||
// 使用 appendChild 替代 insertBefore
|
||||
articleList.appendChild(post);
|
||||
});
|
||||
// 新文章淡入效果
|
||||
Array.from(newPosts).forEach(post => {
|
||||
post.style.opacity = 0;
|
||||
@@ -39,7 +44,7 @@ document.addEventListener('click', function (e) {
|
||||
post.style.opacity = 1;
|
||||
}, 10);
|
||||
});
|
||||
}
|
||||
}
|
||||
// 更新"加载更多"按钮或移除它
|
||||
if (newBtn) {
|
||||
btn.setAttribute('href', newBtn.getAttribute('href'));
|
||||
|
||||
Reference in New Issue
Block a user