User:弃权者/Common.js.bak:修订间差异
来自OGAS数据中枢
更多操作
无编辑摘要 |
无编辑摘要 |
||
| 第57行: | 第57行: | ||
}); | }); | ||
/* | /* 首页导航互斥逻辑:确保同一时间只有一个面板展开 */ | ||
$ | mw.hook('wikipage.content').add(function($content) { | ||
$content.find('.nav-text-btn').on('click', function() { | |||
var $clicked = $(this); | |||
// 提取当前点击的 ID 后缀 (例如 game-1) | |||
var match = $clicked.attr('class').match(/mw-customtoggle-(\w+)/); | |||
if (!match) return; | |||
var currentId = match[1]; | |||
var $myContent = $('#mw-customcollapsible-' + currentId); | |||
// 如果我们正准备打开这个面板 (它目前是折叠状态) | |||
if ($myContent.hasClass('mw-collapsed')) { | |||
// 找到所有【其他】已经展开的导航面板 | |||
$('.nav-content').not($myContent).each(function() { | |||
var $other = $(this); | |||
if (!$other.hasClass('mw-collapsed')) { | |||
// 找到这个面板对应的开关并触发点击,让其收回 | |||
var otherId = $other.attr('id').replace('mw-customcollapsible-', ''); | |||
$('.mw-customtoggle-' + otherId).click(); | |||
} | |||
}); | |||
} | } | ||
}); | }); | ||
}); | }); | ||
2026年4月2日 (四) 01:31的版本
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
// 使用 mw.hook 监听内容变化,兼容 Citizen 的无刷新加载
mw.hook('wikipage.content').add(function($content) {
//强制唤醒折叠元素 (解决导航栏卡住、全展开问题)
mw.loader.using('jquery.makeCollapsible').then(function () {
// 让页面里所有的 .mw-collapsible 重新活过来
$content.find('.mw-collapsible').makeCollapsible();
});
// 2. 萌百风格 Tabs 自动转换脚本
// ==========================================
// 注意这里把原来的 $('.Tabs') 改成了 $content.find('.Tabs')
$content.find('.Tabs').each(function() {
var $tabsContainer = $(this);
// 1. 检查是否已经初始化过
if ($tabsContainer.hasClass('tabs-initialized')) return;
// 2. 提取所有的标签和内容
var $tabItems = $tabsContainer.find('> .Tab');
if ($tabItems.length === 0) return;
// 3. 创建标准的标签栏和内容容器
var $labelWrapper = $('<div class="TabLabel"></div>');
var $contentWrapper = $('<div class="TabContent"></div>');
$tabItems.each(function(index) {
var $item = $(this);
var $label = $item.find('> .TabLabelText');
var $content = $item.find('> .TabContentText');
// 给第一个设为选中
if (index === 0) {
$label.addClass('selected');
$content.addClass('selected');
}
// 绑定点击事件
$label.on('click', function() {
$labelWrapper.find('.TabLabelText').removeClass('selected');
$contentWrapper.find('.TabContentText').removeClass('selected');
$(this).addClass('selected');
$content.addClass('selected');
});
$labelWrapper.append($label);
$contentWrapper.append($content);
});
// 清空原有的“散装”内容,插入标准结构
$tabsContainer.empty().append($labelWrapper).append($contentWrapper).addClass('tabs-initialized');
});
});
/* 首页导航互斥逻辑:确保同一时间只有一个面板展开 */
mw.hook('wikipage.content').add(function($content) {
$content.find('.nav-text-btn').on('click', function() {
var $clicked = $(this);
// 提取当前点击的 ID 后缀 (例如 game-1)
var match = $clicked.attr('class').match(/mw-customtoggle-(\w+)/);
if (!match) return;
var currentId = match[1];
var $myContent = $('#mw-customcollapsible-' + currentId);
// 如果我们正准备打开这个面板 (它目前是折叠状态)
if ($myContent.hasClass('mw-collapsed')) {
// 找到所有【其他】已经展开的导航面板
$('.nav-content').not($myContent).each(function() {
var $other = $(this);
if (!$other.hasClass('mw-collapsed')) {
// 找到这个面板对应的开关并触发点击,让其收回
var otherId = $other.attr('id').replace('mw-customcollapsible-', '');
$('.mw-customtoggle-' + otherId).click();
}
});
}
});
});