MediaWiki:Common.js: Difference between revisions
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 | /* 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( ' | 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 ); | ||
} ); | } ); | ||
} ); | } ); | ||
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 );
} );
} );