MediaWiki:Common.js:修订间差异
跳到导航
跳到搜索
无编辑摘要 |
无编辑摘要 |
||
| 第86行: | 第86行: | ||
// 102. 功能:封面画册JS代码 | // 102. 功能:封面画册JS代码 | ||
/ | <script> | ||
// 核心 轮播 逻辑 | |||
/ | const slides = document.querySelectorAll('.carousel-slide'); | ||
const slideContainer = document.querySelector('.carousel-slides'); | |||
const prevBtn = document.querySelector('.prev'); | |||
const nextBtn = document.querySelector('.next'); | |||
const carouselContainer = document.getElementById('carousel-container'); | |||
let currentSlide = 0; | |||
const slideCount = slides.length; | |||
const intervalTime = 3000; // 轮播间隔3秒 | |||
let autoPlayInterval; | |||
// 更新 轮播 显示 | |||
function updateSlidePosition() { | |||
slideContainer.style.transform = `translateX(-${currentSlide * 100}%)`; | |||
} | } | ||
// 下一张 | |||
function nextSlide() { | function nextSlide() { | ||
currentSlide = (currentSlide + 1) % slideCount; | |||
updateSlidePosition(); | |||
} | } | ||
// 上一张 | |||
function prevSlide() { | function prevSlide() { | ||
currentSlide = (currentSlide - 1 + slideCount) % slideCount; | |||
updateSlidePosition(); | |||
} | } | ||
function | // 自动播放 | ||
function startAutoPlay() { | |||
autoPlayInterval = setInterval(nextSlide, intervalTime); | |||
} | } | ||
// | // 暂停自动播放 | ||
function | function stopAutoPlay() { | ||
clearInterval(autoPlayInterval); | |||
} | } | ||
// | // 绑定按钮 事件 | ||
prevBtn.addEventListener('click', prevSlide); | |||
nextBtn.addEventListener('click', nextSlide); | |||
// 鼠标悬停暂停,离开继续 | |||
carouselContainer.addEventListener('mouseenter', stopAutoPlay); | |||
carouselContainer.addEventListener('mouseleave', startAutoPlay); | |||
// 初始化 | |||
updateSlidePosition(); | |||
startAutoPlay(); | |||
</script> | |||
</div> | |||
2025年12月25日 (四) 22:54的版本
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
/*加载ToolsWIKI的DiffTool 以逐字显示更改,0缓存,具体可见https://wiki.biligame.com/tools/%E4%BC%98%E5%8C%96%E7%89%88%E6%9C%AC%E5%B7%AE%E5%BC%82-DiffTools */
try { mw.loader.load("https://wiki.biligame.com/tools/MediaWiki:DiffTool.js?action=raw&ctype=text/javascript&rand="+Math.random(), "text/javascript");} catch(e) { console.log("Error, MediaWiki:DiffTool.js 加载失败");console.error(e, e.stack);}
/* 参见[[模板:ResourceLoader]]*/
//居中与右对齐,文本默认为左对齐,不用另外添加此按钮。(仅适用于源代码编辑模式)
/*居中*/
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
// Add a hook handler.
mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
// Configure a new toolbar entry on the given $textarea jQuery object.
$textarea.wikiEditor( 'addToToolbar', {
section: 'advanced',
group: 'format',
tools: {
AlignCenter: {
label: '居中',
type: 'button',
oouiIcon: 'alignCenter',
action: {
type: 'encapsulate',
options: {
pre: "<center>",
post: "</center>"
}
}
}
}
} );
} );
}
/*右对齐*/
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
// Add a hook handler.
mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
// Configure a new toolbar entry on the given $textarea jQuery object.
$textarea.wikiEditor( 'addToToolbar', {
section: 'advanced',
group: 'format',
tools: {
AlignCenter: {
label: '右对齐',
type: 'button',
oouiIcon: 'alignRight',
action: {
type: 'encapsulate',
options: {
pre: "<div align=right>",
post: "</div>"
}
}
}
}
} );
} );
}
// 101. 功能:快捷编辑理由。支持编辑摘要时,点击快捷选项填充编辑理由。(仅适用于源代码编辑模式)
//参考Wikipedia:MediaWiki:Common.js/edit.js
if (mw.config.get('wgAction') == "edit" || mw.config.get('wgAction') == "submit" || mw.config.get('wgCanonicalSpecialPageName') == 'Search') { // 编辑页面
( function( $, mw ) { $( function() {
if ( $( '#editform input[name=wpSection]' ).val() === 'new' ) {
if ( $( '#no-new-title' ).length ) {
$( '#wpSummary' ).attr( 'disabled', true );
}
return;
}
$( '#wpSummaryLabel .mw-summary-preset' ).on( 'click', '.mw-summary-preset-item a', function( e ) {
e.preventDefault();
var $this = $( this ), summary = $( '#wpSummary' ).val();
var $item = $this.parent( '.mw-summary-preset-item' );
summary = summary.replace( /\s+$/g, '' );
if ( summary != '' ) {
summary += ' ';
}
summary += $item.attr( 'title' ) || $this.text();
$this.replaceWith( $this.contents() );
$( '#wpSummary' ).val( summary ).focus();
} );
} ); } )( jQuery, mediaWiki );
}
// 102. 功能:封面画册JS代码
<script>
// 核心轮播逻辑
const slides = document.querySelectorAll('.carousel-slide');
const slideContainer = document.querySelector('.carousel-slides');
const prevBtn = document.querySelector('.prev');
const nextBtn = document.querySelector('.next');
const carouselContainer = document.getElementById('carousel-container');
let currentSlide = 0;
const slideCount = slides.length;
const intervalTime = 3000; // 轮播间隔3秒
let autoPlayInterval;
// 更新轮播显示
function updateSlidePosition() {
slideContainer.style.transform = `translateX(-${currentSlide * 100}%)`;
}
// 下一张
function nextSlide() {
currentSlide = (currentSlide + 1) % slideCount;
updateSlidePosition();
}
// 上一张
function prevSlide() {
currentSlide = (currentSlide - 1 + slideCount) % slideCount;
updateSlidePosition();
}
// 自动播放
function startAutoPlay() {
autoPlayInterval = setInterval(nextSlide, intervalTime);
}
// 暂停自动播放
function stopAutoPlay() {
clearInterval(autoPlayInterval);
}
// 绑定按钮事件
prevBtn.addEventListener('click', prevSlide);
nextBtn.addEventListener('click', nextSlide);
// 鼠标悬停暂停,离开继续
carouselContainer.addEventListener('mouseenter', stopAutoPlay);
carouselContainer.addEventListener('mouseleave', startAutoPlay);
// 初始化
updateSlidePosition();
startAutoPlay();
</script>
</div>