MediaWiki r83309 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r83308‎ | r83309 (on ViewVC)‎ | r83310 >
Date:19:00, 5 March 2011
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
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.
Modified paths:

Diff [purge]

Index: trunk/phase3/resources/jquery/jquery.makeCollapsible.js
@@ -35,8 +35,8 @@
3636 // action must be string with 'expand' or 'collapse'
3737 return;
3838 }
39 - if ( $defaultToggle && !$defaultToggle.jquery ) {
40 - // is optional, but if passed must be an instance of jQuery
 39+ if ( typeof $defaultToggle !== 'undefined' && !($defaultToggle instanceof jQuery) ) {
 40+ // is optional (may be undefined), but if passed it must be an instance of jQuery and nothing else
4141 return;
4242 }
4343 var $containers = null;
@@ -49,9 +49,9 @@
5050 // Slide doens't work with tables, but fade does as of jQuery 1.1.3
5151 // http://stackoverflow.com/questions/467336#920480
5252 $containers = $collapsible.find( '>tbody>tr' );
53 - if ( $defaultToggle && $defaultToggle.jquery ) {
 53+ if ( typeof $defaultToggle !== 'undefined' && ($defaultToggle instanceof jQuery) ) {
5454 // Exclude tablerow containing togglelink
55 - $containers.not( $defaultToggle.parent().parent() ).stop(true, true).fadeOut();
 55+ $containers.not( $defaultToggle.closest( 'tr' ) ).stop(true, true).fadeOut();
5656 } else {
5757 if ( instantHide ) {
5858 $containers.hide();
@@ -309,7 +309,7 @@
310310 // The collapsible element could have multiple togglers
311311 // To toggle the initial state only click one of them (ie. the first one, eq(0) )
312312 // Else it would go like: hide,show,hide,show for each toggle link.
313 - toggleElement( $that, 'collapse', null, /* instantHide = */ true );
 313+ toggleElement( $that, 'collapse', $toggleLink.eq(0), /* instantHide = */ true );
314314 $toggleLink.eq(0).click();
315315 }
316316 } );

Follow-up revisions

Rev.Commit summaryAuthorDate
r87743jquery.makeCollapsible improvements...krinkle17:21, 9 May 2011

Past revisions this follows-up on

Rev.Commit summaryAuthorDate
r82471Improving jquery.makeCollapsible & small fixed mw.util...krinkle17:46, 19 February 2011

Comments

#Comment by DieBuche (talk | contribs)   08:27, 9 May 2011

There's still one

 if ( $defaultToggle && $defaultToggle.jquery ) 

left in L52, 103 & 112. Since you evaluate that a lot, why not check it once and set a flag?

Also, a minor typo in L49 (doens't)

#Comment by Krinkle (talk | contribs)   17:55, 9 May 2011

Thanks, I've done a better implementation in r87743.

After the initial check $defaultToggle will be set to null or left as a valid jQuery instance. After that a simple if() statement will be sufficient.

Thanks, prolly faster now too.

Status & tagging log

  • 18:33, 7 March 2011 Catrope (talk | contribs) changed the status of r83309 [removed: new added: ok]