* Pass around parser options instead of users and made some parser options consistenc...
[mediawiki.git] / resources / mediawiki / mediawiki.htmlform.js
blob0b8cf835a64496acc2b970bd6642fa294a57a682
1 /**
2  * Utility functions for jazzing up HTMLForm elements
3  */
4 ( function( $ ) { 
6 // Fade or snap depending on argument
7 $.fn.goIn = function( instantToggle ) {
8         if ( typeof instantToggle != 'undefined' && instantToggle === true ) {
9                 return $(this).show();
10         }
11         return $(this).stop( true, true ).fadeIn();
13 $.fn.goOut = function( instantToggle ) {
14         if ( typeof instantToggle != 'undefined' && instantToggle === true ) {
15                 return $(this).hide();
16         }
17         return $(this).stop( true, true ).fadeOut();
20 /**
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
25  */
26 $.fn.liveAndTestAtStart = function( callback ){
27         $(this)
28                 .live( 'change', callback )
29                 .each( function( index, element ){
30                         callback.call( this, true );
31                 } );
34 // Document ready:
35 $( function() {
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 );
44                 } else {
45                         $other.goOut( instant );
46                 }
47         });
49 });
52 })( jQuery );