Jump to content

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)
  • Edge: Hold Ctrl while clicking Refresh, or 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 () {
	// `#ca-addsection a` is for most skins, `a#ca-addsection` is for the new vector
	const $newSectionLink = $( '#ca-addsection a, a#ca-addsection' );
	if ( $newSectionLink.closest( '.vector-page-titlebar' ).length ) {
		// "Add topic" has been promoted and will float in the personal bar, no need for duplicate link
		return;
	}
	if ( $newSectionLink.length ) {
		const $link = $newSectionLink.clone(); //create a copy
		// avoid duplicate accesskey
		$link.removeAttr( 'accesskey' ).updateTooltipAccessKeys();
		// add it within the brackets
		const $lastEditsectionLink = $( 'span.mw-editsection:last a:last' );
		$lastEditsectionLink.after( $link );
	}
}() );

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