MediaWiki:Common.js: Unterschied zwischen den Versionen

imported>Chloe
Die Seite wurde neu angelegt: „→Das folgende JavaScript wird für alle Benutzer geladen.: //<source lang="javascript"> //Map jQuery over to $ //Will be done by ResourceLoader later on //No…“
 
imported>Yaroneko
An Version aus dem englischen Wiki angeglichen
Zeile 1: Zeile 1:
/* Das folgende JavaScript wird für alle Benutzer geladen. */
//<source lang="javascript">
 
mw.loader.load( '//platform-api.sharethis.com/js/sharethis.js#property=5c076081f30c5a001138ce35&product=inline-follow-buttons&action=raw&ctype=text/javascript');
 
$(function() {
    $(".showExtra").click(function() {
    $(this).closest("table").find(".extraRow").fadeIn("slow");$(this).closest("tr").remove();
   
    });
    filterTable();
    tabContentCreate();
    }
);


//<source lang="javascript">
//Map jQuery over to $
//Will be done by ResourceLoader later on
//No script here is/should use prototype etc.
if (typeof $ == 'undefined') $=jQuery;
/*
* Description: Redirects from /User:UserName/skin.js or .css to the user's actual skin page
* Maintainer: Cacycle
*/
if (wgArticleId == 0 && wgUserName) {
    var slash = wgPageName.indexOf('/');
    var norm = wgPageName.substr(0, slash) + wgPageName.substr(slash).toLowerCase();
    var test = 'User:' + wgUserName.replace(/ /g, '_') + '/skin.';
    var ext = null;
    if (norm == test + 'js') ext = 'js';
    else if (norm == test + 'css') ext = 'css';
    if (ext != null) window.location.href = window.location.href.replace(/\/skin.(css|js)/i, '/' + skin + '.' + ext);
}
/** extract a URL parameter from the current URL **********
* From [[en:User:Lupin/autoedit.js]]
*
* paramName  : the name of the parameter to extract
*/
function getURLParamValue( paramName, url)
{
    if (typeof (url) == 'undefined'  || url === null) url = document.location.href;
    var cmdRe=RegExp( '[&?]' + paramName + '=([^&#]*)' ); // Stop at hash
    var m=cmdRe.exec(url);
    if (m && m.length > 1) return decodeURIComponent(m[1]);
    return null;
}
/** &withJS= URL parameter *******
* Allow to try custom scripts from MediaWiki space
* without editing [[Special:Mypage/monobook.js]]
*/
var extraJS = getURLParamValue("withJS");
if ( extraJS && extraJS.match("^MediaWiki:[^&<>=%]*\.js$") ) {
    importScript(extraJS);
}
/* Import more specific scripts if necessary */
/* Import more specific scripts if necessary */
function customizeWikiEditorToolbar() {
if (wgAction == "edit" || wgAction == "submit" || wgPageName == "Special:Upload") //scripts specific to editing pages
     $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
{
        'section': 'main',
     importScript("MediaWiki:Common.js/edit.js")
        'group': 'insert',
}
        'tools': {
else if (wgPageName == "Special:Watchlist") //watchlist scripts
            'lang-ja': {
{
                label: 'Designate text fragment as written in Japanese',
    importScript("MediaWiki:Common.js/watchlist.js")
                type: 'button',
}
                icon: '/images/7/79/WikiEd-lang-ja.png',
if( wgNamespaceNumber == 6 ) {
                action: {
    importScript('MediaWiki:Common.js/file.js');
                    type: 'encapsulate',
}
                    options: {
                        pre: "{{lang|ja|",
/** For sysops and accountcreators *****************************************
                        post: "}}",
*
                        peri: "\u6771\u65b9"
*  Description: Allows for sysop-specific Javascript at [[MediaWiki:Sysop.js]],
                     }
*              and accountcreator-specific CSS at [[MediaWiki:Accountcreator.css]].
*/
if ( wgUserGroups ) {
    for ( var g = 0; g < wgUserGroups.length; ++g ) {
        if ( wgUserGroups[g] == "sysop" ) {
            importStylesheet("MediaWiki:Sysop.css");
            addOnloadHook( function() {
                if ( !window.disableSysopJS ) {
                     importScript("MediaWiki:Sysop.js");
                 }
                 }
            } );
        }
        else if ( wgUserGroups[g] == "accountcreator" ) {
            importStylesheet("MediaWiki:Accountcreator.css");
        }
    }
}
/* Scripts specific to Internet Explorer */
if (navigator.appName == "Microsoft Internet Explorer")
{
    /** Internet Explorer bug fix **************************************************
    *
    *  Description: Fixes IE horizontal scrollbar bug
    *  Maintainers: [[User:Tom-]]?
    */
    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);
    document.attachEvent("onresize", fixIEScroll);
    // In print IE (7?) does not like line-height
    appendCSS( '@media print { sup, sub, p, .documentDescription { line-height: normal; }}');
    // IE overflow bug
    appendCSS('div.overflowbugx { overflow-x: scroll !important; overflow-y: hidden !important; } div.overflowbugy { overflow-y: scroll !important; overflow-x: hidden !important; }');
    // IE zoomfix
    //Use to fix right floating div/table inside tables.
    appendCSS('.iezoomfix div, .iezoomfix table { zoom: 1;}' );
    //Import scripts specific to Internet Explorer 6
    if (navigator.appVersion.substr(22, 1) == "6") {
        importScript("MediaWiki:Common.js/IE60Fixes.js")
    }
}
/* Load fixes for Windows font rendering */
if ( navigator.platform.indexOf( "Win" ) != -1 ) {
    importStylesheet( 'MediaWiki:Common.css/WinFixes.css' );
}
/* Test if an element has a certain class **************************************
*
* Description: Uses regular expressions and caching for better performance.
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
*/
var hasClass = (function () {
    var reCache = {};
    return function (element, className) {
        return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
    };
})();
/** 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.";
             }
             }
         }
         }
     }
     } );
}
};
 
addOnloadHook( LinkFA );
mw.loader.using('mediawiki.action.edit', function () {
     /* add button for {{lang|ja|}} to editor toolbar */
     /* check for WikiEditor first, then fall back on default */
/** Collapsible tables *********************************************************
     if ( mw.user.options.get('usebetatoolbar') ) {
*
         mw.loader.using( 'ext.wikiEditor.toolbar', function () {
*  Description: Allows tables to be collapsed, showing only the header. See
             $(document).ready( customizeWikiEditorToolbar );
*              [[Wikipedia:NavFrame]].
         });
*  Maintainers: [[User:R. Koot]]
*/
var autoCollapse = 2;
var collapseCaption = "hide";
var expandCaption = "show";
function collapseTable( tableIndex )
{
     var Button = document.getElementById( "collapseButton" + tableIndex );
    var Table = document.getElementById( "collapsibleTable" + tableIndex );
    if ( !Table || !Button ) {
        return false;
    }
     var Rows = Table.rows;
     if ( Button.firstChild.data == collapseCaption ) {
         for ( var i = 1; i < Rows.length; i++ ) {
             Rows[i].style.display = "none";
         }
        Button.firstChild.data = expandCaption;
     } else {
     } else {
         for ( var i = 1; i < Rows.length; i++ ) {
         mw.toolbar.addButton(
             Rows[i].style.display = Rows[0].style.display;
            "/images/d/da/Lang_ja.png", // imageFile
        }
            "Designate text fragment as written in Japanese", // speedTip
         Button.firstChild.data = collapseCaption;
            "{{lang|ja|", // tagOpen
             "}}", // tagClose
            "\u6771\u65b9" // sample text
         );
     }
     }
});
/* Sitenotice autoscroll */
function AutoScroll(obj){ 
        $(obj).find("ul:first").animate({ 
                marginTop:"-25px" 
        },500,function(){ 
                $(this).css({marginTop:"0px"}).find("li:first").appendTo(this); 
        });     
}
}
$(document).ready(function(){    
function createCollapseButtons()
setInterval('AutoScroll("#scrollDiv")',5000);    
{
});
    var tableIndex = 0;
 
    var NavigationBoxes = new Object();
(function(){
    var Tables = document.getElementsByTagName( "table" );
var config = {
song_info_url: mw.config.get('wgScript') + "?title=Touhou_Wiki:SongSource.json&action=raw&ctype=application/json",
    for ( var i = 0; i < Tables.length; i++ ) {
        if ( hasClass( Tables[i], "collapsible" ) ) {
source_regexp: /^\s*source:\s*(.*)/,
            /* only add button and increment count if there is a header row to work with */
original_title_regexp: /^\s*original title:\s*(.*)/,
            var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
tracks_heading_regexp: /^\s*Tracks\s*$/,
            if (!HeaderRow) continue;
            var Header = HeaderRow.getElementsByTagName( "th" )[0];
categories: ["Arrangement CDs", "Official CDs"],
            if (!Header) continue;
};
 
            NavigationBoxes[ tableIndex ] = Tables[i];
jQuery.ajax({
            Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
url: mw.config.get('wgScript') + '?title=MediaWiki:SongSource.js&action=raw&ctype=text/javascript',
dataType: "script",
            var Button    = document.createElement( "span" );
cache: "true",
            var ButtonLink = document.createElement( "a" );
success: function() {
            var ButtonText = document.createTextNode( collapseCaption );
initSongSource(config);
},
            Button.className = "collapseButton";  //Styles are declared in Common.css
});
 
            ButtonLink.style.color = Header.style.color;
})();
            ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
 
            ButtonLink.setAttribute( "href", "#" );
importScript("MediaWiki:ToggleAll.js");
            $(ButtonLink).click(new Function("e", "e.preventDefault(); collapseTable(" + tableIndex + " );"));
 
            ButtonLink.appendChild( ButtonText );
    if ($(window).width() < 1025){
             $("#mp-WorksColumns .mp-image").addClass("mp-smaller-image");
             Button.appendChild( document.createTextNode( "[" ) );
             $("#mp-News .mp-image").addClass("mp-smaller-image");
            Button.appendChild( ButtonLink );
             Button.appendChild( document.createTextNode( "]" ) );
            Header.insertBefore( Button, Header.childNodes[0] );
            tableIndex++;
        }
     }
     }
   
     for ( var i = 0;  i < tableIndex; i++ ) {
     $(window).resize(function(){
        if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
            if ($(this).width() < 1025){
            collapseTable( i );
                    $("#mp-WorksColumns .mp-image").addClass("mp-smaller-image");
        }
                    $("#mp-News .mp-image").addClass("mp-smaller-image");
        else if ( hasClass( NavigationBoxes[i], "innercollapse" ) ) {
             } else {
             var element = NavigationBoxes[i];
                    $("#mp-WorksColumns .mp-image").removeClass("mp-smaller-image");
            while (element = element.parentNode) {
                     $("#mp-News .mp-image").removeClass("mp-smaller-image");
                if ( hasClass( element, "outercollapse" ) ) {
                     collapseTable ( i );
                    break;
                }
             }
             }
        }
     });
     }
   
}
// check JSON pages for syntax validity before saving
// note that it's "weak" check, just for the convenience
addOnloadHook( createCollapseButtons );
// and it can be easily circumvented
if (/\.json$/.test(wgTitle)) {
     // if there's no edit form, nothing bad will happen
/** Dynamic Navigation Bars (experimental) *************************************
     $("#editform").submit(function(evt) {
*
         var data = $(this).find("#wpTextbox1").val();
*  Description: See [[Wikipedia:NavFrame]].
          
*  Maintainers: UNMAINTAINED
         if (data !== undefined) {
*/
             try {
                 $.parseJSON(data);
// set up the words in your language
             } catch (e) {
var NavigationBarHide = '[' + collapseCaption + ']';
                if (!window.confirm("The JSON data appears invalid. Are you sure you want to proceed?")) {
var NavigationBarShow = '[' + expandCaption + ']';
                     evt.preventDefault();
// shows and hides content and picture (if available) of navigation bars
// Parameters:
//    indexNavigationBar: the index of navigation bar to be toggled
function toggleNavigationBar(indexNavigationBar)
{
    var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
    var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
    if (!NavFrame || !NavToggle) {
        return false;
    }
     // if shown now
     if (NavToggle.firstChild.data == NavigationBarHide) {
         for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
            if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) {
                NavChild.style.display = 'none';
            }
        }
         NavToggle.firstChild.data = NavigationBarShow;
         // if hidden now
    } else if (NavToggle.firstChild.data == NavigationBarShow) {
        for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
             if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) {
                 NavChild.style.display = 'block';
             }
        }
        NavToggle.firstChild.data = NavigationBarHide;
    }
}
// adds show/hide-button to navigation bars
function createNavigationBarToggleButton()
{
    var indexNavigationBar = 0;
    // iterate over all < div >-elements
    var divs = document.getElementsByTagName("div");
    for (var i = 0; NavFrame = divs[i]; i++) {
        // if found a navigation bar
        if (hasClass(NavFrame, "NavFrame")) {
            indexNavigationBar++;
            var NavToggle = document.createElement("a");
            NavToggle.className = 'NavToggle';
            NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
            NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
            var isCollapsed = hasClass( NavFrame, "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 equals "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 (var NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling) {
                if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
                     if ( NavChild.style.display == 'none' ) {
                        isCollapsed = true;
                    }
                 }
                 }
             }
             }  
            if (isCollapsed) {
        }  
                for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
    });
                    if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, '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 (hasClass(NavFrame.childNodes[j], "NavHead")) {
                    NavToggle.style.color = NavFrame.childNodes[j].style.color;
                    NavFrame.childNodes[j].appendChild(NavToggle);
                }
            }
            NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
        }
    }
}
}
 
