merging latest master
[lhc/web/wiklou.git] / resources / mediawiki / mediawiki.htmlform.js
index d4265e0..df62105 100644 (file)
@@ -1,19 +1,32 @@
 /**
  * Utility functions for jazzing up HTMLForm elements
  */
+( function ( $ ) {
 
-// Fade or snap depending on argument
-jQuery.fn.goIn = function( instantToggle ) {
-       if ( typeof instantToggle != 'undefined' && instantToggle === true ) {
+/**
+ * jQuery plugin to fade or snap to visible state.
+ *
+ * @param boolean instantToggle (optional)
+ * @return jQuery
+ */
+$.fn.goIn = function ( instantToggle ) {
+       if ( instantToggle === true ) {
                return $(this).show();
        }
-       return jQuery(this).stop( true, true ).fadeIn();
+       return $(this).stop( true, true ).fadeIn();
 };
-jQuery.fn.goOut = function( instantToggle ) {
-       if ( typeof instantToggle != 'undefined' && instantToggle === true ) {
+
+/**
+ * jQuery plugin to fade or snap to hiding state.
+ *
+ * @param boolean instantToggle (optional)
+ * @return jQuery
+ */
+$.fn.goOut = function ( instantToggle ) {
+       if ( instantToggle === true ) {
                return $(this).hide();
        }
-       return jQuery(this).stop( true, true ).fadeOut();
+       return $(this).stop( true, true ).fadeOut();
 };
 
 /**
@@ -22,25 +35,30 @@ jQuery.fn.goOut = function( instantToggle ) {
  * @param callback function taking one paramter, which is Bool true when the event
  *     is called immediately, and the EventArgs object when triggered from an event
  */
-jQuery.fn.liveAndTestAtStart = function( callback ){
+$.fn.liveAndTestAtStart = function ( callback ){
        $(this)
                .live( 'change', callback )
-               .each( function( index, element ){
+               .each( function ( index, element ){
                        callback.call( this, true );
                } );
-}
+};
 
-jQuery( function( $ ) {
+// Document ready:
+$( function () {
 
-       // animate the SelectOrOther fields, to only show the text field when
-       // 'other' is selected
-       $( '.mw-htmlform-select-or-other' ).liveAndTestAtStart( function( instant ){
+       // Animate the SelectOrOther fields, to only show the text field when
+       // 'other' is selected.
+       $( '.mw-htmlform-select-or-other' ).liveAndTestAtStart( function ( instant ) {
                var $other = $( '#' + $(this).attr( 'id' ) + '-other' );
-               if ( $(this).val() == 'other' ) {
+               $other = $other.add( $other.siblings( 'br' ) );
+               if ( $(this).val() === 'other' ) {
                        $other.goIn( instant );
                } else {
                        $other.goOut( instant );
                }
        });
 
-});
\ No newline at end of file
+});
+
+
+}( jQuery ) );