User:Majr/docTabs.js

$( function {

var page = mw.config.get( 'wgTitle' ).replace( / /g, '_' ); var title = page.replace( '/doc', '' ); $( '#p-namespaces li:last' ).after( ' Documentation ' ); $( '#p-namespaces li:last' ).after( ' Documentation discussion ' );

if ( page.indexOf( '/doc' ) != -1 ) { $( '#ca-nstab-template' ).removeClass( 'selected' ); $( '#ca-nstab-template a' ).prop( 'href', function {       return this.href.replace( '/doc', '' );    } ); $( '#ca-talk' ).removeClass( 'selected' ); $( '#ca-talk a' ).prop( 'href', function {       return this.href.replace( '/doc', '' );    } ); if ( mw.config.get( 'wgNamespaceNumber' ) == 10 ) { $( '#ca-doc' ).addClass( 'selected' ) } else { $( '#ca-doc-talk' ).addClass( 'selected' ) } }

function namesToIds( name ) { switch ( name ) { case 'Template:' + title: return '#ca-nstab-template'; case 'Template talk:' + title: return '#ca-talk'; case 'Template:' + title + '/doc': return '#ca-doc'; case 'Template talk:' + title + '/doc': return '#ca-doc-talk'; } }

$.ajax( {   url: '/api.php?format=json&action=query&titles=Template:' + title + '|Template talk:' + title + '|Template:' + title + '/doc|Template talk:' + title + '/doc&prop=info',    dataType: 'json', async: false,    success: function( response ) {        $.each( response.query.pages, function { if ( this.hasOwnProperty( 'missing' ) ) { $( namesToIds( this.title ) ).addClass( 'new' ); // No way to have two different 'this' values? //     $( namesToIds( this.title ) ).prop( 'href', function {        //          return this.href.append( '?action=edit&redlink=1' );        //      } ); } else { $( namesToIds( this.title ) ).removeClass( 'new' ); // No way to have two different 'this' values? //     $( namesToIds( this.title ) ).prop( 'href', function {        //          return this.href.replace( 'action=edit&redlink=1', '' );        //      } ); }       } );    } } );

} );