“MediaWiki:Common.js”的版本间的差异

来自汉服百科
跳转至: 导航搜索
第1行: 第1行:
/**
+
/*
  * Keep code in MediaWiki:Common.js to a minimum as it is unconditionally
+
  所有用戶在加載任何頁面時,這裡的JavaScript都會加載
* loaded for all users on every wiki page. If possible create a gadget that is
+
*/
* enabled by default instead of adding it here (since gadgets are fully
 
* optimized ResourceLoader modules with possibility to add dependencies etc.)
 
*
 
* Since Common.js isn't a gadget, there is no place to declare its
 
* dependencies, so we have to lazy load them with mw.loader.using on demand and
 
* then execute the rest in the callback. In most cases these dependencies will
 
* be loaded (or loading) already and the callback will not be delayed. In case a
 
* dependency hasn't arrived yet it'll make sure those are loaded before this.
 
*/
 
/*global mw, $, importStylesheet, importScript */
 
/*jshint curly:false eqnull:true, strict:false, browser:true, */
 
mw.loader.using( ['mediawiki.util', 'mediawiki.notify', 'jquery.client'], function () {
 
/* Begin of mw.loader.using callback */
 
  
/**
+
mw.loader.using(['mediawiki.Uri'], function() {
* Main Page layout fixes
+
    /* Search Engine variant hack */
*
+
    var ref, loc;
* Description: Adds an additional link to the complete list of languages available.
+
    try {
* Maintainers: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]]
+
        ref = new mw.Uri( document.referrer );
*/
+
         loc = new mw.Uri( location.href );
if ( mw.config.get( 'wgPageName' ) === 'Main_Page' || mw.config.get( 'wgPageName' ) === 'Talk:Main_Page' ) {
+
     } catch ( e ) {
    $( document ).ready( function () {
+
        return;
         mw.util.addPortletLink( 'p-lang', '//meta.wikimedia.org/wiki/List_of_Wikipedias',
+
    }
            'Complete list', 'interwiki-completelist', 'Complete list of Wikipedias' );
+
    if (/\.google\./.test(ref.host) && /\/zh(-[^/]+)?\//.test(loc.path)) {
     } );
+
         loc.path = loc.path.replace(/\/zh(-[^/]+)?\//, "/wiki/");
}
+
         location = loc.toString();
 
 
/**
 
* Redirect User:Name/skin.js and skin.css to the current skin's pages
 
* (unless the 'skin' page really exists)
 
* @source: http://www.mediawiki.org/wiki/Snippets/Redirect_skin.js
 
* @rev: 2
 
*/
 
if ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgNamespaceNumber' ) === 2 ) {
 
    var titleParts = mw.config.get( 'wgPageName' ).split( '/' );
 
    /* Make sure there was a part before and after the slash
 
      and that the latter is 'skin.js' or 'skin.css' */
 
    if ( titleParts.length == 2 ) {
 
         var userSkinPage = titleParts.shift() + '/' + mw.config.get( 'skin' );
 
        if ( titleParts.slice( -1 ) == 'skin.js' ) {
 
            window.location.href = mw.util.wikiGetlink( userSkinPage + '.js' );
 
         } else if ( titleParts.slice( -1 ) == 'skin.css' ) {
 
            window.location.href = mw.util.wikiGetlink( userSkinPage + '.css' );
 
        }
 
 
     }
 
     }
}
+
} );
  
/**
+
mw.loader.using(['mediawiki.util', 'ext.gadget.site-lib'], function () {
* Map addPortletLink to mw.util
+
  (function ($, mw) {
*
+
    /* Cookies */
* @deprecated: Use mw.util.addPortletLink instead.
+
    window.setCookie = function (cookieName, cookieValue, expiryDay) {
*/
+
      $.cookie(cookieName, cookieValue, {
window.addPortletLink = function () {
+
        expires: expiryDay,
    return mw.util.addPortletLink.apply( mw.util, arguments );
+
        path: '/'
};
+
      });
 +
    };
  
/**
+
    window.getCookie = function (cookieName) {
* Extract a URL parameter from the current URL
+
      return $.cookie(cookieName);
*
+
    };
* @deprecated: Use mw.util.getParamValue with proper escaping
 
*/
 
window.getURLParamValue = function () {
 
    return mw.util.getParamValue.apply( mw.util, arguments );
 
};
 
  
/**
+
    window.deleteCookie = function (cookieName) {
* Test if an element has a certain class
+
      $.cookie(cookieName, null);
*
+
    };
* @deprecated:  Use $(element).hasClass() instead.
 
*/
 
window.hasClass = function ( element, className ) {
 
    return $( element ).hasClass( className );
 
};
 
  
/**
+
    /*  當需要時載入對應的 scripts */
  * @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
+
    if (wgAction == "edit" || wgAction == "submit" || wgCanonicalSpecialPageName == 'Search') { // scripts specific to editing pages
* @rev 5
+
      importScript('MediaWiki:Common.js/edit.js');
*/
+
    }
// CSS
 
var extraCSS = mw.util.getParamValue( 'withCSS' );
 
if ( extraCSS ) {
 
if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
 
importStylesheet( extraCSS );
 
} else {
 
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
 
}
 
}
 
  
// JS
+
    /* 辅助处理 */
var extraJS = mw.util.getParamValue( 'withJS' );
+
    /* 1. 功能設定 */
if ( extraJS ) {
+
    window.JSConfig = window.JSconfig || {};
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
+
    window.JSConfig.collapseText = wgULS(' 隐藏▲', '隱藏▲'); // 指示折叠收缩的默认文字
importScript( extraJS );
+
    window.JSConfig.expandText = wgULS(' 显示▼', ' 顯示▼'); // 指示折叠展开的默认文字
} else {
+
    window.JSConfig.autoCollapse = 2; // 文章少于 autoCollapse 个折叠块时,不自动折叠
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
+
    //window.JSConfig.SpecialSearchEnhancedDisabled=false; // 是否禁止增加其它搜索引擎
}
 
}
 
  
/**
+
    /* 2. 用jQuery实现的getElementsByClassName(需不需要返回DOM对象?) */
* Import more specific scripts if necessary
+
    window.getElementsByClassName = function (elm, tag, className) {
  */
+
      return $(tag + '.' + className, elm);
if ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' || mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Upload' ) {
+
     };
    /* scripts specific to editing pages */
 
    importScript( 'MediaWiki:Common.js/edit.js' );
 
} else if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Watchlist' ) {
 
     /* watchlist scripts */
 
    importScript( 'MediaWiki:Common.js/watchlist.js' );
 
}
 
if ( mw.config.get( 'wgNamespaceNumber' ) === 6 ) {
 
    /* file description page scripts */
 
    importScript( 'MediaWiki:Common.js/file.js' );
 
}
 
  
/**
+
    /* 3. 遍历 */
