Common.js:修订间差异
来自卡厄思梦境WIKI
创建页面,内容为“→这里的任何JavaScript将为所有用户在每次页面加载时加载。: →MediaWiki 标签切换功能: (function() { 'use strict'; // 等待DOM加载完成 function initTabSwitcher() { // 查找所有标签容器 var tabContainers = document.querySelectorAll('.resp-tabs'); tabContainers.forEach(function(container) { var tabList = container.querySelector('.resp-tabs-list');…” |
无编辑摘要 |
||
| 第1行: | 第1行: | ||
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */ | /* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */ | ||
(function() { | (function() { | ||
'use strict'; | 'use strict'; | ||
function initTabSwitcher() { | function initTabSwitcher() { | ||
var tabContainers = document.querySelectorAll('.resp-tabs'); | var tabContainers = document.querySelectorAll('.resp-tabs'); | ||
tabContainers.forEach(function(container) { | tabContainers.forEach(function(container) { | ||
var | var tabButtons = container.querySelectorAll('.czn-list-style'); | ||
if (tabButtons.length === 0) return; | |||
// 检测模式 | |||
var tabContents = container.querySelectorAll('.resp-tab-content'); | var tabContents = container.querySelectorAll('.resp-tab-content'); | ||
var | var portraitImages = document.querySelectorAll('.portrait-image'); | ||
// 初始化 | |||
tabButtons.forEach(function(button, index) { | |||
button.classList.toggle('active', index === 0); | |||
}); | |||
if ( | if (tabContents.length > 0) { | ||
tabContents.forEach(function(content, index) { | |||
content.style.display = index === 0 ? 'block' : 'none'; | |||
}); | |||
} | } | ||
if (portraitImages.length > 0) { | |||
if ( | portraitImages.forEach(function(image, index) { | ||
image.style.display = index === 0 ? 'block' : 'none'; | |||
}); | |||
} | } | ||
// | // 点击事件 | ||
tabButtons.forEach(function(button, index) { | tabButtons.forEach(function(button, index) { | ||
button.addEventListener('click', function(e) { | button.addEventListener('click', function(e) { | ||
e.preventDefault(); | e.preventDefault(); | ||
// | // 更新标签状态 | ||
tabButtons.forEach(function(btn) { | tabButtons.forEach(function(btn, i) { | ||
btn.classList. | btn.classList.toggle('active', i === index); | ||
}); | }); | ||
// | // 传统模式切换 | ||
tabContents.forEach(function(content) { | if (tabContents.length > 0) { | ||
tabContents.forEach(function(content, i) { | |||
content.style.display = i === index ? 'block' : 'none'; | |||
}); | |||
} | |||
// | // 立绘模式切换 | ||
if (portraitImages.length > 0) { | |||
portraitImages.forEach(function(image) { | |||
image.style.display = 'none'; | |||
}); | |||
var targetImage = document.querySelector('.portrait-image[data-index="' + index + '"]'); | |||
if (targetImage) { | |||
targetImage.style.display = 'block'; | |||
} | |||
} | } | ||
}); | }); | ||
| 第80行: | 第64行: | ||
} | } | ||
// | // 初始化 | ||
if (document.readyState === 'loading') { | if (document.readyState === 'loading') { | ||
document.addEventListener('DOMContentLoaded', initTabSwitcher); | document.addEventListener('DOMContentLoaded', initTabSwitcher); | ||
| 第86行: | 第70行: | ||
initTabSwitcher(); | initTabSwitcher(); | ||
} | } | ||
})(); | })(); | ||
2025年9月21日 (日) 18:57的版本
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
(function() {
'use strict';
function initTabSwitcher() {
var tabContainers = document.querySelectorAll('.resp-tabs');
tabContainers.forEach(function(container) {
var tabButtons = container.querySelectorAll('.czn-list-style');
if (tabButtons.length === 0) return;
// 检测模式
var tabContents = container.querySelectorAll('.resp-tab-content');
var portraitImages = document.querySelectorAll('.portrait-image');
// 初始化
tabButtons.forEach(function(button, index) {
button.classList.toggle('active', index === 0);
});
if (tabContents.length > 0) {
tabContents.forEach(function(content, index) {
content.style.display = index === 0 ? 'block' : 'none';
});
}
if (portraitImages.length > 0) {
portraitImages.forEach(function(image, index) {
image.style.display = index === 0 ? 'block' : 'none';
});
}
// 点击事件
tabButtons.forEach(function(button, index) {
button.addEventListener('click', function(e) {
e.preventDefault();
// 更新标签状态
tabButtons.forEach(function(btn, i) {
btn.classList.toggle('active', i === index);
});
// 传统模式切换
if (tabContents.length > 0) {
tabContents.forEach(function(content, i) {
content.style.display = i === index ? 'block' : 'none';
});
}
// 立绘模式切换
if (portraitImages.length > 0) {
portraitImages.forEach(function(image) {
image.style.display = 'none';
});
var targetImage = document.querySelector('.portrait-image[data-index="' + index + '"]');
if (targetImage) {
targetImage.style.display = 'block';
}
}
});
});
});
}
// 初始化
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initTabSwitcher);
} else {
initTabSwitcher();
}
})();