Fixing minor issues in mw.htmlform
authorKrinkle <krinkle@users.mediawiki.org>
Thu, 10 Mar 2011 17:38:21 +0000 (17:38 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Thu, 10 Mar 2011 17:38:21 +0000 (17:38 +0000)
* jQuery should be mapped to $ before using it. $ should not be implied as global in-core. ("return $(this).show()" was using $ as global)
** added wrapper and replaced jQuery with $.
* Missing semicolon

resources/mediawiki/mediawiki.htmlform.js

index d4265e0..4692e9e 100644 (file)
@@ -1,19 +1,20 @@
 /**
  * Utility functions for jazzing up HTMLForm elements
  */
+( function( $ ) { 
 
 // Fade or snap depending on argument
-jQuery.fn.goIn = function( instantToggle ) {
+$.fn.goIn = function( instantToggle ) {
        if ( typeof instantToggle != 'undefined' && instantToggle === true ) {
                return $(this).show();
        }
-       return jQuery(this).stop( true, true ).fadeIn();
+       return $(this).stop( true, true ).fadeIn();
 };
-jQuery.fn.goOut = function( instantToggle ) {
+$.fn.goOut = function( instantToggle ) {
        if ( typeof instantToggle != 'undefined' && instantToggle === true ) {
                return $(this).hide();
        }
-       return jQuery(this).stop( true, true ).fadeOut();
+       return $(this).stop( true, true ).fadeOut();
 };
 
 /**
@@ -22,19 +23,20 @@ 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 ){
                        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 ){
+       $( '.mw-htmlform-select-or-other' ).liveAndTestAtStart( function( instant ) {
                var $other = $( '#' + $(this).attr( 'id' ) + '-other' );
                if ( $(this).val() == 'other' ) {
                        $other.goIn( instant );
@@ -43,4 +45,7 @@ jQuery( function( $ ) {
                }
        });
 
-});
\ No newline at end of file
+});
+
+
+})( jQuery );
\ No newline at end of file