From 2cf705bf7910ade43a148373919b1c55789b2cec Mon Sep 17 00:00:00 2001 From: Jan Drewniak Date: Mon, 6 Mar 2023 23:15:25 -0500 Subject: [PATCH] Refactor languageButton.js using mw.util.addPortletLink Per comment in related patch d05f251 Change-Id: If49dfe55e8450f1a7ed6968f4907ae458072560a --- resources/skins.vector.js/languageButton.js | 34 +++++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/resources/skins.vector.js/languageButton.js b/resources/skins.vector.js/languageButton.js index a7c3a83b2..f9160cff4 100644 --- a/resources/skins.vector.js/languageButton.js +++ b/resources/skins.vector.js/languageButton.js @@ -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 = $( '
  • ' ) - // 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' ); + } ); } }