r67559 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67558‎ | r67559 | r67560 >
Date:19:40, 7 June 2010
Author:tparscal
Status:resolved (Comments)
Tags:
Comment:
Added bucket testing for collapsible nav (50% of people get the old version), and also a threshold which makes sure that you don't end up with a "more languages" portal with 1 or 2 links it in. The threshold is set to 3 right now, but it's configurable.
Modified paths:
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php (modified) (history)
  • /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)
  • /trunk/extensions/UsabilityInitiative/Vector/Vector.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/css/combined.css (modified) (history)
  • /trunk/extensions/UsabilityInitiative/css/combined.min.css (modified) (history)
  • /trunk/extensions/UsabilityInitiative/css/vector.collapsibleNav.css (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/css/vector.collapsibleNav.css
@@ -50,6 +50,7 @@
5151 #panel.collapsible-nav div.persistent h5 {
5252 background: none !important;
5353 padding-left: 0.7em;
 54+ cursor: default;
5455 }
5556 #panel.collapsible-nav div.portal div.body ul li {
5657 padding: 0.25em 0;
Index: trunk/extensions/UsabilityInitiative/css/combined.css
@@ -117,6 +117,7 @@
118118 #panel.collapsible-nav div.persistent h5 {
119119 background: none !important;
120120 padding-left: 0.7em;
 121+ cursor: default;
121122 }
122123 #panel.collapsible-nav div.portal div.body ul li {
123124 padding: 0.25em 0;
Index: trunk/extensions/UsabilityInitiative/css/combined.min.css
@@ -115,6 +115,7 @@
116116 #panel.collapsible-nav div.persistent h5{
117117 background:none !important;
118118 padding-left:0.7em;
 119+cursor:default;
