空笺未寄 v1.0 — 基于 DeepSeek UI 的 WordPress 主题
页面:首页、笺文、微言、拾影、文章详情、作者页 功能:三种展示方式、tucao 自定义类型、评论、分页、灯箱 CSS:DeepSeek 原 CSS + 系统字体 + 头像本地化 安装:激活主题后自动创建页面和导航,刷新固定链接即可
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* 空笺未寄 — Lightbox
|
||||
* Adapted from DeepSeek UI
|
||||
*/
|
||||
(function () {
|
||||
const lb = document.getElementById('lightbox');
|
||||
if (!lb) return;
|
||||
|
||||
const lbImg = document.getElementById('lightbox-img');
|
||||
const lbCaption = document.getElementById('lightbox-caption');
|
||||
const lbCounter = document.getElementById('lightbox-counter');
|
||||
const lbClose = lb.querySelector('.lightbox-close');
|
||||
const lbPrev = lb.querySelector('.lightbox-prev');
|
||||
const lbNext = lb.querySelector('.lightbox-next');
|
||||
|
||||
let images = [];
|
||||
let index = 0;
|
||||
|
||||
function show(i) {
|
||||
index = i;
|
||||
const item = images[index];
|
||||
if (!item) return;
|
||||
lbImg.src = item.src || '';
|
||||
lbCaption.textContent = item.caption || '';
|
||||
lbCounter.textContent = images.length > 1
|
||||
? `${index + 1} / ${images.length}`
|
||||
: '';
|
||||
}
|
||||
|
||||
function open(items, startIndex) {
|
||||
images = items;
|
||||
show(startIndex || 0);
|
||||
lb.classList.add('active');
|
||||
document.body.style.overflow = 'hidden';
|
||||
}
|
||||
|
||||
function close() {
|
||||
lb.classList.remove('active');
|
||||
document.body.style.overflow = '';
|
||||
}
|
||||
|
||||
function next() {
|
||||
show((index + 1) % images.length);
|
||||
}
|
||||
|
||||
function prev() {
|
||||
show((index - 1 + images.length) % images.length);
|
||||
}
|
||||
|
||||
// Click handlers
|
||||
lbClose.addEventListener('click', close);
|
||||
lbPrev.addEventListener('click', (e) => { e.stopPropagation(); prev(); });
|
||||
lbNext.addEventListener('click', (e) => { e.stopPropagation(); next(); });
|
||||
|
||||
// Click outside to close
|
||||
lb.addEventListener('click', function (e) {
|
||||
if (e.target === lb) close();
|
||||
});
|
||||
|
||||
// Keyboard navigation
|
||||
document.addEventListener('keydown', function (e) {
|
||||
if (!lb.classList.contains('active')) return;
|
||||
if (e.key === 'ArrowLeft') prev();
|
||||
if (e.key === 'ArrowRight') next();
|
||||
if (e.key === 'Escape') close();
|
||||
});
|
||||
|
||||
// Expose
|
||||
window.kjwejiLightbox = { open, close, next, prev };
|
||||
})();
|
||||
Reference in New Issue
Block a user