addOnloadHook( createNavigationBarToggleButton );
// Filter Table Functions
function filterTable(){
$("table.filterable").each(function(){
/** Main Page layout fixes *********************************************************
var i=0;
*
var cols;
*  Description: Adds an additional link to the complete list of languages available.
$(this).find("tr:first-child th, tr:first-child td").each(function(){
*  Maintainers: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]]
if (!$(this).hasClass("unfilterable")){
*/
cols=[];
$(this).closest("table").find("tr td:nth-child("+(i+1)+")").each(function(){
if (wgPageName == 'Main_Page' || wgPageName == 'Talk:Main_Page')
cols.push($(this).text());
    addOnloadHook(function () {
});
    addPortletLink('p-lang', 'http://meta.wikimedia.org/wiki/List_of_Wikipedias',
cols = arrayUnique(cols);
    'Complete list', 'interwiki-completelist', 'Complete list of Wikipedias')
l=0;
    var nstab = document.getElementById('ca-nstab-main')
for (j=0; j<cols.length; j++){
    if (nstab && wgUserLanguage=='en') {
t=charLength(cols[j]);
    while (nstab.firstChild) nstab = nstab.firstChild
if (l<t) l=t;
    nstab.nodeValue = 'Main Page'
}
    }
$(this).css("position","relative");
});
$(this).html('<a href="javascript:void(0)" class="showFilterMenu">'+$(this).html()+'▼</a>');
$(this).append($('<div class="filterMenu hidden" style="position: absolute; top: '+$(this).height()+35+'px; left: 0; width: '+(50+l*7)+'px; text-align: left; padding: 5px; border: 1px #333333 solid; -moz-border-radius: 8px; -webkit-border-radius: 8px; border-radius: 8px; background: inherit; z-index: 1"></div>'));
for (j=0; j<cols.length; j++){
/** Table sorting fixes ************************************************
$(this).find(".filterMenu").append('<div><input type="checkbox" value="'+cols[j]+'" col="'+(i+1)+'" class="filterOption" checked>'+cols[j]+'</div>');
*
}
*  Description: Disables code in table sorting routine to set classes on even/odd rows
}
*  Maintainers: [[User:Random832]]
i++;
*/
});
$(this).find("tr:nth-child(n+1)").attr("condition", 0);
ts_alternate_row_colors = false;
});
$(".showFilterMenu").click(function(){
if ($(this).parent().find(".filterMenu:visible").length){
/***** uploadwizard_newusers ********
$(".filterMenu").slideUp(150);
* Switches in a message for non-autoconfirmed users at [[Wikipedia:Upload]]
}else{
*
$(".filterMenu").slideUp(150);
*  Maintainers: [[User:Krimpet]]
$(this).parent().find(".filterMenu").slideDown(150);
****/
}
function uploadwizard_newusers() {
});
    if (wgNamespaceNumber == 4 && wgTitle == "Upload" && wgAction == "view") {
$(document).mouseup(function(e){
        var oldDiv = document.getElementById("autoconfirmedusers"),
var container = $(".filterMenu");
        newDiv = document.getElementById("newusers");
    if (!container.is(e.target) && container.has(e.target).length === 0){
        if (oldDiv && newDiv) {
        container.slideUp(150);
            if (typeof wgUserGroups == "object" && wgUserGroups) {
    }
                for (i = 0; i < wgUserGroups.length; i++) {
});
                    if (wgUserGroups[i] == "autoconfirmed") {
$(".filterOption").click(function(){
                        oldDiv.style.display = "block";
col=$(this).attr("col");
                        newDiv.style.display = "none";
val=$(this).val();
                        return;
if ($(this).is(":checked")) chg=1; else chg=-1;
                    }
$(this).closest("table").find("tr:nth-child(n+1)").each(function(){
                }
if ($(this).find("td:nth-child("+col+")").text()==val){
            }
var cond=$(this).attr("condition");
            oldDiv.style.display = "none";
cond=Number(cond)+chg;
            newDiv.style.display = "block";
$(this).attr("condition", cond);
            return;
if (cond==0) $(this).show();
        }
else $(this).hide();
    }
}
});
});
}
}
addOnloadHook(uploadwizard_newusers);
 
