「MediaWiki:Common.js」修訂間的差異

出自宅犬維基
跳至導覽 跳至搜尋
 
(未顯示同一使用者於中間所作的 8 次修訂)
行 1: 行 1:
/*
+
/* Any JavaScript here will be loaded for all users on every page load. */
所有用戶在加載任何頁面時,這裡的JavaScript都會加載
 
  
== 輔助處理 ==
+
// <syntax type="javascript">
*/
 
//功能設定
 
var JSConfig={
 
//showBarA:(wgUserName == null),//設定JS Anonnotice的匿名出現條件
 
//showBarU:false,//設定登入用戶使用JS Anonnotice的開關
 
edittoolsMode:'default', //設置編輯按鈕方案,參看[[Wikipedia:維基百科工具/編輯工具]]
 
isEdit0:true, //設置是否顯示編輯首段按鈕
 
editSectionLink:'right',//設置編輯按鈕是否在右側
 
collapseText:wgULS('隱藏▲','隱藏▲'),//指示折疊收縮的默認文字
 
expandText:wgULS('顯示▼','顯示▼'),//指示折疊展開的默認文字
 
autoCollapse:2,  //文章少於 autoCollapse 個折疊塊時,不自動折疊
 
SpecialSearchEnhancedDisabled:false, //是否禁止增加其它搜索引擎
 
blockMsg:wgULS(
 
'若您來自中國大陸並能順利瀏覽,請<a href="http://zh.wikipedia.org/wiki/Special:Userlogin" title="Special:Userlogin">登錄</a>後至<a href="http://zh.wikipedia.org/wiki/Wikipedia:狀況回報" title="Wikipedia:狀況回報">狀況回報</a>。',
 
'若您來自中國大陸並能順利瀏覽,請<a href="http://zh.wikipedia.org/wiki/Special:Userlogin" title="Special:Userlogin">登入</a>後至<a href="http://zh.wikipedia.org/wiki/Wikipedia:狀況回報" title="Wikipedia:狀況回報">狀況回報</a>。'
 
),
 
siteNotice:wgULS(
 
'歡迎各位參與討論:<b><a href="/wiki/Wikipedia_talk:可供查證">可供查證方針</a>、<a href="/wiki/Wikipedia:申請罷免管理員/方針草案">管理員解任制度</a></b>、<a href="/wiki/Wikipedia_talk:用戶查核方針">用戶查核方針</a>',
 
'歡迎各位參與討論:<b><a href="/wiki/Wikipedia_talk:可供查證">可供查證方針</a>、<a href="/wiki/Wikipedia:申請罷免管理員/方針草案">管理員解任制度</a></b>、<a href="/wiki/Wikipedia_talk:用戶查核方針">用戶查核方針</a>')
 
}
 
// 兼容性修正
 
if (document.attachEvent && document.compatMode && document.compatMode == "CSS1Compat")
 
{
 
var oldWidth;
 
var docEl = document.documentElement;
 
  
function fixIEScroll()
+
    /**
{
+
        Toggles the display of elements on a page
if (!oldWidth || docEl.clientWidth > oldWidth){
+
        Author/contact: Austin Che http://openwetware.org/wiki/User:Austin_J._Che
doFixIEScroll();
+
        See http://openwetware.org/wiki/OpenWetWare:Toggle for examples and documentation
}else{
+
    */
setTimeout(doFixIEScroll, 1);
 
}
 
oldWidth = docEl.clientWidth;
 
}
 
  
function doFixIEScroll() {
+
// indexed array of toggler ids to array of associated toggle operations
docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : "";
+
// each operation is a two element array, the first being the type, the second a class name or array of elements
}
+
// operation types are strings like "_reset" or "" for the default toggle operation
 +
var togglers = new Array();   
 +
var allClasses = new Object(); // associative map of class names to page elements
  
document.attachEvent("onreadystatechange", fixIEScroll);
+
function toggler(id)
attachEvent("onresize", fixIEScroll);
+
{
}
+
    var toBeToggled = togglers[id];
 +
    if (!toBeToggled)
 +
        return;
  
// 移動元素
+
    // if some element is in list more than once, it will be toggled multiple times