119120 }
120121 #panel.collapsible-nav div.portal div.body ul li{
121122 padding:0.25em 0;
Index: trunk/extensions/UsabilityInitiative/Vector/Modules/CollapsibleNav/CollapsibleNav.js
@@ -29,20 +29,108 @@
3030 if ( !$j.wikiEditor.isSupported( mod ) ) {
3131 return true;
3232 }
33 - // Create a new portal for overflow languages
34 - $j( '#p-lang' )
35 - .after( '<div id="p-lang-more" class="portal"><h5></h5><div class="body"><ul></ul></div></div>' )
36 - .addClass( 'persistent' );
37 - $j( '#panel > div.portal:first' )
38 - .addClass( 'first persistent' );
39 - $j( '#p-lang-more h5' ).text( mw.usability.getMsg( 'vector-collapsiblenav-more' ) );
 33+ // Allow new version override
 34+ if ( wgCollapsibleNavForceNewVersion == true ) {
 35+ var version = 2;
 36+ } else {
 37+ // Make bucket testing optional
 38+ if ( wgCollapsibleNavBucketTest == true ) {
 39+ // This is be determined randomly, and then stored in a cookie
 40+ var version = $j.cookie( 'vector-nav-pref-version' );
 41+ // If the cookie didn't exist, or the value is out of range, generate a new one and save it
 42+ if ( version == null ) {
 43+ console.log( version );
 44+ // 50% of the people will get the new version
 45+ version = Math.round( Math.random() + 1 );
 46+ $j.cookie( 'vector-nav-pref-version', version, { 'expires': 30, 'path': '/' } );
 47+ }
 48+ } else {
 49+ // Fallback to old version
 50+ var version = 1;
 51+ }
 52+ }
 53+ // Language portal splitting feature (if it's turned on)
 54+ if ( version == 2 ) {
 55+ // How many links to show in the primary languages portal
 56+ var limit = 5;
 57+ // How many links there must be in the secondary portal to justify having a secondary portal
 58+ var threshold = 3;
 59+ // Make the interwiki language links list a secondary list, and create a new list before it as primary list
 60+ $j( '#p-lang ul' ).addClass( 'secondary' ).before( '<ul class="primary"></ul>' );
 61+ // This is a list of languages in order of Wikipedia project size. This is the lowest fallback for choosing
 62+ // which links to show in the primary list. Ideally the browser's accept-language headers should steer this
 63+ // list, and we should fallback on a site configured (MediaWiki:Common.js) list of prefered languages.
 64+ var languages = [
 65+ 'en', 'fr', 'de', 'es', 'pt', 'it', 'ru', 'ja', 'nl', 'pl', 'zh', 'sv', 'ar', 'tr', 'uk', 'fi', 'no', 'ca',
 66+ 'ro', 'hu', 'ksh', 'id', 'he', 'cs', 'vi', 'ko', 'sr', 'fa', 'da', 'eo', 'sk', 'th', 'lt', 'vo', 'bg',
 67+ 'sl', 'hr', 'hi', 'et', 'mk', 'simple', 'new', 'ms', 'nn', 'gl', 'el', 'eu', 'ka', 'tl', 'bn', 'lv', 'ml',
 68+ 'bs', 'te', 'la', 'az', 'sh', 'war', 'br', 'is', 'mr', 'be-x-old', 'sq', 'cy', 'lb', 'ta', 'zh-classical',
 69+ 'an', 'jv', 'ht', 'oc', 'bpy', 'ceb', 'ur', 'zh-yue', 'pms', 'scn', 'be', 'roa-rup', 'qu', 'af', 'sw',
 70+ 'nds', 'fy', 'lmo', 'wa', 'ku', 'hy', 'su', 'yi', 'io', 'os', 'ga', 'ast', 'nap', 'vec', 'gu', 'cv',
 71+ 'bat-smg', 'kn', 'uz', 'zh-min-nan', 'si', 'als', 'yo', 'li', 'gan', 'arz', 'sah', 'tt', 'bar', 'gd', 'tg',
 72+ 'kk', 'pam', 'hsb', 'roa-tara', 'nah', 'mn', 'vls', 'gv', 'mi', 'am', 'ia', 'co', 'ne', 'fo', 'nds-nl',
 73+ 'glk', 'mt', 'ang', 'wuu', 'dv', 'km', 'sco', 'bcl', 'mg', 'my', 'diq', 'tk', 'szl', 'ug', 'fiu-vro', 'sc',
 74+ 'rm', 'nrm', 'ps', 'nv', 'hif', 'bo', 'se', 'sa', 'pnb', 'map-bms', 'lad', 'lij', 'crh', 'fur', 'kw', 'to',
 75+ 'pa', 'jbo', 'ba', 'ilo', 'csb', 'wo', 'xal', 'krc', 'ckb', 'pag', 'ln', 'frp', 'mzn', 'ce', 'nov', 'kv',
 76+ 'eml', 'gn', 'ky', 'pdc', 'lo', 'haw', 'mhr', 'dsb', 'stq', 'tpi', 'arc', 'hak', 'ie', 'so', 'bh', 'ext',
 77+ 'mwl', 'sd', 'ig', 'myv', 'ay', 'iu', 'na', 'cu', 'pi', 'kl', 'ty', 'lbe', 'ab', 'got', 'sm', 'as', 'mo',
 78+ 'ee', 'zea', 'av', 'ace', 'kg', 'bm', 'cdo', 'cbk-zam', 'kab', 'om', 'chr', 'pap', 'udm', 'ks', 'zu', 'rmy',
 79+ 'cr', 'ch', 'st', 'ik', 'mdf', 'kaa', 'aa', 'fj', 'srn', 'tet', 'or', 'pnt', 'bug', 'ss', 'ts', 'pcd',
 80+ 'pih', 'za', 'sg', 'lg', 'bxr', 'xh', 'ak', 'ha', 'bi', 've', 'tn', 'ff', 'dz', 'ti', 'ki', 'ny', 'rw',
 81+ 'chy', 'tw', 'sn', 'tum', 'ng', 'rn', 'mh', 'ii', 'cho', 'hz', 'kr', 'ho', 'mus', 'kj'
 82+ ];
 83+ // Shortcuts to the two lists
 84+ $primary = $j( '#p-lang ul.primary' );
 85+ $secondary = $j( '#p-lang ul.secondary' );
 86+ // Adjust the limit based on the threshold
 87+ if ( $secondary.children().length < limit + threshold ) {
 88+ limit += threshold;
 89+ }
 90+ // Move up to 5 of the links into the primary list, based on the priorities set forth in the languages list
 91+ var count = 0;
 92+ for ( var i = 0; i < languages.length; i++ ) {
 93+ $link = $secondary.find( '.interwiki-' + languages[i] );
 94+ if ( $link.length ) {
 95+ if ( count++ < limit ) {
 96+ $link.remove().appendTo( $primary );
 97+ } else {
 98+ break;
 99+ }
 100+ }
 101+ }
 102+ // If there's still links in the secondary list and we havn't filled the primary list to it's limit yet, move links
 103+ // into the primary list in order of appearance
 104+ if ( count < limit ) {
 105+ $secondary.children().each( function() {
 106+ if ( count++ < limit ) {
 107+ $j(this).remove().appendTo( $primary );
 108+ } else {
 109+ return false;
 110+ }
 111+ } );
 112+ }
 113+ // Hide the more portal if it's now empty, otherwise make the list into it's very own portal
 114+ if ( $secondary.children().length == 0 ) {
 115+ $secondary.remove();
 116+ } else {
 117+ $j( '#p-lang' ).after( '<div id="p-lang-more" class="portal"><h5></h5><div class="body"></div></div>' );
 118+ $j( '#p-lang-more h5' ).text( mw.usability.getMsg( 'vector-collapsiblenav-more' ) );
 119+ $secondary.remove().appendTo( $j( '#p-lang-more div.body' ) );
 120+ }
 121+ // Always show the primary interwiki language portal
 122+ $j( '#p-lang' ).addClass( 'persistent' );
 123+ }
 124+ // Always show the first portal
 125+ $j( '#panel > div.portal:first' ).addClass( 'first persistent' );
