r62725 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62724‎ | r62725 | r62726 >
Date:23:09, 19 February 2010
Author:tparscal
Status:ok
Tags:
Comment:
When you added a group via the API, it would not get added because it was empty - a trick we were using to hide empty groups. Now, it will be added but will be hidden, and once a tool is added to the group it will be shown. In addition, removing all tools from the group will hide it.
Modified paths:
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toolbar.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -74,7 +74,7 @@
7575 array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 27 ),
7676 array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 144 ),
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 34 ),
78 - array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 49 ),
 78+ array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 50 ),
7979 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 18 ),
8080 array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 93 ),
8181 array( 'src' => 'js/plugins/jquery.wikiEditor.preview.js', 'version' => 11 ),
@@ -82,10 +82,10 @@
8383 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 3 ),
8484 ),
8585 'combined' => array(
86 - array( 'src' => 'js/plugins.combined.js', 'version' => 272 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 273 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 272 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 273 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toolbar.js
@@ -11,15 +11,12 @@
1212 for ( type in data ) {
1313 switch ( type ) {
1414 case 'sections':
15 - var $sections = context.modules.toolbar.$toolbar
16 - .find( 'div.sections' );
17 - var $tabs = context.modules.toolbar.$toolbar
18 - .find( 'div.tabs' );
 15+ var $sections = context.modules.toolbar.$toolbar.find( 'div.sections' );
 16+ var $tabs = context.modules.toolbar.$toolbar.find( 'div.tabs' );
1917 for ( section in data[type] ) {
2018 if ( section == 'main' ) {
2119 // Section
22 - context.modules.toolbar.$toolbar
23 - .prepend(
 20+ context.modules.toolbar.$toolbar.prepend(
2421 $.wikiEditor.modules.toolbar.fn.buildSection(
2522 context, section, data[type][section]
2623 )
@@ -45,33 +42,39 @@
4643 if ( ! ( 'section' in data ) ) {
4744 continue;
4845 }
49 - var $section = context.modules.toolbar.$toolbar
50 - .find( 'div[rel=' + data.section + '].section' );
 46+ var $section = context.modules.toolbar.$toolbar.find( 'div[rel=' + data.section + '].section' );
5147 for ( group in data[type] ) {
5248 // Group
53 - $section
54 - .append( $.wikiEditor.modules.toolbar.fn.buildGroup( context, group, data[type][group] ) );
 49+ $section.append(
 50+ $.wikiEditor.modules.toolbar.fn.buildGroup( context, group, data[type][group] )
 51+ );
5552 }
5653 break;
5754 case 'tools':
5855 if ( ! ( 'section' in data && 'group' in data ) ) {
5956 continue;
6057 }
61 - var $group = context.modules.toolbar.$toolbar
62 - .find( 'div[rel=' + data.section + '].section ' + 'div[rel=' + data.group + '].group' );
 58+ var $group = context.modules.toolbar.$toolbar.find(
 59+ 'div[rel=' + data.section + '].section ' + 'div[rel=' + data.group + '].group'
 60+ );
6361 for ( tool in data[type] ) {
6462 // Tool
6563 $group.append( $.wikiEditor.modules.toolbar.fn.buildTool( context, tool,data[type][tool] ) );
6664 }
 65+ if ( $group.children().length ) {
 66+ $group.show();
 67+ }
6768 break;
6869 case 'pages':
6970 if ( ! ( 'section' in data ) ) {
7071 continue;
7172 }
72 - var $pages = context.modules.toolbar.$toolbar
73 - .find( 'div[rel=' + data.section + '].section .pages' );
74 - var $index = context.modules.toolbar.$toolbar
75 - .find( 'div[rel=' + data.section + '].section .index' );
 73+ var $pages = context.modules.toolbar.$toolbar.find(
 74+ 'div[rel=' + data.section + '].section .pages'
 75+ );
 76+ var $index = context.modules.toolbar.$toolbar.find(
 77+ 'div[rel=' + data.section + '].section .index'
 78+ );
7679 for ( page in data[type] ) {
7780 // Page
7881 $pages.append( $.wikiEditor.modules.toolbar.fn.buildPage( context, page, data[type][page] ) );
@@ -120,15 +123,17 @@
121124 }
122125 },
123126 removeFromToolbar : function( context, data ) {
124 - js_log("f:removeFromToolbar");
125127 if ( typeof data.section == 'string' ) {
126128 // Section
127129 var tab = 'div.tabs span[rel=' + data.section + '].tab';
128130 var target = 'div[rel=' + data.section + '].section';
 131+ var group = null;
129132 if ( typeof data.group == 'string' ) {
130133 // Toolbar group
131134 target += ' div[rel=' + data.group + '].group';
132135 if ( typeof data.tool == 'string' ) {
 136+ // Save for later checking if empty
 137+ group = target;
133138 // Tool
134139 target += ' div[rel=' + data.tool + '].tool';
135140 }
@@ -156,8 +161,14 @@
157162 // Just a section, remove the tab too!
158163 context.modules.toolbar.$toolbar.find( tab ).remove();
159164 }
160 - js_log('target is: ' + target);
161165 context.modules.toolbar.$toolbar.find( target ).remove();
 166+ // Hide empty groups
 167+ if ( group ) {
 168+ $group = context.modules.toolbar.$toolbar.find( group );
 169+ if ( $group.children().length == 0 ) {
 170+ $group.hide();
 171+ }
 172+ }
162173 }
163174 }
164175 },
@@ -271,7 +282,6 @@
272283 if ( label ) {
273284 $group.append( '<div class="label">' + label + '</div>' )
274285 }
275 -
276286 var empty = true;
277287 if ( 'tools' in group ) {
278288 for ( tool in group.tools ) {
@@ -282,7 +292,10 @@
283293 }
284294 }
285295 }
286 - return empty ? null : $group;
 296+ if ( empty ) {
 297+ $group.hide();
 298+ }
 299+ return $group;
287300 },
288301 buildTool : function( context, id, tool ) {
289302 if ( 'filters' in tool ) {
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -10272,15 +10272,12 @@
1027310273 for ( type in data ) {
1027410274 switch ( type ) {
1027510275 case 'sections':
10276 - var $sections = context.modules.toolbar.$toolbar
10277 - .find( 'div.sections' );
10278 - var $tabs = context.modules.toolbar.$toolbar
10279 - .find( 'div.tabs' );
 10276+ var $sections = context.modules.toolbar.$toolbar.find( 'div.sections' );
 10277+ var $tabs = context.modules.toolbar.$toolbar.find( 'div.tabs' );
1028010278 for ( section in data[type] ) {
1028110279 if ( section == 'main' ) {
1028210280 // Section
10283 - context.modules.toolbar.$toolbar
10284 - .prepend(
 10281+ context.modules.toolbar.$toolbar.prepend(
1028510282 $.wikiEditor.modules.toolbar.fn.buildSection(
1028610283 context, section, data[type][section]
1028710284 )
@@ -10306,33 +10303,39 @@
1030710304 if ( ! ( 'section' in data ) ) {
1030810305 continue;
1030910306 }
10310 - var $section = context.modules.toolbar.$toolbar
10311 - .find( 'div[rel=' + data.section + '].section' );
 10307+ var $section = context.modules.toolbar.$toolbar.find( 'div[rel=' + data.section + '].section' );
1031210308 for ( group in data[type] ) {
1031310309 // Group
10314 - $section
10315 - .append( $.wikiEditor.modules.toolbar.fn.buildGroup( context, group, data[type][group] ) );
 10310+ $section.append(
 10311+ $.wikiEditor.modules.toolbar.fn.buildGroup( context, group, data[type][group] )
 10312+ );
1031610313 }
1031710314 break;
1031810315 case 'tools':
1031910316 if ( ! ( 'section' in data && 'group' in data ) ) {
1032010317 continue;
1032110318 }
10322 - var $group = context.modules.toolbar.$toolbar
10323 - .find( 'div[rel=' + data.section + '].section ' + 'div[rel=' + data.group + '].group' );
 10319+ var $group = context.modules.toolbar.$toolbar.find(
 10320+ 'div[rel=' + data.section + '].section ' + 'div[rel=' + data.group + '].group'
 10321+ );
1032410322 for ( tool in data[type] ) {
1032510323 // Tool
1032610324 $group.append( $.wikiEditor.modules.toolbar.fn.buildTool( context, tool,data[type][tool] ) );
1032710325 }
 10326+ if ( $group.children().length ) {
 10327+ $group.show();
 10328+ }
1032810329 break;
1032910330 case 'pages':
1033010331 if ( ! ( 'section' in data ) ) {
1033110332 continue;
1033210333 }
10333 - var $pages = context.modules.toolbar.$toolbar
10334 - .find( 'div[rel=' + data.section + '].section .pages' );
10335 - var $index = context.modules.toolbar.$toolbar
10336 - .find( 'div[rel=' + data.section + '].section .index' );
 10334+ var $pages = context.modules.toolbar.$toolbar.find(
 10335+ 'div[rel=' + data.section + '].section .pages'
 10336+ );
 10337+ var $index = context.modules.toolbar.$toolbar.find(
 10338+ 'div[rel=' + data.section + '].section .index'
 10339+ );
1033710340 for ( page in data[type] ) {
1033810341 // Page
1033910342 $pages.append( $.wikiEditor.modules.toolbar.fn.buildPage( context, page, data[type][page] ) );
@@ -10381,15 +10384,17 @@
1038210385 }
1038310386 },
1038410387 removeFromToolbar : function( context, data ) {
10385 - js_log("f:removeFromToolbar");
1038610388 if ( typeof data.section == 'string' ) {
1038710389 // Section
1038810390 var tab = 'div.tabs span[rel=' + data.section + '].tab';
1038910391 var target = 'div[rel=' + data.section + '].section';
 10392+ var group = null;
1039010393 if ( typeof data.group == 'string' ) {
1039110394 // Toolbar group
1039210395 target += ' div[rel=' + data.group + '].group';
1039310396 if ( typeof data.tool == 'string' ) {
 10397+ // Save for later checking if empty
 10398+ group = target;
1039410399 // Tool
1039510400 target += ' div[rel=' + data.tool + '].tool';
1039610401 }
@@ -10417,8 +10422,14 @@
1041810423 // Just a section, remove the tab too!
1041910424 context.modules.toolbar.$toolbar.find( tab ).remove();
1042010425 }
10421 - js_log('target is: ' + target);
1042210426 context.modules.toolbar.$toolbar.find( target ).remove();
 10427+ // Hide empty groups
 10428+ if ( group ) {
 10429+ $group = context.modules.toolbar.$toolbar.find( group );
 10430+ if ( $group.children().length == 0 ) {
 10431+ $group.hide();
 10432+ }
 10433+ }
1042310434 }
1042410435 }
1042510436 },
@@ -10532,7 +10543,6 @@
1053310544 if ( label ) {
1053410545 $group.append( '<div class="label">' + label + '</div>' )
1053510546 }
10536 -
1053710547 var empty = true;
1053810548 if ( 'tools' in group ) {
1053910549 for ( tool in group.tools ) {
@@ -10543,7 +10553,10 @@
1054410554 }
1054510555 }
1054610556 }
10547 - return empty ? null : $group;
 10557+ if ( empty ) {
 10558+ $group.hide();
 10559+ }
 10560+ return $group;
1054810561 },
1054910562 buildTool : function( context, id, tool ) {
1055010563 if ( 'filters' in tool ) {
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -705,14 +705,15 @@
706706 var $section=context.modules.toolbar.$toolbar.find('div[rel='+data.section+'].section');for(group in data[type]){$section.append($.wikiEditor.modules.toolbar.fn.buildGroup(context,group,data[type][group]));}
707707 break;case'tools':if(!('section'in data&&'group'in data)){continue;}
708708 var $group=context.modules.toolbar.$toolbar.find('div[rel='+data.section+'].section '+'div[rel='+data.group+'].group');for(tool in data[type]){$group.append($.wikiEditor.modules.toolbar.fn.buildTool(context,tool,data[type][tool]));}
 709+if($group.children().length){$group.show();}
709710 break;case'pages':if(!('section'in data)){continue;}
710711 var $pages=context.modules.toolbar.$toolbar.find('div[rel='+data.section+'].section .pages');var $index=context.modules.toolbar.$toolbar.find('div[rel='+data.section+'].section .index');for(page in data[type]){$pages.append($.wikiEditor.modules.toolbar.fn.buildPage(context,page,data[type][page]));$index.append($.wikiEditor.modules.toolbar.fn.buildBookmark(context,page,data[type][page]));}
711712 $.wikiEditor.modules.toolbar.fn.updateBookletSelection(context,page,$pages,$index);break;case'rows':if(!('section'in data&&'page'in data)){continue;}
712713 var $table=context.modules.toolbar.$toolbar.find('div[rel='+data.section+'].section '+'div[rel='+data.page+'].page table');for(row in data[type]){$table.append($.wikiEditor.modules.toolbar.fn.buildRow(context,data[type][row]));}
713714 break;case'characters':if(!('section'in data&&'page'in data)){continue;}
714715 $characters=context.modules.toolbar.$toolbar.find('div[rel='+data.section+'].section '+'div[rel='+data.page+'].page div');var actions=$characters.data('actions');for(character in data[type]){$characters.append($($.wikiEditor.modules.toolbar.fn.buildCharacter(data[type][character],actions)).click(function(){$.wikiEditor.modules.toolbar.fn.doAction($(this).parent().data('context'),$(this).parent().data('actions')[$(this).attr('rel')]);return false;}));}
715 -break;default:break;}}},removeFromToolbar:function(context,data){js_log("f:removeFromToolbar");if(typeof data.section=='string'){var tab='div.tabs span[rel='+data.section+'].tab';var target='div[rel='+data.section+'].section';if(typeof data.group=='string'){target+=' div[rel='+data.group+'].group';if(typeof data.tool=='string'){target+=' div[rel='+data.tool+'].tool';}}else if(typeof data.page=='string'){var index=target+' div.index div[rel='+data.page+']';target+=' div.pages div[rel='+data.page+'].page';if(typeof data.character=='string'){target+=' a[rel='+data.character+']';}else if(typeof data.row=='number'){target+=' table tr:not(:has(th)):eq('+data.row+')';}else{context.modules.toolbar.$toolbar.find(index).remove();$.wikiEditor.modules.toolbar.fn.updateBookletSelection(context,null,context.modules.toolbar.$toolbar.find(target),context.modules.toolbar.$toolbar.find(index));}}else{context.modules.toolbar.$toolbar.find(tab).remove();}
716 -js_log('target is: '+target);context.modules.toolbar.$toolbar.find(target).remove();}}},evt:{resize:function(context,event){context.$ui.find('.sections').height(context.$ui.find('.sections .section:visible').outerHeight());},tocCollapse:function(context,event){$.wikiEditor.modules.toolbar.evt.resize(context,event);},tocExpand:function(context,event){$.wikiEditor.modules.toolbar.evt.resize(context,event);}},fn:{create:function(context,config){if('$toolbar'in context.modules.toolbar){return;}
 716+break;default:break;}}},removeFromToolbar:function(context,data){if(typeof data.section=='string'){var tab='div.tabs span[rel='+data.section+'].tab';var target='div[rel='+data.section+'].section';var group=null;if(typeof data.group=='string'){target+=' div[rel='+data.group+'].group';if(typeof data.tool=='string'){group=target;target+=' div[rel='+data.tool+'].tool';}}else if(typeof data.page=='string'){var index=target+' div.index div[rel='+data.page+']';target+=' div.pages div[rel='+data.page+'].page';if(typeof data.character=='string'){target+=' a[rel='+data.character+']';}else if(typeof data.row=='number'){target+=' table tr:not(:has(th)):eq('+data.row+')';}else{context.modules.toolbar.$toolbar.find(index).remove();$.wikiEditor.modules.toolbar.fn.updateBookletSelection(context,null,context.modules.toolbar.$toolbar.find(target),context.modules.toolbar.$toolbar.find(index));}}else{context.modules.toolbar.$toolbar.find(tab).remove();}
 717+context.modules.toolbar.$toolbar.find(target).remove();if(group){$group=context.modules.toolbar.$toolbar.find(group);if($group.children().length==0){$group.hide();}}}}},evt:{resize:function(context,event){context.$ui.find('.sections').height(context.$ui.find('.sections .section:visible').outerHeight());},tocCollapse:function(context,event){$.wikiEditor.modules.toolbar.evt.resize(context,event);},tocExpand:function(context,event){$.wikiEditor.modules.toolbar.evt.resize(context,event);}},fn:{create:function(context,config){if('$toolbar'in context.modules.toolbar){return;}
717718 context.modules.toolbar.$toolbar=$('<div />').addClass('wikiEditor-ui-toolbar').attr('id','wikiEditor-ui-toolbar');$.wikiEditor.modules.toolbar.fn.build(context,config);context.$ui.find('.wikiEditor-ui-top').append(context.modules.toolbar.$toolbar);},doAction:function(context,action,source){if($.trackAction!=undefined&&source.closest('.wikiEditor-ui-toolbar').size()){var rels=[];var step=source;var i=0;while(!step.hasClass('wikiEditor-ui-toolbar')){if(i>25){break;}
718719 i++;var rel=step.attr('rel');if(rel){rels.push(step.attr('rel'));}
719720 step=step.parent();}
@@ -723,7 +724,8 @@
724725 break;case'callback':if(typeof action.execute=='function'){action.execute(context);}
725726 break;case'dialog':context.fn.saveSelection();context.$textarea.wikiEditor('openDialog',action.module);break;default:break;}},buildGroup:function(context,id,group){var $group=$('<div />').attr({'class':'group group-'+id,'rel':id});var label=$.wikiEditor.autoMsg(group,'label');if(label){$group.append('<div class="label">'+label+'</div>')}
726727 var empty=true;if('tools'in group){for(tool in group.tools){var tool=$.wikiEditor.modules.toolbar.fn.buildTool(context,tool,group.tools[tool]);if(tool){empty=false;$group.append(tool);}}}
727 -return empty?null:$group;},buildTool:function(context,id,tool){if('filters'in tool){for(filter in tool.filters){if($(tool.filters[filter]).size()==0){return null;}}}
 728+if(empty){$group.hide();}
 729+return $group;},buildTool:function(context,id,tool){if('filters'in tool){for(filter in tool.filters){if($(tool.filters[filter]).size()==0){return null;}}}
728730 var label=$.wikiEditor.autoMsg(tool,'label');switch(tool.type){case'button':var src=$.wikiEditor.autoIcon(tool.icon,$.wikiEditor.imgPath+'toolbar/');$button=$('<img />').attr({'src':src,'width':22,'height':22,'alt':label,'title':label,'rel':id,'class':'tool tool-button'});if('action'in tool){$button.data('action',tool.action).data('context',context).mousedown(function(){return false;}).click(function(){$.wikiEditor.modules.toolbar.fn.doAction($(this).data('context'),$(this).data('action'),$(this));return false;});}
729731 return $button;case'select':var $select=$('<div />').attr({'rel':id,'class':'tool tool-select'});$options=$('<div />').addClass('options');if('list'in tool){for(option in tool.list){var optionLabel=$.wikiEditor.autoMsg(tool.list[option],'label');$options.append($('<a />').data('action',tool.list[option].action).data('context',context).mousedown(function(){return false;}).click(function(){$.wikiEditor.modules.toolbar.fn.doAction($(this).data('context'),$(this).data('action'),$(this));if($(this).parent().is(':visible')){$(this).parent().animate({'opacity':'toggle'},'fast');}
730732 return false;}).text(optionLabel).addClass('option').attr({'rel':option,'href':'#'}));}}

Status & tagging log