本館粉絲專頁

MediaWiki:Common.js:修訂版本之間的差異

分享此網頁到Facebook
分享此網頁到Plurk
分享此網頁到百度搜藏
分享此網頁到Twitter
分享此網頁到Del.icio.us
台灣棒球維基館
跳轉到: 導覽搜尋
(取消由LiaoWS對話)所作出的修訂 785756)
第6行: 第6行:
  
  
/**
+
/* 1. 功能設定 */
* Keep code in MediaWiki:Common.js to a minimum as it is unconditionally
+
    window.JSConfig = window.JSconfig || {};
* loaded for all users on every wiki page. If possible create a gadget that is
+
    window.JSConfig.collapseText = wgULS('隐藏▲', '隱藏▲'); // 指示折叠收缩的默认文字
* enabled by default instead of adding it here (since gadgets are fully
+
    window.JSConfig.expandText = wgULS('显示▼', '顯示▼'); // 指示折叠展开的默认文字
* optimized ResourceLoader modules with possibility to add dependencies etc.)
+
    window.JSConfig.autoCollapse = 2; // 文章少于 autoCollapse 个折叠块时,不自动折叠
*
+
    //window.JSConfig.SpecialSearchEnhancedDisabled=false; // 是否禁止增加其它搜索引擎
* 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 */
+
    /* 2. 用jQuery实现的getElementsByClassName(需不需要返回DOM对象?) */
/* jshint strict:false, browser:true */
+
    window.getElementsByClassName = function (elm, tag, className) {
 +
      return $(tag + '.' + className, elm);
 +
    };
  
