From 077bd0f7208a6c29eca34310e8c5313beff5c58f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=AA=E5=AD=90?= Date: Thu, 20 Mar 2025 23:49:27 +0800 Subject: [PATCH] 0.7.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix 头部bug add loadmore --- assets/js/loadmore.js | 48 +++++++++++++++++++++++++++++++++++++++++++ module/header.php | 5 ++++- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 assets/js/loadmore.js diff --git a/assets/js/loadmore.js b/assets/js/loadmore.js new file mode 100644 index 0000000..59b514c --- /dev/null +++ b/assets/js/loadmore.js @@ -0,0 +1,48 @@ + // 加载更多文章 + $(document).on('click', '.post-read-more a', function(e){ + e.preventDefault(); + var $btn = $(this); + var nextPage = $btn.attr('href'); + + if($btn.hasClass('loading')) return false; + + $btn.addClass('loading').text('加载中...'); + + $.ajax({ + url: nextPage, + type: 'GET', + dataType: 'html', + success: function(data){ + // 创建一个临时的DOM元素来解析返回的HTML + var $html = $('
').html(data); + + // 找到新的文章 + var $newPosts = $html.find('.post_loop'); + + // 找到新的"加载更多"按钮 + var $newBtn = $html.find('.post-read-more a'); + + // 将新文章添加到页面 + if ($newPosts.length > 0) { + $('.post_box').append($newPosts); + // 新文章淡入效果 + $newPosts.hide().fadeIn(500); + } + + // 更新"加载更多"按钮或移除它 + if($newBtn.length > 0){ + $btn.attr('href', $newBtn.attr('href')) + .removeClass('loading') + .text('加载更多'); + } else { + $('.post-read-more').remove(); + } + }, + error: function(xhr, status, error){ + console.error("AJAX Error:", status, error); + $btn.removeClass('loading').text('加载失败,点击重试'); + } + }); + + return false; + }); diff --git a/module/header.php b/module/header.php index 8a38395..8ac91e8 100644 --- a/module/header.php +++ b/module/header.php @@ -13,7 +13,10 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> 'tag' => _t('标签 %s 下的文章'), 'date' => _t('在 %s 发布的文章'), 'author' => _t('%s 发布的文章') - ), '', ' - '); ?>is('post')) $this->category(',', false);?>is('post')) echo ' - ';?>options->title(); ?>is('index')) echo ' - '; ?>is('index')) $this->options->description() ?> + ), '', ' - '); ?> + options->title(); ?>is('index')) echo ' - '; ?> + is('index')) $this->options->description() ?> + options->icoUrl): ?>