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
This commit is contained in:
Func 2023-06-01 02:04:38 +08:00
parent 3fae89e967
commit 8457b64a83

View file

@ -5,7 +5,9 @@
* has been released and contains this
*/
function addInterwikiLinkToMainMenu() {
const editLink = document.querySelector( '#p-lang-btn .wbc-editpage' );
const editLink = /** @type {HTMLElement|null} */ (
document.querySelector( '#p-lang-btn .wbc-editpage' )
);
if ( !editLink ) {
return;
@ -26,7 +28,7 @@ function addInterwikiLinkToMainMenu() {
addInterlanguageLink.addEventListener( 'click', function ( /** @type {Event} */ e ) {
e.preventDefault();
// redirect to the detached and original edit link
editLink.dispatchEvent( new Event( 'click' ) );
editLink.click();
} );
}
}