Removing the last occurrences/mentions of mw.loader.go
[lhc/web/wiklou.git] / resources / mediawiki / mediawiki.htmlform.js
1 /**
2 * Utility functions for jazzing up HTMLForm elements
3 */
4 ( function( $ ) {
5
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();
12 };
13 $.fn.goOut = function( instantToggle ) {
14 if ( typeof instantToggle != 'undefined' && instantToggle === true ) {
15 return $(this).hide();
16 }
17 return $(this).stop( true, true ).fadeOut();
18 };
19
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 } );
32 };
33
34 // Document ready:
35 $( function() {
36
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 });
48
49 });
50
51
52 })( jQuery );