mw.loader.using( ['mediawiki.user', 'mediawiki.util', 'mediawiki.notify', 'jquery.client'] ).done( function () {
+
    /* 3. 遍历 */
/* Begin of mw.loader.using callback */
+
    window.applyEach = function (callback, array) {
 +
      var i = 0,
 +
        j = array.length;
 +
      while (i < j) {
 +
        callback(array[i++]);
 +
      }
 +
    };
  
/**
+
    /* 4. 移動元素 */
* Main Page layout fixes
+
    window.elementMoveto = function (node, refNode, pos) { // 默认位置为refNode前
*
+
      if (node && refNode) {
* Description: Adds an additional link to the complete list of languages available.
+
        if (pos && pos == 'after') {
* Maintainers: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]]
+
          $(refNode).after(node);
*/
+
         } else {
if ( mw.config.get( 'wgPageName' ) === 'Main_Page' || mw.config.get( 'wgPageName' ) === 'Talk:Main_Page' ) {
+
          $(refNode).before(node);
    $( function () {
+
        mw.util.addPortletLink( 'p-lang', '//meta.wikimedia.org/wiki/List_of_Wikipedias',
+
            'Complete list', 'interwiki-completelist', 'Complete list of Wikipedias' );
+
    } );
+
}
+
 
+
/**
+
* 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.getUrl( userSkinPage + '.js' );
+
        } else if ( titleParts.slice( -1 ) == 'skin.css' ) {
+
            window.location.href = mw.util.getUrl( userSkinPage + '.css' );
+
 
         }
 
         }
    }
+
      }
}
+
    };
  
/**
+
    /* 5. 创建元素 */
* Map addPortletLink to mw.util
+
    window.createElement = function (tag, children, props) {
* @deprecated: Use mw.util.addPortletLink instead.
+
      var element = document.createElement(tag);
*/
+
      if (!(children instanceof Array)) {
mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' );
+
         children = [children];
 
+
      }
/**
+
      applyEach(function (child) {
* Extract a URL parameter from the current URL
+
        if (typeof child == 'string') {
* @deprecated: Use mw.util.getParamValue with proper escaping
+
          child = document.createTextNode(child);
*/
+
mw.log.deprecate( window, 'getURLParamValue', mw.util.getParamValue, 'Use mw.util.getParamValue instead' );
+
 
+
/**
+
* Test if an element has a certain class
+
* @deprecated:  Use $(element).hasClass() instead.
+
*/
+
mw.log.deprecate( window, 'hasClass', function ( element, className ) {
+
    return $( element ).hasClass( className );
+
}, 'Use jQuery.hasClass() instead' );
+
 
+
/**
+
* @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
+
* @rev 6
+
*/
+
var extraCSS = mw.util.getParamValue( 'withCSS' ),
+
    extraJS = mw.util.getParamValue( 'withJS' );
+
 
+
if ( extraCSS ) {
+
    if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
+
         importStylesheet( extraCSS );
+
    } else {
+
        mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
+
    }
+
}
+
 
+
if ( extraJS ) {
+
    if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
+
        importScript( extraJS );
+
    } else {
+
        mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
+
    }
+
}
+
 
+
/**
+
* Import more specific scripts if necessary
+
*/
+
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' );
+
}
+
 
+
/**
+
* Helper script for .hlist class in Common.css
+
* Add pseudo-selector class to last-child list items in IE8
+
* @source mediawiki.org/wiki/Snippets/Horizontal_lists
+
* @revision 6 (2014-08-23)
+
* @author [[User:Edokter]]
+
*/
+
( function ( mw, $ ) {
+
    var profile = $.client.profile();
+
    if ( profile.name === 'msie' && profile.versionNumber === 8 ) {
+
        mw.hook( 'wikipage.content' ).add( function ( $content ) {
+
            $content.find( '.hlist' ).find( 'dd:last-child, dt:last-child, li:last-child' )
+
                .addClass( 'hlist-last-child' );
+
        } );
+
    }
+
}( mediaWiki, jQuery ) );
+
 
+
/**
+
* Fix for Windows XP Unicode 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"; } ' );
+
}
+
 
+
/**
+
* Add (faux) userpage link and (real) talkpage and contributions links for anon users in personal toolbar.
+
* TODO(?): Load system messages using mw.msg(), but requires API call first.
+
*/
+
function addAnonToolbarLinks() {
+
var ptUserPage = mw.util.addPortletLink( 'p-personal', '#', '', 'pt-userpage', null, null, '#pt-login' );
+
ptUserPage.innerHTML = '<span style="color: gray;">Not logged in</span>';
+
mw.util.addPortletLink( 'p-personal', '/wiki/Special:MyTalk', 'Talk', 'pt-mytalk', 'Your talk page', 'n', '#pt-login' );
+
mw.util.addPortletLink( 'p-personal', '/wiki/Special:MyContributions', 'Contributions', 'pt-mycontris', 'A list of your contributions', 'y', '#pt-login' );
+
}
+
if ( mw.user.isAnon() ) {
+
$( addAnonToolbarLinks );
+
}
+
 
+
/**
+
* WikiMiniAtlas
+
*
+
* Description: WikiMiniAtlas is a popup click and drag world map.
+
*              This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
+
*              The script itself is located on meta because it is used by many projects.
+
*              See [[Meta:WikiMiniAtlas]] for more information.
+
* Maintainers: [[User:Dschwen]]
+
*/
+
( function () {
+
    var require_wikiminiatlas = false;
+
    var coord_filter = /geohack/;
+
    $( 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) {
* Collapsible tables
+
          case 'styles':
*
+
            var styles = props.styles;
* Allows tables to be collapsed, showing only the header. See [[Wikipedia:NavFrame]].
+
            for (var s in styles) {
*
+
              element.style[s] = styles[s];
* @version 2.0.3 (2014-03-14)
+
* @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
+
* @author [[User:R. Koot]]
+
* @author [[User:Krinkle]]
+
* @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
+
* is supported in MediaWiki core.
+
*/
+
 
+
var autoCollapse = 2;
+
var collapseCaption = 'hide';
+
var expandCaption = 'show';
+
var tableIndex = 0;
+
 
+
function collapseTable( tableIndex ) {
+
    var Button = document.getElementById( 'collapseButton' + tableIndex );
+
    var Table = document.getElementById( 'collapsibleTable' + tableIndex );
+
 
+
    if ( !Table || !Button ) {
+
         return false;
+
    }
+
 
+
    var Rows = Table.rows;
+
    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;
+
    }
+
}
+
 
+
function createClickHandler( tableIndex ) {
+
    return function ( e ) {
+
        e.preventDefault();
+
        collapseTable( tableIndex );
+
    };
+
}
+
 
+
function createCollapseButtons( $content ) {
+
    var NavigationBoxes = {};
+
    var $Tables = $content.find( 'table' );
+
    var i;
+
 
+
    $Tables.each( function( i, table ) {
+
        if ( $(table).hasClass( 'collapsible' ) ) {
+
 
+
            /* only add button and increment count if there is a header row to work with */
+
            var HeaderRow = table.getElementsByTagName( 'tr' )[0];
+
            if ( !HeaderRow ) {
+
                return;
+
 
             }
 
             }
             var Header = table.getElementsByTagName( 'th' )[0];
+
            break;
             if ( !Header ) {
+
          case 'events':
                return;
+
             var events = props.events;
 +
             for (var e in events) {
 +
              addHandler(element, e, events[e]);
 
             }
 
             }
 
+
             break;
             NavigationBoxes[ tableIndex ] = table;
+
          case 'class':
            table.setAttribute( 'id', 'collapsibleTable' + tableIndex );
+
             element.className = props[k];
 
+
             break;
             var Button    = document.createElement( 'span' );
+
          default:
            var ButtonLink = document.createElement( 'a' );
+
             element.setAttribute(k, props[k]);
            var ButtonText = document.createTextNode( collapseCaption );
+
          }
            // Styles are declared in [[MediaWiki:Common.css]]
+
            Button.className = 'collapseButton';
+
 
+
             ButtonLink.style.color = Header.style.color;
+
            ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
+
             ButtonLink.setAttribute( 'href', '#' );
+
            $( ButtonLink ).on( 'click', createClickHandler( tableIndex ) );
+
            ButtonLink.appendChild( ButtonText );
+
 
+
            Button.appendChild( document.createTextNode( '[' ) );
+
            Button.appendChild( ButtonLink );
+
            Button.appendChild( document.createTextNode( ']' ) );
+
 
+
            Header.insertBefore( Button, Header.firstChild );
+
            tableIndex++;
+
 
         }
 
         }
     } );
+
      }
 +
      return element;
 +
     };
  
     for ( i = 0;  i < tableIndex; i++ ) {
+
     /* 测试元素中是否含有指定的样式 */
        if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) ||