function elementMoveto(node, refNode, pos){//默認位置為refNode前
+
    for (var i = 0; i < toBeToggled.length; i++)
if(node && refNode){
+
    {
var parent=refNode.parentNode;
+
        // get array of elements to operate on
if (pos && pos=='after') {refNode=refNode.nextSibling;}
+
        var toggles = toBeToggled[i][1];
try {
+
        if (typeof(toggles) == "string")
if(refNode){
+
        {
parent.insertBefore(node, refNode);
+
            if (toggles.charAt(0) == '-')
}else{
+
            {
parent.appendChild(node);
+
                // treat as an element ID, not as class
}
+
                toggles = document.getElementById(toggles.substring(1));
} catch (DOMException) {};
+
                if (toggles)
}
+
                    toggles = new Array(toggles);
}
+
            }
//創建元素
+
            else
function createElement(tag,children,props){
+
                toggles = allClasses[toggles];
var element = document.createElement(tag);
+
        }
if(!(children instanceof Array)){children=[children];}
+
        if (!toggles || !toggles.length)
for(var i=0;i<children.length;i++){
+
            continue;
var child=children[i];
 
if(typeof child=='string'){child=document.createTextNode(child);}
 
if(child){element.appendChild(child);}
 
}
 
if(typeof props=='object'){
 
for(var k in props){
 
switch(k){
 
case 'styles':
 
var styles=props.styles;
 
for(var s in styles){element.style[s]=styles[s];}
 
break;
 
case 'events':
 
var events=props.events;
 
for(var e in events){ addHandler(element,e,events[e]); }
 
break;
 
case 'class':
 
element.className=props[k];break;
 
default:
 
element.setAttribute(k,props[k]);
 
}
 
}
 
}
 
return element;
 
}
 
  
//wiki URL
+
        var op = toBeToggled[i][0]; // what the operation will be
var wgProjectURL={
 
en:'http://en.wikipedia.org/',de:'http://de.wikipedia.org/',fr:'http://fr.wikipedia.org/',
 
pl:'http://pl.wikipedia.org/',ja:'http://ja.wikipedia.org/',it:'http://it.wikipedia.org/',
 
nl:'http://nl.wikipedia.org/',pt:'http://pt.wikipedia.org/',es:'http://es.wikipedia.org/',
 
sv:'http://sv.wikipedia.org/',//僅列前十名其它語言百科
 
m:'http://meta.wikimedia.org/',b:'http://zh.wikibooks.org/',q:'http://zh.wikiquote.org/',
 
n:'http://zh.wikinews.org/',wikt:'http://zh.wiktionary.org/',mw:'http://www.mediawiki.org/'
 
}
 
/**
 
* 將頁面名稱轉換為URL
 
*
 
* @param page 頁面名稱
 
* @param paras 附加後綴對象,用空對像{}做參數可以取得源碼
 
*/
 
function getWikiPath(page,paras){
 
var reg=/^[a-z]+:/;
 
var pre=page.match(reg);
 
pre = pre && wgProjectURL[pre[0].replace(/:$/,'')];
 
if (pre) {page=page.replace(reg,'');} else {pre='';}
 
var url = pre + wgScript + '?title=' + encodeURI( page.replace( ' ', '_' ) );
 
if(typeof paras=='object'){
 
paras.ctype=paras.ctype||'text';
 
paras.dontcountme=paras.dontcountme||'s';
 
paras.action=paras.action||'raw';
 
for(var k in paras){url += '&' + k + '=' + paras[k]; }
 
}
 
return url;
 
}
 
  
//JS、CSS導入模塊
+
        switch (op)
function importScript( page ) {
+
        {
var src= /^https?:\/\//.test(page) ? page : getWikiPath(page,{'ctype':'text/javascript'});
+
            case "_reset":
var scriptElem = createElement( 'script',null,{'src':src,'type':'text/javascript'} );
+
                for (var j = 0; j < toggles.length; j++)
document.getElementsByTagName( 'head' )[0].appendChild( scriptElem );
+
                    toggles[j].style.display = toggles[j]._toggle_original_display;
}
+
                break;
function importStylesheet( page ) {
+
            case "_show":
var sheet= /^https?:\/\//.test(page) ? page : getWikiPath(page,{'ctype':'text/css'});
+
                for (var j = 0; j < toggles.length; j++)
var styleElem = createElement( 'style', ['@import "'+sheet+'";'], {'type':'text/css'} );
+
                    toggles[j].style.display = '';
document.getElementsByTagName( 'head' )[0].appendChild( styleElem );
+
                break;
 +
            case "_hide":
 +
                for (var j = 0; j < toggles.length; j++)
 +
                    toggles[j].style.display = 'none';
 +
                break;
 +
            case "":
 +
            default:
 +
                // Toggle
 +
                for (var j = 0; j < toggles.length; j++)
 +
                    toggles[j].style.display = ((toggles[j].style.display == 'none') ? '' : 'none');
 +
                break;
 +
        }
 +
    }
 
}
 
}
  
/* 測試元素中是否含有指定的樣式 **************************************
+
function createTogglerLink(toggler, id)
* Description: 使用正則式與緩存來提高性能
+
{
* Maintainers: User:fdcn @zh.wikipedia
+
    var toggle = document.createElement("a");
*              [[en:User:Mike Dillon]], [[en:User:R. Koot]], [[en:User:SG]] @en.wikipedia
+
    toggle.className = 'toggler-link';
*/
+
    toggle.setAttribute('id', 'toggler' + id);
var hasClass = (function () {
+
    toggle.setAttribute('href', 'javascript:toggler("' + id + '");');
var reCache = {};
+
    var child = toggler.firstChild;
return function (element, className) {
+
    toggler.removeChild(child);
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
+
    toggle.appendChild(child);
};
+
    toggler.insertBefore(toggle, toggler.firstChild);
})();
 
 
 
