Cambios

Saltar a: navegación, buscar

MediaWiki:Common.js

49 bytes eliminados, 19:01 12 abr 2014
sin resumen de edición
/**
* Dynamic Navigation Bars. See [[Wikipedia:NavFrame]]Instead of cluttering up the global scope with * variables, they should instead be set as a * Based on script from en.wikipedia.org, 2008-09-15.property of this global variable
*
* @source wwwE.mediawiki.org/wiki/MediaWikig:Gadget-NavFrame.jsInstead of * myVar = 'blah'; * @maintainer Helder.wiki, 2012–2013use * @maintainer Krinkle, 2013 mcw.myVar = 'blah';
*/
( function () window.mcw = {};  /* Legacy support */ Set up the words in your languagevar collapseCaption mcw.baseURL = 'hide/';var expandCaption mcw.wikiURL = 'show/'; var navigationBarHide /* Variables for interface text used throughout the script, for ease of translating */mcw.i18n = { // Collapsible tables and page loader hideText: '[hide', showText: 'show' + collapseCaption + , // Page loader loadErrorTitle: ']An error occurred loading the content', // File upload defaultLicense: 'License'};var navigationBarShow = /* Add extra buttons to the classic toolbar */if ( mw.user.options.get( '[showtoolbar' + expandCaption + ) && !mw.user.options.get( ']usebetatoolbar') ) { importScript( 'MediaWiki:Toolbar.js' ); }  /* Wait for DOMContentLoaded */$( function() { 
/**
* Shows and hides content and picture (if available) of navigation bars.Collapsible tables
*
* @param {number} indexNavigationBar The index of navigation bar to be toggled * @param {jQueryBased on http://www.Event} e Event objectmediawiki.org/wiki/Manual:Collapsible_tables#Common.js_script_.28before_1.18.29
*/
mcw.makeCollapsible = function toggleNavigationBar( indexNavigationBar, e $content ) { var navChild,if ( $content === undefined ) { navToggle $content = document.getElementById$( 'NavToggletable.collapsible' + indexNavigationBar ),; } else { navFrame $content = document$content.getElementByIdfind( 'NavFrametable.collapsible' + indexNavigationBar ); // Prevent browser from jumping to href "#" e.preventDefault(); } if ( !navFrame || !navToggle $content.length ) {
return false;
}
var buttonText = ' <span class="collapsible-button">[<span class="jslink">' + mcw.i18n.hideText + '</span>]</ If shown nowspan> '; if $content.each( function( navToggle.firstChild.data == navigationBarHide ) { for var $table = $( navChild = navFrame.firstChildthis ), $header, $collapseButton, firstWidth, secondWidth; navChild != null; navChild = navChild // This table is already collapsible if ( $table.nextSibling data( 'collapsible' ) ) { return true; } // Use the collapse-button if specified otherwise the first header cell of the first row $header = $table.find( hasClass( navChild, 'NavPictr:first .collapse-button' ) ; if ( !$header.length ) { navChild $header = $table.style.display = find( 'nonetr:first > th:first'); } // No header or the table body is empty if ( hasClass!$header.length || !$table.find( navChild, 'NavContenttr:not(tr:first)' ) .text() { navChild.style.display = replace( /\n/g, 'none';).length ) { }return true;
}
navToggle.firstChild.data = navigationBarShow; // For the button to float properly, it has to be /before/ If hidden now } else if ( navToggle.firstChild.data == navigationBarShow ) {the cell text for ( navChild = navFrame.firstChild; navChild != null; navChild = navChild.nextSibling ) { if ( $( navChild )table.hasClass( 'NavPiccollapse-button-none' ) || ) { $( navChild )header.hasClassappend( 'NavContent' ) buttonText ) ; } else { navChild $header.style.display = 'block'prepend( buttonText ); }
}
navToggle.firstChild.data = navigationBarHide; }} /** * Adds show/hideFind max button size, and set its min-button width to navigation bars.it * * @param {jQuery} $content */function createNavigationBarToggleButton( $content ) { var i, j, navFrame, navToggle, navToggleText, navChild, indexNavigationBar = 0, navFrames collapseButton = $contenttable.find( 'div.NavFramecollapsible-button' ).toArray(); // Iterate over all (new) nav frames for ( i = 0; i < navFrames.length; i++ ) { navFrame firstWidth = navFrames[i]; // If found a navigation bar indexNavigationBar++; navToggle = document$collapseButton.createElementwidth( 'a' ); navToggle$collapseButton.className = find( 'NavToggle'; navToggle> .setAttribute( 'id', 'NavTogglejslink' + indexNavigationBar ); navToggle.setAttributetext( 'href', '#' mcw.i18n.showText ); secondWidth = $( navToggle ).on( 'click', $collapseButton.proxywidth( toggleNavigationBar, null, indexNavigationBar ) ); navToggleText = document.createTextNode( navigationBarHide ); for if ( navChild = navFrame.firstChild; navChild firstWidth != null; navChild = navChild.nextSibling secondWidth ) { if ( $( navChild firstWidth < secondWidth ).hasClass( 'NavPic' ) || { $( navChild )collapseButton.hasClasscss( 'NavContentmin-width' , secondWidth ) ) ; } else { if $collapseButton.css( navChild.style.display == 'nonemin-width' , firstWidth ) { navToggleText = document.createTextNode( navigationBarShow ); break; }
}
}
navToggle.appendChild( navToggleText ); // Find Set the NavHead and attach the toggle link (Must be this complicated because Moztext back to hide if it's firstChild handling is borked)not collapsed to begin with for ( j = 0; j < navFrame.childNodes.length; j++ ) { if ( !$( navFrame.childNodes[j] )table.hasClass( 'NavHeadcollapsed' ) ) { navFrame $collapseButton.find( '> .childNodes[j]jslink' ).appendChildtext( navToggle mcw.i18n.hideText ); }
}
navFrame $table.setAttributedata( 'idcollapsible', true ); } );}; $( '#mw-content-text' ).on( 'click', 'table.collapsible .collapsible-button .jslink', function( e ) { var $table = $( this ).closest( 'table.collapsible' ); // Stop table sorting activating when clicking the link e.stopPropagation(); if ( $table.hasClass( 'collapsed' ) ) { $table.removeClass( 'collapsed' ).addClass( 'expanded' ); $( this ).text( mcw.i18n.hideText ); } else { $table.removeClass( 'NavFrameexpanded' + indexNavigationBar ).addClass( 'collapsed' ); $( this ).text( mcw.i18n.showText );
}
} mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton ); }mcw.makeCollapsible());

Menú de navegación