MediaWiki:Common.js: Difference between revisions

From TenthFleet
Jump to navigation Jump to search
Add Contributor's guide button to the WikiEditor toolbar (opens guide in a new tab)
 
m Relabel toolbar tab-link 'Editor's Guide' -> 'Guide'
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
/* Add a "Contributor's guide" button to the WikiEditor toolbar (top-right utility group). */
/* Add an "Editor's Guide" tab-link to the WikiEditor toolbar tabs row
  (next to Advanced / Special characters / Help). Opens the guide in a new
  tab; it is a plain link, not a section toggle. */
mw.loader.using( [ 'ext.wikiEditor', 'mediawiki.util' ] ).then( function () {
mw.loader.using( [ 'ext.wikiEditor', 'mediawiki.util' ] ).then( function () {
mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
$textarea.wikiEditor( 'addToToolbar', {
var $tabs = $textarea.closest( '.wikiEditor-ui' )
section: 'secondary',
.find( '.wikiEditor-ui-toolbar .tabs' ).first();
group: 'default',
if ( !$tabs.length || $tabs.find( '.tab-guide' ).length ) {
tools: {
return;
contributorsguide: {
}
label: "Contributor's guide",
var $link = $( '<a>' )
type: 'button',
.addClass( 'skin-invert' )
oouiIcon: 'help',
.attr( {
action: {
href: mw.util.getUrl( "TenthFleet:Contributor's guide" ),
type: 'callback',
target: '_blank',
execute: function () {
rel: 'noopener'
window.open(
} )
mw.util.getUrl( "TenthFleet:Contributor's guide" ),
.text( "Guide" )
'_blank'
.on( 'click', function ( e ) {
);
// Prevent WikiEditor's tab-toggle handler from intercepting;
}
// let the native link open the guide in a new tab.
}
e.stopPropagation();
}
} );
}
$( '<span>' ).addClass( 'tab tab-guide' ).append( $link ).appendTo( $tabs );
} );
} );
} );
} );
} );

Latest revision as of 00:35, 29 July 2026

/* Add an "Editor's Guide" tab-link to the WikiEditor toolbar tabs row
   (next to Advanced / Special characters / Help). Opens the guide in a new
   tab; it is a plain link, not a section toggle. */
mw.loader.using( [ 'ext.wikiEditor', 'mediawiki.util' ] ).then( function () {
	mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
		var $tabs = $textarea.closest( '.wikiEditor-ui' )
			.find( '.wikiEditor-ui-toolbar .tabs' ).first();
		if ( !$tabs.length || $tabs.find( '.tab-guide' ).length ) {
			return;
		}
		var $link = $( '<a>' )
			.addClass( 'skin-invert' )
			.attr( {
				href: mw.util.getUrl( "TenthFleet:Contributor's guide" ),
				target: '_blank',
				rel: 'noopener'
			} )
			.text( "Guide" )
			.on( 'click', function ( e ) {
				// Prevent WikiEditor's tab-toggle handler from intercepting;
				// let the native link open the guide in a new tab.
				e.stopPropagation();
			} );
		$( '<span>' ).addClass( 'tab tab-guide' ).append( $link ).appendTo( $tabs );
	} );
} );