用户域一次性收口:统一公开主页资源归属并折叠作者页双路径
把 uh-forum 样式收进 user-home 路由、author.php 收成 301 回退、公开主页脚本以 author.js 为唯一实现,并去掉 enqueue/body class 中的 is_author 分叉。
This commit is contained in:
1 parent
c28c1226ac
commit
f76d4650e5
9 files changed
+157
-360
No files matched your search
+3
-2
@@ -1,7 +1,8 @@
|
||||
/**
|
||||
* AKSRT Author Page
|
||||
* AKSRT Public User Home runtime
|
||||
*
|
||||
* Handles public author dashboard tabs and profile cover uploads.
|
||||
* Handles public user-home dashboard tabs and cover uploads.
|
||||
* Loaded on /user/{nicename}/ (author archives 301-redirect here).
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
@@ -1,70 +1,10 @@
|
||||
/**
|
||||
* AKSRT User Home — 公开用户主页专属脚本
|
||||
* Deprecated path.
|
||||
*
|
||||
* 负责公开主页 Tab 切换和 URL 同步。
|
||||
* Public user-home tabs/cover are handled by assets/js/author.js
|
||||
* (enqueued as aksrt-author on profile/user-home routes).
|
||||
* This file intentionally does nothing to avoid double-binding.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function initUserHomeTabs() {
|
||||
var tabContainer = document.querySelector('.dashboard--public .dashboard-tabs');
|
||||
if (!tabContainer) return;
|
||||
|
||||
var tabs = tabContainer.querySelectorAll('[data-tab]');
|
||||
var panels = {};
|
||||
var defaultTab = tabs.length ? tabs[0].getAttribute('data-tab') : 'posts';
|
||||
|
||||
tabs.forEach(function(tab) {
|
||||
var name = tab.getAttribute('data-tab');
|
||||
var panel = document.getElementById('panel-' + name);
|
||||
if (panel) {
|
||||
panels[name] = { tab: tab, panel: panel };
|
||||
}
|
||||
});
|
||||
|
||||
function switchTo(name) {
|
||||
if (!panels[name]) name = defaultTab;
|
||||
|
||||
Object.keys(panels).forEach(function(key) {
|
||||
var active = key === name;
|
||||
panels[key].tab.classList.toggle('is-active', active);
|
||||
panels[key].tab.setAttribute('aria-selected', active ? 'true' : 'false');
|
||||
panels[key].panel.classList.toggle('is-active', active);
|
||||
panels[key].panel.hidden = !active;
|
||||
});
|
||||
}
|
||||
|
||||
function tabFromUrl() {
|
||||
var m = window.location.search.match(/[?&]tab=([^&]+)/);
|
||||
return m ? decodeURIComponent(m[1]) : defaultTab;
|
||||
}
|
||||
|
||||
function updateUrl(name) {
|
||||
if (!window.history.replaceState) return;
|
||||
var u = new URL(window.location);
|
||||
if (name === defaultTab) {
|
||||
u.searchParams.delete('tab');
|
||||
} else {
|
||||
u.searchParams.set('tab', name);
|
||||
}
|
||||
window.history.replaceState({}, '', u);
|
||||
}
|
||||
|
||||
tabs.forEach(function(tab) {
|
||||
tab.addEventListener('click', function() {
|
||||
var name = this.getAttribute('data-tab');
|
||||
switchTo(name);
|
||||
updateUrl(name);
|
||||
});
|
||||
});
|
||||
|
||||
switchTo(tabFromUrl());
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', initUserHomeTabs);
|
||||
} else {
|
||||
initUserHomeTabs();
|
||||
}
|
||||
})();
|
||||
Reference in new issue
Block a user