From: Krinkle Date: Sat, 5 Mar 2011 19:00:19 +0000 (+0000) Subject: Fix bug in makeCollapsible. X-Git-Tag: 1.31.0-rc.0~31622 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=27b5c803d7b8d4be316b7329e5363188a2ae0694;p=lhc%2Fweb%2Fwiklou.git Fix bug in makeCollapsible. * 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. --- diff --git a/resources/jquery/jquery.makeCollapsible.js b/resources/jquery/jquery.makeCollapsible.js index 17e7e0a64a..786d8471b5 100644 --- a/resources/jquery/jquery.makeCollapsible.js +++ b/resources/jquery/jquery.makeCollapsible.js @@ -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(); } } );