* Load scripts specific to Internet Explorer
+
    window.applyEach = function (callback, array) {
  */
+
      var i = 0,
if ( $.client.profile().name === 'msie' ) {
+
        j = array.length;
    importScript( 'MediaWiki:Common.js/IEFixes.js' );
+
      while (i < j) {
}
+
        callback(array[i++]);
 +
      }
 +
    };
  
/**
+
    /* 4. 移動元素 */
* Fix for Windows XP Unicode font rendering
+
    window.elementMoveto = function (node, refNode, pos) { // 默认位置为refNode前
  */
+
      if (node && refNode) {
if ( navigator.appVersion.search(/windows nt 5/i) !== -1 ) {
+
        if (pos && pos == 'after') {
    mw.util.addCSS( '.IPA { font-family: "Lucida Sans Unicode", "Arial Unicode MS"; } ' +
+
          $(refNode).after(node);
                '.Unicode { font-family: "Arial Unicode MS", "Lucida Sans Unicode"; } ' );
+
        } else {
}
+
          $(refNode).before(node);
 +
        }
 +
      }
 +
    };
  
/**
+
    /* 5创建元素 */
* WikiMiniAtlas
+
    window.createElement = function (tag, children, props) {
*
+
      var element = document.createElement(tag);
* Description: WikiMiniAtlas is a popup click and drag world map.
+
      if (!(children instanceof Array)) {
  *             This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
+
        children = [children];
*              The script itself is located on meta because it is used by many projects.
+
      }
*              See [[Meta:WikiMiniAtlas]] for more information.
+
      applyEach(function (child) {
* Maintainers: [[User:Dschwen]]
+
         if (typeof child == 'string') {
*/
+
          child = document.createTextNode(child);
( function () {
 
    var require_wikiminiatlas = false;
 
    var coord_filter = /geohack/;
 
    $( document ).ready( function() {
 
        $( 'a.external.text' ).each( function( key, link ) {
 
            if ( link.href && coord_filter.exec( link.href ) ) {
 
                require_wikiminiatlas = true;
 
                // break from loop
 
                return false;
 
            }
 
        } );
 
         if ( $( 'div.kmldata' ).length ) {
 
            require_wikiminiatlas = true;
 
 
         }
 
         }
         if ( require_wikiminiatlas ) {
+
         if (child) {
            mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' );
+
          element.appendChild(child);
 
         }
 
         }
    } );
+
      }, children);
} )();
+
      if (typeof props == 'object') {
 
+
        for (var k in props) {
/**
+
          switch (k) {
* Interwiki links to featured articles ***************************************
+
          case 'styles':
*
+
            var styles = props.styles;
* Description: Highlights interwiki links to featured articles (or
+
            for (var s in styles) {
*              equivalents) by changing the bullet before the interwiki link
+
              element.style[s] = styles[s];
*              into a star.
+
            }
* Maintainers: [[User:R. Koot]]
+
            break;
*/
+
          case 'events':
function LinkFA() {
+
            var events = props.events;
    if ( document.getElementById( 'p-lang' ) ) {
+
             for (var e in events) {
        var InterwikiLinks = document.getElementById( 'p-lang' ).getElementsByTagName( 'li' );
+
              addHandler(element, e, events[e]);
 
 
        for ( var i = 0; i < InterwikiLinks.length; i++ ) {
 
            if ( document.getElementById( InterwikiLinks[i].className + '-fa' ) ) {
 
                InterwikiLinks[i].className += ' FA';
 
                InterwikiLinks[i].title = 'This is a featured article in another language.';
 
             } else if ( document.getElementById( InterwikiLinks[i].className + '-ga' ) ) {
 
                InterwikiLinks[i].className += ' GA';
 
                InterwikiLinks[i].title = 'This is a good article in another language.';
 
 
             }
 
             }
 +
            break;
 +
          case 'class':
 +
            element.className = props[k];
 +
            break;
 +
          default:
 +
            element.setAttribute(k, props[k]);
 +
          }
 
         }
 
         }
    }
+
      }
}
+
      return element;
 +
    };
  
$( LinkFA );
+
    // wiki URL
 +
    window.wgProjectURL = {
 +
      en: '//en.wikipedia.org',
 +
      de: '//de.wikipedia.org',
 +
      fr: '//fr.wikipedia.org',
 +
      pl: '//pl.wikipedia.org',
 +
      ja: '//ja.wikipedia.org',
 +
      it: '//it.wikipedia.org',
 +
      nl: '//nl.wikipedia.org',
 +
      pt: '//pt.wikipedia.org',
 +
      es: '//es.wikipedia.org',
 +
      sv: '//sv.wikipedia.org',
 +
      // 僅列前十名其它語言百科
 +
      m: '//meta.wikimedia.org',
 +
      b: '//zh.wikibooks.org',
 +
      q: '//zh.wikiquote.org',
 +
      n: '//zh.wikinews.org',
 +
      wikt: '//zh.wiktionary.org',
 +
      mw: '//www.mediawiki.org',
 +
      commons: '//commons.wikimedia.org'
 +
    };
  
/**
+
    /** 将页面名称转换为URL
* Collapsible tables *********************************************************
+
    *
*
+
    * @param page 页面名称
* Description: Allows tables to be collapsed, showing only the header. See
+
    * @param paras 附加后缀对象,用空对象{}做参数可以取得源码
*              [[Wikipedia:NavFrame]].
+
    */
* Maintainers: [[User:R. Koot]]
+
    window.getWikiPath = function (page, paras) {
*/
+
      var reg = /^[a-z]+:/;
 
+
      var pre = page.match(reg);
var autoCollapse = 2;
+
      pre = pre && wgProjectURL[pre[0].replace(/:$/, '').toLowerCase()];
var collapseCaption = 'hide';
+
      if (pre) {
var expandCaption = 'show';
+
        page = page.replace(reg, '');
 
+
      } else {
window.collapseTable = function ( tableIndex ) {
+
        pre = wgServer;
    var Button = document.getElementById( 'collapseButton' + tableIndex );
+
      } // 保障没有相对路径,以照顾在线代理。
     var Table = document.getElementById( 'collapsibleTable' + tableIndex );
+
      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;
 +
     };
  
     if ( !Table || !Button ) {
+
    /* 引入[[Special:Gadgets]]要求的腳本和樣式 */
        return false;
+
     if (window.requireScripts instanceof Array) {
 +
      applyEach(importScript, requireScripts);
 
     }
 
     }
 
+
     if (window.requireStylesheets instanceof Array) {
    var Rows = Table.rows;
+
      applyEach(importStylesheet, requireStylesheets);
    var i;
 
 
 
     if ( Button.firstChild.data === collapseCaption ) {
 
        for ( i = 1; i < Rows.length; i++ ) {
 
            Rows[i].style.display = 'none';
 
        }
 
        Button.firstChild.data = expandCaption;
 
    } else {
 
        for ( i = 1; i < Rows.length; i++ ) {
 
            Rows[i].style.display = Rows[0].style.display;
 
        }
 
        Button.firstChild.data = collapseCaption;
 
 
     }
 
     }
};
+
    window.requireScripts = [];
 +
    window.requireScripts.push = function (script) {
 +
      importScript(script);
 +
    };
 +
    window.requireStylesheets = [];
 +
    window.requireStylesheets.push = function (style) {
 +
      importStylesheet(style);
 +
    };
  
