查看“︁MediaWiki:Common.js”︁的源代码
来自神国反恶俗
←
MediaWiki:Common.js
跳到导航
跳到搜索
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
此页面为本wiki上的软件提供界面文本,并受到保护以防止滥用。如欲修改所有wiki的翻译,请访问
translatewiki.net
上的MediaWiki本地化项目。
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有访问者。
您可以查看和复制此页面的源代码。
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */ ( function () { /* ========================================================== 一、把页面里的目录(TOC)搬到左侧栏 —— 你原来就有的功能,保持不动 ========================================================== */ function moveTOC() { var toc = document.getElementById( 'toc' ) || document.querySelector( '.mw-table-of-contents-container' ) || document.querySelector( '.mw-table-of-contents' ); var sidebar = document.getElementById( 'column-one' ) || document.getElementById( 'mw-panel' ); if ( !toc || !sidebar || document.getElementById( 'p-toc' ) ) { return; } var box = document.createElement( 'div' ); box.className = 'portlet'; box.id = 'p-toc'; var title = document.createElement( 'h3' ); title.textContent = '目录'; var inner = document.createElement( 'div' ); inner.className = 'pBody'; inner.appendChild( toc ); box.appendChild( title ); box.appendChild( inner ); sidebar.appendChild( box ); } /* ========================================================== 二、吸顶:左侧栏 / 顶部编辑标签栏 / 右上账号栏 —— 按页面实际有没有这些栏目动态处理,不会多留空白 ========================================================== */ var STICKY_CSS = [ '#sg-personal-bar,#sg-cactions-bar{', ' position:fixed;top:0;z-index:401;', ' background:#fff;box-shadow:0 1px 4px rgba(0,0,0,.18);', ' padding:4px 10px;font-size:88%;line-height:1.4;', ' white-space:nowrap;overflow-x:auto;overflow-y:hidden;', '}', '#sg-personal-bar{right:0;border-radius:0 0 0 8px;}', '#sg-cactions-bar{border-radius:0 0 8px 0;}', '#sg-personal-bar a,#sg-cactions-bar a{', ' color:#36c;text-decoration:none;padding:2px 5px;', '}', '#sg-personal-bar a:hover,#sg-cactions-bar a:hover{', ' text-decoration:underline;', '}', '#sg-cactions-bar a{border-right:1px solid #e3e5e8;}', '#sg-cactions-bar a:last-child{border-right:none;}', '#column-one{', ' position:sticky;top:var(--sg-top-offset,0px);', ' max-height:calc(100vh - var(--sg-top-offset,0px));', ' overflow-y:auto;', '}', 'body.sg-sticky-on #content{', ' padding-top:var(--sg-top-offset,0px) !important;', '}' ].join( '\n' ); function injectCSS() { if ( document.getElementById( 'sg-sticky-style' ) ) { return; } var s = document.createElement( 'style' ); s.id = 'sg-sticky-style'; s.type = 'text/css'; s.textContent = STICKY_CSS; document.head.appendChild( s ); } /* 把某个栏目里的链接复制到一条固定栏上;栏目为空就不做 */ function buildBar( portlet, barId ) { if ( !portlet ) { return null; } var links = portlet.querySelectorAll( 'ul a' ); if ( !links.length ) { return null; } var old = document.getElementById( barId ); if ( old && old.parentNode ) { old.parentNode.removeChild( old ); } var bar = document.createElement( 'div' ); bar.id = barId; Array.prototype.forEach.call( links, function ( a ) { var copy = document.createElement( 'a' ); copy.href = a.href; copy.textContent = a.textContent; bar.appendChild( copy ); } ); document.body.appendChild( bar ); return bar; } function makeSticky() { injectCSS(); var personal = document.getElementById( 'p-personal' ); /* 账号那排 */ var cactions = document.getElementById( 'p-cactions' ); /* 编辑标签那排 */ /* 账号栏:永远吸顶、靠右 */ if ( buildBar( personal, 'sg-personal-bar' ) && personal ) { personal.style.visibility = 'hidden'; } /* 编辑标签栏:吸顶,排在账号栏下面 */ var ca = buildBar( cactions, 'sg-cactions-bar' ); if ( ca && cactions ) { cactions.style.visibility = 'hidden'; } /* 算出顶部实际占多高,动态决定正文留白 */ var topH = 0; var pBar = document.getElementById( 'sg-personal-bar' ); if ( pBar ) { topH += pBar.offsetHeight; } if ( ca ) { ca.style.top = topH + 'px'; topH += ca.offsetHeight; } document.documentElement.style.setProperty( '--sg-top-offset', topH + 'px' ); if ( topH > 0 ) { document.body.classList.add( 'sg-sticky-on' ); } else { document.body.classList.remove( 'sg-sticky-on' ); } } /* ========================================================== 启动 ========================================================== */ function run() { moveTOC(); makeSticky(); } if ( document.readyState === 'loading' ) { document.addEventListener( 'DOMContentLoaded', run ); } else { run(); } window.addEventListener( 'resize', function () { clearTimeout( window.__sgTimer ); window.__sgTimer = setTimeout( makeSticky, 150 ); } ); }() );
返回
MediaWiki:Common.js
。
导航菜单
页面操作
系统消息
讨论
阅读
查看源代码
历史
页面操作
系统消息
讨论
更多
工具
个人工具
创建账号
登录
导航
首页
最近更改
审核队列
随机页面
特殊页面
日志
用户墙
讨论区
个人资料
好友
搜索
帮助
反恶俗指导思想
道歉受理中心
关于本站
服务条款
友情链接
世拥维基
特色站点
kit维基
秋府维基
恶俗狗维基
恶俗维基
工具
链入页面
相关更改
页面信息