//設置中文語言頁
 
var htmlE=document.documentElement;
 
htmlE.setAttribute("lang",wgUserLanguage);
 
htmlE.setAttribute("xml:lang",wgUserLanguage);
 
 
 
//返回繁簡字串
 
function wgULS(cn,tw,hk,sg,zh){//保證每一語言有值
 
return {'zh-cn':cn||sg,'zh-sg':sg||cn,'zh-tw':tw||hk,'zh-hk':hk||tw,'zh':zh||cn||tw||hk||sg}[wgUserLanguage];
 
 
}
 
}
/*
 
  
== 語言地區轉換增強 ==
+
function toggleInit()
*/
 
/** lan enhanced Conversion ***********************************************************
 
*
 
*  Description: 根據當前用戶語言顯示相應內容
 
*  Maintainers: Fdcn@zh.wikipedia
 
*/
 
addOnloadHook(function(){
 
var lanBlocks=getElementsByClassName(document.getElementById('bodyContent'),"*","lanOptional");
 
for(var i = 0; i < lanBlocks.length; i++) {
 
if(!hasClass(lanBlocks[i],wgUserLanguage)){lanBlocks[i].style.display="none";}
 
}
 
});
 
 
 
/*
 
 
 
== 工具提示與快捷鍵 ==
 
*/
 
ta = {
 
'ca-article'        : ['a',wgULS('瀏覽條目正文','瀏覽條目正文')],
 
'ca-nomove'          : ['',wgULS('你不能移動這個頁面','你不能移動這個頁面')],
 
'n-Featured_content' : ['',wgULS('查看中文維基百科的特色內容','查看中文維基百科的特色內容')],
 
'n-indexpage'        : ['',wgULS('以分類索引搜尋中文維基百科','以分類索引搜尋中文維基百科')],
 
'n-commonsupload'    : ['',wgULS('把自由版權圖片上傳到維基共享資源','把自由版權圖片上傳到維基共享資源')],
 
'n-contact'          : ['',wgULS('如何聯絡維基百科','如何聯絡維基百科')],
 
'n-villagepump'      : ['',wgULS('參與維基百科社群的討論','參與維基百科社群的討論')],
 
'n-Information_desk' : ['',wgULS('解答任何與維基百科無關的問題的地方','解答任何與維基百科無關的問題的地方')],
 
'n-conversion'      : ['',wgULS('提出繁簡體轉換請求','提出繁簡體轉換請求')],
 
'n-allpages'        : ['',wgULS('瀏覽所有頁面的清單','瀏覽所有頁面的清單')],
 
'ca-nstab-project'  : ['a',wgULS('查看維基計劃頁面','查看維基計畫頁面','查看維基計劃頁面')],
 
'n-policy'          : ['',wgULS('查看維基百科的方針和指引','查看維基百科的方針和指引')],
 
'n-about'            : ['',wgULS('查看維基百科的簡介','查看維基百科的簡介')]
 
}
 
 
 
/*
 
 
 
== 特色條目優良與條目鏈接顯示==
 
*/
 
 
 
