feat: remove forum feature (Phase 1)
This commit is contained in:
1 parent
f3e4cdd9cf
commit
2bbd7c01a3
173 files changed
+51
-27360
No files matched your search
@@ -156,73 +156,6 @@
|
||||
});
|
||||
}
|
||||
|
||||
// Forum multi-tab topics.
|
||||
function initForumTabTopics() {
|
||||
document.querySelectorAll('.aksrt-ftab[data-aksrt-ftab]').forEach(function (root) {
|
||||
if (root.dataset.aksrtFtabBound === '1') return;
|
||||
root.dataset.aksrtFtabBound = '1';
|
||||
var rest = root.getAttribute('data-rest') || '';
|
||||
var count = root.getAttribute('data-count') || '6';
|
||||
var style = root.getAttribute('data-style') || 'mini';
|
||||
var plate = root.getAttribute('data-plate') || '0';
|
||||
var btns = [].slice.call(root.querySelectorAll('.aksrt-ftab__btn'));
|
||||
var panels = [].slice.call(root.querySelectorAll('.aksrt-ftab__panel'));
|
||||
|
||||
function load(panel, orderby) {
|
||||
if (!panel || panel.getAttribute('data-loaded') === '1' || !rest) return;
|
||||
var qs = new URLSearchParams({
|
||||
page: '1',
|
||||
count: count,
|
||||
orderby: orderby || 'date',
|
||||
style: style,
|
||||
plate: plate,
|
||||
period: 'all',
|
||||
paginate: 'none',
|
||||
});
|
||||
var url = rest + (rest.indexOf('?') > -1 ? '&' : '?') + qs.toString();
|
||||
panel.classList.add('is-ajax-loading');
|
||||
fetch(url, { credentials: 'same-origin', headers: restHeaders() })
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (j) {
|
||||
var d = (j && j.data) || j || {};
|
||||
var html = d.html || '';
|
||||
panel.innerHTML = html || '<div class="ajax-item aksrt-ftab__empty muted-2-color">暂无内容</div>';
|
||||
panel.setAttribute('data-loaded', '1');
|
||||
panel.classList.remove('is-ajax-loading');
|
||||
})
|
||||
.catch(function () {
|
||||
panel.classList.remove('is-ajax-loading');
|
||||
});
|
||||
}
|
||||
|
||||
function go(i) {
|
||||
btns.forEach(function (b, idx) {
|
||||
var on = idx === i;
|
||||
b.classList.toggle('is-active', on);
|
||||
b.setAttribute('aria-selected', on ? 'true' : 'false');
|
||||
});
|
||||
panels.forEach(function (p, idx) {
|
||||
var on = idx === i;
|
||||
p.classList.toggle('is-active', on);
|
||||
if (on) {
|
||||
p.removeAttribute('hidden');
|
||||
} else {
|
||||
p.setAttribute('hidden', '');
|
||||
}
|
||||
});
|
||||
var btn = btns[i];
|
||||
var panel = panels[i];
|
||||
if (btn && panel) load(panel, btn.getAttribute('data-orderby') || 'date');
|
||||
}
|
||||
|
||||
btns.forEach(function (b) {
|
||||
b.addEventListener('click', function () {
|
||||
go(parseInt(b.getAttribute('data-index') || '0', 10));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Product multi-tab.
|
||||
function initProductTabs() {
|
||||
document.querySelectorAll('[data-aksrt-product-tab]').forEach(function (root) {
|
||||
@@ -383,86 +316,6 @@
|
||||
}
|
||||
|
||||
|
||||
function initModeratorApplyModal() {
|
||||
document.addEventListener('click', function (e) {
|
||||
var openBtn = e.target.closest('[data-aksrt-mod-apply-open]');
|
||||
if (openBtn) {
|
||||
e.preventDefault();
|
||||
var id = openBtn.getAttribute('data-aksrt-mod-apply-open');
|
||||
var modal = id ? document.getElementById(id) : null;
|
||||
if (modal) {
|
||||
modal.hidden = false;
|
||||
document.body.classList.add('aksrt-mod-apply-open');
|
||||
}
|
||||
return;
|
||||
}
|
||||
var closeBtn = e.target.closest('[data-aksrt-mod-apply-close]');
|
||||
if (closeBtn) {
|
||||
var box = closeBtn.closest('.aksrt-mod-apply-modal');
|
||||
if (box) {
|
||||
box.hidden = true;
|
||||
document.body.classList.remove('aksrt-mod-apply-open');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
document.querySelectorAll('.js-aksrt-moderator-apply-form').forEach(function (form) {
|
||||
if (form.dataset.aksrtModApplyBound === '1') return;
|
||||
form.dataset.aksrtModApplyBound = '1';
|
||||
form.addEventListener('submit', function (event) {
|
||||
event.preventDefault();
|
||||
var boardId = parseInt(form.getAttribute('data-board-id') || '0', 10);
|
||||
var reasonField = form.querySelector('[name="reason"]');
|
||||
var reason = reasonField ? reasonField.value.trim() : '';
|
||||
var feedback = form.querySelector('.js-aksrt-action-feedback');
|
||||
var submitButton = form.querySelector('button[type="submit"]');
|
||||
if (!boardId || !reason) {
|
||||
if (feedback) {
|
||||
feedback.textContent = '请填写完整的申请理由。';
|
||||
feedback.className = 'js-aksrt-action-feedback mb10 is-error';
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (submitButton) submitButton.disabled = true;
|
||||
if (feedback) {
|
||||
feedback.textContent = '正在提交申请…';
|
||||
feedback.className = 'js-aksrt-action-feedback mb10 is-loading';
|
||||
}
|
||||
var siteUrl = (window.aksrtData && aksrtData.siteUrl) ? String(aksrtData.siteUrl).replace(/\/+$/, '') : '';
|
||||
var url = siteUrl + '/wp-json/aksrt/v1/forum/moderator/apply';
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
'X-WP-Nonce': (window.aksrtData && aksrtData.restNonce) || '',
|
||||
},
|
||||
body: JSON.stringify({ board_id: boardId, reason: reason }),
|
||||
})
|
||||
.then(function (r) { return r.json().then(function (j) { return { ok: r.ok, j: j }; }); })
|
||||
.then(function (res) {
|
||||
if (!res.ok || (res.j && res.j.success === false)) {
|
||||
throw new Error((res.j && res.j.message) || '申请提交失败');
|
||||
}
|
||||
var msg = (res.j && (res.j.message || (res.j.data && res.j.data.message))) || '申请已提交';
|
||||
if (feedback) {
|
||||
feedback.textContent = msg;
|
||||
feedback.className = 'js-aksrt-action-feedback mb10 is-success';
|
||||
}
|
||||
if (reasonField) reasonField.disabled = true;
|
||||
})
|
||||
.catch(function (err) {
|
||||
if (feedback) {
|
||||
feedback.textContent = (err && err.message) || '申请提交失败。';
|
||||
feedback.className = 'js-aksrt-action-feedback mb10 is-error';
|
||||
}
|
||||
if (submitButton) submitButton.disabled = false;
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function initFloatingQRCodes() {
|
||||
var wrap = document.querySelector('.float-right');
|
||||
if (!wrap) return;
|
||||
@@ -508,11 +361,9 @@
|
||||
function init() {
|
||||
initWidgetTabs();
|
||||
initCategoryTabs();
|
||||
initForumTabTopics();
|
||||
initProductTabs();
|
||||
initMainPostsLazy();
|
||||
initFeatureIntro();
|
||||
initModeratorApplyModal();
|
||||
initFloatingQRCodes();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user