Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
No edit summary
No edit summary
Line 2: Line 2:


     function injectThemeOption(container) {
     function injectThemeOption(container) {
   
    function createRadio(id, label) {
    const radioWrapper = document.createElement('div');
    radioWrapper.className = 'citizen-client-prefs-radio';
    const input = document.createElement('input');
    input.type = 'radio';
    input.name = 'lt-theme-group';
    input.id = id;
    input.className = 'citizen-client-prefs-radio__input';
    const icon = document.createElement('span');
    icon.className = 'citizen-client-prefs-radio__icon';
    const labelEl = document.createElement('label');
    labelEl.className = 'citizen-client-prefs-radio__label';
    labelEl.htmlFor = id;
    labelEl.textContent = label;
    radioWrapper.appendChild(input);
    radioWrapper.appendChild(icon);
    radioWrapper.appendChild(labelEl);
    return radioWrapper;
}


         if (document.getElementById('lt-theme-test')) return;
         if (document.getElementById('lt-theme-test')) return;
Line 33: Line 58:
         const form = document.createElement('form');
         const form = document.createElement('form');


         // Radio wrapper
         form.appendChild(createRadio('lt-theme-default', 'Velvet Room'));
        const radioWrapper = document.createElement('div');
form.appendChild(createRadio('lt-theme-red', 'Courtroom'));
        radioWrapper.className = 'citizen-client-prefs-radio';
form.appendChild(createRadio('lt-theme-blue', 'Mementos'));
 
        // Input
        const input = document.createElement('input');
        input.type = 'radio';
        input.name = 'lt-theme-group';
        input.id = 'lt-theme-default';
        input.className = 'citizen-client-prefs-radio__input';
 
        // Icon
        const icon = document.createElement('span');
        icon.className = 'citizen-client-prefs-radio__icon';
 
        // Label
        const label = document.createElement('label');
        label.className = 'citizen-client-prefs-radio__label';
        label.htmlFor = 'lt-theme-default';
        label.textContent = 'Velvet Room';
 
        // Assemble radio
        radioWrapper.appendChild(input);
        radioWrapper.appendChild(icon);
        radioWrapper.appendChild(label);


         // Assemble hierarchy
         // Assemble hierarchy
        form.appendChild(radioWrapper);
         innerDiv.appendChild(form);
         innerDiv.appendChild(form);
         item.appendChild(innerDiv);
         item.appendChild(innerDiv);

Revision as of 16:54, 20 February 2026

mw.loader.using(['mediawiki.util']).then(function () {

    function injectThemeOption(container) {
    	
    	function createRadio(id, label) {
		    const radioWrapper = document.createElement('div');
		    radioWrapper.className = 'citizen-client-prefs-radio';
		
		    const input = document.createElement('input');
		    input.type = 'radio';
		    input.name = 'lt-theme-group';
		    input.id = id;
		    input.className = 'citizen-client-prefs-radio__input';
		
		    const icon = document.createElement('span');
		    icon.className = 'citizen-client-prefs-radio__icon';
		
		    const labelEl = document.createElement('label');
		    labelEl.className = 'citizen-client-prefs-radio__label';
		    labelEl.htmlFor = id;
		    labelEl.textContent = label;
		
		    radioWrapper.appendChild(input);
		    radioWrapper.appendChild(icon);
		    radioWrapper.appendChild(labelEl);
		
		    return radioWrapper;
		}

        if (document.getElementById('lt-theme-test')) return;

        // Portlet wrapper
        const wrapper = document.createElement('div');
        wrapper.id = 'lt-theme-test';
        wrapper.className = 'mw-portlet citizen-menu';

        // Heading
        const heading = document.createElement('div');
        heading.className = 'citizen-menu__heading';
        heading.textContent = 'Theme';

        // Content wrapper
        const content = document.createElement('div');
        content.className = 'citizen-menu__content';

        // UL
        const list = document.createElement('ul');
        list.className = 'citizen-menu__content-list';

        // LI
        const item = document.createElement('li');
        item.className = 'mw-list-item mw-list-item-js';

        // Inner div (matches Citizen structure)
        const innerDiv = document.createElement('div');

        // FORM (this is important for spacing)
        const form = document.createElement('form');

        form.appendChild(createRadio('lt-theme-default', 'Velvet Room'));
		form.appendChild(createRadio('lt-theme-red', 'Courtroom'));
		form.appendChild(createRadio('lt-theme-blue', 'Mementos'));

        // Assemble hierarchy
        innerDiv.appendChild(form);
        item.appendChild(innerDiv);
        list.appendChild(item);
        content.appendChild(list);
        wrapper.appendChild(heading);
        wrapper.appendChild(content);

        container.appendChild(wrapper);
    }

    const observer = new MutationObserver(function () {
        const container = document.querySelector('.citizen-preferences-content');
        if (container) {
            injectThemeOption(container);
        }
    });

    observer.observe(document.body, { childList: true, subtree: true });

});