MediaWiki:Common.js:修订间差异

来自神国维基
跳到导航跳到搜索
七叶​(留言 | 贡献)
创建页面,内容为“→这里的任何JavaScript将为所有用户在每次页面加载时加载。:​ →===== 把目录搬到左侧边栏(工具框下面) =====:​ ( function () { function moveTOC() { // 只在宽屏生效(手机屏太窄会挤坏布局) if ( !window.matchMedia( '(min-width: 768px)' ).matches ) { return; } // 已经搬过了就不重复 if ( document.getElementById( 'p-toc' ) ) { return; } var toc = document.querySelector( '.mw-table…”
 
七叶​(留言 | 贡献)
无编辑摘要
第1行: 第1行:
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
/* ===== 把目录搬到左侧边栏(工具框下面) ===== */
/*  
( function () {
( function () {
function moveTOC() {
function moveTOC() {
// 只在宽屏生效(手机屏太窄会挤坏布局)
//  
if ( !window.matchMedia( '(min-width: 768px)' ).matches ) {
if ( !window.matchMedia( '(min-width: 768px)' ).matches ) {
return;
return;
第28行: 第28行:
var body = document.createElement( 'div' );
var body = document.createElement( 'div' );
body.className = 'pBody';
body.className = 'pBody';
body.appendChild( toc );  // ← 把目录整个搬进来
body.appendChild( toc );  //  


portlet.appendChild( h3 );
portlet.appendChild( h3 );
portlet.appendChild( body );
portlet.appendChild( body );
sidebar.appendChild( portlet );  // ← 挂到"工具"框下面
sidebar.appendChild( portlet );  //  
}
}



2026年10月5日 (一) 19:11的版本

/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
/* 
( function () {
	function moveTOC() {
		// 
		if ( !window.matchMedia( '(min-width: 768px)' ).matches ) {
			return;
		}
		// 已经搬过了就不重复
		if ( document.getElementById( 'p-toc' ) ) {
			return;
		}
		var toc = document.querySelector( '.mw-table-of-contents-container' )
			|| document.querySelector( '.mw-table-of-contents' )
			|| document.getElementById( 'toc' );
		var sidebar = document.getElementById( 'column-one' );
		if ( !toc || !sidebar ) {
			return;
		}

		var portlet = document.createElement( 'div' );
		portlet.className = 'portlet';
		portlet.id = 'p-toc';

		var h3 = document.createElement( 'h3' );
		h3.textContent = '目录';

		var body = document.createElement( 'div' );
		body.className = 'pBody';
		body.appendChild( toc );   // 

		portlet.appendChild( h3 );
		portlet.appendChild( body );
		sidebar.appendChild( portlet );   // 
	}

	if ( document.readyState === 'loading' ) {
		document.addEventListener( 'DOMContentLoaded', moveTOC );
	} else {
		moveTOC();
	}
}() );