40126 // Apply a class to the entire panel to activate styles
41127 $j( '#panel' ).addClass( 'collapsible-nav' );
42128 // Use cookie data to restore preferences of what to show and hide
43129 $j( '#panel > div.portal:not(.persistent)' )
44130 .each( function( i ) {
45 - var state = $j.cookie( 'vector-nav-' + $j(this).attr( 'id' ) );
46 - if ( state == 'true' || ( state == null && i < 1 ) ) {
 131+ var id = $j(this).attr( 'id' );
 132+ var state = $j.cookie( 'vector-nav-' + id );
 133+ // In the case that we are not showing the new version, let's show the languages by default
 134+ if ( state == 'true' || ( state == null && i < 1 ) || version == 1 && id == 'p-lang' ) {
47135 $j(this)
48136 .addClass( 'expanded' )
49137 .find( 'div.body' )
@@ -52,13 +140,16 @@
53141 }
54142 // Re-save cookie
55143 if ( state != null ) {
56 - $j.cookie( 'vector-nav-' + $j(this).attr( 'id' ), state, { expires: 30, path: '/' } );
 144+ $j.cookie( 'vector-nav-' + $j(this).attr( 'id' ), state, { 'expires': 30, 'path': '/' } );
57145 }
58146 } );
59 -
60147 // Use the same function for all navigation headings - don't repeat yourself
61148 function toggle( $element ) {
62 - $j.cookie( 'vector-nav-' + $element.parent().attr( 'id' ), $element.parent().is( '.collapsed' ), { expires: 30, path: '/' } );
 149+ $j.cookie(
 150+ 'vector-nav-' + $element.parent().attr( 'id' ),
 151+ $element.parent().is( '.collapsed' ),
 152+ { 'expires': 30, 'path': '/' }
 153+ );
63154 $element
64155 .parent()
65156 .toggleClass( 'expanded' )
@@ -96,47 +187,4 @@
97188 $j(this).blur();
98189 return false;
99190 } );
100 - // Split the language lists, showing the first 5 in the original portal and all others in the overflow portal
101 - var limit = 5;
102 - var count = 0;
103 - $more = $j( '#p-lang-more ul' );
104 - $j( '#p-lang li' ).each( function() {
105 - if ( count++ >= limit ) {
106 - $j(this).remove().appendTo( $more );
107 - }
108 - } );
109 - /*
110 - * It may be clever to use something like this to steer which languages get shown by default...
111 - var wikipediaProjectSizes = {
112 - 'en': 1, 'fr': 2, 'de': 3, 'es': 4, 'pt': 5, 'it': 6, 'ru': 7, 'ja': 8, 'nl': 9, 'pl': 10, 'zh': 11, 'sv': 12,
113 - 'ar': 13, 'tr': 14, 'uk': 15, 'fi': 16, 'no': 17, 'ca': 18, 'ro': 19, 'hu': 20, 'ksh': 21, 'id': 22, 'he': 23,
114 - 'cs': 24, 'vi': 25, 'ko': 26, 'sr': 27, 'fa': 28, 'da': 29, 'eo': 30, 'sk': 31, 'th': 32, 'lt': 33, 'vo': 34,
115 - 'bg': 35, 'sl': 36, 'hr': 37, 'hi': 38, 'et': 39, 'mk': 40, 'simple': 41, 'new': 42, 'ms': 43, 'nn': 44,
116 - 'gl': 45, 'el': 46, 'eu': 47, 'ka': 48, 'tl': 49, 'bn': 50, 'lv': 51, 'ml': 52, 'bs': 53, 'te': 54, 'la': 55,
117 - 'az': 56, 'sh': 57, 'war': 58, 'br': 59, 'is': 60, 'mr': 61, 'be-x-old': 62, 'sq': 63, 'cy': 64, 'lb': 65,
118 - 'ta': 66, 'zh-classical': 67, 'an': 68, 'jv': 69, 'ht': 70, 'oc': 71, 'bpy': 72, 'ceb': 73, 'ur': 74,
119 - 'zh-yue': 75, 'pms': 76, 'scn': 77, 'be': 78, 'roa-rup': 79, 'qu': 80, 'af': 81, 'sw': 82, 'nds': 83, 'fy': 84,
120 - 'lmo': 85, 'wa': 86, 'ku': 87, 'hy': 88, 'su': 89, 'yi': 90, 'io': 91, 'os': 92, 'ga': 93, 'ast': 94, 'nap': 95,
121 - 'vec': 96, 'gu': 97, 'cv': 98, 'bat-smg': 99, 'kn': 100, 'uz': 101, 'zh-min-nan': 102, 'si': 103, 'als': 104,
122 - 'yo': 105, 'li': 106, 'gan': 107, 'arz': 108, 'sah': 109, 'tt': 110, 'bar': 111, 'gd': 112, 'tg': 113,
123 - 'kk': 114, 'pam': 115, 'hsb': 116, 'roa-tara': 117, 'nah': 118, 'mn': 119, 'vls': 120, 'gv': 121, 'mi': 122,
124 - 'am': 123, 'ia': 124, 'co': 125, 'ne': 126, 'fo': 127, 'nds-nl': 128, 'glk': 129, 'mt': 130, 'ang': 131,
125 - 'wuu': 132, 'dv': 133, 'km': 134, 'sco': 135, 'bcl': 136, 'mg': 137, 'my': 138, 'diq': 139, 'tk': 140,
126 - 'szl': 141, 'ug': 142, 'fiu-vro': 143, 'sc': 144, 'rm': 145, 'nrm': 146, 'ps': 147, 'nv': 148, 'hif': 149,
127 - 'bo': 150, 'se': 151, 'sa': 152, 'pnb': 153, 'map-bms': 154, 'lad': 155, 'lij': 156, 'crh': 157, 'fur': 158,
128 - 'kw': 159, 'to': 160, 'pa': 161, 'jbo': 162, 'ba': 163, 'ilo': 164, 'csb': 165, 'wo': 166, 'xal': 167,
129 - 'krc': 168, 'ckb': 169, 'pag': 170, 'ln': 171, 'frp': 172, 'mzn': 173, 'ce': 174, 'nov': 175, 'kv': 176,
130 - 'eml': 177, 'gn': 178, 'ky': 179, 'pdc': 180, 'lo': 181, 'haw': 182, 'mhr': 183, 'dsb': 184, 'stq': 185,
131 - 'tpi': 186, 'arc': 187, 'hak': 188, 'ie': 189, 'so': 190, 'bh': 191, 'ext': 192, 'mwl': 193, 'sd': 194,
132 - 'ig': 195, 'myv': 196, 'ay': 197, 'iu': 198, 'na': 199, 'cu': 200, 'pi': 201, 'kl': 202, 'ty': 203, 'lbe': 204,
133 - 'ab': 205, 'got': 206, 'sm': 207, 'as': 208, 'mo': 209, 'ee': 210, 'zea': 211, 'av': 212, 'ace': 213, 'kg': 214,
134 - 'bm': 215, 'cdo': 216, 'cbk-zam': 217, 'kab': 218, 'om': 219, 'chr': 220, 'pap': 221, 'udm': 222, 'ks': 223,
135 - 'zu': 224, 'rmy': 225, 'cr': 226, 'ch': 227, 'st': 228, 'ik': 229, 'mdf': 230, 'kaa': 231, 'aa': 232, 'fj': 233,
136 - 'srn': 234, 'tet': 235, 'or': 236, 'pnt': 237, 'bug': 238, 'ss': 239, 'ts': 240, 'pcd': 241, 'pih': 242,
137 - 'za': 243, 'sg': 244, 'lg': 245, 'bxr': 246, 'xh': 247, 'ak': 248, 'ha': 249, 'bi': 250, 've': 251, 'tn': 252,
138 - 'ff': 253, 'dz': 254, 'ti': 255, 'ki': 256, 'ny': 257, 'rw': 258, 'chy': 259, 'tw': 260, 'sn': 261, 'tum': 262,
139 - 'ng': 263, 'rn': 264, 'mh': 265, 'ii': 266, 'cho': 267, 'hz': 268, 'kr': 269, 'ho': 270, 'mus': 271, 'kj': 272
140 - };
141 - */
142 - */
143191 } );
Index: trunk/extensions/UsabilityInitiative/Vector/Vector.php
@@ -30,6 +30,11 @@
3131
3232 /* Setup */
3333
 34+// Enable bucket testing for new version of collapsible nav
 35+$wgCollapsibleNavBucketTest = false;
 36+// Force the new version
 37+$wgCollapsibleNavForceNewVersion = false;
 38+
