"MediaWiki:Common.js" 修訂間的差異

出自 淡水維基館
前往: 導覽搜尋
(使用 "此處的JavaScript將載入於所有用戶每一個頁面。:" 取代內容)
行 1: 行 1:
/* 此處的JavaScript將載入於所有用戶每一個頁面。
+
/* 此處的JavaScript將載入於所有用戶每一個頁面。*/
// 2013-10-06 按鈕呈現 by R
 
  mw.loader.load( 'jquery.ui.button' ); function my_accordion() {
 
  jQuery( "#button" ).accordion({ collapsible: true, active: false });
 
} jQuery( my_button);
 
 
 
// 下拉隱藏和顯示 by Vanya
 
/**
 
* 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' );
 
        }
 
    }
 
}
 
 
 
/**
 
* Map addPortletLink to mw.util
 
*
 
* @deprecated: Use mw.util.addPortletLink instead.
 
*/
 
window.addPortletLink = function () {
 
    return mw.util.addPortletLink.apply( mw.util, arguments );
 
};
 
 
 
/**
 
* Extract a URL parameter from the current URL
 
*
 
* @deprecated: Use mw.util.getParamValue with proper escaping
 
*/
 
window.getURLParamValue = function () {
 
    return mw.util.getParamValue.apply( mw.util, arguments );
 
};
 
 
 
/**
 
* Test if an element has a certain class
 
*
 
* @deprecated:  Use $(element).hasClass() instead.
 
*/
 
window.hasClass = function ( element, className ) {
 
    return $( element ).hasClass( className );
 
};
 
 
 
/**
 
* @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
 
* @rev 5
 
*/
 
// 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' );
 
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' );
 
}
 
if ( mw.config.get( 'wgNamespaceNumber' ) === 6 ) {
 
    /* file description page scripts */
 
    importScript( 'MediaWiki:Common.js/file.js' );
 
}
 
 
 
/**
 
* Load scripts specific to Internet Explorer
 
*/
 
if ( $.client.profile().name === 'msie' ) {
 
    importScript( 'MediaWiki:Common.js/IEFixes.js' );
 
}
 
 
 
/**
 
* 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"; } ' );
 
}
 
 
 
/**
 
* 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/;
 
    $( 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 ) {
 
            mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' );
 
 
 
        }
 
    } );
 
} )();
 
 
 
/**
 
* Interwiki links to featured articles ***************************************
 
*
 
* Description: Highlights interwiki links to featured articles (or
 
*              equivalents) by changing the bullet before the interwiki link
 
*              into a star.
 
* Maintainers: [[User:R. Koot]]
 
*/
 
function LinkFA() {
 
    if ( document.getElementById( 'p-lang' ) ) {
 
        var InterwikiLinks = document.getElementById( 'p-lang' ).getElementsByTagName( 'li' );
 
 
 
        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.';
 
            }
 
        }
 
    }
 
}
 
 
 
$( LinkFA );
 
 
 
 
 
/*試試看別的
 
下拉!!!
 
*/
 
/** 增加摺疊功能
 
    *
 
    * 实现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;
 
      }
 
    });
 
importScript('MediaWiki:Tangle/' + wgPageName + '.js');
 
/*下拉*/
 
$(function(){
 
    $("#menuv li").append('<div class="arrow-bottom"></div>');
 
    $("#menuv ul li").append('<div class="arrow-right"></div>');
 
});
 
*/
 

於 2018年7月3日 (二) 11:44 的修訂

/* 此處的JavaScript將載入於所有用戶每一個頁面。*/