function arrayUnique(a) {
/** Magic editintros ****************************************************
    return a.reduce(function(p, c) {
*
        if (p.indexOf(c) < 0) p.push(c);
*  Description: Adds editintros on disambiguation pages and BLP pages.
         return p;
*  Maintainers: [[User:RockMFR]]
     }, []);
*/
function addEditIntro(name)
{
    var el = document.getElementById('ca-edit');
    if (!el)
         return;
     el = el.getElementsByTagName('a')[0];
    if (el)
        el.href += '&editintro=' + name;
}
}
 
function charLength(s){
if (wgNamespaceNumber == 0) {
return s.length+(encodeURI(s).split(/%..|./).length-1-s.length)/2;
    addOnloadHook(function(){
        if (document.getElementById('disambigbox'))
            addEditIntro('Template:Disambig_editintro');
    });
    addOnloadHook(function(){
        var cats = document.getElementById('mw-normal-catlinks');
        if (!cats)
            return;
        cats = cats.getElementsByTagName('a');
        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;
            }
        }
    });
}
}
 
// Define ta for now. Bugzilla 23175
function tabContentCreate () {
window.ta = [];
var group1 = $('.tab_content_container'), group1l = group1.length;
for(var i = 0; i < group1l; i++){
(function(){
var group = group1.eq(i);
// SongSource.js (User:WGH)
var container = group.find('.tab_content_button_container').eq(0);
var i;
var default_div = group.find('.tab_content_default').eq(0);
var need_import = (window.wgPageName.indexOf("Lyrics:") === 0);
var width = default_div.attr('data-width');
var group2 = group.find('.tab_content_button'), group2l = group2.length;
if (!need_import) {
for(var j = 0; j < group2l; j++){
    for (i = 0; i < window.wgCategories.length; i++) {
group2.eq(j).appendTo(container);
        if (window.wgCategories[i] == "Arrange CDs") {
}
            need_import = true;
var group2 = group.find('.tab_content_button'), group2l = group2.length;
            break;
for(var j = 0; j < group2l; j++){
        }
group2.eq(j).css('width', width);
    }
group2.eq(j).on('click', function(){
var a = $(this);
var key = a.attr('data-index');
var tab = a.parents('.tab_content_container').find('.tab_content_content[data-index="' + key + '"]');
a.parents('.tab_content_container').find('.tab_content_content').css('display', 'none');
a.parents('.tab_content_button_container').find('.tab_content_button').css({
'cursor' : 'pointer',
'background-color' : '#eee',
'box-shadow' : '0 0 3px 0 #000'
});
tab.css('display', 'block');
a.css({
'cursor' : 'default',
'background-color' : '#fff',
'box-shadow' : '0 0 2px 0 #000 inset, 0 0 2px 0 #000 inset'
})
});
}
var default_value = default_div.attr('data-value');
if(default_value === '0'){
group.find('.tab_content_button').eq(0).trigger('click');
} else {
group.find('.tab_content_button[data-index="' + default_value + '"]').eq(0).trigger('click');
}
}
}
}
if (need_import) importScript("MediaWiki:SongSource.js");
})();