Alright, IE7 is fixed by r89613. IE6 stays problematic, for some reason it contains...
[mediawiki.git] / resources / mediawiki / mediawiki.htmlform.js
blob1a6acd6f1dbd9b8e7ab8e353c7542bdac8f57932
1 /**
2  * Utility functions for jazzing up HTMLForm elements
3  */
4 ( function( $ ) { 
6 /**
7  * jQuery plugin to fade or snap to visible state.
8  *
9  * @param boolean instantToggle (optional)
10  * @return jQuery
11  */
12 $.fn.goIn = function( instantToggle ) {
13         if ( instantToggle !== undefined && instantToggle === true ) {
14                 return $(this).show();
15         }
16         return $(this).stop( true, true ).fadeIn();
19 /**
20  * jQuery plugin to fade or snap to hiding state.
21  *
22  * @param boolean instantToggle (optional)
23  * @return jQuery
24  */
25 $.fn.goOut = function( instantToggle ) {
26         if ( instantToggle !== undefined && instantToggle === true ) {
27                 return $(this).hide();
28         }
29         return $(this).stop( true, true ).fadeOut();
32 /**
33  * Bind a function to the jQuery object via live(), and also immediately trigger
34  * the function on the objects with an 'instant' paramter set to true
35  * @param callback function taking one paramter, which is Bool true when the event
36  *     is called immediately, and the EventArgs object when triggered from an event
37  */
38 $.fn.liveAndTestAtStart = function( callback ){
39         $(this)
40                 .live( 'change', callback )
41                 .each( function( index, element ){
42                         callback.call( this, true );
43                 } );
46 // Document ready:
47 $( function() {
49         // Animate the SelectOrOther fields, to only show the text field when
50         // 'other' is selected.
51         $( '.mw-htmlform-select-or-other' ).liveAndTestAtStart( function( instant ) {
52                 var $other = $( '#' + $(this).attr( 'id' ) + '-other' );
53                 $other = $other.add( $other.siblings( 'br' ) );
54                 if ( $(this).val() === 'other' ) {
55                         $other.goIn( instant );
56                 } else {
57                         $other.goOut( instant );
58                 }
59         });
61 });
64 })( jQuery );