- 替换全部 11 个文件中 36 处 alert() 为 showToast() - API 错误/异常使用 showToast(msg, 'error'),3秒自动消失 - 表单校验提示使用 showToast(msg, 'warning'),3秒自动消失 - 成功确认使用 showToast(msg, 'success'),3秒自动消失 - 移除 post-energize.js 中与全局 showToast 冲突的本地实现 - 删除 posts.css 中已失去引用的 .energize-toast 样式 - 保留 showConfirm() 自定义确认弹窗(需用户确认的操作)
51 lines
2.0 KiB
JavaScript
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 { showToast(d.message || '提交失败', 'error'); }
|
|
})
|
|
.catch(function() { showToast('请求失败', 'error'); });
|
|
});
|
|
});
|
|
}
|
|
})();
|