addOnloadHook(function()  
 
 
{
 
{
if ( document.getElementById( "p-lang" ) ) {
+
    var togglerElems = new Array();
var InterwikiLinks = document.getElementById( "p-lang" ).getElementsByTagName( "li" );
+
    var toggleGroup = new Array();
 
 
for ( var i = 0; i < InterwikiLinks.length; i++ ) {
 
if ( document.getElementById( InterwikiLinks[i].className + "-fa" ) ) {
 
InterwikiLinks[i].className += " FA"
 
InterwikiLinks[i].title = wgULS("此條目為特色條目。","此條目為特色條目。");
 
}
 
if ( document.getElementById( InterwikiLinks[i].className + "-ga" ) ) {
 
InterwikiLinks[i].className += " GA"
 
InterwikiLinks[i].title = wgULS("此條目為優良條目。","此條目為優良條目。");
 
}
 
}
 
}
 
});
 
/*
 
 
 
== 調整編輯工具欄==
 
*/
 
/**
 
* custom edittools and add menu for selecting subsets of secial characters
 
*
 
* Maintainers: fdcn@zh.wikipedia
 
*/
 
 
 
addOnloadHook(function(){
 
// 調整符號表
 
var wpEditToolbar=document.getElementById("toolbar");
 
if(!wpEditToolbar){return;}
 
var editspecialchars=document.getElementById("editpage-specialchars");
 
if (editspecialchars) {
 
function chooseCharSubset() {// select subsection of special characters
 
var s=menu.selectedIndex;
 
for (var i = 0,p; p=lines[i] ; i++) {
 
p.style.display = i == s ? 'inline' : 'none';
 
}
 
}
 
// 增加特殊符號的下拉選單
 
var lines = editspecialchars.getElementsByTagName('p');
 
var menu=createElement("select",null,{
 
'styles':{'display':"inline"},
 
'events':{'change':chooseCharSubset}
 
});
 
for (var i = 0,p; p=lines[i] ; i++) {
 
menu.options[i]=new Option(p.title?p.title:p.id);
 
}
 
editspecialchars.insertBefore(menu,editspecialchars.firstChild);
 
chooseCharSubset();
 
// 移動特殊符號的下拉選單
 
elementMoveto(editspecialchars , wpEditToolbar , 'after' );
 
}
 
 
 
//加載編輯工具功能
 
if(JSConfig.edittoolsMode=='builtin'){return false;}
 
importScript('MediaWiki:Edittools.js');
 
mwEditButtons=[];//清除原系統按鈕
 
var modes=JSConfig.edittoolsMode.split(',');
 
for(var i=0;i<modes.length;i++){
 
switch (modes[i]){
 
case '': break;
 
case 'default':
 
importScript('MediaWiki:edittool-default.js');
 
break;
 
case    'plus':
 
importScript('MediaWiki:edittool-plus.js');
 
break;
 
case    'user':
 
importScript('User:'+wgUserName +'/customEdittools.js');
 
break;
 
default      :
 
importScript('Wikipedia:維基百科工具/編輯工具/'+modes[i]+'.js');
 
break;
 
}
 
}
 
});
 
 
 
/*
 
 
 
== 段落編輯連結 ==
 
*/
 
//JSConfig.isEdit0 設置是否出現「編輯首段」按鈕
 
//對不需要編輯首段的頁面,還可在頁面中加 Template:NoEdit 模板來禁用。
 
//JSConfig.editSectionLink 設置「編輯」按鈕的位置
 
if (wgIsArticle && wgAction == "view") {
 
//增加編輯首段按鈕
 
addOnloadHook(function(){
 
if(!JSConfig.isEdit0||(document.getElementById&&document.getElementById('no-edit-0'))){return;}
 
var caEdit=document.getElementById&&document.getElementById('ca-edit');
 
if (!caEdit){return;}
 
var linkAttributes={
 
'href':caEdit.firstChild.href + '&section=0',
 
'title':wgULS('編輯正文所有標題之前的文字(通常稱為首段或導言)','編輯正文所有標題之前的文字(通常稱首段或導言)'),
 
'accesskey':'0'
 
}
 
 
 
//增加0按鈕標籤
 
var caEdit0 = createElement(
 
'li',
 
[createElement('A',['0'],linkAttributes)],
 
{id:'ca-edit-0'}
 
);
 
caEdit.className = 'istalk';
 
elementMoveto(caEdit0,caEdit,"after");
 
 
 
//增加條目標題下的「編輯首段」按鈕
 
var editsection0= createElement(
 
'span',
 
['[',createElement('A',[wgULS('編輯首段','編輯首段')],linkAttributes),']'],
 
{'class':'editsection'}
 
);
 
var siteSub=document.getElementById&&document.getElementById('siteSub');
 
elementMoveto( editsection0 , siteSub.firstChild );
 
});
 
 
//設置編輯按鈕位置是否浮動
 
addOnloadHook(function(){
 
if (JSConfig.editSectionLink=='right') { return; }
 
var editLinks=getElementsByClassName(document.getElementById('bodyContent'),"span","editsection");
 
for(var i = 0; i < editLinks.length; i++) {
 
editLinks[i].style.cssFloat = editLinks[i].style.float = 'none';
 
editLinks[i].style.textAlign = "left" ;
 
editLinks[i].parentNode.appendChild(editLinks[i]);
 
}
 
});
 
}
 
 
 
/*
 
  
== 增加折疊功能 ==
+
    // initialize/clear any old information
*/
+
    togglers = new Array();   
/** 折疊 div table *****************************
+
    allClasses = new Object();
*  Description: 實現div.NavFrame和table.collapsible的可折疊性。
+
       
*  JSConfig的collapseText、expandText、autoCollapse屬性定義默認文字和默認最少自動折疊塊
+
    // make list of all document classes
*  Maintainers: User:fdcn
+
    var elems = document.getElementsByTagName("*");
*/
+
    var numelems = elems.length;
addOnloadHook(function(){
+
    for (var i = 0; i < elems.length; i++)
function toggleState(item){
+
    {
var oldState=item.state;
+
        var elem = elems[i];
item.state=1-oldState;
+
        if (!elem.className)
if(item.text[0]){
+
            continue;
item.text[oldState].style.display = 'inline';
 
item.text[item.state].style.display='none';
 
}
 
item.action(item);
 
}
 
  
function cancelBubble(e){
+
        elem._toggle_original_display = elem.style.display;
e=e||window.event;
+
        var togglerID = -1;
if(e.stopPropagation){e.stopPropagation();}else{e.cancelBubble=true;}
+
        var elemClasses = elem.className.split(' '); // get list of classes
}
+
        for (var j = 0; j < elemClasses.length; j++)
function createToggleButton(head,frame,toggle){
+
        {
var textS,textH;
+
            var elemClass = elemClasses[j];
var button=getElementsByClassName(head,"span","NavToggle")[0];
+
            if (! allClasses[elemClass])
if(button){
+
                allClasses[elemClass] = new Array();
textS=getElementsByClassName(button,"span","NavToggleShow")[0]
+
            allClasses[elemClass].push(elem);
textH=getElementsByClassName(button,"span","NavToggleHide")[0];
 
}else {
 
textS=createElement("span",[JSConfig.expandText]);
 
textH=createElement('span',[JSConfig.collapseText]);
 
button=createElement("span",[textS,textH],{'class':"NavToggle",styles:{'width':"3.8em"}});
 
}
 
if(textS){textS.style.display='none';}
 
button.style.display='inline';
 
var item={'state':0, 'text':[textS,textH],'frame':frame,'action':toggle}
 
  
var links=head.getElementsByTagName("A");
+
            // all the special classes begin with _toggle
for(var i=0,l;l=links[i];i++){ addClickHandler(l,cancelBubble); }
+
            if (elemClass.substring(0, 7) != "_toggle")
+
                continue;
head.insertBefore( button, head.childNodes[0] );
 
head.style.cursor = "pointer";
 
addClickHandler( head, function(){toggleState(item);} );
 
return item;
 
}
 
 
// 折疊div
 
function toggleNavigationBar(item)
 
{
 
var cls=item.state?'none':'block';
 
for (
 
var NavChild = item.frame.firstChild;
 
NavChild != null;
 
NavChild = NavChild.nextSibling
 
){
 
if (NavChild.className == 'NavPic' || NavChild.className == 'NavContent') {
 
NavChild.style.display = cls;
 
}
 
}
 
}
 
 
// 折疊表格
 
function collapseTable( item )
 
{
 
var rows = item.frame.getElementsByTagName( "tr" );
 
var display = item.state? 'none':rows[0].style.display;
 
for (var i=1,row; row=rows[i]; i++) { row.style.display = display; }
 
}
 
 
//init
 
var item,items=[];
 
var NavFrames=getElementsByClassName(document,"div","NavFrame");
 
for(var i=0,NavFrame;NavFrame = NavFrames[i];i++) {
 
var heads=getElementsByClassName(NavFrame,"div","NavHead");
 
for(var ih=0,head; head = heads[ih]; ih++ ) {
 
if (head.parentNode != NavFrame) {continue;}
 
items.push(createToggleButton(head,NavFrame,toggleNavigationBar));
 
break;
 
}
 
}
 
  
var tables = getElementsByClassName(document,"table","collapsible");
+
            if (elemClass == "_togglegroup")
for ( var i = 0,table; table= tables[i]; i++ ) {
+
                toggleGroup = new Array();
var head = table.getElementsByTagName( "tr" )[0].getElementsByTagName( "th" )[0];
+
            else if (elemClass == "_toggle")
items.push(createToggleButton(head,table,collapseTable));
+
                toggleGroup.push(elem);
}
+
            else if (elemClass.substring(0, 12) == "_toggle_init")
 +
            {
 +
                // set initial value for display (ignore the original CSS set value)
 +
                // understands _toggle_initshow and _toggle_inithide
 +
                var disp = elemClass.substring(12);
 +
                if (disp == "show")
 +
                    elem.style.display = '';
 +
                else if (disp == "hide")
 +
                    elem.style.display = 'none';
 +
                elem._toggle_original_display = disp;
 +
            }
 +
            else if (elemClass.substring(0, 8) == "_toggler")
 +
            {
 +
                if (togglerID == -1)
 +
                {
 +
                    togglerID = togglers.length;
 +
                    togglers[togglerID] = new Array();
 +
                    togglerElems[togglerID] = elem;
 +
                }
  
var count=items.length;
+
                // all classes are of form _toggler_op-CLASS
for ( var i = 0;  i<count; i++ ) {
+
                // figure out what class we're toggling
item=items[i];
+
                // if none is specified, then we use the current toggle group
if ( hasClass( item.frame, "collapsed" ) || ( count >= JSConfig.autoCollapse && hasClass( item.frame, "autocollapse" ) ) ) {
+
                var toBeToggled;
toggleState(item);
+
                var hyphen = elemClass.indexOf('-');
}
+
                if (hyphen != -1)
}
+
                    toBeToggled = elemClass.substring(hyphen+1);
});
+
                else
 +
                {
 +
                    toBeToggled = toggleGroup;
 +
                    hyphen = elemClass.length;
 +
                }
  
//修正折疊後定位變化
+
                var op = elemClass.substring(8, hyphen);
hookEvent("load",function(){if(location.hash){location.href=location.hash;}});
+
                togglers[togglerID].push(new Array(op, toBeToggled));
 +
            }
 +
        }
 +
    }
  
/*
+
    // add javascript links to all toggler elements
 
+
    for (var i = 0; i < togglerElems.length; i++)
== 首頁輸出修正 ==
+
        createTogglerLink(togglerElems[i], i);
*/
 
/** 首頁輸出修正 *******************************************************
 
  描述:
 
  維護者: [[User:Fdcn]]
 
*/
 
 
 
var isMainPageFront = ("首頁" == wgTitle);// "首頁" == wgTitle 代表重定向頁
 
var isMainPage = ( isMainPageFront  && /(title=|\/wiki\/)([Tt]alk:|)/.test(document.location) );
 
var locationsearch=document.location.search;
 
var isDiff = ( locationsearch && (locationsearch.indexOf("diff=") != -1 || locationsearch.indexOf("oldid=") != -1));
 
 
 
if (isMainPage){
 
//首頁的跨語言鏈接中加入維基百科語言列表鏈接
 
function appendOtherLanguageLink() {
 
var mpInterwiki = document.getElementById("p-lang")
 
var ul=mpInterwiki&&mpInterwiki.getElementsByTagName("ul")[0];
 
if(ul) {
 
var link=createElement('A',
 
[ createElement('strong',[wgULS('維基百科語言列表','維基百科語言列表')]) ],
 
{'href':getWikiPath('Wikipedia:維基百科語言列表')}
 
);
 
ul.appendChild(createElement("li",[link]));
 
}
 
}
 
 
 
if (isMainPageFront && !isDiff){
 
document.write('<style type="text/css">/*<![CDATA[*/ #lastmod, #siteSub, #contentSub, h1.firstHeading { display: none !important; } /*]]>*/</style>');
 
onloadFuncts.push(appendOtherLanguageLink);
 
}
 
 
 
var mpSmallEnabled;
 
var mpMinWidth = 700;
 
 
 
function mainPageTransform(){
 
if (document.getElementById('ca-nstab-main')) {
 
document.getElementById('ca-nstab-main').firstChild.innerHTML = wgULS('首頁','首頁');
 
}
 
 
 
var mpContentEl = document.getElementById("bodyContent");
 
var mpBrowseEl = document.getElementById("EnWpMpBrowse");
 
var mpContainEl = document.getElementById("EnWpMpBrowseContainer");
 
var mpMarginEl = document.getElementById("EnWpMpMargin");
 
var mpEl = document.getElementById("EnWpMainPage");
 
 
 
if (!mpContentEl || !mpBrowseEl || !mpContainEl || !mpMarginEl || !mpEl)
 
return;
 
 
 
if (!mpSmallEnabled && mpContentEl.offsetWidth < mpMinWidth)
 
{
 
mpContainEl.insertBefore(mpBrowseEl, mpContainEl.firstChild);
 
mpBrowseEl.className = "EnWpMpBrowseBottom";
 
mpMarginEl.style.marginRight = 0;
 
mpSmallEnabled = true;
 
}
 
else if (mpSmallEnabled && mpContentEl.offsetWidth > mpMinWidth)
 
{
 
mpEl.insertBefore(mpBrowseEl, mpEl.firstChild);
 
mpBrowseEl.className = "EnWpMpBrowseRight";
 
mpMarginEl.style.marginRight = "13.8em";
 
mpSmallEnabled = false;
 
}
 
}
 
 
 
addOnloadHook(mainPageTransform);
 
 
 
hookEvent("resize", mainPageTransform);
 
 
}
 
}
  
