Jump to content

MediaWiki:Common.js: Difference between revisions

From RiskiPedia
No edit summary
No edit summary
Line 17: Line 17:
mw.loader.using('oojs-ui', function () {
mw.loader.using('oojs-ui', function () {
     // Now OOUI is loaded and we can use it
     // Now OOUI is loaded and we can use it
 
     // Create an OOUI dropdown
     // Create an OOUI button
     var dropDown = new OO.ui.DropdownWidget( {
     var dropDown = new OO.ui.DropdownWidget( {
label: 'Dropdown menu: Select one option',
label: 'Dropdown menu: Select one option',
Line 48: Line 47:
}
}
} ),
} ),
// Trigger an event when an item in the menu is selected.
// Trigger an event when an item in the menu is selected.
itemSelected = function(){
itemSelected = function(){
console.log( 'item selected' );
console.log( dropDown.getData() );
};
};
 
// Tell the menu to call itemSelected() on select
 
dropDown.getMenu().on('select', itemSelected);
     // Append the button to the content area of the page
     // Append the button to the content area of the page
     $('.genderSelect').replaceWith(dropDown.$element);
     $('.genderSelect').replaceWith(dropDown.$element);
});
});

Revision as of 00:46, 31 January 2025

/* Any JavaScript here will be loaded for all users on every page load. */

MMtoHuman(document.getElementsByClassName("micromorts"));

function MMtoHuman ( elementArray ){
    for (let span of elementArray){
        if (span !== null){
            let chance = 1000000 / parseInt(span.textContent);
            let digits = Math.round(chance).toString().length;
            let rounded = Math.round(chance / Math.pow(10, digits - 2)) * Math.pow(10, digits - 2);
            span.textContent = "1 in " + rounded.toLocaleString();
        }
    }
}


mw.loader.using('oojs-ui', function () {
    // Now OOUI is loaded and we can use it
    // Create an OOUI dropdown
    var dropDown = new OO.ui.DropdownWidget( {
		label: 'Dropdown menu: Select one option',
		// The menu is composed within the DropdownWidget
		menu: {
			items: [
				new OO.ui.MenuOptionWidget( {
					data: 'a',
					label: 'First'
				} ),
				new OO.ui.MenuOptionWidget( {
					data: 'b',
					label: 'Second (disabled option)',
					disabled: true
				} ),
				new OO.ui.MenuOptionWidget( {
					data: 'c',
					label: 'Third'
				} ),
				new OO.ui.MenuOptionWidget( {
					data: 'd',
					label: 'The fourth option has a long label'
				} ),
				new OO.ui.MenuOptionWidget( {
					data: 'e',
					label: 'Fifth'
				} )
			]
		}
	} ),
	// Trigger an event when an item in the menu is selected.
	itemSelected = function(){
		console.log( dropDown.getData() );
	};
	// Tell the menu to call itemSelected() on select
	dropDown.getMenu().on('select', itemSelected);
    // Append the button to the content area of the page
    $('.genderSelect').replaceWith(dropDown.$element);
});