MediaWiki:Gadget-idle-util.js

From Idle Clans wiki
Revision as of 19:04, 10 June 2024 by Uraxys (talk | contribs)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.

			/**
			 * Create a button widget with the given label and flags.
			 *
			 * @param   {string} [label]
			 *          Optionally, the label for the button.
			 * @param   {string[]} [flags]
			 *          Optionally, the flags for the button.
			 *
			 * @returns {OO.ui.ButtonWidget}
			 *          The button widget.
			 */
			button: function(label, flags) {
				label = label || "Button";
				flags = flags || [];
				return new OO.ui.ButtonWidget({ label: label, flags: flags });
			},

			/**
			 * Create a button input widget with the given label and flags.
			 *
			 * @param   {string} [label]
			 *          Optionally, the label for the button.
			 * @param   {string[]} [flags]
			 *          Optionally, the flags for the button.
			 *
			 * @returns {OO.ui.ButtonInputWidget}
			 *          The button input widget.
			 */
			buttonInput: function(label, flags) {
				label = label || "Button";
				flags = flags || [];
				return new OO.ui.ButtonInputWidget({ label: label, flags: flags });
			},

			 /**
			 * 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 || {});