MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
Line 19: | Line 19: | ||
// Create an OOUI dropdown | // Create an OOUI dropdown | ||
var dropDown = new OO.ui.DropdownWidget( { | var dropDown = new OO.ui.DropdownWidget( { | ||
label: ' | label: 'person', | ||
// The menu is composed within the DropdownWidget | // The menu is composed within the DropdownWidget | ||
menu: { | menu: { | ||
items: [ | items: [ | ||
new OO.ui.MenuOptionWidget( { | new OO.ui.MenuOptionWidget( { | ||
data: 'man', | data: 'man', | ||
Line 38: | Line 34: | ||
} | } | ||
} ); | } ); | ||
// Select even handler | |||
// | |||
dropDown.getMenu().on('select', function (item) { | dropDown.getMenu().on('select', function (item) { | ||
console.log( item.getData() ); | console.log( item.getData() ); |
Revision as of 01:20, 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: 'person', // The menu is composed within the DropdownWidget menu: { items: [ new OO.ui.MenuOptionWidget( { data: 'man', label: 'man', } ), new OO.ui.MenuOptionWidget( { data: 'woman', label: 'woman' } ) ] } } ); // Select even handler dropDown.getMenu().on('select', function (item) { console.log( item.getData() ); }); // Append the button to the content area of the page $('.genderSelect').replaceWith(dropDown.$element); });