+
    window.hasClass = function (elem, cls) {
            ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) )
+
      return $(elem).hasClass(cls);
        ) {
+
     };
            collapseTable( i );
+
        }
+
        else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) {
+
            var element = NavigationBoxes[i];
+
            while ((element = element.parentNode)) {
+
                if ( $( element ).hasClass( 'outercollapse' ) ) {
+
                    collapseTable ( i );
+
                    break;
+
                }
+
            }
+
        }
+
     }
+
}
+
  
mw.hook( 'wikipage.content' ).add( createCollapseButtons );
+
    /** 增加摺疊功能
 
+
    *
/**
+
    * 实现div.NavFrame和table.collapsible的可折叠性。
* Dynamic Navigation Bars (experimental)
+
    * JSConfig的collapseText、expandText、autoCollapse属性定义默认文字和默认最少自动折叠块
*
+
    * Maintainers: User:fdcn
* Description: See [[Wikipedia:NavFrame]].
+
    */
* Maintainers: UNMAINTAINED
+
     function cancelBubble(e) {
*/
+
      e = e || window.event;
 
+
      if (e.stopPropagation) {
/* set up the words in your language */
+
        e.stopPropagation();
var NavigationBarHide = '[' + collapseCaption + ']';
+
      } else {
var NavigationBarShow = '[' + expandCaption + ']';
+
         e.cancelBubble = true;
var indexNavigationBar = 0;
+
      }
 
+
/**
+
* Shows and hides content and picture (if available) of navigation bars
+
* Parameters:
+
*     indexNavigationBar: the index of navigation bar to be toggled
+
**/
+
window.toggleNavigationBar = function ( indexNavigationBar, event ) {
+
    var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
+
    var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
+
    var NavChild;
+
 
+
    if ( !NavFrame || !NavToggle ) {
+
         return false;
+
 
     }
 
     }
  
     /* if shown now */
+
     function createToggleButton(head) {
    if ( NavToggle.firstChild.data === NavigationBarHide ) {
+
      var parent = head;
        for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
+
      if (head.tagName.toLowerCase() == 'tr') { // 对表格特别处理
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
+
        if (head.getElementsByTagName("th").length) {
                NavChild.style.display = 'none';
+
          parent = head.cells[parent.cells.length - 1];
            }
+
        } else {
 +
          return;
 
         }
 
         }
    NavToggle.firstChild.data = NavigationBarShow;
+
      }
 
+
      var textS, textH, button = getElementsByClassName(head, "span", "NavToggle")[0];
    /* if hidden now */
+
      if (button) {
    } else if ( NavToggle.firstChild.data === NavigationBarShow ) {
+
         parent = button.parentNode;
         for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
+
      } else {
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
+
        textS = createElement("span", [JSConfig.expandText], {
                NavChild.style.display = 'block';
+
          'class': 'toggleShow'
            }
+
        });
        }
