2 * Utility functions for jazzing up HTMLForm elements
6 // Fade or snap depending on argument
7 $.fn.goIn = function( instantToggle ) {
8 if ( typeof instantToggle != 'undefined' && instantToggle === true ) {
11 return $(this).stop( true, true ).fadeIn();
13 $.fn.goOut = function( instantToggle ) {
14 if ( typeof instantToggle != 'undefined' && instantToggle === true ) {
15 return $(this).hide();
17 return $(this).stop( true, true ).fadeOut();
21 * Bind a function to the jQuery object via live(), and also immediately trigger
22 * the function on the objects with an 'instant' paramter set to true
23 * @param callback function taking one paramter, which is Bool true when the event
24 * is called immediately, and the EventArgs object when triggered from an event
26 $.fn.liveAndTestAtStart = function( callback ){
28 .live( 'change', callback )
29 .each( function( index, element ){
30 callback.call( this, true );
37 // animate the SelectOrOther fields, to only show the text field when
38 // 'other' is selected
39 $( '.mw-htmlform-select-or-other' ).liveAndTestAtStart( function( instant ) {
40 var $other = $( '#' + $(this).attr( 'id' ) + '-other' );
41 $other = $other.add( $other.siblings( 'br' ) );
42 if ( $(this).val() == 'other' ) {
43 $other.goIn( instant );
45 $other.goOut( instant );