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

出自宅犬維基
跳至導覽 跳至搜尋
 
(未顯示同一使用者於中間所作的 3 次修訂)
行 1: 行 1:
/*
+
/* Any JavaScript here will be loaded for all users on every page load. */
所有用戶在加載任何頁面時,這裡的JavaScript都會加載
 
  
== 辅助处理 ==
+
// <syntax type="javascript">
*/
 
//功能設定
 
if(!window.JSConfig){var JSConfig={};}
 
JSConfig.isEdit0=true; //设置是否显示编辑首段按钮
 
JSConfig.editSectionLink='right';//设置编辑按钮是否在右侧
 
JSConfig.collapseText=wgULS('隐藏▲','隱藏▲');//指示折叠收缩的默认文字
 
JSConfig.expandText=wgULS('显示▼','顯示▼');//指示折叠展开的默认文字
 
JSConfig.autoCollapse=2;  //文章少于 autoCollapse 个折叠块时,不自动折叠
 
JSConfig.SpecialSearchEnhancedDisabled=false; //是否禁止增加其它搜索引擎
 
  
// 移動元素
+
    /**
function elementMoveto(node, refNode, pos){//默认位置为refNode前
+
        Toggles the display of elements on a page
if(node && refNode){
+
        Author/contact: Austin Che http://openwetware.org/wiki/User:Austin_J._Che
var parent=refNode.parentNode;
+
        See http://openwetware.org/wiki/OpenWetWare:Toggle for examples and documentation
if (pos && pos=='after') {refNode=refNode.nextSibling;}
+
    */
try {
 
if(refNode){
 
parent.insertBefore(node, refNode);
 
}else{
 
parent.appendChild(node);
 
}
 
} catch (DOMException) {};
 
}
 
}
 
//创建元素
 
function createElement(tag,children,props){
 
var element = document.createElement(tag);
 
if(!(children instanceof Array)){children=[children];}
 
for(var i=0;i<children.length;i++){
 
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
+
// indexed array of toggler ids to array of associated toggle operations
var wgProjectURL={
+
// each operation is a two element array, the first being the type, the second a class name or array of elements
en:'http://en.wikipedia.org/',de:'http://de.wikipedia.org/',fr:'http://fr.wikipedia.org/',
+
// operation types are strings like "_reset" or "" for the default toggle operation
pl:'http://pl.wikipedia.org/',ja:'http://ja.wikipedia.org/',it:'http://it.wikipedia.org/',
+
var togglers = new Array();    
nl:'http://nl.wikipedia.org/',pt:'http://pt.wikipedia.org/',es:'http://es.wikipedia.org/',
+
var allClasses = new Object(); // associative map of class names to page elements
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导入模块
+
function toggler(id)
importedURLs = {}; //用以保證腳本和樣式只载入一次
+
{
function importScript( page ) {
+
    var toBeToggled = togglers[id];
var src= /^https?:\/\//.test(page) ? page : getWikiPath(page,{'ctype':'text/javascript'});
+
    if (!toBeToggled)
if( importedURLs[src] ) { return; }
+
        return;
importedURLs[src] = true;
 
var scriptElem = createElement( 'script',null,{'src':src,'type':'text/javascript'} );
 
document.getElementsByTagName( 'head' )[0].appendChild( scriptElem );
 
}
 
function importStylesheet( page ) {
 
var sheet= /^https?:\/\//.test(page) ? page : getWikiPath(page,{'ctype':'text/css'});
 
if( importedURLs[sheet] ) { return; }
 
importedURLs[sheet] = true;
 
var styleElem = createElement( 'style', ['@import "'+sheet+'";'], {'type':'text/css'} );
 
document.getElementsByTagName( 'head' )[0].appendChild( styleElem );
 
}
 
 
 
//引入[[Special:Gadgets]]要求的腳本和樣式
 
if(window.requireScripts instanceof Array){
 
for(var i=0;i<requireScripts.length;i++){
 
importScript(requireScripts[i]);
 
}
 
}
 
if(window.requireStylesheets instanceof Array){
 
for(var i=0;i<requireStylesheets.length;i++){
 
importStylesheet(requireStylesheets[i]);
 
}
 
}
 
  
/* 测试元素中是否含有指定的样式 **************************************
+
    // if some element is in list more than once, it will be toggled multiple times
* Description: 使用正则式与缓存来提高性能
+
    for (var i = 0; i < toBeToggled.length; i++)
* Maintainers: User:fdcn @zh.wikipedia
+
    {
*              [[en:User:Mike Dillon]], [[en:User:R. Koot]], [[en:User:SG]] @en.wikipedia
+
        // get array of elements to operate on
*/
+
        var toggles = toBeToggled[i][1];
var hasClass = (function () {
+
        if (typeof(toggles) == "string")
var reCache = {};
+
        {
return function (element, className) {
+
            if (toggles.charAt(0) == '-')
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
+
            {
};
+
                // 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)
//设置中文语言页
+
        {
var htmlE=document.documentElement;
+
            case "_reset":
htmlE.setAttribute("lang",wgUserLanguage);
+
                for (var j = 0; j < toggles.length; j++)
htmlE.setAttribute("xml:lang",wgUserLanguage);
+
                    toggles[j].style.display = toggles[j]._toggle_original_display;
 
+
                break;
//返回繁簡字串
+
            case "_show":
function wgULS(hans,hant,cn,tw,hk,sg,zh){
+
                for (var j = 0; j < toggles.length; j++)
return {//保證每一語言有值
+
                    toggles[j].style.display = '';
'zh-hans':hans||cn||sg,
+
                break;
'zh-hant':hant||tw||hk,
+
            case "_hide":
'zh-cn':cn||hans||sg,
+
                for (var j = 0; j < toggles.length; j++)
'zh-sg':sg||hans||cn,
+
                    toggles[j].style.display = 'none';
'zh-tw':tw||hant||hk,
+
                break;
'zh-hk':hk||hant||tw,
+
            case "":
'zh':zh||hant||hans||cn||tw||hk||sg
+
            default:
}[wgUserLanguage];
+
                // Toggle
 +
                for (var j = 0; j < toggles.length; j++)
 +
                    toggles[j].style.display = ((toggles[j].style.display == 'none') ? '' : 'none');
 +
                break;
 +
        }
 +
    }
 
}
 
}
  
/*
+
function createTogglerLink(toggler, id)
 
+
{
== IE兼容性修正 ==
+
    var toggle = document.createElement("a");
*/
+
    toggle.className = 'toggler-link';
if (navigator.appName == "Microsoft Internet Explorer" && document.compatMode == "CSS1Compat"){
+
    toggle.setAttribute('id', 'toggler' + id);
(function(){
+
    toggle.setAttribute('href', 'javascript:toggler("' + id + '");');
var oldWidth;
+
    var child = toggler.firstChild;
var docEl = document.documentElement;
+
    toggler.removeChild(child);
 
+
    toggle.appendChild(child);
function fixIEScroll(){
+
    toggler.insertBefore(toggle, toggler.firstChild);
if (!oldWidth || docEl.clientWidth > oldWidth){
 
doFixIEScroll();
 
}else{
 
setTimeout(doFixIEScroll, 1);
 
}
 
oldWidth = docEl.clientWidth;
 
}
 
 
 
function doFixIEScroll() {
 
docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : "";
 
}
 
 
 
document.attachEvent("onreadystatechange", fixIEScroll);
 
attachEvent("onresize", fixIEScroll);
 
})();
 
 
}
 
}
  
/*
+
function toggleInit()
 
 
== 工具提示與快捷鍵 ==
 
*/
 
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++ ) {
+
    // initialize/clear any old information
if ( document.getElementById( InterwikiLinks[i].className + "-fa" ) ) {
+
    togglers = new Array();   
InterwikiLinks[i].className += " FA"
+
    allClasses = new Object();
InterwikiLinks[i].title = wgULS("此条目为特色条目。","此條目為特色條目。");
+
       
}
+
    // make list of all document classes
if ( document.getElementById( InterwikiLinks[i].className + "-ga" ) ) {
+
    var elems = document.getElementsByTagName("*");
InterwikiLinks[i].className += " GA"
+
    var numelems = elems.length;
InterwikiLinks[i].title = wgULS("此条目为优良条目。","此條目為優良條目。");
+
    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")
* custom edittools and add menu for selecting subsets of secial characters
+
                toggleGroup = new Array();
*
+
            else if (elemClass == "_toggle")
* Maintainers: fdcn@zh.wikipedia
+
                toggleGroup.push(elem);
*/
+
            else if (elemClass.substring(0, 12) == "_toggle_init")
hookEvent("load",function(){
+
            {
// 增加对未注册用户的提示
+
                // set initial value for display (ignore the original CSS set value)
var wpEditToolbar=document.getElementById("toolbar");
+
                // understands _toggle_initshow and _toggle_inithide
if(!wpEditToolbar){return;}
+
                var disp = elemClass.substring(12);
if(!mwCustomEditButtons.state){
+
                if (disp == "show")
var tip=createElement("a","扩展编辑按钮?",{
+
                    elem.style.display = '';
'href':getWikiPath('Wikipedia:維基百科工具/編輯工具'),
+
                else if (disp == "hide")
'title':wgULS('注册一个用户,即可以定制自己的编辑按钮','註冊一個賬號,即可以定制自己的編輯按鈕'),
+
                    elem.style.display = 'none';
'styles':{'fontSize':'smaller','marginLeft':'1em'}
+
                elem._toggle_original_display = disp;
});
+
            }
wpEditToolbar.appendChild(tip);
+
            else if (elemClass.substring(0, 8) == "_toggler")
}
+
            {
if(mwCustomEditButtons.state=='rID'){
+
                if (togglerID == -1)
tip=createElement("span"," ! ",{
+
                {
'title':wgULS('你选择的编辑按钮扩展可能有重复的按钮','你選擇的編輯按鈕擴展可能有重複的按鈕'),
+
                    togglerID = togglers.length;
'styles':{'color':'red','cursor':'pointer'}
+
                    togglers[togglerID] = new Array();
});
+
                    togglerElems[togglerID] = elem;
wpEditToolbar.appendChild(tip);
+
                }
}
 
});
 
  
addOnloadHook(function(){
+
                // all classes are of form _toggler_op-CLASS
// 調整符號表
+
                // figure out what class we're toggling
var wpEditToolbar=document.getElementById("toolbar");
+
                // if none is specified, then we use the current toggle group
if(!wpEditToolbar){return;}
+
                var toBeToggled;
var editspecialchars=document.getElementById("editpage-specialchars");
+
                var hyphen = elemClass.indexOf('-');
if (editspecialchars) {
+
                if (hyphen != -1)
function chooseCharSubset() {// select subsection of special characters
+
                    toBeToggled = elemClass.substring(hyphen+1);
var s=menu.selectedIndex;
+
                else
for (var i = 0,p; p=lines[i] ; i++) {
+
                {
p.style.display = i == s ? 'inline' : 'none';
+
                    toBeToggled = toggleGroup;
}
+
                    hyphen = elemClass.length;
}
+
                }
// 增加特殊符號的下拉選單
 
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' );
 
}
 
});
 
  
/*
+
                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++)
//JSConfig.isEdit0 设置是否出现「编辑首段」按钮
+
        createTogglerLink(togglerElems[i], i);
//对不需要编辑首段的页面,还可在页面中加 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]);
 
}
 
});
 
 
}
 
}
  
/*
 
== 强制预览 ==
 
*/
 
 
if (wgUserName == null && wgAction == "edit") { addOnloadHook (function(){
 
var saveButton = document.getElementById("wpSave");
 
if (!saveButton) return;
 
saveButton.disabled = true;
 
saveButton.value += wgULS(" (预览后可用)"," (預覽後可用)");
 
saveButton.style.fontWeight = "normal";
 
document.getElementById("wpPreview").style.fontWeight = "bold";
 
});}
 
 
/*
 
 
== 增加折疊功能 ==
 
*/
 
/** 折疊 div table *****************************
 
*  Description: 实现div.NavFrame和table.collapsible的可折叠性。
 
*  JSConfig的collapseText、expandText、autoCollapse属性定义默认文字和默认最少自动折叠块
 
*  Maintainers: User:fdcn
 
*/
 
addOnloadHook(function(){
 
function toggleState(item){
 
var oldState=item.state;
 
item.state=1-oldState;
 
if(item.text[0]){
 
item.text[oldState].style.display = 'inline';
 
item.text[item.state].style.display='none';
 
}
 
item.action(item);
 
}
 
 
function cancelBubble(e){
 
e=e||window.event;
 
if(e.stopPropagation){e.stopPropagation();}else{e.cancelBubble=true;}
 
}
 
function createToggleButton(head,frame,toggle){
 
var textS,textH;
 
var button=getElementsByClassName(head,"span","NavToggle")[0];
 
if(button){
 
textS=getElementsByClassName(button,"span","NavToggleShow")[0]
 
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");
 
for(var i=0,l;l=links[i];i++){ addClickHandler(l,cancelBubble); }
 
 
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");
 
for ( var i = 0,table; table= tables[i]; i++ ) {
 
var head = table.getElementsByTagName( "tr" )[0].getElementsByTagName( "th" )[0];
 
items.push(createToggleButton(head,table,collapseTable));
 
}
 
 
var count=items.length;
 
for ( var i = 0;  i<count; i++ ) {
 
item=items[i];
 
if ( hasClass( item.frame, "collapsed" ) || ( count >= JSConfig.autoCollapse && hasClass( item.frame, "autocollapse" ) ) ) {
 
toggleState(item);
 
}
 
}
 
});
 
 
//修正折疊後定位變化
 
hookEvent("load",function(){if(location.hash){location.href=location.hash;}});
 
 
/*
 
 
== 首頁輸出修正 ==
 
*/
 
/** 首页输出修正 *******************************************************
 
  描述:
 
  维护者: [[User:Fdcn]]
 
*/
 
 
// "首頁" == wgTitle 代表重定向頁
 
if ( wgTitle == '首页' && ( wgNamespaceNumber == 0 || wgNamespaceNumber == 1 ) ) {
 
addOnloadHook( function () {
 
try {
 
var Node = document.getElementById( 'ca-nstab-main' ).firstChild;
 
var label = wgULS('首页','首頁');
 
if ( Node.textContent ) {      // Per DOM Level 3
 
Node.textContent = label;
 
} else if ( Node.innerText ) { // IE doesn't handle .textContent
 
Node.innerText = label;
 
} else {                      // Fallback
 
Node.replaceChild( Node.firstChild, document.createTextNode( label ) );
 
}
 
} catch(e) {}// bailing out!
 
} );
 
if(wgNamespaceNumber == 0){
 
addOnloadHook( function () {
 
addPortletLink('p-lang', getWikiPath('Wikipedia:维基百科语言列表'),
 
wgULS('维基百科语言列表','維基百科語言列表'), 'interwiki-completelist',wgULS('维基百科的完整各语言列表', '維基百科的完整各語言列表'));
 
});
 
}
 
}
 
 
/*
 
 
== 取消修訂編輯摘要修正 ==
 
*/
 
/**
 
  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媒體播放器==
+
addOnloadHook(toggleInit);
*/
 
  
/** MediaWiki media player *******************************************************
+
// </syntax>
  *
 
  *  Description: A Java player for in-browser playback of media files.
 
  *  Created by: [[:en:User:Gmaxwell]]
 
  */
 
importScript('Mediawiki:Wikimediaplayer.js');
 

於 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>