Cambios

Saltar a: navegación, buscar

MediaWiki:Common.js

49 bytes añadidos, 23:03 11 abr 2014
sin resumen de edición
/**
* Instead of cluttering up the global scope withDynamic Navigation Bars. See [[Wikipedia:NavFrame]] * variables, they should instead be set as a * property of this global variableBased on script from en.wikipedia.org, 2008-09-15.
*
* E@source www.gmediawiki.org/wiki/MediaWiki: Instead ofGadget-NavFrame.js * myVar = 'blah';@maintainer Helder.wiki, 2012–2013 * use * mcw.myVar = 'blah';@maintainer Krinkle, 2013
*/
window.mcw = ( function () {};  /* Legacy support */Set up the words in your languagemcw.baseURL var collapseCaption = '/hide';mcw.wikiURL var expandCaption = '/show';  /* Variables for interface text used throughout the script, for ease of translating */mcw.i18n var navigationBarHide = { // Collapsible tables and page loader hideText: 'hide', showText: 'show[', // Page loader loadErrorTitle: + collapseCaption + 'An error occurred loading the content]', // File upload defaultLicense: 'License'}/* Add extra buttons to the classic toolbar */if ( mw.user.options.get( var navigationBarShow = 'showtoolbar[' ) && !mw.user.options.get( + expandCaption + 'usebetatoolbar]' ) ) { importScript( 'MediaWiki:Toolbar.js' );}  /* Wait for DOMContentLoaded */$( function() {
/**
* Collapsible tablesShows and hides content and picture (if available) of navigation bars.
*
* Based on http://www@param {number} indexNavigationBar The index of navigation bar to be toggled * @param {jQuery.mediawiki.org/wiki/Manual:Collapsible_tables#Common.js_script_.28before_1.18.29Event} e Event object
*/
mcw.makeCollapsible = functiontoggleNavigationBar( $content indexNavigationBar, e ) { if var navChild, navToggle = document.getElementById( $content === undefined 'NavToggle' + indexNavigationBar ) {, $content navFrame = $document.getElementById( 'table.collapsibleNavFrame' + indexNavigationBar ); } else {// Prevent browser from jumping to href "#" $content = $content e.findpreventDefault( 'table.collapsible' ); } if ( !$content.length navFrame || !navToggle ) {
return false;
}
// If shown now var buttonText if ( navToggle.firstChild.data = ' <span class="collapsible-button">[<span classnavigationBarHide ) { for ( navChild ="jslink">' + mcwnavFrame.i18nfirstChild; navChild != null; navChild = navChild.hideText + '</span>]</span> ';nextSibling ) { $content.each if ( functionhasClass(navChild, 'NavPic' ) ) { var $table navChild.style.display = $( this ), $header, $collapseButton, firstWidth, secondWidth'none'; } // This table is already collapsible if ( $table.datahasClass( navChild, 'collapsibleNavContent' ) ) { navChild.style.display = 'none'; return true;}
}
navToggle.firstChild.data = navigationBarShow; // Use the collapse-button If hidden now } else if specified otherwise the first header cell of the first row $header = $table( navToggle.find( 'tr:first firstChild.collapse-button' data == navigationBarShow );{ if for ( navChild = navFrame.firstChild; navChild !$header= null; navChild = navChild.length nextSibling ) { if ( $header = ( navChild ).hasClass( 'NavPic' ) || $table( navChild ).findhasClass( 'tr:first > th:firstNavContent' )) { navChild.style.display = 'block'; }
}
navToggle.firstChild.data = navigationBarHide; }} /** * Adds show/ No header or the table body is emptyhide-button to navigation bars. if * * @param {jQuery} $content */function createNavigationBarToggleButton( !$header.length || !content ) { var i, j, navFrame, navToggle, navToggleText, navChild, indexNavigationBar = 0, navFrames = $tablecontent.find( 'tr:notdiv.NavFrame' ).toArray(tr:first); // Iterate over all (new) nav frames for ( i = 0; i < navFrames.length; i++ ) { navFrame = navFrames[i]; // If found a navigation bar indexNavigationBar++; navToggle = document.createElement( 'a' ); navToggle.className = 'NavToggle'; navToggle.textsetAttribute('id', 'NavToggle' + indexNavigationBar ); navToggle.replacesetAttribute( /\n/g'href', '#' ); $( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) ); navToggleText = document.length createTextNode( navigationBarHide ); for ( navChild = navFrame.firstChild; navChild != null; navChild = navChild.nextSibling ) { return trueif ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) { if ( navChild.style.display == 'none' ) { navToggleText = document.createTextNode( navigationBarShow ); break; } }
}
// For the button to float properly, it has to be /before/ the cell text if ( $table.hasClass( 'collapse-button-none' ) ) { $header.append( buttonText ); } else { $headernavToggle.prependappendChild( buttonText navToggleText ); } // Find max button size, the NavHead and set its min-width to it $collapseButton = $table.findattach the toggle link ( Must be this complicated because Moz'.collapsible-button' s firstChild handling is borked); firstWidth for ( j = $collapseButton.width()0; $collapseButtonj < navFrame.find( '> childNodes.jslink' ).text( mcw.i18n.showText ); secondWidth = $collapseButton.width()length; if ( firstWidth != secondWidth j++ ) { if ( firstWidth < secondWidth $( navFrame.childNodes[j] ) { $collapseButton.csshasClass( 'min-widthNavHead', secondWidth ); } else ) { $collapseButtonnavFrame.childNodes[j].cssappendChild( 'min-width', firstWidth navToggle );
}
}
// Set the text back to hide if it's not collapsed to begin with if ( !$table.hasClass( 'collapsed' ) ) { $collapseButton.find( '> .jslink' ).text( mcw.i18n.hideText ); } $tablenavFrame.datasetAttribute( 'collapsibleid', true ); } );}; $( '#mw-content-text' ).on( 'click', NavFrame'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( 'expanded' ).addClass( 'collapsed' ); $( this ).text( mcw.i18n.showText + indexNavigationBar );
}
} mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );mcw.makeCollapsible }());
552
ediciones

Menú de navegación