r79604 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79603‎ | r79604 | r79605 >
Date:21:52, 4 January 2011
Author:krinkle
Status:deferred
Tags:
Comment:
can't cache from the beginning since the toggles haven't been created yet at that point.
* leaving it out of the click() scope so that it is cached, but populated after first click instead of when running the script. Small performance gain :-)
* moving the code to add the allToggle-button after the script that adds the normal toggles to make sure all are matched
Modified paths:
  • /trunk/extensions/Translate/js/translate.langstats.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/js/translate.langstats.js
@@ -12,31 +12,6 @@
1313 // Only do stuff if there are any meta group rows on this pages
1414 if ( $metaRows.size() ) {
1515
16 - var $allChildRows = $( 'tr[data-parentgroups]', $translateTable ),
17 - $allToggles = $( '.mw-sp-langstats-toggle', $translateTable ),
18 - $toggleAllButton = $( '<span class="mw-sp-langstats-expander">[</span>' ).append( $( '<a href="#" onclick="return false;">' ).text( mw.msg( 'translate-langstats-expandall' ) ) ).append( ']' ).click( function() {
19 - var $el = $( this );
20 - // Switch the state and toggle the rows
21 - // and update the local toggles too
22 - if ( $el.hasClass( 'mw-sp-langstats-expander' ) ) {
23 - $allChildRows.show();
24 - $el.add( $allToggles ).removeClass( 'mw-sp-langstats-expander' ).addClass( 'mw-sp-langstats-collapser' )
25 - $el.find( '> a' ).text( mw.msg( 'translate-langstats-collapseall' ) );
26 - $allToggles.find( '> a' ).text( mw.msg( 'translate-langstats-collapse' ) );
27 - } else {
28 - $allChildRows.hide();
29 - $el.add( $allToggles ).addClass( 'mw-sp-langstats-expander' ).removeClass( 'mw-sp-langstats-collapser' )
30 - $el.find( '> a' ).text( mw.msg( 'translate-langstats-expandall' ) );
31 - $allToggles.find( '> a' ).text( mw.msg( 'translate-langstats-expand' ) );
32 - }
33 - } );
34 -
35 - // Initially hide them
36 - $allChildRows.hide();
37 -
38 - // Add the toggle-all button above the table
39 - $( '<p class="mw-sp-langstats-toggleall"></p>' ).append( $toggleAllButton ).insertBefore( $translateTable );
40 -
4116 $metaRows.each( function() {
4217 // Get info and cache selectors
4318 var $thisGroup = $(this),
@@ -65,5 +40,32 @@
6641 $thisGroup.find( ' > td:first' ).append( $toggler );
6742 }
6843 } );
 44+
 45+ // Create, bind and append the toggle-all button
 46+ var $allChildRows = $( 'tr[data-parentgroups]', $translateTable ),
 47+ $allToggles_cache = null,
 48+ $toggleAllButton = $( '<span class="mw-sp-langstats-expander">[</span>' ).append( $( '<a href="#" onclick="return false;">' ).text( mw.msg( 'translate-langstats-expandall' ) ) ).append( ']' ).click( function() {
 49+ var $el = $( this ),
 50+ $allToggles = !!$allToggles_cache ? $allToggles_cache : $( '.mw-sp-langstats-toggle', $translateTable ),
 51+ // Switch the state and toggle the rows
 52+ // and update the local toggles too
 53+ if ( $el.hasClass( 'mw-sp-langstats-expander' ) ) {
 54+ $allChildRows.show();
 55+ $el.add( $allToggles ).removeClass( 'mw-sp-langstats-expander' ).addClass( 'mw-sp-langstats-collapser' )
 56+ $el.find( '> a' ).text( mw.msg( 'translate-langstats-collapseall' ) );
 57+ $allToggles.find( '> a' ).text( mw.msg( 'translate-langstats-collapse' ) );
 58+ } else {
 59+ $allChildRows.hide();
 60+ $el.add( $allToggles ).addClass( 'mw-sp-langstats-expander' ).removeClass( 'mw-sp-langstats-collapser' )
 61+ $el.find( '> a' ).text( mw.msg( 'translate-langstats-expandall' ) );
 62+ $allToggles.find( '> a' ).text( mw.msg( 'translate-langstats-expand' ) );
 63+ }
 64+ } );
 65+
 66+ // Initially hide them
 67+ $allChildRows.hide();
 68+
 69+ // Add the toggle-all button above the table
 70+ $( '<p class="mw-sp-langstats-toggleall"></p>' ).append( $toggleAllButton ).insertBefore( $translateTable );
6971 }
7072 } );
\ No newline at end of file

Status & tagging log