fix(users): keep management inside center
This commit is contained in:
1 parent
c3bfd12c69
commit
ce2b266890
44 files changed
+194
-2584
No files matched your search
@@ -994,6 +994,8 @@
|
||||
var nav = document.querySelectorAll('[data-aksrt-asset-tab]');
|
||||
if (!nav.length) return;
|
||||
nav.forEach(function (link) {
|
||||
if (link.dataset.aksrtAssetTabBound === 'true') return;
|
||||
link.dataset.aksrtAssetTabBound = 'true';
|
||||
link.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
var key = link.getAttribute('data-aksrt-asset-tab');
|
||||
@@ -1054,4 +1056,8 @@
|
||||
} else {
|
||||
bootAssets();
|
||||
}
|
||||
|
||||
if (window.AksrtFrontend && typeof window.AksrtFrontend.register === 'function') {
|
||||
window.AksrtFrontend.register('credits', function () { initAssetTabs(); });
|
||||
}
|
||||
})();
|
||||
@@ -1,197 +0,0 @@
|
||||
/**
|
||||
* Document navigation AJAX (zibll page-template documentnav subset).
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function ajaxUrl() {
|
||||
if (window.aksrtData && window.aksrtData.ajaxUrl) return window.aksrtData.ajaxUrl;
|
||||
return '/wp-admin/admin-ajax.php';
|
||||
}
|
||||
|
||||
function toast(msg, type) {
|
||||
if (window.aksrt && typeof window.aksrt.toast === 'function') {
|
||||
window.aksrt.toast(msg, type || 'info');
|
||||
return;
|
||||
}
|
||||
// eslint-disable-next-line no-alert
|
||||
window.alert(msg);
|
||||
}
|
||||
|
||||
function qs(sel, root) {
|
||||
return (root || document).querySelector(sel);
|
||||
}
|
||||
|
||||
function qsa(sel, root) {
|
||||
return Array.prototype.slice.call((root || document).querySelectorAll(sel));
|
||||
}
|
||||
|
||||
function documentAjax(triggerEl, data, url) {
|
||||
var container = qs('.document-nav-container');
|
||||
var searchBox = qs('.document-search');
|
||||
if (!container) return;
|
||||
|
||||
container.classList.add('is-loading');
|
||||
if (searchBox && data && data.search) searchBox.classList.add('is-loading');
|
||||
|
||||
data = data || {};
|
||||
data.one_cat = container.getAttribute('data-one-cat') || '';
|
||||
data.action = 'aksrt_documentnav_posts';
|
||||
|
||||
var body = new URLSearchParams();
|
||||
Object.keys(data).forEach(function (k) {
|
||||
if (data[k] !== undefined && data[k] !== null) body.append(k, data[k]);
|
||||
});
|
||||
|
||||
fetch(url || ajaxUrl(), {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
|
||||
body: body.toString(),
|
||||
})
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (n) {
|
||||
if (!n || n.error || !n.html) {
|
||||
toast((n && n.msg) || '加载失败,请重试', 'danger');
|
||||
}
|
||||
if (n && n.html) container.innerHTML = n.html;
|
||||
if (n && n.history_search) {
|
||||
var hist = qs('.history-search > div');
|
||||
if (hist) hist.innerHTML = n.history_search;
|
||||
}
|
||||
})
|
||||
.catch(function () {
|
||||
toast('网络错误', 'danger');
|
||||
})
|
||||
.finally(function () {
|
||||
container.classList.remove('is-loading');
|
||||
if (searchBox) searchBox.classList.remove('is-loading');
|
||||
if (triggerEl && triggerEl.classList) triggerEl.classList.remove('is-loading');
|
||||
});
|
||||
}
|
||||
|
||||
function initAccordion() {
|
||||
var nav = qs('.document-nav');
|
||||
if (!nav) return;
|
||||
nav.addEventListener('click', function (e) {
|
||||
var toggle = e.target.closest('.panel-toggle[data-toggle="collapse"]');
|
||||
if (!toggle) return;
|
||||
e.preventDefault();
|
||||
var targetSel = toggle.getAttribute('data-target');
|
||||
var panel = targetSel ? qs(targetSel, nav) : null;
|
||||
if (!panel) return;
|
||||
var parentSel = toggle.getAttribute('data-parent');
|
||||
if (parentSel) {
|
||||
var parent = qs(parentSel, nav);
|
||||
if (parent) {
|
||||
qsa('.panel-collapse.is-open, .panel-collapse.in', parent).forEach(function (p) {
|
||||
if (p !== panel) {
|
||||
p.classList.remove('is-open', 'in');
|
||||
var t = parent.querySelector('[data-target="#' + p.id + '"]');
|
||||
if (t) t.classList.add('collapsed');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
var open = panel.classList.contains('is-open') || panel.classList.contains('in');
|
||||
if (open) {
|
||||
panel.classList.remove('is-open', 'in');
|
||||
toggle.classList.add('collapsed');
|
||||
} else {
|
||||
panel.classList.add('is-open', 'in');
|
||||
toggle.classList.remove('collapsed');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function initSearch() {
|
||||
var form = qs('.document-search-form');
|
||||
if (!form) return;
|
||||
form.addEventListener('submit', function (e) {
|
||||
e.preventDefault();
|
||||
var input = form.querySelector('[name="s"]');
|
||||
var search = input ? String(input.value || '').trim() : '';
|
||||
if (!search.length) {
|
||||
toast('请输入搜索关键词', 'warning');
|
||||
return;
|
||||
}
|
||||
if (search.length < 2) {
|
||||
toast('关键词太短', 'warning');
|
||||
return;
|
||||
}
|
||||
qsa('.cat-load').forEach(function (el) {
|
||||
el.classList.remove('is-loading', 'active');
|
||||
});
|
||||
documentAjax(qs('.document-search'), { search: search });
|
||||
});
|
||||
|
||||
document.addEventListener('click', function (e) {
|
||||
var kw = e.target.closest('.document-search .search_keywords');
|
||||
if (!kw) return;
|
||||
e.preventDefault();
|
||||
var text = (kw.textContent || '').trim();
|
||||
var input = qs('.document-search-form [name="s"]');
|
||||
if (input) {
|
||||
input.value = text;
|
||||
input.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
}
|
||||
if (form) form.dispatchEvent(new Event('submit', { cancelable: true, bubbles: true }));
|
||||
});
|
||||
}
|
||||
|
||||
function initCatLoad() {
|
||||
document.addEventListener('click', function (e) {
|
||||
var a = e.target.closest('.cat-load');
|
||||
if (!a) return;
|
||||
e.preventDefault();
|
||||
qsa('.cat-load').forEach(function (el) {
|
||||
el.classList.remove('is-loading', 'active');
|
||||
});
|
||||
a.classList.add('is-loading', 'active');
|
||||
var catId = a.getAttribute('data-cat-id') || a.getAttribute('cat-id') || '';
|
||||
documentAjax(a, { cat_id: catId });
|
||||
});
|
||||
}
|
||||
|
||||
function initPager() {
|
||||
document.addEventListener('click', function (e) {
|
||||
var a = e.target.closest('.document-nav-container .pagenav a');
|
||||
if (!a) return;
|
||||
e.preventDefault();
|
||||
var paged = a.getAttribute('data-paged') || '';
|
||||
var href = a.getAttribute('href') || '';
|
||||
if (paged) {
|
||||
// Prefer current context from last active cat or search.
|
||||
var active = qs('.cat-load.active');
|
||||
var searchInput = qs('.document-search-form [name="s"]');
|
||||
var data = { paged: paged };
|
||||
if (active) {
|
||||
data.cat_id = active.getAttribute('data-cat-id') || '';
|
||||
} else if (searchInput && searchInput.value) {
|
||||
data.search = searchInput.value.trim();
|
||||
}
|
||||
documentAjax(a, data);
|
||||
return;
|
||||
}
|
||||
if (href && href.indexOf('admin-ajax.php') !== -1) {
|
||||
documentAjax(a, {}, href);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function init() {
|
||||
if (!qs('.document-nav-container') && !qs('.document-nav')) return;
|
||||
initAccordion();
|
||||
initSearch();
|
||||
initCatLoad();
|
||||
initPager();
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
})();
|
||||
@@ -97,6 +97,10 @@
|
||||
btn.title = '关注该用户';
|
||||
}
|
||||
|
||||
if (!isFollowing && btn.closest('.uc-follow-management__item')) {
|
||||
btn.closest('.uc-follow-management__item').remove();
|
||||
}
|
||||
|
||||
// Update follower count display if exists
|
||||
var countEl = document.querySelector('.aksrt-user-home__stat-value[data-followers]');
|
||||
if (countEl && count !== undefined) {
|
||||
|
||||
@@ -1,221 +0,0 @@
|
||||
/**
|
||||
* AKSRT 网址导航页 — search tabs, sticky cat nav, submit modal/AJAX.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function qs(sel, root) {
|
||||
return (root || document).querySelector(sel);
|
||||
}
|
||||
|
||||
function qsa(sel, root) {
|
||||
return Array.prototype.slice.call((root || document).querySelectorAll(sel));
|
||||
}
|
||||
|
||||
function ajaxUrl() {
|
||||
if (window.aksrtData && window.aksrtData.ajaxUrl) return window.aksrtData.ajaxUrl;
|
||||
if (window.ajaxurl) return window.ajaxurl;
|
||||
return '/wp-admin/admin-ajax.php';
|
||||
}
|
||||
|
||||
function toast(msg, type) {
|
||||
if (window.aksrt && typeof window.aksrt.toast === 'function') {
|
||||
window.aksrt.toast(msg, type || 'info');
|
||||
return;
|
||||
}
|
||||
if (window.notyf) {
|
||||
try {
|
||||
window.notyf(msg, type === 'danger' ? 'danger' : '');
|
||||
return;
|
||||
} catch (e) { /* ignore */ }
|
||||
}
|
||||
// eslint-disable-next-line no-alert
|
||||
window.alert(msg);
|
||||
}
|
||||
|
||||
/* ---------- search engine tabs ---------- */
|
||||
function initSearchTabs() {
|
||||
var cover = qs('.link-page-search-cover');
|
||||
if (!cover) return;
|
||||
|
||||
qsa('.tab-nav-theme a[data-aksrt-tab-target]', cover).forEach(function (a) {
|
||||
a.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
var target = a.getAttribute('data-aksrt-tab-target');
|
||||
if (!target) return;
|
||||
qsa('.tab-nav-theme li', cover).forEach(function (li) {
|
||||
li.classList.remove('active');
|
||||
});
|
||||
if (a.parentElement) a.parentElement.classList.add('active');
|
||||
qsa('.tab-pane', cover).forEach(function (pane) {
|
||||
pane.classList.remove('active', 'in');
|
||||
});
|
||||
var pane = qs(target, cover);
|
||||
if (pane) pane.classList.add('active', 'in');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------- sticky category nav highlight ---------- */
|
||||
function initCatNav() {
|
||||
var wrap = qs('.links-page-container .fixed-wrap');
|
||||
if (!wrap) return;
|
||||
var nav = qs('.link-nav-box', wrap);
|
||||
var links = qsa('.link-nav-box a[href^="#"]', wrap);
|
||||
var sections = links
|
||||
.map(function (a) {
|
||||
var id = a.getAttribute('href');
|
||||
return id ? document.getElementById(id.replace(/^#/, '')) : null;
|
||||
})
|
||||
.filter(Boolean);
|
||||
if (!links.length || !sections.length) return;
|
||||
|
||||
links.forEach(function (a) {
|
||||
a.addEventListener('click', function (e) {
|
||||
var id = a.getAttribute('href');
|
||||
var el = id ? document.getElementById(id.replace(/^#/, '')) : null;
|
||||
if (!el) return;
|
||||
e.preventDefault();
|
||||
var top = el.getBoundingClientRect().top + window.pageYOffset - 90;
|
||||
window.scrollTo({ top: top, behavior: 'smooth' });
|
||||
});
|
||||
});
|
||||
|
||||
function updateActive() {
|
||||
var y = window.pageYOffset + 120;
|
||||
var current = sections[0];
|
||||
for (var i = 0; i < sections.length; i++) {
|
||||
if (sections[i].offsetTop <= y) current = sections[i];
|
||||
}
|
||||
if (!current) return;
|
||||
links.forEach(function (a) {
|
||||
var li = a.parentElement;
|
||||
if (!li) return;
|
||||
if (a.getAttribute('href') === '#' + current.id) {
|
||||
li.classList.add('active');
|
||||
} else {
|
||||
li.classList.remove('active');
|
||||
}
|
||||
});
|
||||
if (nav) nav.classList.add('affix');
|
||||
}
|
||||
|
||||
window.addEventListener('scroll', updateActive, { passive: true });
|
||||
updateActive();
|
||||
}
|
||||
|
||||
/* ---------- submit modal ---------- */
|
||||
function initSubmitModal() {
|
||||
var modal = qs('#submit-links-modal');
|
||||
if (!modal) return;
|
||||
|
||||
function openModal(e) {
|
||||
if (e) e.preventDefault();
|
||||
modal.classList.add('is-open', 'show');
|
||||
modal.setAttribute('aria-hidden', 'false');
|
||||
document.documentElement.classList.add('aksrt-modal-open');
|
||||
}
|
||||
|
||||
function closeModal(e) {
|
||||
if (e) e.preventDefault();
|
||||
modal.classList.remove('is-open', 'show');
|
||||
modal.setAttribute('aria-hidden', 'true');
|
||||
document.documentElement.classList.remove('aksrt-modal-open');
|
||||
}
|
||||
|
||||
qsa('a[href="#submit-links-modal"], [data-toggle="modal"][href="#submit-links-modal"]').forEach(function (btn) {
|
||||
btn.addEventListener('click', openModal);
|
||||
});
|
||||
|
||||
qsa('[data-dismiss="modal"]', modal).forEach(function (btn) {
|
||||
btn.addEventListener('click', closeModal);
|
||||
});
|
||||
|
||||
modal.addEventListener('click', function (e) {
|
||||
if (e.target === modal) closeModal(e);
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Escape' && modal.classList.contains('is-open')) closeModal(e);
|
||||
});
|
||||
|
||||
var fileInput = qs('.aksrt-links-logo-input', modal);
|
||||
var preview = qs('.aksrt-links-logo-preview', modal);
|
||||
if (fileInput && preview) {
|
||||
fileInput.addEventListener('change', function () {
|
||||
var file = fileInput.files && fileInput.files[0];
|
||||
if (!file) return;
|
||||
var url = URL.createObjectURL(file);
|
||||
preview.src = url;
|
||||
});
|
||||
}
|
||||
|
||||
var form = qs('.aksrt-links-submit-form', modal);
|
||||
if (!form) return;
|
||||
|
||||
form.addEventListener('submit', function (e) {
|
||||
e.preventDefault();
|
||||
var btn = qs('.aksrt-links-submit-btn', form);
|
||||
if (btn) {
|
||||
btn.disabled = true;
|
||||
btn.classList.add('loading');
|
||||
}
|
||||
|
||||
var fd = new FormData(form);
|
||||
if (!fd.get('action')) fd.set('action', 'aksrt_frontend_links_submit');
|
||||
|
||||
fetch(ajaxUrl(), {
|
||||
method: 'POST',
|
||||
body: fd,
|
||||
credentials: 'same-origin',
|
||||
})
|
||||
.then(function (r) {
|
||||
return r.json();
|
||||
})
|
||||
.then(function (data) {
|
||||
if (!data || data.error) {
|
||||
toast((data && data.msg) || '提交失败', 'danger');
|
||||
return;
|
||||
}
|
||||
toast(data.msg || '提交成功', 'success');
|
||||
if (data.reload) {
|
||||
window.setTimeout(function () {
|
||||
window.location.reload();
|
||||
}, 600);
|
||||
} else {
|
||||
closeModal();
|
||||
form.reset();
|
||||
}
|
||||
})
|
||||
.catch(function () {
|
||||
toast('网络错误,请稍后重试', 'danger');
|
||||
})
|
||||
.finally(function () {
|
||||
if (btn) {
|
||||
btn.disabled = false;
|
||||
btn.classList.remove('loading');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function init() {
|
||||
if (!document.body.classList.contains('page-template-templates-pages-page-links-php')
|
||||
&& !qs('.page-template-links')
|
||||
&& !qs('.links-page-container')
|
||||
&& !qs('#submit-links-modal')) {
|
||||
// Still bind if modal exists alone.
|
||||
}
|
||||
initSearchTabs();
|
||||
initCatNav();
|
||||
initSubmitModal();
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
})();
|
||||
@@ -82,11 +82,11 @@
|
||||
}
|
||||
target.classList.add('is-loading');
|
||||
var url = restUrl.replace(/\/$/, '') + '/user-center/panel/' + encodeURIComponent(name);
|
||||
if (name === 'creator' || name === 'revenue') {
|
||||
if (name === 'creator' || name === 'revenue' || name === 'posts' || name === 'follow') {
|
||||
var params = queryParams || new URLSearchParams(window.location.search);
|
||||
var allowedParams = name === 'creator'
|
||||
? ['income_page']
|
||||
: ['reward_tab', 'commission_page', 'invite_page'];
|
||||
var allowedParams = name === 'creator' ? ['income_page'] :
|
||||
(name === 'revenue' ? ['reward_tab', 'commission_page', 'invite_page'] :
|
||||
(name === 'posts' ? ['post_status', 'posts_page'] : ['follow_list', 'follow_page']));
|
||||
allowedParams.forEach(function(key) {
|
||||
if (params.get(key)) url += (url.indexOf('?') === -1 ? '?' : '&') + key + '=' + encodeURIComponent(params.get(key));
|
||||
});
|
||||
@@ -328,6 +328,33 @@
|
||||
});
|
||||
}
|
||||
|
||||
function initPostDeletion() {
|
||||
if (document.documentElement.dataset.aksrtPostDeletionBound === 'true') return;
|
||||
document.documentElement.dataset.aksrtPostDeletionBound = 'true';
|
||||
document.addEventListener('click', function(e) {
|
||||
var btn = e.target && e.target.closest ? e.target.closest('[data-action="delete-post"]') : null;
|
||||
if (!btn || btn.disabled || !confirm('确定删除这篇文章?')) return;
|
||||
e.preventDefault();
|
||||
btn.disabled = true;
|
||||
var body = new URLSearchParams();
|
||||
body.set('action', 'aksrt_delete_post');
|
||||
body.set('post_id', btn.getAttribute('data-post-id') || '');
|
||||
body.set('nonce', btn.getAttribute('data-nonce') || submitNonce);
|
||||
fetch(ajaxUrl, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }, credentials: 'same-origin', body: body.toString() })
|
||||
.then(function(response) { return response.json(); })
|
||||
.then(function(response) {
|
||||
if (!response || !response.success) throw new Error('delete-failed');
|
||||
var item = btn.closest('.profile-list-item');
|
||||
if (item) item.remove();
|
||||
if (typeof showToast === 'function') showToast('文章已删除');
|
||||
})
|
||||
.catch(function() {
|
||||
btn.disabled = false;
|
||||
if (typeof showToast === 'function') showToast(i18n.operationFailed || '操作失败');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/* ==================== 通知中心 ==================== */
|
||||
function initNotifications() {
|
||||
var list = document.getElementById('aksrt-notification-list');
|
||||
@@ -755,6 +782,7 @@
|
||||
initProfileForm();
|
||||
initAuthForm();
|
||||
initUnfavorite();
|
||||
initPostDeletion();
|
||||
initNotifications();
|
||||
initSettings();
|
||||
});
|
||||
@@ -763,7 +791,8 @@
|
||||
initProfileForm();
|
||||
initAuthForm();
|
||||
initUnfavorite();
|
||||
initNotifications();
|
||||
initPostDeletion();
|
||||
initNotifications();
|
||||
initSettings();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user