/*
 
 
== 取消修訂編輯摘要修正 ==
 
*/
 
/**
 
  fix edit summary prompt for undo
 
  this code fixes the fact that the undo function combined with the "no edit summary prompter" causes problems if leaving the edit summary unchanged
 
  this was added by [[:en:User:Deskana]], code by [[:en:User:Tra]]
 
*/
 
addOnloadHook(function () {
 
var autoSummary=document.getElementsByName('wpAutoSummary')[0];
 
if (document.location.search.indexOf("undo=") != -1 && autoSummary)
 
{
 
autoSummary.value='';
 
}
 
})
 
 
/*
 
 
==[[Special:Search]]其他搜尋引擎連結表單==
 
*/
 
var searchEngines=[];
 
var createSearchForm;//可在用戶皮膚JS中自行增加引擎。
 
function SpecialSearchEnhanced()
 
{
 
if (
 
JSConfig.SpecialSearchEnhancedDisabled ||
 
wgCanonicalNamespace != "Special" ||
 
wgCanonicalSpecialPageName != "Search"
 
){return;}
 
if(skin == "monobook" || skin == "cologneblue" || skin == "simple"){
 
var mainNode = document.getElementsByTagName("form")[0];
 
}
 
if (!mainNode) return;
 
var searchbox=document.getElementById("lsearchbox");
 
var div= createElement("div",null,{styles:{'width':"100%",'textAlign':'center'}});
 
mainNode.appendChild(div);
 
 
/**
 
* 建立一個搜索引擎
 
*/
 
createSearchForm=function(engine_name, engine_url, logo_url, search_action_url,
 
search_field_name, add_search_field, field_array, logo_width, logo_height)
 
{
 
var input=createElement("input",null,{'type':"hidden",'name':search_field_name})
 
var inputs = [input];
 
for( var k in field_array){
 
inputs.push(createElement(
 
"input",null,{'type':"hidden",'name':k,'value':field_array[k]}
 
));
 
}
 
inputs.push(createElement(
 
"input",null,{'type':"submit",'value':wgULS('搜索','搜尋')}
 
));
 
var form = createElement("form",inputs,
 
{
 
'method':"get",
 
'action':search_action_url,
 
'styles':{'display':"inline"},
 
'events':{'submit':function(){input.value = searchbox.value+add_search_field;}}
 
}
 
);
 
 
var img = createElement("img",null,{
 
'src':logo_url,
 
'alt':engine_name,
 
'styles':{'borderWidth':"0",'padding':"5px",'width':logo_width||'135px','height':logo_height||'35px'}
 
});
 
var a = createElement("a",[img],{'href':engine_url});
 
var span= createElement("span",[form,a],{styles:{'marginRight':"1em"}});
 
 
searchEngines.push(span);
 
searchEngines[engine_name]=span;
 
div.appendChild(span);
 
}
 
 
//於此開始列示各引擎。
 
//google
 
createSearchForm(
 
"Google","http://www.google.com/", 
 
"http://www.google.com/logos/powered_by_google_135x35.gif",
 
"http://www.google.com/search","q", "",
 
{"as_sitesearch": "zh.wikipedia.org"},
 
"77px","20px"
 
);
 
//live search
 
createSearchForm(
 
"Live", "http://search.live.com/", 
 
"http://upload.wikimedia.org/wikipedia/zh/thumb/1/17/Mslivelogo.png/120px-Mslivelogo.png",
 
"http://search.live.com/results.aspx","q", "",
 
{"q1":"site:zh.wikipedia.org"},
 
'100px','20px'
 
);
 
//yahoo
 
createSearchForm(
 
"Yahoo!", "http://www.yahoo.com/", 
 
"http://upload.wikimedia.org/wikipedia/zh/thumb/a/ad/Yahoo_Logo.svg/135px-Yahoo_Logo.svg.png",
 
"http://search.yahoo.com/search","p", "",
 
{"vs": "zh.wikipedia.org","ei":"UTF-8"},
 
'80px','15px'
 
);
 
//zhosisterps
 
createSearchForm(
 
"中文系維基跨計劃搜尋", "http://www.google.com/coop/",
 
"http://www.google.com/coop/images/google_coop_sm.gif",
 
"http://www.google.com/"+"cse","q","",
 
{"cx":"009212467671870524522:mw9ug06rtl4","cof":"FORID:0","sa":"Search"},
 
"51px","20px"
 
);
 
//zhsisterps
 
createSearchForm(
 
"中文維基媒體搜索", "http://www.google.com/coop/",
 
"http://www.google.com/coop/images/google_coop_sm.gif",
 
"http://www.google.com/"+"cse","q","",
 
{"cx":"012948615710733534834:sce7kigca9g","cof":"FORID:0","sa":"Search"},
 
"51px","20px"
 
);
 
  
 +
function owwsitesearch(f){
 +
    f.q.value='site:http://openwetware.org/wiki/'+
 +
        f.base.value+'++'+f.qfront.value
 
}
 
}
  
