MediaWiki:Gadget-AddTopic.js

From Meta, a Wikimedia project coordination wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// Adds an "Add Topic" link to the header of the last section.
// originally taken from [[:w:de:Mediawiki:Common.js]] and added to meta's MediaWiki:Common.js,
// subsequently moved to a gadget, see [[Special:Permalink/22811299#MediaWiki:Common.js#L-428 (archived discussion)]]
( function () {
	var $newSectionLink = $( '#ca-addsection a' );
	if ( $newSectionLink.length ) {
		var $link = $newSectionLink.clone(); //create a copy
		//avoid duplicate accesskey
		$link.removeAttr( 'accesskey' ).updateTooltipAccessKeys();
		//add it within the brackets
		var $lastEditsectionLink = $( 'span.mw-editsection:last a:last' );
		$lastEditsectionLink.after( $link );
		$lastEditsectionLink.after( ' | ' ); //see [[MediaWiki:Pipe-separator]]
	}
}() );

// [[Category:Gadgets|AddTopic.js]]