Debian Codegraph @

skins/Vector/resources/skins.vector.js/languageButton.js

raw symbols SCIP
1 /**
2 * Copies interwiki links to main menu
3 *
4 * Temporary solution to T287206, can be removed when the new ULS built in Vue.js
5 * has been released and contains this
6 */
7 function addInterwikiLinkToMainMenu() {
8 const editLink = /** @type {HTMLElement|null} */ (
9 document.querySelector( '#p-lang-btn .wbc-editpage' )
10 );
11
12 if ( !editLink ) {
13 return;
14 }
15 const title = editLink.getAttribute( 'title' ) || '';
16
17 const addInterlanguageLink = mw.util.addPortletLink(
18 'p-tb',
19 editLink.getAttribute( 'href' ) || '#',
20 // Original text is "Edit links".
21 // Since its taken out of context the title is more descriptive.
22 title,
23 'wbc-editpage',
24 title
25 );
26
27 if ( addInterlanguageLink ) {
28 addInterlanguageLink.addEventListener( 'click', ( /** @type {Event} */ e ) => {
29 e.preventDefault();
30 // redirect to the detached and original edit link
31 editLink.click();
32 } );
33 }
34 }
35
36 /**
37 * Checks if ULS is disabled, and makes sure the language dropdown continues
38 * to work if it is.
39 */
40 function checkIfULSDisabled() {
41 const langModuleState = mw.loader.getState( 'ext.uls.interface' );
42 if ( langModuleState === null || langModuleState === 'registered' ) {
43 document.documentElement.classList.add( 'vector-uls-disabled' );
44 }
45 }
46
47 /**
48 * Initialize the language button.
49 */
50 module.exports = function () {
51 checkIfULSDisabled();
52 addInterwikiLinkToMainMenu();
53 };