mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-24 07:43:47 +00:00
Refactor languageButton.js using mw.util.addPortletLink
Per comment in related patch d05f251
Change-Id: If49dfe55e8450f1a7ed6968f4907ae458072560a
This commit is contained in:
parent
6ad3ad889e
commit
2cf705bf79
|
@ -6,16 +6,30 @@
|
|||
*/
|
||||
function addInterwikiLinkToMainMenu() {
|
||||
// eslint-disable-next-line no-jquery/no-global-selector
|
||||
var $editLink = $( '#p-lang-btn .wbc-editpage' );
|
||||
if ( $editLink.length ) {
|
||||
// Use title attribute for link text
|
||||
$editLink.text( $editLink.attr( 'title' ) || '' );
|
||||
var $li = $( '<li>' )
|
||||
// If the Wikibase code runs last, this class is required so it matches the selector @:
|
||||
// https://gerrit.wikimedia.org/g/mediawiki/extensions/Wikibase/+/f2e96e1b08fc5ae2e2e92f05d5eda137dc6b1bc8/client/resources/wikibase.client.linkitem.init.js#82
|
||||
.addClass( 'wb-langlinks-link mw-list-item' )
|
||||
.append( $editLink );
|
||||
$li.appendTo( '#p-tb ul' );
|
||||
var $editLink = $( '#p-lang-btn .wbc-editpage' ),
|
||||
addInterlanguageLink;
|
||||
|
||||
if ( !$editLink.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
addInterlanguageLink = mw.util.addPortletLink(
|
||||
'p-tb',
|
||||
$editLink.attr( 'href' ) || '#',
|
||||
// Original text is "Edit links".
|
||||
// Since its taken out of context the title is more descriptive.
|
||||
$editLink.attr( 'title' ),
|
||||
'wbc-editpage',
|
||||
$editLink.attr( 'title' )
|
||||
);
|
||||
|
||||
if ( addInterlanguageLink ) {
|
||||
addInterlanguageLink.addEventListener( 'click', function ( /** @type {Event} */ e ) {
|
||||
e.preventDefault();
|
||||
// redirect to the detached and original edit link
|
||||
$editLink.trigger( 'click' );
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue