Line 1: |
Line 1: |
− | /* Any JavaScript here will be loaded for all users on every page load. */
| |
− |
| |
| /** | | /** |
| * Keep code in MediaWiki:Common.js to a minimum as it is unconditionally | | * Keep code in MediaWiki:Common.js to a minimum as it is unconditionally |
Line 13: |
Line 11: |
| * dependency hasn't arrived yet it'll make sure those are loaded before this. | | * dependency hasn't arrived yet it'll make sure those are loaded before this. |
| */ | | */ |
− | /*global mw, $, importStylesheet, importScript */ | + | |
− | /*jshint curly:false eqnull:true, strict:false, browser:true, */ | + | /* global mw, $ */ |
− |
| + | /* jshint strict:false, browser:true */ |
− | mw.loader.using( ['mediawiki.util', 'mediawiki.notify', 'jquery.client'], function () { | + | |
| + | mw.loader.using( ['mediawiki.user', 'mediawiki.util', 'mediawiki.notify'] ).done( function () { |
| /* Begin of mw.loader.using callback */ | | /* Begin of mw.loader.using callback */ |
− |
| + | |
| /** | | /** |
| * Main Page layout fixes | | * Main Page layout fixes |
Line 26: |
Line 25: |
| */ | | */ |
| if ( mw.config.get( 'wgPageName' ) === 'Main_Page' || mw.config.get( 'wgPageName' ) === 'Talk:Main_Page' ) { | | if ( mw.config.get( 'wgPageName' ) === 'Main_Page' || mw.config.get( 'wgPageName' ) === 'Talk:Main_Page' ) { |
− | $( document ).ready( function () {
| + | $( function () { |
− | mw.util.addPortletLink( 'p-lang', '//meta.wikimedia.org/wiki/List_of_Wikipedias',
| + | mw.util.addPortletLink( 'p-lang', '//meta.wikimedia.org/wiki/List_of_Wikipedias', |
− | 'Complete list', 'interwiki-completelist', 'Complete 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 | | * Redirect User:Name/skin.js and skin.css to the current skin's pages |
Line 39: |
Line 38: |
| */ | | */ |
| if ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgNamespaceNumber' ) === 2 ) { | | if ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgNamespaceNumber' ) === 2 ) { |
− | var titleParts = mw.config.get( 'wgPageName' ).split( '/' );
| + | var titleParts = mw.config.get( 'wgPageName' ).split( '/' ); |
− | /* Make sure there was a part before and after the slash
| + | /* Make sure there was a part before and after the slash |
− | and that the latter is 'skin.js' or 'skin.css' */
| + | and that the latter is 'skin.js' or 'skin.css' */ |
− | if ( titleParts.length == 2 ) {
| + | if ( titleParts.length == 2 ) { |
− | var userSkinPage = titleParts.shift() + '/' + mw.config.get( 'skin' );
| + | var userSkinPage = titleParts.shift() + '/' + mw.config.get( 'skin' ); |
− | if ( titleParts.slice( -1 ) == 'skin.js' ) {
| + | if ( titleParts.slice( -1 ) == 'skin.js' ) { |
− | window.location.href = mw.util.wikiGetlink( userSkinPage + '.js' );
| + | window.location.href = mw.util.getUrl( userSkinPage + '.js' ); |
− | } else if ( titleParts.slice( -1 ) == 'skin.css' ) {
| + | } else if ( titleParts.slice( -1 ) == 'skin.css' ) { |
− | window.location.href = mw.util.wikiGetlink( userSkinPage + '.css' );
| + | window.location.href = mw.util.getUrl( userSkinPage + '.css' ); |
− | }
| + | } |
− | }
| + | } |
| } | | } |
− |
| + | |
| /** | | /** |
− | * Map addPortletLink to mw.util | + | * Map addPortletLink to mw.util |
− | *
| |
| * @deprecated: Use mw.util.addPortletLink instead. | | * @deprecated: Use mw.util.addPortletLink instead. |
| */ | | */ |
− | mw.log.deprecate( window, 'addPortletLink', function () { | + | mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' ); |
− | return mw.util.addPortletLink.apply( mw.util, arguments );
| + | |
− | }, 'Use mw.util.addPortletLink() instead' );
| |
− |
| |
| /** | | /** |
| * Extract a URL parameter from the current URL | | * Extract a URL parameter from the current URL |
− | *
| |
| * @deprecated: Use mw.util.getParamValue with proper escaping | | * @deprecated: Use mw.util.getParamValue with proper escaping |
| */ | | */ |
− | mw.log.deprecate( window, 'getURLParamValue', function () { | + | mw.log.deprecate( window, 'getURLParamValue', mw.util.getParamValue, 'Use mw.util.getParamValue instead' ); |
− | return mw.util.getParamValue.apply( mw.util, arguments );
| + | |
− | }, 'Use mw.util.getParamValue() instead' );
| + | /** |
− |
| |
− | /** | |
| * Test if an element has a certain class | | * Test if an element has a certain class |
− | *
| |
| * @deprecated: Use $(element).hasClass() instead. | | * @deprecated: Use $(element).hasClass() instead. |
| */ | | */ |
| mw.log.deprecate( window, 'hasClass', function ( element, className ) { | | mw.log.deprecate( window, 'hasClass', function ( element, className ) { |
− | return $( element ).hasClass( className );
| + | return $( element ).hasClass( className ); |
| }, 'Use jQuery.hasClass() instead' ); | | }, 'Use jQuery.hasClass() instead' ); |
− |
| + | |
| /** | | /** |
| * @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL | | * @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL |
− | * @rev 5 | + | * @rev 6 |
| */ | | */ |
− | // CSS
| + | var extraCSS = mw.util.getParamValue( 'withCSS' ), |
− | var extraCSS = mw.util.getParamValue( 'withCSS' ); | + | extraJS = mw.util.getParamValue( 'withJS' ); |
| + | |
| if ( extraCSS ) { | | if ( extraCSS ) { |
| if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) { | | if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) { |
− | importStylesheet( extraCSS ); | + | mw.loader.load( '/w/index.php?title=' + extraCSS + '&action=raw&ctype=text/css', 'text/css' ); |
| } else { | | } else { |
| mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } ); | | 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 ) { |
| if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) { | | if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) { |
− | importScript( extraJS ); | + | mw.loader.load( '/w/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' ); |
| } else { | | } else { |
| mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } ); | | 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 | | * WikiMiniAtlas |
Line 139: |
Line 100: |
| * This script causes all of our coordinate links to display the WikiMiniAtlas popup button. | | * 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. | | * The script itself is located on meta because it is used by many projects. |
− | * See [[Meta:WikiMiniAtlas]] for more information. | + | * See [[Meta:WikiMiniAtlas]] for more information. |
| * Maintainers: [[User:Dschwen]] | | * Maintainers: [[User:Dschwen]] |
| */ | | */ |
| ( function () { | | ( function () { |
− | var require_wikiminiatlas = false;
| + | var require_wikiminiatlas = false; |
− | var coord_filter = /geohack/;
| + | var coord_filter = /geohack/; |
− | $( document ).ready( function() {
| + | $( function () { |
− | $( 'a.external.text' ).each( function( key, link ) {
| + | $( 'a.external.text' ).each( function( key, link ) { |
− | if ( link.href && coord_filter.exec( link.href ) ) {
| + | if ( link.href && coord_filter.exec( link.href ) ) { |
− | require_wikiminiatlas = true;
| + | require_wikiminiatlas = true; |
− | // break from loop
| + | // break from loop |
− | return false;
| + | return false; |
− | }
| + | } |
− | } );
| + | } ); |
− | if ( $( 'div.kmldata' ).length ) {
| + | if ( $( 'div.kmldata' ).length ) { |
− | require_wikiminiatlas = true;
| + | require_wikiminiatlas = true; |
− | }
| + | } |
− | if ( require_wikiminiatlas ) {
| + | if ( require_wikiminiatlas ) { |
− | mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' );
| + | mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' ); |
− | }
| + | } |
− | } );
| + | } ); |
| } )(); | | } )(); |
− |
| + | |
| /** | | /** |
− | * Interwiki links to featured articles *************************************** | + | * Collapsible tables |
| * | | * |
− | * Description: Highlights interwiki links to featured articles (or | + | * Allows tables to be collapsed, showing only the header. See [[Help:Collapsing]]. |
− | * 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++ ) {
| |
− | var className = InterwikiLinks[i].className.match(/interwiki-[-\w]+/);
| |
− | if ( document.getElementById( className + '-fa' ) ) {
| |
− | InterwikiLinks[i].className += ' FA';
| |
− | InterwikiLinks[i].title = 'This is a featured article in this language.';
| |
− | } else if ( document.getElementById( className + '-ga' ) ) {
| |
− | InterwikiLinks[i].className += ' GA';
| |
− | InterwikiLinks[i].title = 'This is a good article in this language.';
| |
− | }
| |
− | }
| |
− | }
| |
− | }
| |
− |
| |
− | mw.hook( 'wikipage.content' ).add( LinkFA );
| |
− |
| |
− | /**
| |
− | * Collapsible tables *********************************************************
| |
| * | | * |
− | * Description: Allows tables to be collapsed, showing only the header. See | + | * @version 2.0.3 (2014-03-14) |
− | * [[Wikipedia:NavFrame]]. | + | * @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js |
− | * Maintainers: [[User:R. Koot]] | + | * @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 autoCollapse = 2; |
| var collapseCaption = 'hide'; | | var collapseCaption = 'hide'; |
| var expandCaption = 'show'; | | var expandCaption = 'show'; |
− |
| + | var tableIndex = 0; |
− | window.collapseTable = function ( tableIndex ) {
| + | |
− | var Button = document.getElementById( 'collapseButton' + tableIndex );
| + | function collapseTable( tableIndex ) { |
− | var Table = document.getElementById( 'collapsibleTable' + tableIndex );
| + | var Button = document.getElementById( 'collapseButton' + tableIndex ); |
− |
| + | var Table = document.getElementById( 'collapsibleTable' + tableIndex ); |
− | if ( !Table || !Button ) {
| + | |
− | return false;
| + | if ( !Table || !Button ) { |
− | }
| + | return false; |
− |
| + | } |
− | var Rows = Table.rows;
| + | |
− | var i;
| + | var Rows = Table.rows; |
− |
| + | var i; |
− | if ( Button.firstChild.data === collapseCaption ) {
| + | var $row0 = $(Rows[0]); |
− | for ( i = 1; i < Rows.length; i++ ) {
| + | |
− | Rows[i].style.display = 'none';
| + | if ( Button.firstChild.data === collapseCaption ) { |
− | }
| + | for ( i = 1; i < Rows.length; i++ ) { |
− | Button.firstChild.data = expandCaption;
| + | Rows[i].style.display = 'none'; |
− | } else {
| + | } |
− | for ( i = 1; i < Rows.length; i++ ) {
| + | Button.firstChild.data = expandCaption; |
− | Rows[i].style.display = Rows[0].style.display;
| + | } else { |
− | }
| + | for ( i = 1; i < Rows.length; i++ ) { |
− | Button.firstChild.data = collapseCaption;
| + | Rows[i].style.display = $row0.css( 'display' ); |
− | }
| + | } |
− | }; | + | Button.firstChild.data = collapseCaption; |
− |
| + | } |
− | function createCollapseButtons() { | + | } |
− | var tableIndex = 0;
| + | |
− | var NavigationBoxes = {};
| + | function createClickHandler( tableIndex ) { |
− | var Tables = document.getElementsByTagName( 'table' );
| + | return function ( e ) { |
− | var i;
| + | e.preventDefault(); |
− |
| + | collapseTable( tableIndex ); |
− | function handleButtonLink( index, e ) {
| + | }; |
− | window.collapseTable( index );
| + | } |
− | e.preventDefault();
| + | |
− | }
| + | function createCollapseButtons( $content ) { |
− |
| + | var NavigationBoxes = {}; |
− | for ( i = 0; i < Tables.length; i++ ) {
| + | var $Tables = $content.find( 'table' ); |
− | if ( $( Tables[i] ).hasClass( 'collapsible' ) ) {
| + | var i; |
− |
| + | |
− | /* only add button and increment count if there is a header row to work with */
| + | $Tables.each( function( i, table ) { |
− | var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
| + | if ( $(table).hasClass( 'collapsible' ) ) { |
− | if ( !HeaderRow ) continue;
| + | |
− | var Header = HeaderRow.getElementsByTagName( 'th' )[0];
| + | /* only add button and increment count if there is a header row to work with */ |
− | if ( !Header ) continue;
| + | var HeaderRow = table.getElementsByTagName( 'tr' )[0]; |
− |
| + | if ( !HeaderRow ) { |
− | NavigationBoxes[ tableIndex ] = Tables[i];
| + | return; |
− | Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
| + | } |
− |
| + | var Header = table.getElementsByTagName( 'th' )[0]; |
− | var Button = document.createElement( 'span' );
| + | if ( !Header ) { |
− | var ButtonLink = document.createElement( 'a' );
| + | return; |
− | var ButtonText = document.createTextNode( collapseCaption );
| + | } |
− |
| + | |
− | Button.className = 'collapseButton'; /* Styles are declared in Common.css */
| + | NavigationBoxes[ tableIndex ] = table; |
− |
| + | table.setAttribute( 'id', 'collapsibleTable' + tableIndex ); |
− | ButtonLink.style.color = Header.style.color;
| + | |
− | ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
| + | var Button = document.createElement( 'span' ); |
− | ButtonLink.setAttribute( 'href', '#' );
| + | var ButtonLink = document.createElement( 'a' ); |
− | $( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) );
| + | var ButtonText = document.createTextNode( collapseCaption ); |
− | ButtonLink.appendChild( ButtonText );
| + | // Styles are declared in [[MediaWiki:Common.css]] |
− |
| + | Button.className = 'collapseButton'; |
− | Button.appendChild( document.createTextNode( '[' ) );
| + | |
− | Button.appendChild( ButtonLink );
| + | ButtonLink.style.color = Header.style.color; |
− | Button.appendChild( document.createTextNode( ']' ) );
| + | ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex ); |
− |
| + | ButtonLink.setAttribute( 'href', '#' ); |
− | Header.insertBefore( Button, Header.firstChild );
| + | $( ButtonLink ).on( 'click', createClickHandler( tableIndex ) ); |
− | tableIndex++;
| + | ButtonLink.appendChild( ButtonText ); |
− | }
| + | |
− | }
| + | Button.appendChild( document.createTextNode( '[' ) ); |
− |
| + | Button.appendChild( ButtonLink ); |
− | for ( i = 0; i < tableIndex; i++ ) {
| + | Button.appendChild( document.createTextNode( ']' ) ); |
− | if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) || ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) ) ) {
| + | |
− | window.collapseTable( i );
| + | Header.insertBefore( Button, Header.firstChild ); |
− | }
| + | tableIndex++; |
− | else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) {
| + | } |
− | var element = NavigationBoxes[i];
| + | } ); |
− | while ((element = element.parentNode)) {
| + | |
− | if ( $( element ).hasClass( 'outercollapse' ) ) {
| + | for ( i = 0; i < tableIndex; i++ ) { |
− | window.collapseTable ( i );
| + | if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) || |
− | break;
| + | ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) ) |
− | }
| + | ) { |
− | }
| + | 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 ); | | mw.hook( 'wikipage.content' ).add( createCollapseButtons ); |
− | | + | |
| + | /** |
| + | * Add support to mw-collapsible for autocollapse, innercollapse and outercollapse |
| + | * |
| + | * Maintainers: TheDJ |
| + | */ |
| + | function mwCollapsibleSetup( $collapsibleContent ) { |
| + | var $element, |
| + | $toggle, |
| + | autoCollapseThreshold = 2; |
| + | $.each( $collapsibleContent, function (index, element) { |
| + | $element = $( element ); |
| + | if ( $collapsibleContent.length > autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) { |
| + | $element.data( 'mw-collapsible' ).collapse(); |
| + | } else if ( $element.hasClass( 'innercollapse' ) ) { |
| + | if ( $element.parents( '.outercollapse' ).length > 0 ) { |
| + | $element.data( 'mw-collapsible' ).collapse(); |
| + | } |
| + | } |
| + | $toggle = $element.find( '.mw-collapsible-toggle' ); |
| + | if ( $toggle.length ) { |
| + | // Make the toggle inherit text color |
| + | if( $toggle.parent()[0].style.color ) { |
| + | $toggle.find( 'a' ).css( 'color', 'inherit' ); |
| + | } |
| + | } |
| + | } ); |
| + | } |
| + | |
| + | mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup ); |
| + | |
| /** | | /** |
| * Dynamic Navigation Bars (experimental) | | * Dynamic Navigation Bars (experimental) |
Line 293: |
Line 271: |
| * Maintainers: UNMAINTAINED | | * Maintainers: UNMAINTAINED |
| */ | | */ |
− |
| + | |
| /* set up the words in your language */ | | /* set up the words in your language */ |
| var NavigationBarHide = '[' + collapseCaption + ']'; | | var NavigationBarHide = '[' + collapseCaption + ']'; |
| var NavigationBarShow = '[' + expandCaption + ']'; | | var NavigationBarShow = '[' + expandCaption + ']'; |
− |
| + | var indexNavigationBar = 0; |
| + | |
| /** | | /** |
| * Shows and hides content and picture (if available) of navigation bars | | * Shows and hides content and picture (if available) of navigation bars |
Line 304: |
Line 283: |
| **/ | | **/ |
| window.toggleNavigationBar = function ( indexNavigationBar, event ) { | | window.toggleNavigationBar = function ( indexNavigationBar, event ) { |
− | var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
| + | var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar ); |
− | var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
| + | var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar ); |
− | var NavChild;
| + | var NavChild; |
− |
| + | |
− | if ( !NavFrame || !NavToggle ) {
| + | if ( !NavFrame || !NavToggle ) { |
− | return false;
| + | return false; |
− | }
| + | } |
− |
| + | |
− | /* if shown now */
| + | /* if shown now */ |
− | if ( NavToggle.firstChild.data === NavigationBarHide ) {
| + | if ( NavToggle.firstChild.data === NavigationBarHide ) { |
− | for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
| + | for ( NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling ) { |
− | if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
| + | if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) { |
− | NavChild.style.display = 'none';
| + | NavChild.style.display = 'none'; |
− | }
| + | } |
− | }
| + | } |
− | NavToggle.firstChild.data = NavigationBarShow;
| + | NavToggle.firstChild.data = NavigationBarShow; |
− |
| + | |
− | /* if hidden now */
| + | /* if hidden now */ |
− | } else if ( NavToggle.firstChild.data === NavigationBarShow ) {
| + | } else if ( NavToggle.firstChild.data === NavigationBarShow ) { |
− | for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
| + | for ( NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling ) { |
− | if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
| + | if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) { |
− | NavChild.style.display = 'block';
| + | NavChild.style.display = 'block'; |
− | }
| + | } |
− | }
| + | } |
− | NavToggle.firstChild.data = NavigationBarHide;
| + | NavToggle.firstChild.data = NavigationBarHide; |
− | }
| + | } |
− |
| + | |
− | event.preventDefault();
| + | event.preventDefault(); |
| }; | | }; |
− |
| + | |
| /* adds show/hide-button to navigation bars */ | | /* adds show/hide-button to navigation bars */ |
− | function createNavigationBarToggleButton() { | + | function createNavigationBarToggleButton( $content ) { |
− | var indexNavigationBar = 0;
| + | var NavChild; |
− | var NavFrame;
| + | /* iterate over all < div >-elements */ |
− | var NavChild;
| + | var $divs = $content.find( 'div' ); |
− | /* iterate over all < div >-elements */
| + | $divs.each( function ( i, NavFrame ) { |
− | var divs = document.getElementsByTagName( 'div' );
| + | /* if found a navigation bar */ |
− | for ( var i = 0; (NavFrame = divs[i]); i++ ) {
| + | if ( $( NavFrame ).hasClass( 'NavFrame' ) ) { |
− | /* if found a navigation bar */
| + | |
− | if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {
| + | indexNavigationBar++; |
− |
| + | var NavToggle = document.createElement( 'a' ); |
− | indexNavigationBar++;
| + | NavToggle.className = 'NavToggle'; |
− | var NavToggle = document.createElement( 'a' );
| + | NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar ); |
− | NavToggle.className = 'NavToggle';
| + | NavToggle.setAttribute( 'href', '#' ); |
− | NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
| + | $( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) ); |
− | NavToggle.setAttribute( 'href', '#' );
| + | |
− | $( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );
| + | var isCollapsed = $( NavFrame ).hasClass( 'collapsed' ); |
− |
| + | /** |
− | 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" |
− | * Check if any children are already hidden. This loop is here for backwards compatibility:
| + | * to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make |
− | * the old way of making NavFrames start out collapsed was to manually add style="display:none"
| + | * the content visible without JavaScript support), the new recommended way is to add the class |
− | * to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make
| + | * "collapsed" to the NavFrame itself, just like with collapsible tables. |
− | * 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' ) ) { |
− | for ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling ) {
| + | if ( NavChild.style.display === 'none' ) { |
− | if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
| + | isCollapsed = true; |
− | if ( NavChild.style.display === 'none' ) {
| + | } |
− | isCollapsed = true;
| + | } |
− | }
| + | } |
− | }
| + | if ( isCollapsed ) { |
− | }
| + | for ( NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling ) { |
− | if ( isCollapsed ) {
| + | if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) { |
− | for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
| + | NavChild.style.display = 'none'; |
− | if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
| + | } |
− | NavChild.style.display = 'none';
| + | } |
− | }
| + | } |
− | }
| + | var NavToggleText = document.createTextNode( isCollapsed ? NavigationBarShow : NavigationBarHide ); |
− | }
| + | NavToggle.appendChild( NavToggleText ); |
− | 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++ ) { |
− | /* Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) */
| + | if ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) { |
− | for( var j = 0; j < NavFrame.childNodes.length; j++ ) {
| + | NavToggle.style.color = NavFrame.childNodes[j].style.color; |
− | if ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
| + | NavFrame.childNodes[j].appendChild( NavToggle ); |
− | NavToggle.style.color = NavFrame.childNodes[j].style.color;
| + | } |
− | NavFrame.childNodes[j].appendChild( NavToggle );
| + | } |
− | }
| + | NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar ); |
− | }
| + | } |
− | NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
| + | } ); |
− | }
| |
− | }
| |
| } | | } |
− |
| + | |
| mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton ); | | mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton ); |
− |
| + | |
| /** | | /** |
| * Uploadwizard_newusers | | * Uploadwizard_newusers |
Line 398: |
Line 375: |
| */ | | */ |
| function uploadwizard_newusers() { | | function uploadwizard_newusers() { |
− | if ( mw.config.get( 'wgNamespaceNumber' ) === 4 && mw.config.get( 'wgTitle' ) === 'Upload' && mw.config.get( 'wgAction' ) === 'view' ) {
| + | if ( mw.config.get( 'wgNamespaceNumber' ) === 4 && mw.config.get( 'wgTitle' ) === 'Upload' && mw.config.get( 'wgAction' ) === 'view' ) { |
− | var oldDiv = document.getElementById( 'autoconfirmedusers' ),
| + | var oldDiv = document.getElementById( 'autoconfirmedusers' ), |
− | newDiv = document.getElementById( 'newusers' );
| + | newDiv = document.getElementById( 'newusers' ); |
− | if ( oldDiv && newDiv ) {
| + | if ( oldDiv && newDiv ) { |
− | var userGroups = mw.config.get( 'wgUserGroups' );
| + | var userGroups = mw.config.get( 'wgUserGroups' ); |
− | if ( userGroups ) {
| + | if ( userGroups ) { |
− | for ( var i = 0; i < userGroups.length; i++ ) {
| + | for ( var i = 0; i < userGroups.length; i++ ) { |
− | if ( userGroups[i] === 'autoconfirmed' ) {
| + | if ( userGroups[i] === 'autoconfirmed' ) { |
− | oldDiv.style.display = 'block';
| + | oldDiv.style.display = 'block'; |
− | newDiv.style.display = 'none';
| + | newDiv.style.display = 'none'; |
− | return;
| + | return; |
− | }
| + | } |
− | }
| + | } |
− | }
| + | } |
− | oldDiv.style.display = 'none';
| + | oldDiv.style.display = 'none'; |
− | newDiv.style.display = 'block';
| + | newDiv.style.display = 'block'; |
− | return;
| + | return; |
− | }
| + | } |
− | }
| + | } |
| } | | } |
− |
| + | |
| $(uploadwizard_newusers); | | $(uploadwizard_newusers); |
− |
| + | |
| /** | | /** |
| * Magic editintros **************************************************** | | * Magic editintros **************************************************** |
Line 428: |
Line 405: |
| */ | | */ |
| function addEditIntro( name ) { | | function addEditIntro( name ) { |
− | $( '.mw-editsection, #ca-edit' ).find( 'a' ).each( function ( i, el ) {
| + | $( '.mw-editsection, #ca-edit' ).find( 'a' ).each( function ( i, el ) { |
− | el.href = $( this ).attr( 'href' ) + '&editintro=' + name;
| + | el.href = $( this ).attr( 'href' ) + '&editintro=' + name; |
− | } );
| + | } ); |
| } | | } |
− |
| + | |
| if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) { | | if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) { |
− | $( function () {
| + | $( function () { |
− | if ( document.getElementById( 'disambigbox' ) ) {
| + | if ( document.getElementById( 'disambigbox' ) ) { |
− | addEditIntro( 'Template:Disambig_editintro' );
| + | addEditIntro( 'Template:Disambig_editintro' ); |
− | }
| + | } |
− | } );
| + | } ); |
− |
| + | |
− | $( function () {
| + | $( function () { |
− | var cats = document.getElementById( 'mw-normal-catlinks' );
| + | var cats = mw.config.get('wgCategories'); |
− | if ( !cats ) {
| + | if ( !cats ) { |
− | return;
| + | return; |
− | }
| + | } |
− | cats = cats.getElementsByTagName( 'a' );
| + | if ( $.inArray( 'Living people', cats ) !== -1 || $.inArray( 'Possibly living people', cats ) !== -1 ) { |
− | for ( var i = 0; i < cats.length; i++ ) {
| + | addEditIntro( 'Template:BLP_editintro' ); |
− | if ( cats[i].title === 'Category:Living people' || cats[i].title === 'Category:Possibly living people' ) {
| + | } |
− | addEditIntro( 'Template:BLP_editintro' );
| + | } ); |
− | break;
| |
− | }
| |
− | }
| |
− | } );
| |
| } | | } |
− |
| + | |
− | /** | + | /* Actions specific to the edit page */ |
− | * Description: Stay on the secure server as much as possible | + | if ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' ) { |
− | * Maintainers: [[User:TheDJ]] | + | /** |
− | */ | + | * Fix edit summary prompt for undo |
− | if ( document.location && document.location.protocol && document.location.protocol === 'https:' ) { | + | * |
− | /* New secure servers */
| + | * Fixes the fact that the undo function combined with the "no edit summary prompter" |
− | importScript( 'MediaWiki:Common.js/secure new.js' );
| + | * complains about missing editsummary, if leaving the edit summary unchanged. |
| + | * Added by [[User:Deskana]], code by [[User:Tra]]. |
| + | * See also [[phab:T10912]]. |
| + | */ |
| + | $(function () { |
| + | if (document.location.search.indexOf('undo=') !== -1 && document.getElementsByName('wpAutoSummary')[0]) { |
| + | document.getElementsByName('wpAutoSummary')[0].value = '1'; |
| + | } |
| + | }); |
| } | | } |
− |
| + | |
| /* End of mw.loader.using callback */ | | /* End of mw.loader.using callback */ |
| } ); | | } ); |
| /* DO NOT ADD CODE BELOW THIS LINE */ | | /* DO NOT ADD CODE BELOW THIS LINE */ |