function createCollapseButtons() {
+
     /* 测试元素中是否含有指定的样式 */
     var tableIndex = 0;
+
     window.hasClass = function (elem, cls) {
     var NavigationBoxes = {};
+
      return $(elem).hasClass(cls);
    var Tables = document.getElementsByTagName( 'table' );
+
     };
     var i;
 
  
     function handleButtonLink( index, e ) {
+
     /** IE兼容性修正
        window.collapseTable( index );
+
    *
        e.preventDefault();
+
    *  Description: Fixes IE horizontal scrollbar bug
    }
+
    *  Maintainers: [[User:fdcn]]
 +
    */
 +
    if ($.browser.msie) {
 +
      var oldWidth;
 +
      var docEl = document.documentElement;
  
    for ( i = 0; i < Tables.length; i++ ) {
+
      function fixIEScroll() {
         if ( $( Tables[i] ).hasClass( 'collapsible' ) ) {
+
         if (!oldWidth || docEl.clientWidth > oldWidth) {
 +
          doFixIEScroll();
 +
        } else {
 +
          setTimeout(doFixIEScroll, 1);
 +
        }
 +
        oldWidth = docEl.clientWidth;
 +
      }
  
            /* only add button and increment count if there is a header row to work with */
+
      function doFixIEScroll() {
            var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
+
        docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : "";
            if ( !HeaderRow ) continue;
+
      }
            var Header = HeaderRow.getElementsByTagName( 'th' )[0];
 
            if ( !Header ) continue;
 
  
            NavigationBoxes[ tableIndex ] = Tables[i];
+
      document.attachEvent("onreadystatechange", fixIEScroll);
            Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
+
      attachEvent("onresize", fixIEScroll);
  
            var Button    = document.createElement( 'span' );
+
      /* Import scripts specific to Internet Explorer 6 */
            var ButtonLink = document.createElement( 'a' );
+
      if (navigator.appVersion.substr(22, 1) == "6") {
            var ButtonText = document.createTextNode( collapseCaption );
+
        importScript("MediaWiki:Common.js/IE60Fixes.js")
 +
      }
 +
    }
  
            Button.className = 'collapseButton'; /* Styles are declared in Common.css */
+
    /* Fixes for Windows XP font rendering */
 +
    if (navigator.appVersion.search(/windows nt 5/i) != -1) {
 +
        mw.util.addCSS('.IPA {font-family: "Lucida Sans Unicode", "Arial Unicode MS";} ' +
 +
                      '.Unicode {font-family: "Arial Unicode MS", "Lucida Sans Unicode";}');
 +
    }
  
            ButtonLink.style.color = Header.style.color;
+
    /* 特色條目優良與條目鏈接顯示 */
            ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
+
    $(function () {
            ButtonLink.setAttribute( 'href', '#' );
+
      $('#p-lang li').each(function () {
            $( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) );
+
        if ($('#' + this.className + '-fa').length) {
            ButtonLink.appendChild( ButtonText );
+
          this.className += " FA"
 +
          this.title = wgULS("此条目在此语言版本中为特色条目", "此條目在此語言版本中為特色條目");
 +
        } else if ($('#' + this.className + '-ga').length) {
 +
          this.className += " GA"
 +
          this.title = wgULS("此条目在此语言版本中为优良条目", "此條目在此語言版本中為優良條目");
 +
        }
 +
      });
 +
    });
  
            Button.appendChild( document.createTextNode( '[' ) );
+
    /** 增加摺疊功能
            Button.appendChild( ButtonLink );
+
    *
            Button.appendChild( document.createTextNode( ']' ) );
+
    * 实现div.NavFrame和table.collapsible的可折叠性。
 +
    * JSConfig的collapseText、expandText、autoCollapse属性定义默认文字和默认最少自动折叠块
 +
    * Maintainers: User:fdcn
 +
    */
 +
    function cancelBubble(e) {
 +
      e = e || window.event;
 +
      if (e.stopPropagation) {
 +
        e.stopPropagation();
 +
      } else {
 +
        e.cancelBubble = true;
 +
      }
 +
    }
  
            Header.insertBefore( Button, Header.firstChild );
+
    function createToggleButton(head) {
            tableIndex++;
+
      var parent = head;
 +
      if (head.tagName.toLowerCase() == 'tr') { // 对表格特别处理
 +
        if (head.getElementsByTagName("th").length) {
 +
          parent = head.cells[parent.cells.length - 1];
 +
        } else {
 +
          return;
 
         }
 
         }
 +
      }
 +
      var textS, textH, button = getElementsByClassName(head, "span", "NavToggle")[0];
 +
      if (button) {
 +
        parent = button.parentNode;
 +
      } else {
 +
        textS = createElement("span", [JSConfig.expandText], {
 +
          'class': 'toggleShow'
 +
        });
 +
        textH = createElement("span", [JSConfig.collapseText], {
 +
          'class': 'toggleHide'
 +
        });
 +
        button = createElement("span", [textS, textH], {
 +
          'class': 'NavToggle collapseButton'
 +
        });
 +
      }
 +
      button.style.visibility = "visible";
 +
      head.className += " uncollapse toggleHotspot";
 +
      parent.insertBefore(button, parent.childNodes[0]);
 
     }
 
     }
 
+
     window.wgCollapse = function (head, container, defaultCollapse) {
     for ( i = 0;  i < tableIndex; i++ ) {
+
      if (head) {
        if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) || ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) ) ) {
+
        createToggleButton(head);
            window.collapseTable( i );
+
      }
        }  
+
      var self = this;
        else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) {
+
      this.state = 0;
            var element = NavigationBoxes[i];
+
      this.container = container;
            while ((element = element.parentNode)) {
+
      applyEach(function (h) {
                if ( $( element ).hasClass( 'outercollapse' ) ) {
+
        if (h.nodeType == 1 && !hasClass(h, "uncollapse") && !hasClass(h, "toggleShow") && !hasClass(h, "toggleHide")) {
                    window.collapseTable ( i );
+
          h.className += " toggleHide";
                    break;
 
                }
 
            }
 
 
         }
 
         }
    }
+
      }, defaultCollapse); // 预设的隐藏元素
}
 
  
$( createCollapseButtons );
 
  
/**
+
      function getArray(clsname) {
* Dynamic Navigation Bars (experimental)
+
        var r = [],
*
+
          i = 0,
* Description: See [[Wikipedia:NavFrame]].
+
          e, ea = getElementsByClassName(container, "*", clsname);
* Maintainers: UNMAINTAINED
+
        while (e = ea[i++]) {
*/
+
          var parent = e.parentNode;
 +
          while (!hasClass(parent, 'NavFrame') && !hasClass(parent, 'collapsible')) {
 +
            parent = parent.parentNode;
 +
          }
 +
          if (parent == container) {
 +
            r.push(e);
 +
          }
 +
        }
 +
        return r;
 +
      }
 +
      var toggleA = getArray("toggleShow");
 +
      var toggleB = getArray("toggleHide");
 +
      var hotspots = getArray("toggleHotspot");
  
