| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
( function () { |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
mw.widgets.ToggleSwitchWidget = function MwWidgetsToggleWidget( config ) { |
| 20 |
|
| 21 |
mw.widgets.ToggleSwitchWidget.super.call( this, Object.assign( {}, config, {} ) ); |
| 22 |
|
| 23 |
if ( 'name' in config ) { |
| 24 |
|
| 25 |
|
| 26 |
this.$hiddenInput = $( '<input>' ) |
| 27 |
.addClass( 'oo-ui-element-hidden' ) |
| 28 |
.attr( 'type', 'checkbox' ) |
| 29 |
.attr( 'name', config.name ) |
| 30 |
.attr( 'id', config.inputId ) |
| 31 |
.appendTo( this.$element ); |
| 32 |
|
| 33 |
this.updateHiddenInput(); |
| 34 |
|
| 35 |
this.$hiddenInput.prop( 'defaultChecked', this.isSelected() ); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
this.connect( this, { |
| 41 |
change: 'updateHiddenInput' |
| 42 |
} ); |
| 43 |
}; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
OO.inheritClass( mw.widgets.ToggleSwitchWidget, OO.ui.ToggleSwitchWidget ); |
| 48 |
|
| 49 |
mw.widgets.ToggleSwitchWidget.static.tagName = 'span'; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
mw.widgets.ToggleSwitchWidget.prototype.isSelected = function () { |
| 54 |
return mw.widgets.ToggleSwitchWidget.super.prototype.getValue.call( this ); |
| 55 |
}; |
| 56 |
|
| 57 |
mw.widgets.ToggleSwitchWidget.prototype.getValue = function () { |
| 58 |
return this.isSelected() ? '1' : '0'; |
| 59 |
}; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
mw.widgets.ToggleSwitchWidget.prototype.updateHiddenInput = function () { |
| 67 |
if ( '$hiddenInput' in this ) { |
| 68 |
this.$hiddenInput.prop( 'checked', this.isSelected() ); |
| 69 |
|
| 70 |
|
| 71 |
this.$hiddenInput.trigger( 'change' ); |
| 72 |
} |
| 73 |
}; |
| 74 |
|
| 75 |
}() ); |