3439 // Credits
3540 $wgExtensionCredits['other'][] = array(
3641 'path' => __FILE__,
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' => 16 ),
 16+ array( 'src' => 'Modules/CollapsibleNav/CollapsibleNav.js', 'version' => 17 ),
1717 array( 'src' => 'Modules/CollapsibleTabs/CollapsibleTabs.js', 'version' => 8 ),
1818 array( 'src' => 'Modules/ExpandableSearch/ExpandableSearch.js', 'version' => 2 ),
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' => 38 ),
 24+ array( 'src' => 'Vector.combined.js', 'version' => 39 ),
2525 ),
2626 'minified' => array(
27 - array( 'src' => 'Vector.combined.min.js', 'version' => 38 ),
 27+ array( 'src' => 'Vector.combined.min.js', 'version' => 39 ),
2828 ),
2929 );
3030 static $modules = array(
@@ -42,6 +42,10 @@
4343 'messages' => array(
4444 'vector-collapsiblenav-more',
4545 ),
 46+ 'variables' => array(
 47+ 'wgCollapsibleNavBucketTest',
 48+ 'wgCollapsibleNavForceNewVersion',
 49+ ),
4650 ),
4751 'collapsibletabs' => array(
4852 ),
Index: trunk/extensions/UsabilityInitiative/Vector/Vector.combined.js
@@ -29,18 +29,108 @@
3030 if ( !$j.wikiEditor.isSupported( mod ) ) {
3131 return true;
3232 }
33 -
 33+ // Allow new version override
 34+ if ( wgCollapsibleNavForceNewVersion == true ) {
 35+ var version = 2;
 36+ } else {
 37+ // Make bucket testing optional
 38+ if ( wgCollapsibleNavBucketTest == true ) {
 39+ // This is be determined randomly, and then stored in a cookie
 40+ var version = $j.cookie( 'vector-nav-pref-version' );
 41+ // If the cookie didn't exist, or the value is out of range, generate a new one and save it
 42+ if ( version == null ) {
 43+ console.log( version );
 44+ // 50% of the people will get the new version
 45+ version = Math.round( Math.random() + 1 );
 46+ $j.cookie( 'vector-nav-pref-version', version, { 'expires': 30, 'path': '/' } );
 47+ }
 48+ } else {
 49+ // Fallback to old version
 50+ var version = 1;
 51+ }
 52+ }
 53+ // Language portal splitting feature (if it's turned on)
 54+ if ( version == 2 ) {
 55+ // How many links to show in the primary languages portal
 56+ var limit = 5;
 57+ // How many links there must be in the secondary portal to justify having a secondary portal
 58+ var threshold = 3;
 59+ // Make the interwiki language links list a secondary list, and create a new list before it as primary list
 60+ $j( '#p-lang ul' ).addClass( 'secondary' ).before( '<ul class="primary"></ul>' );
 61+ // This is a list of languages in order of Wikipedia project size. This is the lowest fallback for choosing
 62+ // which links to show in the primary list. Ideally the browser's accept-language headers should steer this
 63+ // list, and we should fallback on a site configured (MediaWiki:Common.js) list of prefered languages.
 64+ var languages = [
 65+ 'en', 'fr', 'de', 'es', 'pt', 'it', 'ru', 'ja', 'nl', 'pl', 'zh', 'sv', 'ar', 'tr', 'uk', 'fi', 'no', 'ca',
 66+ 'ro', 'hu', 'ksh', 'id', 'he', 'cs', 'vi', 'ko', 'sr', 'fa', 'da', 'eo', 'sk', 'th', 'lt', 'vo', 'bg',
 67+ 'sl', 'hr', 'hi', 'et', 'mk', 'simple', 'new', 'ms', 'nn', 'gl', 'el', 'eu', 'ka', 'tl', 'bn', 'lv', 'ml',
 68+ 'bs', 'te', 'la', 'az', 'sh', 'war', 'br', 'is', 'mr', 'be-x-old', 'sq', 'cy', 'lb', 'ta', 'zh-classical',
 69+ 'an', 'jv', 'ht', 'oc', 'bpy', 'ceb', 'ur', 'zh-yue', 'pms', 'scn', 'be', 'roa-rup', 'qu', 'af', 'sw',
 70+ 'nds', 'fy', 'lmo', 'wa', 'ku', 'hy', 'su', 'yi', 'io', 'os', 'ga', 'ast', 'nap', 'vec', 'gu', 'cv',
 71+ 'bat-smg', 'kn', 'uz', 'zh-min-nan', 'si', 'als', 'yo', 'li', 'gan', 'arz', 'sah', 'tt', 'bar', 'gd', 'tg',
 72+ 'kk', 'pam', 'hsb', 'roa-tara', 'nah', 'mn', 'vls', 'gv', 'mi', 'am', 'ia', 'co', 'ne', 'fo', 'nds-nl',
 73+ 'glk', 'mt', 'ang', 'wuu', 'dv', 'km', 'sco', 'bcl', 'mg', 'my', 'diq', 'tk', 'szl', 'ug', 'fiu-vro', 'sc',
 74+ 'rm', 'nrm', 'ps', 'nv', 'hif', 'bo', 'se', 'sa', 'pnb', 'map-bms', 'lad', 'lij', 'crh', 'fur', 'kw', 'to',
 75+ 'pa', 'jbo', 'ba', 'ilo', 'csb', 'wo', 'xal', 'krc', 'ckb', 'pag', 'ln', 'frp', 'mzn', 'ce', 'nov', 'kv',
 76+ 'eml', 'gn', 'ky', 'pdc', 'lo', 'haw', 'mhr', 'dsb', 'stq', 'tpi', 'arc', 'hak', 'ie', 'so', 'bh', 'ext',
 77+ 'mwl', 'sd', 'ig', 'myv', 'ay', 'iu', 'na', 'cu', 'pi', 'kl', 'ty', 'lbe', 'ab', 'got', 'sm', 'as', 'mo',
 78+ 'ee', 'zea', 'av', 'ace', 'kg', 'bm', 'cdo', 'cbk-zam', 'kab', 'om', 'chr', 'pap', 'udm', 'ks', 'zu', 'rmy',
 79+ 'cr', 'ch', 'st', 'ik', 'mdf', 'kaa', 'aa', 'fj', 'srn', 'tet', 'or', 'pnt', 'bug', 'ss', 'ts', 'pcd',
 80+ 'pih', 'za', 'sg', 'lg', 'bxr', 'xh', 'ak', 'ha', 'bi', 've', 'tn', 'ff', 'dz', 'ti', 'ki', 'ny', 'rw',
 81+ 'chy', 'tw', 'sn', 'tum', 'ng', 'rn', 'mh', 'ii', 'cho', 'hz', 'kr', 'ho', 'mus', 'kj'
 82+ ];
 83+ // Shortcuts to the two lists
 84+ $primary = $j( '#p-lang ul.primary' );
 85+ $secondary = $j( '#p-lang ul.secondary' );
 86+ // Adjust the limit based on the threshold
 87+ if ( $secondary.children().length < limit + threshold ) {
 88+ limit += threshold;
 89+ }
 90+ // Move up to 5 of the links into the primary list, based on the priorities set forth in the languages list
 91+ var count = 0;
 92+ for ( var i = 0; i < languages.length; i++ ) {
 93+ $link = $secondary.find( '.interwiki-' + languages[i] );
 94+ if ( $link.length ) {
 95+ if ( count++ < limit ) {
 96+ $link.remove().appendTo( $primary );
 97+ } else {
 98+ break;
 99+ }
 100+ }
 101+ }
 102+ // If there's still links in the secondary list and we havn't filled the primary list to it's limit yet, move links
 103+ // into the primary list in order of appearance
 104+ if ( count < limit ) {
 105+ $secondary.children().each( function() {
 106+ if ( count++ < limit ) {
 107+ $j(this).remove().appendTo( $primary );
 108+ } else {
 109+ return false;
 110+ }
 111+ } );
 112+ }
 113+ // Hide the more portal if it's now empty, otherwise make the list into it's very own portal
 114+ if ( $secondary.children().length == 0 ) {
 115+ $secondary.remove();
 116+ } else {
 117+ $j( '#p-lang' ).after( '<div id="p-lang-more" class="portal"><h5></h5><div class="body"></div></div>' );
 118+ $j( '#p-lang-more h5' ).text( mw.usability.getMsg( 'vector-collapsiblenav-more' ) );
 119+ $secondary.remove().appendTo( $j( '#p-lang-more div.body' ) );
 120+ }
 121+ // Always show the primary interwiki language portal
 122+ $j( '#p-lang' ).addClass( 'persistent' );
 123+ }
 124+ // Always show the first portal
 125+ $j( '#panel > div.portal:first' ).addClass( 'first persistent' );
 126+ // Apply a class to the entire panel to activate styles
34127 $j( '#panel' ).addClass( 'collapsible-nav' );
35 - // Always show the first portal
36 - $j( '#panel > div.portal:first' )
37 - .addClass( 'expanded' )
38 - .find( 'div.body' )
39 - .show();
40 - // Remember which portals to hide and show
41 - $j( '#panel > div.portal:not(:first)' )
 128+ // Use cookie data to restore preferences of what to show and hide
 129+ $j( '#panel > div.portal:not(.persistent)' )
42130 .each( function( i ) {
43 - var state = $j.cookie( 'vector-nav-' + $j(this).attr( 'id' ) );
44 - if ( state == 'true' || ( state == null && i < 1 ) ) {
 131+ var id = $j(this).attr( 'id' );
 132+ var state = $j.cookie( 'vector-nav-' + id );
 133+ // In the case that we are not showing the new version, let's show the languages by default
 134+ if ( state == 'true' || ( state == null && i < 1 ) || version == 1 && id == 'p-lang' ) {
45135 $j(this)
46136 .addClass( 'expanded' )
47137 .find( 'div.body' )
@@ -50,12 +140,16 @@
51141 }
52142 // Re-save cookie
53143 if ( state != null ) {
54 - $j.cookie( 'vector-nav-' + $j(this).attr( 'id' ), state, { expires: 30, path: '/' } );
 144+ $j.cookie( 'vector-nav-' + $j(this).attr( 'id' ), state, { 'expires': 30, 'path': '/' } );
55145 }
56146 } );
57147 // Use the same function for all navigation headings - don't repeat yourself
58148 function toggle( $element ) {
59 - $j.cookie( 'vector-nav-' + $element.parent().attr( 'id' ), $element.parent().is( '.collapsed' ), { expires: 30, path: '/' } );
 149+ $j.cookie(
 150+ 'vector-nav-' + $element.parent().attr( 'id' ),
 151+ $element.parent().is( '.collapsed' ),
 152+ { 'expires': 30, 'path': '/' }
 153+ );
60154 $element
61155 .parent()
62156 .toggleClass( 'expanded' )
@@ -63,7 +157,7 @@
64158 .find( 'div.body' )
65159 .slideToggle( 'fast' );
66160 }
67 - var $headings = $j( '#panel > div.portal > h5' );
 161+ var $headings = $j( '#panel > div.portal:not(.persistent) > h5' );
68162 /** Copy-pasted from jquery.wikiEditor.dialogs - :( */
69163 // Find the highest tabindex in use
70164 var maxTI = 0;
Index: trunk/extensions/UsabilityInitiative/Vector/Vector.combined.min.js
@@ -1,9 +1,15 @@
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 -$j('#panel').addClass('collapsible-nav');$j('#panel > div.portal:first').addClass('expanded').find('div.body').show();$j('#panel > div.portal:not(:first)').each(function(i){var state=$j.cookie('vector-nav-'+$j(this).attr('id'));if(state=='true'||(state==null&&i<1)){$j(this).addClass('expanded').find('div.body').show();}else{$j(this).addClass('collapsed');}
6 -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');}
7 -var $headings=$j('#panel > div.portal > h5');var maxTI=0;$j('[tabindex]').each(function(){var ti=parseInt($j(this).attr('tabindex'));if(ti>maxTI)
 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;}}
 6+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'];$primary=$j('#p-lang ul.primary');$secondary=$j('#p-lang ul.secondary');if($secondary.children().length<limit+threshold){limit+=threshold;}
 7+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;}}}
 8+if(count<limit){$secondary.children().each(function(){if(count++<limit){$j(this).remove().appendTo($primary);}else{return false;}});}
 9+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'));}
 10+$j('#p-lang').addClass('persistent');}
 11+$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');}
 12+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');}
 13+var $headings=$j('#panel > div.portal:not(.persistent) > h5');var maxTI=0;$j('[tabindex]').each(function(){var ti=parseInt($j(this).attr('tabindex'));if(ti>maxTI)
814 maxTI=ti;});var tabIndex=maxTI+1;$j('#searchInput').attr('tabindex',tabIndex++);$headings.each(function(){$j(this).attr('tabindex',tabIndex++);});$headings.keydown(function(event){if(event.which==13||event.which==32){toggle($j(this));}}).mousedown(function(){toggle($j(this));$j(this).blur();return false;});});$j(document).ready(function(){if(!wgVectorEnabledModules.collapsibletabs){return true;}
915 var rtl=$j('body').is('.rtl');$j.collapsibleTabs.moveToCollapsed=function(ele){var $moving=$j(ele);$j.collapsibleTabs.getSettings($j($j.collapsibleTabs.getSettings($moving).expandedContainer)).shifting=true;var data=$j.collapsibleTabs.getSettings($moving);var target=data.collapsedContainer;$moving.css("position","relative").css((rtl?'left':'right'),0).animate({width:'1px'},"normal",function(){$j(this).hide();$j('<span class="placeholder" style="display:none;"></span>').insertAfter(this);$j(this).remove().prependTo(target).data('collapsibleTabsSettings',data);$j(this).attr('style','display:list-item;');$j.collapsibleTabs.getSettings($j($j.collapsibleTabs.getSettings($j(ele)).expandedContainer)).shifting=false;$j.collapsibleTabs.handleResize();});};$j.collapsibleTabs.moveToExpanded=function(ele){var $moving=$j(ele);$j.collapsibleTabs.getSettings($j($j.collapsibleTabs.getSettings($moving).expandedContainer)).shifting=true;var data=$j.collapsibleTabs.getSettings($moving);var $target=$j(data.expandedContainer).find('span.placeholder:first');var expandedWidth=data.expandedWidth;$moving.css("position","relative").css((rtl?'right':'left'),0).css('width','1px');$target.replaceWith($moving.remove().css('width','1px').data('collapsibleTabsSettings',data).animate({width:expandedWidth+"px"},"normal",function(){$j(this).attr('style','display:block;');$j.collapsibleTabs.getSettings($j($j.collapsibleTabs.getSettings($moving).expandedContainer)).shifting=false;$j.collapsibleTabs.handleResize();}));};$j('#p-views ul').bind("beforeTabCollapse",function(){if($j('#p-cactions').css('display')=='none')
1016 $j("#p-cactions").addClass("filledPortlet").removeClass("emptyPortlet").find('h5').css('width','1px').animate({'width':'26px'},390);}).bind("beforeTabExpand",function(){if($j('#p-cactions li').length==1)
Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -19,7 +19,7 @@
2020 'base_sets' => array(
2121 'raw' => array(
2222 array( 'src' => 'css/suggestions.css', 'version' => 14 ),
23 - array( 'src' => 'css/vector.collapsibleNav.css', 'version' => 10 ),
 23+ array( 'src' => 'css/vector.collapsibleNav.css', 'version' => 11 ),
2424 array( 'src' => 'css/vector.expandableSearch.css', 'version' => 2 ),
2525 array( 'src' => 'css/vector.footerCleanup.css', 'version' => 2 ),
2626 array( 'src' => 'css/wikiEditor.css', 'version' => 14 ),
@@ -30,11 +30,11 @@
3131 array( 'src' => 'css/vector/jquery-ui-1.7.2.css', 'version' => '1.7.2y' ),
3232 ),
3333 'combined' => array(
34 - array( 'src' => 'css/combined.css', 'version' => 98 ),
 34+ array( 'src' => 'css/combined.css', 'version' => 99 ),
3535 array( 'src' => 'css/vector/jquery-ui-1.7.2.css', 'version' => '1.7.2y' ),
3636 ),
3737 'minified' => array(
38 - array( 'src' => 'css/combined.min.css', 'version' => 98 ),
 38+ array( 'src' => 'css/combined.min.css', 'version' => 99 ),
3939 array( 'src' => 'css/vector/jquery-ui-1.7.2.css', 'version' => '1.7.2y' ),
4040 ),
4141 )

Follow-up revisions

RevisionCommit summaryAuthorDate
r67744Solves code style issue in r67559 and removes debugger statement added in r67...tparscal18:54, 9 June 2010

Comments

#Comment by Catrope (talk | contribs)   20:08, 7 June 2010
+		var version = 2;
...
+			var version = $j.cookie( 'vector-nav-pref-version' );
...
+			var version = 1;

I would feel a lot safer if you just did var version; to declare version before going into a complex if-else structure that is now obliged to declare version in every possible code path.

+	if ( wgCollapsibleNavForceNewVersion == true ) {
...
+		if ( wgCollapsibleNavBucketTest == true ) {

== true? Really? What's wrong with just using if ( wgFoo )?

+				console.log( version );

Bad Trevor ;)

+		$primary = $j( '#p-lang ul.primary' );
+		$secondary = $j( '#p-lang ul.secondary' );
...
+			$link = $secondary.find( '.interwiki-' + languages[i] );

Use var $primary = ... so you don't pollute the global scope or accidentally overwrite something that's already there.

+					$link.remove().appendTo( $primary );
...
+			$secondary.remove().appendTo( $j( '#p-lang-more div.body' ) );

My warning against using remove() in the CR comments on r67548 applies here as well.

+			if ( state == 'true' || ( state == null && i < 1 ) || version == 1 && id == 'p-lang' ) {

Please be consistent in parenthesizing here.

Status & tagging log