/* set up the words in your language */
+
      function _toggle(list, state) {
var NavigationBarHide = '[' + collapseCaption + ']';
+
        var i = 0,
var NavigationBarShow = '[' + expandCaption + ']';
+
          e;
 +
        while (e = list[i++]) {
 +
          e.style.display = state ? e.showStyle || '' : 'none';
 +
        }
 +
      }
 +
      this.toggle = function (state) {
 +
        self.state = (typeof state == 'undefined') ? 1 - self.state : state;
 +
        _toggle(toggleA, self.state);
 +
        _toggle(toggleB, 1 - self.state);
 +
      }
 +
      var i = 0,
 +
        h;
 +
      while (h = hotspots[i++]) {
 +
        applyEach(function (link) {
 +
          addClickHandler(link, cancelBubble);
 +
        }, h.getElementsByTagName("A"));
 +
        h.style.cursor = "pointer";
 +
        $(h).attr('tabindex', '0').keydown(function (event) {
 +
          if (event.which == 13) { // Enter
 +
            self.toggle();
 +
          }
 +
        });
 +
        addClickHandler(h, function () {
 +
          self.toggle();
 +
        });
 +
      }
 +
    };
  
/**
+
    $(function () {
* Shows and hides content and picture (if available) of navigation bars
+
      if (!window.disableCollapse) {
* Parameters:
+
        // init
*    indexNavigationBar: the index of navigation bar to be toggled
+
        var items = [];
**/
+
        applyEach(function (NavFrame) {
window.toggleNavigationBar = function ( indexNavigationBar, event ) {
+
          var i = 0,
    var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
+
            child = NavFrame.childNodes,
    var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
+
            head;
     var NavChild;
+
          while (head = child[i++]) {
 +
            if (head.className && hasClass(head, "NavHead")) {
 +
              break;
 +
            }
 +
          }
 +
          items.push(new wgCollapse(head, NavFrame, NavFrame.childNodes));
 +
        }, getElementsByClassName(document, "div", "NavFrame"));
 +
        applyEach(function (table) {
 +
          var rows = table.rows;
 +
          items.push(new wgCollapse(rows[0], table, rows));
 +
        }, getElementsByClassName(document, "table", "collapsible"));
 +
        var item, i = 0,
 +
          count = items.length;
 +
        while (item = items[i++]) {
 +
          item.toggle(
 +
          hasClass(item.container, "collapsed") || (count >= JSConfig.autoCollapse && hasClass(item.container, "autocollapse")));
 +
        }
 +
      }
 +
    });
 +
    // 修正摺疊後定位變化
 +
    hookEvent("load", function () {
 +
      if (location.hash) {
 +
        location.href = location.hash;
 +
      }
 +
     });
  
     if ( !NavFrame || !NavToggle ) {
+
     /* 取消討論頁的[+]按鈕 */
         return false;
+
    $(function () {
     }
+
      if ($('#no-newsection').length) {
 +
         $('#ca-addsection').css('display', 'none');
 +
      }
 +
     });
  
     /* if shown now */
+
     /* 避免在主條目中出現捲軸框 */
     if ( NavToggle.firstChild.data === NavigationBarHide ) {
+
     if (!wgCanonicalNamespace) $(function () {
         for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
+
      var disableDivOverflowScroll = function (obj) {
             if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
+
        var targetdiv;
                NavChild.style.display = 'none';
+
         for (var i = obj.childNodes.length; i-- > 0;) {
 +
          if (obj.childNodes[i] && ("" + obj.childNodes[i].tagName).toLowerCase() == "div") {
 +
            targetdiv = obj.childNodes[i];
 +
             if (("" + targetdiv.className).indexOf("noprint") == -1 && ("" + targetdiv.className).indexOf("thumb") == -1) {
 +
              if ( !! (targetdiv.style.overflow) || !! (targetdiv.style.overflowY)) with(targetdiv.style) {
 +
                overflowY = "visible";
 +
                padding = "";
 +
                border = "";
 +
                height = "";
 +
              }
 +
              disableDivOverflowScroll(targetdiv);
 
             }
 
             }
 +
          }
 
         }
 
         }
     NavToggle.firstChild.data = NavigationBarShow;
+
      }
 +
      disableDivOverflowScroll(document.getElementsByTagName("body")[0]);
 +
     });
  
     /* if hidden now */
+
     /** metaBox
     } else if ( NavToggle.firstChild.data === NavigationBarShow ) {
+
    *
         for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
+
    * Funcionament de la Plantilla:Metacaixa
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
+
    * Implementat per: Usuari:Peleguer.
                NavChild.style.display = 'block';
+
    * Actualitzat per Joanjoc seguint les indicacions d'en Martorell
            }
+
    */
 +
     function MetaCaixaInit() {
 +
      // S'executa al carregar-se la pàgina, si hi ha metacaixes,
 +
      // s'assignen els esdeveniments als botons
 +
      //alert("MetaCaixaInit");
 +
      var i = 0 // Inicialitzem comptador de caixes
 +
      for (i = 0; i <= 9; i++) {
 +
        var vMc = document.getElementById("mc" + i);
 +
        if (!vMc) break;
 +
        //alert("MetaCaixaInit, trobada Metacaixa mc"+i);
 +
        var j = 1 // Inicialitzem comptador de botons dins de la caixa
 +
        var vPsIni = 0 // Pestanya visible inicial
 +
         for (j = 1; j <= 9; j++) {
 +
          var vBt = document.getElementById("mc" + i + "bt" + j);
 +
          if (!vBt) break;
 +
          //alert("MetaCaixaInit, trobat botó mc"+i+"bt"+j);
 +
          vBt.onclick = MetaCaixaMostraPestanya; // A cada botó assignem l'esdeveniment onclick
 +
          //alert (vBt.className);
 +
          if (vBt.className == "mcBotoSel") vPsIni = j; // Si tenim un botó seleccionat, en guardem l'index
 +
        }
 +
        //alert ("mc="+i+", ps="+j+", psini="+vPsIni );
 +
        if (vPsIni == 0) { // Si no tenim cap botó seleccionat, n'agafem un aleatòriament
 +
          vPsIni = 1 + Math.floor((j - 1) * Math.random());
 +
          //alert ("Activant Pestanya a l'atzar; _mc"+i+"bt"+vPsIni +"_");
 +
          document.getElementById("mc" + i + "ps" + vPsIni).style.display = "block";
 +
          document.getElementById("mc" + i + "ps" + vPsIni).style.visibility = "visible";
 +
          document.getElementById("mc" + i + "bt" + vPsIni).className = "mcBotoSel";
 
         }
 
         }
        NavToggle.firstChild.data = NavigationBarHide;
+
      }
 
     }
 
     }
  
     event.preventDefault();
