Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1430482
mw.widgets.ToggleSwitchWidget.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
mw.widgets.ToggleSwitchWidget.js
View Options
/*!
* MediaWiki Widgets - ToggleSwitchWidget class.
*
* @copyright 2017 MediaWiki Widgets Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
(
function
()
{
/**
* @classdesc Add an invisible checkbox element which will be used to submit the value.
*
* @class
* @extends OO.ui.ToggleSwitchWidget
*
* @constructor
* @description Create an instance of `mw.widgets.ToggleSwitchWidget`.
* @param {Object} [config] Configuration options
* @param {string} [config.name] Name of input to submit results (when used in HTML forms)
*/
mw
.
widgets
.
ToggleSwitchWidget
=
function
MwWidgetsToggleWidget
(
config
)
{
// Parent constructor
mw
.
widgets
.
ToggleSwitchWidget
.
super
.
call
(
this
,
Object
.
assign
(
{},
config
,
{}
)
);
if
(
'name'
in
config
)
{
// Use this instead of <input type="hidden">, because hidden inputs do not have separate
// 'value' and 'defaultValue' properties.
this
.
$hiddenInput
=
$
(
'<input>'
)
.
addClass
(
'oo-ui-element-hidden'
)
.
attr
(
'type'
,
'checkbox'
)
.
attr
(
'name'
,
config
.
name
)
.
attr
(
'id'
,
config
.
inputId
)
.
appendTo
(
this
.
$element
);
// Update with preset values
this
.
updateHiddenInput
();
// Set the default value (it might be different from just being empty)
this
.
$hiddenInput
.
prop
(
'defaultChecked'
,
this
.
isSelected
()
);
}
// Events
// When list of selected tags changes, update hidden input
this
.
connect
(
this
,
{
change
:
'updateHiddenInput'
}
);
};
/* Setup */
OO
.
inheritClass
(
mw
.
widgets
.
ToggleSwitchWidget
,
OO
.
ui
.
ToggleSwitchWidget
);
mw
.
widgets
.
ToggleSwitchWidget
.
static
.
tagName
=
'span'
;
/* Methods */
mw
.
widgets
.
ToggleSwitchWidget
.
prototype
.
isSelected
=
function
()
{
return
mw
.
widgets
.
ToggleSwitchWidget
.
super
.
prototype
.
getValue
.
call
(
this
);
};
mw
.
widgets
.
ToggleSwitchWidget
.
prototype
.
getValue
=
function
()
{
return
this
.
isSelected
()
?
'1'
:
'0'
;
};
/**
* If used inside HTML form, then update hiddenInput.
*
* @private
*/
mw
.
widgets
.
ToggleSwitchWidget
.
prototype
.
updateHiddenInput
=
function
()
{
if
(
'$hiddenInput'
in
this
)
{
this
.
$hiddenInput
.
prop
(
'checked'
,
this
.
isSelected
()
);
// Trigger a 'change' event as if a user edited the text
// (it is not triggered when changing the value from JS code).
this
.
$hiddenInput
.
trigger
(
'change'
);
}
};
}()
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, May 16, 18:48 (5 h, 37 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
08/80/7b85e668c5021639f1722284540d
Default Alt Text
mw.widgets.ToggleSwitchWidget.js (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment