MediaWiki:Gadget-idle-util.js: Difference between revisions
From Idle Clans wiki
(Created page with "//") |
No edit summary |
||
Line 1: | Line 1: | ||
// | /** | ||
* Create a checkbox widget with an optional label and selected | |||
* state. | |||
* | |||
* @param {boolean} [selected] | |||
* Optionally, whether the checkbox is selected. | |||
* @param {string} [label] | |||
* Optionally, the label for the checkbox. | |||
* | |||
* @returns {OO.ui.CheckboxInputWidget|OO.ui.FieldLayout} | |||
* The checkbox widget, or a field layout with the checkbox | |||
* and the label. | |||
*/ | |||
checkbox: function(selected, label) { | |||
var checkbox = new OO.ui.CheckboxInputWidget({ selected: selected }); | |||
if (label !== undefined && typeof label === 'string') { | |||
return new OO.ui.FieldLayout(checkbox, { label: label, align: 'inline' }); | |||
} | |||
return checkbox; | |||
}, | |||
/** | |||
* Create a toggle switch widget with an optional initial state. | |||
* | |||
* @param {boolean} [switched] | |||
* Optionally, whether the switch is on. | |||
* | |||
* @returns {OO.ui.ToggleSwitchWidget} | |||
* The toggle switch widget. | |||
*/ | |||
switch: function(switched) { | |||
switched = switched || false; | |||
return new OO.ui.ToggleSwitchWidget({ value: switched }); | |||
} | |||
} | |||
} | |||
})(window.jQuery, window.mw, window.idleClans = window.idleClans || {}); |
Revision as of 19:03, 10 June 2024
/** * Create a checkbox widget with an optional label and selected * state. * * @param {boolean} [selected] * Optionally, whether the checkbox is selected. * @param {string} [label] * Optionally, the label for the checkbox. * * @returns {OO.ui.CheckboxInputWidget|OO.ui.FieldLayout} * The checkbox widget, or a field layout with the checkbox * and the label. */ checkbox: function(selected, label) { var checkbox = new OO.ui.CheckboxInputWidget({ selected: selected }); if (label !== undefined && typeof label === 'string') { return new OO.ui.FieldLayout(checkbox, { label: label, align: 'inline' }); } return checkbox; }, /** * Create a toggle switch widget with an optional initial state. * * @param {boolean} [switched] * Optionally, whether the switch is on. * * @returns {OO.ui.ToggleSwitchWidget} * The toggle switch widget. */ switch: function(switched) { switched = switched || false; return new OO.ui.ToggleSwitchWidget({ value: switched }); } } } })(window.jQuery, window.mw, window.idleClans = window.idleClans || {});