parent
5ca790f631
commit
5dc3ec7059
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 6.6 KiB |
|
@ -4,13 +4,10 @@ document.addEventListener('click', function (e) {
|
|||
e.preventDefault();
|
||||
var btn = e.target.closest('.loadmore a');
|
||||
var nextPage = btn.getAttribute('href');
|
||||
|
||||
// 防止重复点击
|
||||
if (btn.classList.contains('loading')) return false;
|
||||
|
||||
btn.classList.add('loading');
|
||||
btn.textContent = '加载中...';
|
||||
|
||||
// 发起 AJAX 请求
|
||||
fetch(nextPage)
|
||||
.then(response => {
|
||||
|
@ -23,22 +20,17 @@ document.addEventListener('click', function (e) {
|
|||
// 创建一个临时的 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');
|
||||
|
||||
if (newPosts.length > 0) {
|
||||
newPosts.forEach(post => {
|
||||
articleList.insertBefore(post, postReadMore);
|
||||
});
|
||||
|
||||
// 新文章淡入效果
|
||||
Array.from(newPosts).forEach(post => {
|
||||
post.style.opacity = 0;
|
||||
|
@ -48,7 +40,6 @@ document.addEventListener('click', function (e) {
|
|||
}, 10);
|
||||
});
|
||||
}
|
||||
|
||||
// 更新"加载更多"按钮或移除它
|
||||
if (newBtn) {
|
||||
btn.setAttribute('href', newBtn.getAttribute('href'));
|
||||
|
|
|
@ -1,28 +1,23 @@
|
|||
<?php
|
||||
// 确保退出安全
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
|
||||
/** 文章置顶 */
|
||||
$sticky = $this->options->sticky; // 置顶的文章id,多个用|隔开
|
||||
$db = Typecho_Db::get();
|
||||
$pageSize = $this->options->pageSize;
|
||||
|
||||
if ($sticky && !empty(trim($sticky))) {
|
||||
$sticky_cids = array_filter(explode('|', $sticky)); // 分割文本并过滤空值
|
||||
if (!empty($sticky_cids)) {
|
||||
$sticky_html = " <span class='sticky--post'> 置顶 </span> "; // 置顶标题的 html
|
||||
|
||||
// 清空原有文章的队列
|
||||
$this->row = [];
|
||||
$this->stack = [];
|
||||
$this->length = 0;
|
||||
|
||||
// 获取总数,并排除置顶文章数量
|
||||
if (isset($this->currentPage) && $this->currentPage == 1) {
|
||||
$totalOriginal = $this->getTotal();
|
||||
$stickyCount = count($sticky_cids);
|
||||
$this->setTotal(max($totalOriginal - $stickyCount, 0));
|
||||
|
||||
// 构建置顶文章的查询
|
||||
$selectSticky = $this->select()->where('type = ?', 'post');
|
||||
foreach ($sticky_cids as $i => $cid) {
|
||||
|
@ -31,21 +26,17 @@ if ($sticky && !empty(trim($sticky))) {
|
|||
else
|
||||
$selectSticky->orWhere('cid = ?', $cid);
|
||||
}
|
||||
|
||||
// 获取置顶文章
|
||||
$stickyPosts = $db->fetchAll($selectSticky);
|
||||
|
||||
// 压入置顶文章到文章队列
|
||||
foreach ($stickyPosts as &$stickyPost) {
|
||||
$stickyPost['title'] .= $sticky_html;
|
||||
$this->push($stickyPost);
|
||||
}
|
||||
|
||||
$standardPageSize = $pageSize - count($stickyPosts);
|
||||
} else {
|
||||
$standardPageSize = $pageSize;
|
||||
}
|
||||
|
||||
// 构建正常文章查询,排除置顶文章
|
||||
$selectNormal = $this->select()
|
||||
->where('type = ?', 'post')
|
||||
|
@ -53,7 +44,6 @@ if ($sticky && !empty(trim($sticky))) {
|
|||
->where('created < ?', time())
|
||||
->order('created', Typecho_Db::SORT_DESC)
|
||||
->page(isset($this->currentPage) ? $this->currentPage : 1, $standardPageSize);
|
||||
|
||||
foreach ($sticky_cids as $cid) {
|
||||
$selectNormal->where('table.contents.cid != ?', $cid);
|
||||
}
|
||||
|
@ -75,7 +65,6 @@ if ($sticky && !empty(trim($sticky))) {
|
|||
->order('created', Typecho_Db::SORT_DESC)
|
||||
->page(isset($this->currentPage) ? $this->currentPage : 1, $pageSize);
|
||||
}
|
||||
|
||||
// 登录用户显示私密文章
|
||||
if ($this->user->hasLogin()) {
|
||||
$uid = $this->user->uid;
|
||||
|
@ -83,16 +72,13 @@ if ($this->user->hasLogin()) {
|
|||
$selectNormal->orWhere('authorId = ? AND status = ?', $uid, 'private');
|
||||
}
|
||||
}
|
||||
|
||||
$normalPosts = $db->fetchAll($selectNormal);
|
||||
|
||||
// 如果之前没有清空队列(没有置顶文章的情况),现在清空
|
||||
if (empty($sticky) || empty(trim($sticky)) || empty($sticky_cids)) {
|
||||
$this->row = [];
|
||||
$this->stack = [];
|
||||
$this->length = 0;
|
||||
}
|
||||
|
||||
// 压入正常文章到文章队列
|
||||
foreach ($normalPosts as $normalPost) {
|
||||
$this->push($normalPost);
|
||||
|
|
Loading…
Reference in New Issue