r67566 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67565‎ | r67566 | r67567 >
Date:21:09, 7 June 2010
Author:tparscal
Status:ok
Tags:
Comment:
Fixed issues in r67548 to do with declaring vars nicely and using appendTo rather than remove and then appendTo
Modified paths:
  • /trunk/extensions/UsabilityInitiative/Vector/Modules/CollapsibleNav/CollapsibleNav.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/Vector/Vector.combined.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/Vector/Vector.combined.min.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/Vector/Vector.hooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/Vector/Modules/CollapsibleNav/CollapsibleNav.js
@@ -29,14 +29,16 @@
3030 if ( !$j.wikiEditor.isSupported( mod ) ) {
3131 return true;
3232 }
 33+ // Fallback to old version
 34+ var version = 1;
3335 // Allow new version override
3436 if ( wgCollapsibleNavForceNewVersion == true ) {
35 - var version = 2;
 37+ version = 2;
3638 } else {
3739 // Make bucket testing optional
3840 if ( wgCollapsibleNavBucketTest == true ) {
3941 // This is be determined randomly, and then stored in a cookie
40 - var version = $j.cookie( 'vector-nav-pref-version' );
 42+ version = $j.cookie( 'vector-nav-pref-version' );
4143 // If the cookie didn't exist, or the value is out of range, generate a new one and save it
4244 if ( version == null ) {
4345 console.log( version );
@@ -44,9 +46,6 @@
4547 version = Math.round( Math.random() + 1 );
4648 $j.cookie( 'vector-nav-pref-version', version, { 'expires': 30, 'path': '/' } );
4749 }
48 - } else {
49 - // Fallback to old version
50 - var version = 1;
5150 }
5251 }
5352 // Language portal splitting feature (if it's turned on)
@@ -101,7 +100,6 @@
102101 $j.cookie( 'accept-language', langs.join( ',' ), { 'path': '/', 'expires': 30 } );
103102 } );
104103 }
105 -
106104 // Shortcuts to the two lists
107105 $primary = $j( '#p-lang ul.primary' );
108106 $secondary = $j( '#p-lang ul.secondary' );
@@ -115,7 +113,7 @@
116114 $link = $secondary.find( '.interwiki-' + languages[i] );
117115 if ( $link.length ) {
118116 if ( count++ < limit ) {
119 - $link.remove().appendTo( $primary );
 117+ $link.appendTo( $primary );
120118 } else {
121119 break;
122120 }
@@ -126,7 +124,7 @@
127125 if ( count < limit ) {
128126 $secondary.children().each( function() {
129127 if ( count++ < limit ) {
130 - $j(this).remove().appendTo( $primary );
 128+ $j(this).appendTo( $primary );
131129 } else {
132130 return false;
133131 }
@@ -138,7 +136,7 @@
139137 } else {
140138 $j( '#p-lang' ).after( '<div id="p-lang-more" class="portal"><h5></h5><div class="body"></div></div>' );
141139 $j( '#p-lang-more h5' ).text( mw.usability.getMsg( 'vector-collapsiblenav-more' ) );
142 - $secondary.remove().appendTo( $j( '#p-lang-more div.body' ) );
 140+ $secondary.appendTo( $j( '#p-lang-more div.body' ) );
143141 }
144142 // Always show the primary interwiki language portal
145143 $j( '#p-lang' ).addClass( 'persistent' );
Index: trunk/extensions/UsabilityInitiative/Vector/Vector.hooks.php
@@ -12,7 +12,7 @@
1313
1414 static $scripts = array(
1515 'raw' => array(
16 - array( 'src' => 'Modules/CollapsibleNav/CollapsibleNav.js', 'version' => 18 ),
 16+ array( 'src' => 'Modules/CollapsibleNav/CollapsibleNav.js', 'version' => 19 ),
1717 array( 'src' => 'Modules/CollapsibleTabs/CollapsibleTabs.js', 'version' => 8 ),
1818 array( 'src' => 'Modules/ExpandableSearch/ExpandableSearch.js', 'version' => 3 ),
1919 array( 'src' => 'Modules/EditWarning/EditWarning.js', 'version' => 8 ),
@@ -20,10 +20,10 @@
2121 array( 'src' => 'Modules/SimpleSearch/SimpleSearch.js', 'version' => 15 ),
2222 ),
2323 'combined' => array(
24 - array( 'src' => 'Vector.combined.js', 'version' => 41 ),
 24+ array( 'src' => 'Vector.combined.js', 'version' => 42 ),
2525 ),
2626 'minified' => array(
27 - array( 'src' => 'Vector.combined.min.js', 'version' => 41 ),
 27+ array( 'src' => 'Vector.combined.min.js', 'version' => 42 ),
2828 ),
2929 );
3030 static $modules = array(
Index: trunk/extensions/UsabilityInitiative/Vector/Vector.combined.js
@@ -29,14 +29,16 @@
3030 if ( !$j.wikiEditor.isSupported( mod ) ) {
3131 return true;
3232 }
 33+ // Fallback to old version
 34+ var version = 1;
3335 // Allow new version override
3436 if ( wgCollapsibleNavForceNewVersion == true ) {
35 - var version = 2;
 37+ version = 2;
3638 } else {
3739 // Make bucket testing optional
3840 if ( wgCollapsibleNavBucketTest == true ) {
3941 // This is be determined randomly, and then stored in a cookie
40 - var version = $j.cookie( 'vector-nav-pref-version' );
 42+ version = $j.cookie( 'vector-nav-pref-version' );
4143 // If the cookie didn't exist, or the value is out of range, generate a new one and save it
4244 if ( version == null ) {
4345 console.log( version );
@@ -44,9 +46,6 @@
4547 version = Math.round( Math.random() + 1 );
4648 $j.cookie( 'vector-nav-pref-version', version, { 'expires': 30, 'path': '/' } );
4749 }
48 - } else {
49 - // Fallback to old version
50 - var version = 1;
5150 }
5251 }
5352 // Language portal splitting feature (if it's turned on)
@@ -101,7 +100,6 @@
102101 $j.cookie( 'accept-language', langs.join( ',' ), { 'path': '/', 'expires': 30 } );
103102 } );
104103 }
105 -
106104 // Shortcuts to the two lists
107105 $primary = $j( '#p-lang ul.primary' );
108106 $secondary = $j( '#p-lang ul.secondary' );
@@ -115,7 +113,7 @@
116114 $link = $secondary.find( '.interwiki-' + languages[i] );
117115 if ( $link.length ) {
118116 if ( count++ < limit ) {
119 - $link.remove().appendTo( $primary );
 117+ $link.appendTo( $primary );
120118 } else {
121119 break;
122120 }
@@ -126,7 +124,7 @@
127125 if ( count < limit ) {
128126 $secondary.children().each( function() {
129127 if ( count++ < limit ) {
130 - $j(this).remove().appendTo( $primary );
 128+ $j(this).appendTo( $primary );
131129 } else {
132130 return false;
133131 }
@@ -138,7 +136,7 @@
139137 } else {
140138 $j( '#p-lang' ).after( '<div id="p-lang-more" class="portal"><h5></h5><div class="body"></div></div>' );
141139 $j( '#p-lang-more h5' ).text( mw.usability.getMsg( 'vector-collapsiblenav-more' ) );
142 - $secondary.remove().appendTo( $j( '#p-lang-more div.body' ) );
 140+ $secondary.appendTo( $j( '#p-lang-more div.body' ) );
143141 }
144142 // Always show the primary interwiki language portal
145143 $j( '#p-lang' ).addClass( 'persistent' );
Index: trunk/extensions/UsabilityInitiative/Vector/Vector.combined.min.js
@@ -1,13 +1,13 @@
22
33 $j(document).ready(function(){if(!wgVectorEnabledModules.collapsiblenav){return true;}
44 var mod={'browsers':{'ltr':{'opera':[['>=',9.6]],'konqueror':[['>=',4.0]],'blackberry':false,'ipod':false,'iphone':false},'rtl':{'opera':[['>=',9.6]],'konqueror':[['>=',4.0]],'blackberry':false,'ipod':false,'iphone':false}}};if(!$j.wikiEditor.isSupported(mod)){return true;}
5 -if(wgCollapsibleNavForceNewVersion==true){var version=2;}else{if(wgCollapsibleNavBucketTest==true){var version=$j.cookie('vector-nav-pref-version');if(version==null){console.log(version);version=Math.round(Math.random()+1);$j.cookie('vector-nav-pref-version',version,{'expires':30,'path':'/'});}}else{var version=1;}}
 5+var version=1;if(wgCollapsibleNavForceNewVersion==true){version=2;}else{if(wgCollapsibleNavBucketTest==true){version=$j.cookie('vector-nav-pref-version');if(version==null){console.log(version);version=Math.round(Math.random()+1);$j.cookie('vector-nav-pref-version',version,{'expires':30,'path':'/'});}}}
66 if(version==2){var limit=5;var threshold=3;$j('#p-lang ul').addClass('secondary').before('<ul class="primary"></ul>');var languages=['en','fr','de','es','pt','it','ru','ja','nl','pl','zh','sv','ar','tr','uk','fi','no','ca','ro','hu','ksh','id','he','cs','vi','ko','sr','fa','da','eo','sk','th','lt','vo','bg','sl','hr','hi','et','mk','simple','new','ms','nn','gl','el','eu','ka','tl','bn','lv','ml','bs','te','la','az','sh','war','br','is','mr','be-x-old','sq','cy','lb','ta','zh-classical','an','jv','ht','oc','bpy','ceb','ur','zh-yue','pms','scn','be','roa-rup','qu','af','sw','nds','fy','lmo','wa','ku','hy','su','yi','io','os','ga','ast','nap','vec','gu','cv','bat-smg','kn','uz','zh-min-nan','si','als','yo','li','gan','arz','sah','tt','bar','gd','tg','kk','pam','hsb','roa-tara','nah','mn','vls','gv','mi','am','ia','co','ne','fo','nds-nl','glk','mt','ang','wuu','dv','km','sco','bcl','mg','my','diq','tk','szl','ug','fiu-vro','sc','rm','nrm','ps','nv','hif','bo','se','sa','pnb','map-bms','lad','lij','crh','fur','kw','to','pa','jbo','ba','ilo','csb','wo','xal','krc','ckb','pag','ln','frp','mzn','ce','nov','kv','eml','gn','ky','pdc','lo','haw','mhr','dsb','stq','tpi','arc','hak','ie','so','bh','ext','mwl','sd','ig','myv','ay','iu','na','cu','pi','kl','ty','lbe','ab','got','sm','as','mo','ee','zea','av','ace','kg','bm','cdo','cbk-zam','kab','om','chr','pap','udm','ks','zu','rmy','cr','ch','st','ik','mdf','kaa','aa','fj','srn','tet','or','pnt','bug','ss','ts','pcd','pih','za','sg','lg','bxr','xh','ak','ha','bi','ve','tn','ff','dz','ti','ki','ny','rw','chy','tw','sn','tum','ng','rn','mh','ii','cho','hz','kr','ho','mus','kj'];var acceptLangCookie=$j.cookie('accept-language');if(acceptLangCookie!=null){if(acceptLangCookie!=''){languages=acceptLangCookie.split(',').concat(languages);}}else{$j.getJSON(wgScriptPath+'/api.php?action=query&meta=userinfo&uiprop=acceptlang&format=json',function(data){var langs=[];if(typeof data.query!='undefined'&&typeof data.query.userinfo!='undefined'&&typeof data.query.userinfo.acceptlang!='undefined'){for(var j=0;j<data.query.userinfo.acceptlang.length;j++){if(data.query.userinfo.acceptlang[j].q!=0){langs.push(data.query.userinfo.acceptlang[j]['*']);}}}
77 $j.cookie('accept-language',langs.join(','),{'path':'/','expires':30});});}
88 $primary=$j('#p-lang ul.primary');$secondary=$j('#p-lang ul.secondary');if($secondary.children().length<limit+threshold){limit+=threshold;}
9 -var count=0;for(var i=0;i<languages.length;i++){$link=$secondary.find('.interwiki-'+languages[i]);if($link.length){if(count++<limit){$link.remove().appendTo($primary);}else{break;}}}
10 -if(count<limit){$secondary.children().each(function(){if(count++<limit){$j(this).remove().appendTo($primary);}else{return false;}});}
11 -if($secondary.children().length==0){$secondary.remove();}else{$j('#p-lang').after('<div id="p-lang-more" class="portal"><h5></h5><div class="body"></div></div>');$j('#p-lang-more h5').text(mw.usability.getMsg('vector-collapsiblenav-more'));$secondary.remove().appendTo($j('#p-lang-more div.body'));}
 9+var count=0;for(var i=0;i<languages.length;i++){$link=$secondary.find('.interwiki-'+languages[i]);if($link.length){if(count++<limit){$link.appendTo($primary);}else{break;}}}
 10+if(count<limit){$secondary.children().each(function(){if(count++<limit){$j(this).appendTo($primary);}else{return false;}});}
 11+if($secondary.children().length==0){$secondary.remove();}else{$j('#p-lang').after('<div id="p-lang-more" class="portal"><h5></h5><div class="body"></div></div>');$j('#p-lang-more h5').text(mw.usability.getMsg('vector-collapsiblenav-more'));$secondary.appendTo($j('#p-lang-more div.body'));}
1212 $j('#p-lang').addClass('persistent');}
1313 $j('#panel > div.portal:first').addClass('first persistent');$j('#panel').addClass('collapsible-nav');$j('#panel > div.portal:not(.persistent)').each(function(i){var id=$j(this).attr('id');var state=$j.cookie('vector-nav-'+id);if(state=='true'||(state==null&&i<1)||version==1&&id=='p-lang'){$j(this).addClass('expanded').find('div.body').show();}else{$j(this).addClass('collapsed');}
1414 if(state!=null){$j.cookie('vector-nav-'+$j(this).attr('id'),state,{'expires':30,'path':'/'});}});function toggle($element){$j.cookie('vector-nav-'+$element.parent().attr('id'),$element.parent().is('.collapsed'),{'expires':30,'path':'/'});$element.parent().toggleClass('expanded').toggleClass('collapsed').find('div.body').slideToggle('fast');}

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r67548Changed collapsible navigation to split languages into two portals, one that'...tparscal17:49, 7 June 2010

Status & tagging log