addOnloadHook(SpecialSearchEnhanced); //啟動Search Engine
 
 
/*
 
 
==WikiMiniAtlas世界地圖==
 
*/
 
/** WikiMiniAtlas *******************************************************
 
  *
 
  *  描述:WikiMiniAtlas是一個popup而可點選與拖曳的世界地圖。
 
  *              這個腳本將會讓所有的經緯度標示中顯示WikiMiniAtlas的popup開啟按鈕。
 
  *              由於被許多計畫使用,因此腳本放置在元維基中。
 
  *              更多資訊請詳見[[Meta:WikiMiniAtlas]]。
 
  *  創建者:[[:en:User:Dschwen]]
 
  */
 
 
importScript('m:MediaWiki:Wikiminiatlas.js');
 
/*
 
 
==Wikimedia媒體播放器==
 
*/
 
 
/** MediaWiki media player *******************************************************
 
  *
 
  *  Description: A Java player for in-browser playback of media files.
 
  *  Created by: [[:en:User:Gmaxwell]]
 
  */
 
importScript('Mediawiki:Wikimediaplayer.js');
 
/*
 
  
==Anonnotice顯示==
+
addOnloadHook(toggleInit);
  
*/
+
// </syntax>
/** anonnotice for IP user **************************
 
  *
 
  * Maintainced by Alexsh@zhwiki, PhiLiP@zhwiki
 
  */
 