+
        textH = createElement("span", [JSConfig.collapseText], {
        NavToggle.firstChild.data = NavigationBarHide;
+
          '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) {
     event.preventDefault();
+
      if (head) {
};
+
        createToggleButton(head);
 
+
      }
/* adds show/hide-button to navigation bars */
+
      var self = this;
function createNavigationBarToggleButton( $content ) {
+
      this.state = 0;
    var NavChild;
+
      this.container = container;
    /* iterate over all < div >-elements */
+
      applyEach(function (h) {
    var $divs = $content.find( 'div' );
+
        if (h.nodeType == 1 && !hasClass(h, "uncollapse") && !hasClass(h, "toggleShow") && !hasClass(h, "toggleHide")) {
    $divs.each( function ( i, NavFrame ) {
+
          h.className += " toggleHide";
        /* if found a navigation bar */
+
        if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {
+
 
+
            indexNavigationBar++;
+
            var NavToggle = document.createElement( 'a' );
+
            NavToggle.className = 'NavToggle';
+
            NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
+
            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 );
+
 
         }
 
         }
    } );
+
      }, defaultCollapse); // 预设的隐藏元素
}
+
  
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );
 
  
/**
+
      function getArray(clsname) {
* Uploadwizard_newusers
+
        var r = [],
* Switches in a message for non-autoconfirmed users at [[Wikipedia:Upload]]
+
          i = 0,
*
+
          e, ea = getElementsByClassName(container, "*", clsname);
* Maintainers: [[User:Krimpet]]
+
        while (e = ea[i++]) {
*/
+
          var parent = e.parentNode;
function uploadwizard_newusers() {
+
          while (!hasClass(parent, 'NavFrame') && !hasClass(parent, 'collapsible')) {
    if ( mw.config.get( 'wgNamespaceNumber' ) === 4 && mw.config.get( 'wgTitle' ) === 'Upload' && mw.config.get( 'wgAction' ) === 'view' ) {
+
            parent = parent.parentNode;
        var oldDiv = document.getElementById( 'autoconfirmedusers' ),
+
          }
            newDiv = document.getElementById( 'newusers' );
+
          if (parent == container) {
        if ( oldDiv && newDiv ) {
+
            r.push(e);
            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;
+
 
         }
 
         }
    }
+
        return r;
}
+
      }
 +
      var toggleA = getArray("toggleShow");
 +
      var toggleB = getArray("toggleHide");
 +
      var hotspots = getArray("toggleHotspot");
  
$(uploadwizard_newusers);
+
      function _toggle(list, state) {
 
+
        var i = 0,
/**
+
          e;
* Magic editintros ****************************************************
+
         while (e = list[i++]) {
*
+
          e.style.display = state ? e.showStyle || '' : 'none';
* Description: Adds editintros on disambiguation pages and BLP pages.
+
* Maintainers: [[User:RockMFR]]
+
*/
+
function addEditIntro( name ) {
+
    $( '.mw-editsection, #ca-edit' ).find( 'a' ).each( function ( i, el ) {
+
         el.href = $( this ).attr( 'href' ) + '&editintro=' + name;
+
    } );
+
}
+
 
+
if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) {
+
    $( function () {
+
        if ( document.getElementById( 'disambigbox' ) ) {
+
            addEditIntro( 'Template:Disambig_editintro' );
+
 
         }
 
         }
    } );
+
      }
 +
      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 () {
+
     $(function () {
         var cats = mw.config.get('wgCategories');
+
      if (!window.disableCollapse) {
         if ( !cats ) {
+
        // init
            return;
+
         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")));
 
         }
 
         }
        if ( $.inArray( 'Living people', cats ) !== -1 || $.inArray( 'Possibly living people', cats ) !== -1 ) {
+
      }
            addEditIntro( 'Template:BLP_editintro' );
+
     });
        }
+
     } );
+
}
+
 
+
/* End of mw.loader.using callback */
+
} );
+
/* DO NOT ADD CODE BELOW THIS LINE */
+

2015年10月9日 (五) 22:02的修訂版本

/* 此處的JavaScript將載入於所有用戶每一個頁面。 */
mw.loader.load( 'jquery.ui.button' ); function my_accordion() {
 
  jQuery( "#button" ).accordion({ collapsible: true, active: false });
} jQuery( my_button);
 
 
 /* 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;
    };
 
    /* 测试元素中是否含有指定的样式 */
    window.hasClass = function (elem, cls) {
      return $(elem).hasClass(cls);
    };
 
    /** 增加摺疊功能
     *
     * 实现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")));
        }
      }
    });