+
     function MetaCaixaMostraPestanya() {
};
+
      // S'executa al clicar una pestanya,
 
+
      // aquella es fa visible i les altres s'oculten
/* adds show/hide-button to navigation bars */
+
      var vMcNom = this.id.substr(0, 3); // A partir del nom del botó, deduïm el nom de la caixa
function createNavigationBarToggleButton() {
+
      var vIndex = this.id.substr(5, 1); // I l'index
    var indexNavigationBar = 0;
+
      var i = 1
    var NavFrame;
+
      for (i = 1; i <= 9; i++) { // busquem totes les pestanyes d'aquella caixa
    var NavChild;
+
         //alert(vMcNom+"ps"+i);
    /* iterate over all < div >-elements */
+
        var vPsElem = document.getElementById(vMcNom + "ps" + i);
    var divs = document.getElementsByTagName( 'div' );
+
        if (!vPsElem) break;
    for ( var i = 0; (NavFrame = divs[i]); i++ ) {
+
        if (vIndex == i) { // Si és la pestanya bona la mostrem i canviem la classe de botó
         /* if found a navigation bar */
+
          vPsElem.style.display = "block";
        if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {
+
          vPsElem.style.visibility = "visible";
 
+
          document.getElementById(vMcNom + "bt" + i).className = "mcBotoSel";
            indexNavigationBar++;
+
        } else { // Sinó, l'ocultem i canviem la classe de botó
            var NavToggle = document.createElement( 'a' );
+
          vPsElem.style.display = "none";
            NavToggle.className = 'NavToggle';
+
          vPsElem.style.visibility = "hidden";
            NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
+
          document.getElementById(vMcNom + "bt" + i).className = "mcBoto";
            NavToggle.setAttribute( 'href', '#' );
 
            $( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );
 
 
 
            var isCollapsed = $( NavFrame ).hasClass( 'collapsed' );
 
            /**
 
            * Check if any children are already hidden. This loop is here for backwards compatibility:
 
            * the old way of making NavFrames start out collapsed was to manually add style="display:none"
 
            * to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make
 
            * the content visible without JavaScript support), the new recommended way is to add the class
 
            * "collapsed" to the NavFrame itself, just like with collapsible tables.
 
            */
 
            for ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling ) {
 
                if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
 
                    if ( NavChild.style.display === 'none' ) {
 
                        isCollapsed = true;
 
                    }
 
                }
 
            }
 
            if ( isCollapsed ) {
 
                for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
 
                    if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
 
                        NavChild.style.display = 'none';
 
                    }
 
                }
 
            }
 
            var NavToggleText = document.createTextNode( isCollapsed ? NavigationBarShow : NavigationBarHide );
 
            NavToggle.appendChild( NavToggleText );
 
 
 
            /* Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) */
 
            for( var j = 0; j < NavFrame.childNodes.length; j++ ) {
 
                if ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
 
                    NavToggle.style.color = NavFrame.childNodes[j].style.color;
 
                    NavFrame.childNodes[j].appendChild( NavToggle );
 
                }
 
            }
 
            NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
 
 
         }
 
         }
 +
      }
 +
      return false; // evitem la recàrrega de la pàgina
 
     }
 
     }
}
+
    addOnloadHook(MetaCaixaInit);
 +
 
 +
    /* 智能讨论页编辑(新建) */
 +
    $(function () {
 +
      var catalk = $('#ca-talk');
 +
      if (catalk.hasClass('new') && wgNamespaceNumber != 2) {
 +
        var a = $('a:first', catalk);
 +
        a.attr('href', a.attr('href') + '&section=new');
 +
      }
 +
    });
  
$( createNavigationBarToggleButton );
+
    /** Magic editintros
 +
    *
 +
    * Description: Adds editintros on disambiguation pages and BLP pages.
 +
    * Maintainers: [[:en:User:RockMFR]], [[User:PhiLiP]]
 +
    */
 +
    var addEditIntro = function (name) {
 +
      $('#ca-edit, .editsection').each(function () {
 +
        $('a', this).attr('href',
 +
        $('a', this).attr('href') + '&editintro=' + mw.util.wikiUrlencode(name));
 +
      });
 +
    };
  
/**
+
     if (wgNamespaceNumber == 0) {
* Uploadwizard_newusers
+
      $(function () {
* Switches in a message for non-autoconfirmed users at [[Wikipedia:Upload]]
+
         var uei = $('#useeditintro, .useeditintro');
*
+
         if (uei.length) {
* Maintainers: [[User:Krimpet]]
+
          addEditIntro(uei.eq(-1).attr('title'));
*/
+
          uei.attr('title', '');
function uploadwizard_newusers() {
 
     if ( mw.config.get( 'wgNamespaceNumber' ) === 4 && mw.config.get( 'wgTitle' ) === 'Upload' && mw.config.get( 'wgAction' ) === 'view' ) {
 
         var oldDiv = document.getElementById( 'autoconfirmedusers' ),
 
            newDiv = document.getElementById( 'newusers' );
 
         if ( oldDiv && newDiv ) {
 
            var userGroups = mw.config.get( 'wgUserGroups' );
 
            if ( userGroups ) {
 
                for ( var i = 0; i < userGroups.length; i++ ) {
 
                    if ( userGroups[i] === 'autoconfirmed' ) {
 
                        oldDiv.style.display = 'block';
 
                        newDiv.style.display = 'none';
 
                        return;
 
                    }
 
                }
 
            }
 
            oldDiv.style.display = 'none';
 
            newDiv.style.display = 'block';
 
            return;
 
 
         }
 
         }
 +
      });
 
     }
 
     }
}
 
  
$(uploadwizard_newusers);
+
    /* Top icon: [[Template:Topicon]] */
 +
    $(function () {
 +
      // nostalgia, standard and cologneblue use .pagetitle
 +
      // what's the problem on modern?
 +
      $('<div />').css('float', 'right').append($('.topicon').css({
 +
        'float': 'right',
 +
        'position': 'static'
 +
      }).show()).insertBefore('#firstHeading span[dir=auto], #article .pagetitle span[dir=auto]');
 +
    });
  
/**
+
    /*  引用錯誤標籤名字解碼 */
* Magic editintros ****************************************************
+
    $(function () {
*
+
      $('.anchordecodeme').each(function () {
* Description: Adds editintros on disambiguation pages and BLP pages.
+
         $(this).text(decodeURIComponent($(this).text().replace(/\.([0-9A-F]{2})/g, '%$1')));
* Maintainers: [[User:RockMFR]]
+
      });
  */
+
    });