addOnloadHook(function(){
 
document.writeln('<div style="position:absolute; z-index:40; left:155px; top:0px; clear:both; float:left;text-align:left; margin:0 auto;" id="donate">'+ ( wgUserName ? JSConfig.siteNotice : JSConfig.blockMsg )+'</div>');
 
});
 

於 2013年6月13日 (四) 11:12 的最新修訂

/* Any JavaScript here will be loaded for all users on every page load. */

// <syntax type="javascript">

    /** 
        Toggles the display of elements on a page 
        Author/contact: Austin Che http://openwetware.org/wiki/User:Austin_J._Che
        See http://openwetware.org/wiki/OpenWetWare:Toggle for examples and documentation
     */

// indexed array of toggler ids to array of associated toggle operations
// each operation is a two element array, the first being the type, the second a class name or array of elements
// operation types are strings like "_reset" or "" for the default toggle operation
var togglers = new Array();     
var allClasses = new Object(); // associative map of class names to page elements

function toggler(id)
{
    var toBeToggled = togglers[id];
    if (!toBeToggled)
        return;

    // if some element is in list more than once, it will be toggled multiple times
    for (var i = 0; i < toBeToggled.length; i++)
    {
        // get array of elements to operate on
        var toggles = toBeToggled[i][1];
        if (typeof(toggles) == "string")
        {
            if (toggles.charAt(0) == '-')
            {
                // treat as an element ID, not as class
                toggles = document.getElementById(toggles.substring(1));
                if (toggles)
                    toggles = new Array(toggles);
            }
            else
                toggles = allClasses[toggles];
        }
        if (!toggles || !toggles.length)
            continue;

        var op = toBeToggled[i][0]; // what the operation will be

        switch (op)
        {
            case "_reset":
                for (var j = 0; j < toggles.length; j++)
                    toggles[j].style.display = toggles[j]._toggle_original_display;
                break;
            case "_show":
                for (var j = 0; j < toggles.length; j++)
                    toggles[j].style.display = '';
                break;
            case "_hide":
                for (var j = 0; j < toggles.length; j++)
                    toggles[j].style.display = 'none';
                break;
            case "":
            default:
                // Toggle
                for (var j = 0; j < toggles.length; j++)
                    toggles[j].style.display = ((toggles[j].style.display == 'none') ? '' : 'none');
                break;
        }
    }
}

