mediawiki-skins-Vector/resources/skins.vector.js/languageButton.js
Func 8457b64a83 languageButton: Use click method instead of dispatchEvent
For pages with interlanguage links, this link has no event listener
and only functions as a plain link to the corresponding Wikidata page.

Bug: T336931
Change-Id: I8c1456b3c524824ccc59aee5f999c8017c59fc0b
2023-06-01 02:27:24 +08:00

42 lines
1,000 B
JavaScript

/**
* Copies interwiki links to main menu
*
* Temporary solution to T287206, can be removed when the new ULS built in Vue.js
* has been released and contains this
*/
function addInterwikiLinkToMainMenu() {
const editLink = /** @type {HTMLElement|null} */ (
document.querySelector( '#p-lang-btn .wbc-editpage' )
);
if ( !editLink ) {
return;
}
const title = editLink.getAttribute( 'title' ) || '';
const addInterlanguageLink = mw.util.addPortletLink(
'p-tb',
editLink.getAttribute( 'href' ) || '#',
// Original text is "Edit links".
// Since its taken out of context the title is more descriptive.
title,
'wbc-editpage',
title
);
if ( addInterlanguageLink ) {
addInterlanguageLink.addEventListener( 'click', function ( /** @type {Event} */ e ) {
e.preventDefault();
// redirect to the detached and original edit link
editLink.click();
} );
}
}
/**
* Initialize the language button.
*/
module.exports = function () {
addInterwikiLinkToMainMenu();
};