function addEditIntro( name ) {
 
    $( '.editsection, #ca-edit' ).find( 'a' ).each( function ( i, el ) {
 
         el.href = $( this ).attr( 'href' ) + '&editintro=' + name;
 
    } );
 
}
 
  
if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) {
+
    /** &withCSS= and &withJS= URL parameters
    $( function () {
+
    * Allow to try custom scripts from MediaWiki space
        if ( document.getElementById( 'disambigbox' ) ) {
+
    * without editing personal .css or .js files
            addEditIntro( 'Template:Disambig_editintro' );
+
    */
        }
+
    {
     } );
+
      var extraCSS = mw.util.getParamValue("withCSS");
 +
      if ( extraCSS && extraCSS.match(/^MediaWiki:[^&<>=%]*\.css$/i) ) {
 +
        importStylesheet(extraCSS);
 +
      }
 +
      var extraJS = mw.util.getParamValue("withJS");
 +
      if ( extraJS && extraJS.match(/^MediaWiki:[^&<>=%]*\.js$/i) ) {
 +
        importScript(extraJS);
 +
      }
 +
     }
  
     $( function () {
+
     /* 页面历史加&hilight=高亮 */
        var cats = document.getElementById( 'mw-normal-catlinks' );
+
    {
        if ( !cats ) {
+
      var hilight = mw.util.getParamValue('hilight');
            return;
+
      if (wgAction === 'history' && hilight) {
        }
+
          $.each(hilight.split(','), function (_, v) {
        cats = cats.getElementsByTagName( 'a' );
+
            $('input[name=oldid][value=' + v + ']').parent().addClass('not-patrolled');
        for ( var i = 0; i < cats.length; i++ ) {
+
          });
            if ( cats[i].title === 'Category:Living people' || cats[i].title === 'Category:Possibly living people' ) {
+
      }
                addEditIntro( 'Template:BLP_editintro' );
+
     }
                break;
 
            }
 
        }
 
     } );
 
}
 
  
/**
+
    /*  维基百科语言列表 */
* Description: Stay on the secure server as much as possible
+
    if (mw.config.get('wgIsMainPage') || wgPageName == 'Wikipedia_talk: 首页' || wgPageName.indexOf("Wikipedia:首頁/自訂首頁設計/") == 0) {
* Maintainers: [[User:TheDJ]]
+
      $(function () {
  */
+
        mw.util.addPortletLink('p-lang', wgScriptPath + '/index.php?title=Wikipedia:维基百科语言列表', wgULS('维基百科语言列表', '維基百科語言列表'), 'interwiki-completelist', wgULS('维基百科的完整各语言列表', '維基百科的完整各語言列表'));
if ( document.location && document.location.protocol  && document.location.protocol === 'https:' ) {
+
      });
    /* New secure servers */
+
    }
    importScript( 'MediaWiki:Common.js/secure new.js' );
+
  })(jQuery, mediaWiki);
}
+
});
 
 
/* End of mw.loader.using callback */
 
} );
 
/* DO NOT ADD CODE BELOW THIS LINE */
 

2013年4月6日 (六) 07:48的版本

/*
所有用戶在加載任何頁面時,這裡的JavaScript都會加載
*/

