mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-24 15:53:46 +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() {
|
function addInterwikiLinkToMainMenu() {
|
||||||
// eslint-disable-next-line no-jquery/no-global-selector
|
// eslint-disable-next-line no-jquery/no-global-selector
|
||||||
var $editLink = $( '#p-lang-btn .wbc-editpage' );
|
var $editLink = $( '#p-lang-btn .wbc-editpage' ),
|
||||||
if ( $editLink.length ) {
|
addInterlanguageLink;
|
||||||
// Use title attribute for link text
|
|
||||||
$editLink.text( $editLink.attr( 'title' ) || '' );
|
if ( !$editLink.length ) {
|
||||||
var $li = $( '<li>' )
|
return;
|
||||||
// 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' )
|
// @ts-ignore
|
||||||
.append( $editLink );
|
addInterlanguageLink = mw.util.addPortletLink(
|
||||||
$li.appendTo( '#p-tb ul' );
|
'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