Fix bug in makeCollapsible.
authorKrinkle <krinkle@users.mediawiki.org>
Sat, 5 Mar 2011 19:00:19 +0000 (19:00 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Sat, 5 Mar 2011 19:00:19 +0000 (19:00 +0000)
* The instantHide implementation (added in r82471) didn't cover the case where a table is collapsed by default, it needs to pass the toggle to the function so that the row it is in can be excluded.
* The bug was found by user Helder.wiki, also reproducable on the demonstration page (I guess it was cached for everyone, since nobody noticed?)
* Demonstration page has been refreshed and all tests are passed now.

resources/jquery/jquery.makeCollapsible.js

index 17e7e0a..786d847 100644 (file)
@@ -35,8 +35,8 @@ $.fn.makeCollapsible = function() {
                                        // action must be string with 'expand' or 'collapse'
                                        return;
                                }
-                               if ( $defaultToggle && !$defaultToggle.jquery ) {
-                                       // is optional, but if passed must be an instance of jQuery
+                               if ( typeof $defaultToggle !== 'undefined' && !($defaultToggle instanceof jQuery) ) {
+                                       // is optional (may be undefined), but if passed it must be an instance of jQuery and nothing else
                                        return;
                                }
                                var $containers = null;
@@ -49,9 +49,9 @@ $.fn.makeCollapsible = function() {
                                                // Slide doens't work with tables, but fade does as of jQuery 1.1.3
                                                // http://stackoverflow.com/questions/467336#920480
                                                $containers = $collapsible.find( '>tbody>tr' );
-                                               if ( $defaultToggle && $defaultToggle.jquery ) { 
+                                               if ( typeof $defaultToggle !== 'undefined' && ($defaultToggle instanceof jQuery) ) { 
                                                        // Exclude tablerow containing togglelink
-                                                       $containers.not( $defaultToggle.parent().parent() ).stop(true, true).fadeOut();
+                                                       $containers.not( $defaultToggle.closest( 'tr' ) ).stop(true, true).fadeOut();
                                                } else {
                                                        if ( instantHide ) {    
                                                                $containers.hide();
@@ -309,7 +309,7 @@ $.fn.makeCollapsible = function() {
                        // The collapsible element could have multiple togglers
                        // To toggle the initial state only click one of them (ie. the first one, eq(0) )
                        // Else it would go like: hide,show,hide,show for each toggle link.
-                       toggleElement( $that, 'collapse', null, /* instantHide = */ true );
+                       toggleElement( $that, 'collapse', $toggleLink.eq(0), /* instantHide = */ true );
                        $toggleLink.eq(0).click();
                }
        } );