This repository has been archived on 2026-06-21. You can view files and clone it, but cannot push or open issues or pull requests.
Files
MetaLab/templates/MetaLab-2026/static/js/post-view.js
Victor_Jay c73b131b83 feat: prompt/confirm 替换为自定义弹窗
- shared/utils.js 新增 showConfirm()/showPrompt() 通用函数(inline CSS,无需额外样式)
- admin/common.js 移除重复 showConfirm(),统一使用 utils.js
- admin/posts.js: 3 处 confirm/prompt 替换(审核/退回/锁定)
- admin/comments.js: 1 处 confirm 替换
- settings/index.html: 4 处 confirm + 1 处 prompt 替换
- studio/posts.html + drafts.html: 3 处 confirm 替换
- post-view.js + login.js + post-favorite.js: 3 处 confirm 替换
2026-06-02 20:11:48 +08:00

51 lines
2.0 KiB
JavaScript

// Vditor Markdown 渲染 + 外部链接处理 + 提交审核按钮
(function() {
// ====== Vditor 渲染 ======
var el = document.getElementById('postContent');
var mdEl = document.getElementById('postMdContent');
if (el && mdEl) {
var md = mdEl.value;
Vditor.preview(el, md, {
cdn: '/static/vditor',
theme: { current: 'light', path: '/static/vditor/dist/css/content-theme' },
hljs: { style: 'github-dark', enable: true },
after: function() {
var host = window.location.host;
var links = el.querySelectorAll('a[href^="http"]');
for (var i = 0; i < links.length; i++) {
var a = links[i];
if (a.host && a.host !== host) {
a.setAttribute('rel', 'nofollow noopener noreferrer');
a.setAttribute('target', '_blank');
}
}
}
});
// shortcode 占位 div 替换为对应卡片 UI
renderShortcodes(el);
}
// ====== 提交审核按钮 ======
var submitBtn = document.getElementById('submitAuditBtn');
if (submitBtn) {
submitBtn.addEventListener('click', function() {
showConfirm('确认', '确认提交审核?审核通过后将公开发布。').then(function(ok) {
if (!ok) return;
fetch('/api/posts/' + submitBtn.dataset.id + '/submit', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': getCSRFToken()
}
})
.then(function(r) { return r.json(); })
.then(function(d) {
if (d.success) { window.location.reload(); }
else { alert(d.message || '提交失败'); }
})
.catch(function() { alert('请求失败'); });
});
});
}
})();