mw.loader.using(['mediawiki.Uri'], function() {
    /* Search Engine variant hack */
    var ref, loc;
    try {
        ref = new mw.Uri( document.referrer );
        loc = new mw.Uri( location.href );
    } catch ( e ) {
        return;
    }
    if (/\.google\./.test(ref.host) && /\/zh(-[^/]+)?\//.test(loc.path)) {
        loc.path = loc.path.replace(/\/zh(-[^/]+)?\//, "/wiki/");
        location = loc.toString();
    }
} );

mw.loader.using(['mediawiki.util', 'ext.gadget.site-lib'], function () {
  (function ($, mw) {
    /* Cookies */
    window.setCookie = function (cookieName, cookieValue, expiryDay) {
      $.cookie(cookieName, cookieValue, {
        expires: expiryDay,
        path: '/'
      });
    };

    window.getCookie = function (cookieName) {
      return $.cookie(cookieName);
    };

    window.deleteCookie = function (cookieName) {
      $.cookie(cookieName, null);
    };

    /* 當需要時載入對應的 scripts */
    if (wgAction == "edit" || wgAction == "submit" || wgCanonicalSpecialPageName == 'Search') { // scripts specific to editing pages
      importScript('MediaWiki:Common.js/edit.js');
    }

    /* 辅助处理 */
    /* 1. 功能設定 */
    window.JSConfig = window.JSconfig || {};
    window.JSConfig.collapseText = wgULS('隐藏▲', '隱藏▲'); // 指示折叠收缩的默认文字
    window.JSConfig.expandText = wgULS('显示▼', '顯示▼'); // 指示折叠展开的默认文字
    window.JSConfig.autoCollapse = 2; // 文章少于 autoCollapse 个折叠块时,不自动折叠
    //window.JSConfig.SpecialSearchEnhancedDisabled=false; // 是否禁止增加其它搜索引擎

    /* 2. 用jQuery实现的getElementsByClassName(需不需要返回DOM对象?) */
    window.getElementsByClassName = function (elm, tag, className) {
      return $(tag + '.' + className, elm);
    };

    /* 3. 遍历 */
    window.applyEach = function (callback, array) {
      var i = 0,
        j = array.length;
      while (i < j) {
        callback(array[i++]);
      }
    };

    /* 4. 移動元素 */
    window.elementMoveto = function (node, refNode, pos) { // 默认位置为refNode前
      if (node && refNode) {
        if (pos && pos == 'after') {
          $(refNode).after(node);
        } else {
          $(refNode).before(node);
        }
      }
    };

    /* 5. 创建元素 */
    window.createElement = function (tag, children, props) {
      var element = document.createElement(tag);
      if (!(children instanceof Array)) {
        children = [children];
      }
      applyEach(function (child) {
        if (typeof child == 'string') {
          child = document.createTextNode(child);
        }
        if (child) {
          element.appendChild(child);
        }
      }, children);
      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
    window.wgProjectURL = {
      en: '//en.wikipedia.org',
      de: '//de.wikipedia.org',
      fr: '//fr.wikipedia.org',
      pl: '//pl.wikipedia.org',
      ja: '//ja.wikipedia.org',
      it: '//it.wikipedia.org',
      nl: '//nl.wikipedia.org',
      pt: '//pt.wikipedia.org',
      es: '//es.wikipedia.org',
      sv: '//sv.wikipedia.org',
      // 僅列前十名其它語言百科
      m: '//meta.wikimedia.org',
      b: '//zh.wikibooks.org',
      q: '//zh.wikiquote.org',
      n: '//zh.wikinews.org',
      wikt: '//zh.wiktionary.org',
      mw: '//www.mediawiki.org',
      commons: '//commons.wikimedia.org'
    };

    /** 将页面名称转换为URL
     *
     * @param page 页面名称
     * @param paras 附加后缀对象,用空对象{}做参数可以取得源码
     */
    window.getWikiPath = function (page, paras) {
      var reg = /^[a-z]+:/;
      var pre = page.match(reg);
      pre = pre && wgProjectURL[pre[0].replace(/:$/, '').toLowerCase()];
      if (pre) {
        page = page.replace(reg, '');
      } else {
        pre = wgServer;
      } // 保障没有相对路径,以照顾在线代理。
      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;
    };

    /* 引入[[Special:Gadgets]]要求的腳本和樣式 */
    if (window.requireScripts instanceof Array) {
      applyEach(importScript, requireScripts);
    }
    if (window.requireStylesheets instanceof Array) {
      applyEach(importStylesheet, requireStylesheets);
    }
    window.requireScripts = [];
    window.requireScripts.push = function (script) {
      importScript(script);
    };
    window.requireStylesheets = [];
    window.requireStylesheets.push = function (style) {
      importStylesheet(style);
    };

    /* 测试元素中是否含有指定的样式 */
    window.hasClass = function (elem, cls) {
      return $(elem).hasClass(cls);
    };

    /** IE兼容性修正
     *
     *  Description: Fixes IE horizontal scrollbar bug
     *  Maintainers: [[User:fdcn]]
     */
    if ($.browser.msie) {
      var oldWidth;
      var docEl = document.documentElement;

      function fixIEScroll() {
        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);

      /* Import scripts specific to Internet Explorer 6 */
      if (navigator.appVersion.substr(22, 1) == "6") {
        importScript("MediaWiki:Common.js/IE60Fixes.js")
      }
    }

    /* Fixes for Windows XP font rendering */
    if (navigator.appVersion.search(/windows nt 5/i) != -1) {
        mw.util.addCSS('.IPA {font-family: "Lucida Sans Unicode", "Arial Unicode MS";} ' + 
                       '.Unicode {font-family: "Arial Unicode MS", "Lucida Sans Unicode";}');
    }

    /* 特色條目優良與條目鏈接顯示 */
    $(function () {
      $('#p-lang li').each(function () {
        if ($('#' + this.className + '-fa').length) {
          this.className += " FA"
          this.title = wgULS("此条目在此语言版本中为特色条目", "此條目在此語言版本中為特色條目");
        } else if ($('#' + this.className + '-ga').length) {
          this.className += " GA"
          this.title = wgULS("此条目在此语言版本中为优良条目", "此條目在此語言版本中為優良條目");
        }
      });
    });

    /** 增加摺疊功能
     *
     * 实现div.NavFrame和table.collapsible的可折叠性。
     * JSConfig的collapseText、expandText、autoCollapse属性定义默认文字和默认最少自动折叠块
     * Maintainers: User:fdcn
     */
    function cancelBubble(e) {
      e = e || window.event;
      if (e.stopPropagation) {
        e.stopPropagation();
      } else {
        e.cancelBubble = true;
      }
    }

    function createToggleButton(head) {
      var parent = head;
      if (head.tagName.toLowerCase() == 'tr') { // 对表格特别处理
        if (head.getElementsByTagName("th").length) {
          parent = head.cells[parent.cells.length - 1];
        } else {
          return;
        }
      }
      var textS, textH, button = getElementsByClassName(head, "span", "NavToggle")[0];
      if (button) {
        parent = button.parentNode;
      } else {
        textS = createElement("span", [JSConfig.expandText], {
          'class': 'toggleShow'
        });
        textH = createElement("span", [JSConfig.collapseText], {
          'class': 'toggleHide'
        });
        button = createElement("span", [textS, textH], {
          'class': 'NavToggle collapseButton'
        });
      }
      button.style.visibility = "visible";
      head.className += " uncollapse toggleHotspot";
      parent.insertBefore(button, parent.childNodes[0]);
    }
    window.wgCollapse = function (head, container, defaultCollapse) {
      if (head) {
        createToggleButton(head);
      }
      var self = this;
      this.state = 0;
      this.container = container;
      applyEach(function (h) {
        if (h.nodeType == 1 && !hasClass(h, "uncollapse") && !hasClass(h, "toggleShow") && !hasClass(h, "toggleHide")) {
          h.className += " toggleHide";
        }
      }, defaultCollapse); // 预设的隐藏元素


      function getArray(clsname) {
        var r = [],
          i = 0,
          e, ea = getElementsByClassName(container, "*", clsname);
        while (e = ea[i++]) {
          var parent = e.parentNode;
          while (!hasClass(parent, 'NavFrame') && !hasClass(parent, 'collapsible')) {
            parent = parent.parentNode;
          }
          if (parent == container) {
            r.push(e);
          }
        }
        return r;
      }
      var toggleA = getArray("toggleShow");
      var toggleB = getArray("toggleHide");
      var hotspots = getArray("toggleHotspot");

      function _toggle(list, state) {
        var i = 0,
          e;
        while (e = list[i++]) {
          e.style.display = state ? e.showStyle || '' : 'none';
        }
      }
      this.toggle = function (state) {
        self.state = (typeof state == 'undefined') ? 1 - self.state : state;
        _toggle(toggleA, self.state);
        _toggle(toggleB, 1 - self.state);
      }
      var i = 0,
        h;
      while (h = hotspots[i++]) {
        applyEach(function (link) {
          addClickHandler(link, cancelBubble);
        }, h.getElementsByTagName("A"));
        h.style.cursor = "pointer";
        $(h).attr('tabindex', '0').keydown(function (event) {
          if (event.which == 13) { // Enter
            self.toggle();
          }
        });
        addClickHandler(h, function () {
          self.toggle();
        });
      }
    };

    $(function () {
      if (!window.disableCollapse) {
        // init
        var items = [];
        applyEach(function (NavFrame) {
          var i = 0,
            child = NavFrame.childNodes,
            head;
          while (head = child[i++]) {
            if (head.className && hasClass(head, "NavHead")) {
              break;
            }
          }
          items.push(new wgCollapse(head, NavFrame, NavFrame.childNodes));
        }, getElementsByClassName(document, "div", "NavFrame"));
        applyEach(function (table) {
          var rows = table.rows;
          items.push(new wgCollapse(rows[0], table, rows));
        }, getElementsByClassName(document, "table", "collapsible"));
        var item, i = 0,
          count = items.length;
        while (item = items[i++]) {
          item.toggle(
          hasClass(item.container, "collapsed") || (count >= JSConfig.autoCollapse && hasClass(item.container, "autocollapse")));
        }
      }
    });
    // 修正摺疊後定位變化
    hookEvent("load", function () {
      if (location.hash) {
        location.href = location.hash;
      }
    });

    /* 取消討論頁的[+]按鈕 */
    $(function () {
      if ($('#no-newsection').length) {
        $('#ca-addsection').css('display', 'none');
      }
    });

    /* 避免在主條目中出現捲軸框 */
    if (!wgCanonicalNamespace) $(function () {
      var disableDivOverflowScroll = function (obj) {
        var targetdiv;
        for (var i = obj.childNodes.length; i-- > 0;) {
          if (obj.childNodes[i] && ("" + obj.childNodes[i].tagName).toLowerCase() == "div") {
            targetdiv = obj.childNodes[i];
            if (("" + targetdiv.className).indexOf("noprint") == -1 && ("" + targetdiv.className).indexOf("thumb") == -1) {
              if ( !! (targetdiv.style.overflow) || !! (targetdiv.style.overflowY)) with(targetdiv.style) {
                overflowY = "visible";
                padding = "";
                border = "";
                height = "";
              }
              disableDivOverflowScroll(targetdiv);
            }
          }
        }
      }
      disableDivOverflowScroll(document.getElementsByTagName("body")[0]);
    });

    /** metaBox
     *
     * Funcionament de la Plantilla:Metacaixa
     * Implementat per: Usuari:Peleguer.
     * Actualitzat per Joanjoc seguint les indicacions d'en Martorell
     */
    function MetaCaixaInit() {
      // S'executa al carregar-se la pàgina, si hi ha metacaixes,
      // s'assignen els esdeveniments als botons
      //alert("MetaCaixaInit");
      var i = 0 // Inicialitzem comptador de caixes
      for (i = 0; i <= 9; i++) {
        var vMc = document.getElementById("mc" + i);
        if (!vMc) break;
        //alert("MetaCaixaInit, trobada Metacaixa mc"+i);
        var j = 1 // Inicialitzem comptador de botons dins de la caixa
        var vPsIni = 0 // Pestanya visible inicial
        for (j = 1; j <= 9; j++) {
          var vBt = document.getElementById("mc" + i + "bt" + j);
          if (!vBt) break;
          //alert("MetaCaixaInit, trobat botó mc"+i+"bt"+j);
          vBt.onclick = MetaCaixaMostraPestanya; // A cada botó assignem l'esdeveniment onclick
          //alert (vBt.className);
          if (vBt.className == "mcBotoSel") vPsIni = j; // Si tenim un botó seleccionat, en guardem l'index
        }
        //alert ("mc="+i+", ps="+j+", psini="+vPsIni );
        if (vPsIni == 0) { // Si no tenim cap botó seleccionat, n'agafem un aleatòriament
          vPsIni = 1 + Math.floor((j - 1) * Math.random());
          //alert ("Activant Pestanya a l'atzar; _mc"+i+"bt"+vPsIni +"_");
          document.getElementById("mc" + i + "ps" + vPsIni).style.display = "block";
          document.getElementById("mc" + i + "ps" + vPsIni).style.visibility = "visible";
          document.getElementById("mc" + i + "bt" + vPsIni).className = "mcBotoSel";
        }
      }
    }

    function MetaCaixaMostraPestanya() {
      // S'executa al clicar una pestanya,
      // aquella es fa visible i les altres s'oculten
      var vMcNom = this.id.substr(0, 3); // A partir del nom del botó, deduïm el nom de la caixa
      var vIndex = this.id.substr(5, 1); // I l'index
      var i = 1
      for (i = 1; i <= 9; i++) { // busquem totes les pestanyes d'aquella caixa
        //alert(vMcNom+"ps"+i);
        var vPsElem = document.getElementById(vMcNom + "ps" + i);
        if (!vPsElem) break;
        if (vIndex == i) { // Si és la pestanya bona la mostrem i canviem la classe de botó
          vPsElem.style.display = "block";
          vPsElem.style.visibility = "visible";
          document.getElementById(vMcNom + "bt" + i).className = "mcBotoSel";
        } else { // Sinó, l'ocultem i canviem la classe de botó
          vPsElem.style.display = "none";
          vPsElem.style.visibility = "hidden";
          document.getElementById(vMcNom + "bt" + i).className = "mcBoto";
        }
      }
      return false; // evitem la recàrrega de la pàgina
    }
    addOnloadHook(MetaCaixaInit);

    /* 智能讨论页编辑(新建) */
    $(function () {
      var catalk = $('#ca-talk');
      if (catalk.hasClass('new') && wgNamespaceNumber != 2) {
        var a = $('a:first', catalk);
        a.attr('href', a.attr('href') + '&section=new');
      }
    });

    /** Magic editintros
     *
     * Description: Adds editintros on disambiguation pages and BLP pages.
     * Maintainers: [[:en:User:RockMFR]], [[User:PhiLiP]]
     */
    var addEditIntro = function (name) {
      $('#ca-edit, .editsection').each(function () {
        $('a', this).attr('href',
        $('a', this).attr('href') + '&editintro=' + mw.util.wikiUrlencode(name));
      });
    };

    if (wgNamespaceNumber == 0) {
      $(function () {
        var uei = $('#useeditintro, .useeditintro');
        if (uei.length) {
          addEditIntro(uei.eq(-1).attr('title'));
          uei.attr('title', '');
        }
      });
    }

    /* Top icon: [[Template:Topicon]] */
    $(function () {
      // nostalgia, standard and cologneblue use .pagetitle
      // what's the problem on modern?
      $('<div />').css('float', 'right').append($('.topicon').css({
        'float': 'right',
        'position': 'static'
      }).show()).insertBefore('#firstHeading span[dir=auto], #article .pagetitle span[dir=auto]');
    });

    /* 引用錯誤標籤名字解碼 */
    $(function () {
      $('.anchordecodeme').each(function () {
        $(this).text(decodeURIComponent($(this).text().replace(/\.([0-9A-F]{2})/g, '%$1')));
      });
    });

    /** &withCSS= and &withJS= URL parameters
     * Allow to try custom scripts from MediaWiki space 
     * without editing personal .css or .js files
     */
    {
      var extraCSS = mw.util.getParamValue("withCSS");
      if ( extraCSS && extraCSS.match(/^MediaWiki:[^&<>=%]*\.css$/i) ) {
        importStylesheet(extraCSS);
      }
      var extraJS = mw.util.getParamValue("withJS");
      if ( extraJS && extraJS.match(/^MediaWiki:[^&<>=%]*\.js$/i) ) {
        importScript(extraJS);
      }
    }

    /* 页面历史加&hilight=高亮 */
    {
       var hilight = mw.util.getParamValue('hilight');
       if (wgAction === 'history' && hilight) {
          $.each(hilight.split(','), function (_, v) {
             $('input[name=oldid][value=' + v + ']').parent().addClass('not-patrolled');
          });
       }
    }

    /* 维基百科语言列表 */
    if (mw.config.get('wgIsMainPage') || wgPageName == 'Wikipedia_talk:首页' || wgPageName.indexOf("Wikipedia:首頁/自訂首頁設計/") == 0) {
      $(function () {
        mw.util.addPortletLink('p-lang', wgScriptPath + '/index.php?title=Wikipedia:维基百科语言列表', wgULS('维基百科语言列表', '維基百科語言列表'), 'interwiki-completelist', wgULS('维基百科的完整各语言列表', '維基百科的完整各語言列表'));
      });
    }
  })(jQuery, mediaWiki);
});