function createTogglerLink(toggler, id)
{
    var toggle = document.createElement("a");
    toggle.className = 'toggler-link';
    toggle.setAttribute('id', 'toggler' + id);
    toggle.setAttribute('href', 'javascript:toggler("' + id + '");');
    var child = toggler.firstChild;
    toggler.removeChild(child);
    toggle.appendChild(child);
    toggler.insertBefore(toggle, toggler.firstChild);
}

function toggleInit()
{
    var togglerElems = new Array();
    var toggleGroup = new Array();

    // initialize/clear any old information
    togglers = new Array();     
    allClasses = new Object();
        
    // make list of all document classes
    var elems = document.getElementsByTagName("*");
    var numelems = elems.length;
    for (var i = 0; i < elems.length; i++)
    {
        var elem = elems[i];
        if (!elem.className)
            continue;

        elem._toggle_original_display = elem.style.display;
        var togglerID = -1;
        var elemClasses = elem.className.split(' '); // get list of classes
        for (var j = 0; j < elemClasses.length; j++)
        {
            var elemClass = elemClasses[j];
            if (! allClasses[elemClass])
                allClasses[elemClass] = new Array();
            allClasses[elemClass].push(elem);

            // all the special classes begin with _toggle
            if (elemClass.substring(0, 7) != "_toggle")
                continue;

            if (elemClass == "_togglegroup")
                toggleGroup = new Array();
            else if (elemClass == "_toggle")
                toggleGroup.push(elem);
            else if (elemClass.substring(0, 12) == "_toggle_init")
            {
                // set initial value for display (ignore the original CSS set value)
                // understands _toggle_initshow and _toggle_inithide
                var disp = elemClass.substring(12);
                if (disp == "show")
                    elem.style.display = '';
                else if (disp == "hide")
                    elem.style.display = 'none';
                elem._toggle_original_display = disp;
            }
            else if (elemClass.substring(0, 8) == "_toggler")
            {
                if (togglerID == -1)
                {
                    togglerID = togglers.length;
                    togglers[togglerID] = new Array();
                    togglerElems[togglerID] = elem;
                }

                // all classes are of form _toggler_op-CLASS
                // figure out what class we're toggling
                // if none is specified, then we use the current toggle group
                var toBeToggled;
                var hyphen = elemClass.indexOf('-');
                if (hyphen != -1)
                    toBeToggled = elemClass.substring(hyphen+1);
                else
                {
                    toBeToggled = toggleGroup;
                    hyphen = elemClass.length;
                }

                var op = elemClass.substring(8, hyphen);
                togglers[togglerID].push(new Array(op, toBeToggled));
            }
        }
    }

    // add javascript links to all toggler elements
    for (var i = 0; i < togglerElems.length; i++)
        createTogglerLink(togglerElems[i], i);
}


function owwsitesearch(f){
    f.q.value='site:http://openwetware.org/wiki/'+
        f.base.value+'++'+f.qfront.value
}


addOnloadHook(toggleInit);

// </syntax>