2 * HTMLForm enhancements:
3 * Animate the SelectOrOther fields, to only show the text field when 'other' is selected.
7 * jQuery plugin to fade or snap to visible state.
9 * @param {boolean} [instantToggle=false]
12 $.fn.goIn = function ( instantToggle ) {
13 if ( instantToggle === true ) {
16 return this.stop( true, true ).fadeIn();
20 * jQuery plugin to fade or snap to hiding state.
22 * @param {boolean} [instantToggle=false]
25 $.fn.goOut = function ( instantToggle ) {
26 if ( instantToggle === true ) {
29 return this.stop( true, true ).fadeOut();
32 mw.hook( 'htmlform.enhance' ).add( ( $root ) => {
35 * @param {boolean|jQuery.Event} instant
37 function handleSelectOrOther( instant ) {
38 const $select = $( this ).find( 'select' );
39 let $other = $( this ).find( 'input' );
40 $other = $other.add( $other.siblings( 'br' ) );
41 if ( $select.val() === 'other' ) {
42 $other.goIn( instant );
44 $other.goOut( instant );
48 // Exclude OOUI widgets, since they're infused and SelectWithInputWidget
49 // is responsible for this logic.
51 .on( 'change', '.mw-htmlform-select-or-other:not(.oo-ui-widget)', handleSelectOrOther )
52 .find( '.mw-htmlform-select-or-other:not(.oo-ui-widget)' )
54 handleSelectOrOther.call( this, true );