r66644 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66643‎ | r66644 | r66645 >
Date:18:42, 19 May 2010
Author:catrope
Status:deferred
Tags:
Comment:
UsabilityInitiative: Remove maxExpandFactor in suggestions plugin, width of suggestions box is now only bounded by the edge of the screen.
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.suggestions.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -70,7 +70,7 @@
7171 array( 'src' => 'js/plugins/jquery.color.js', 'version' => 1 ),
7272 array( 'src' => 'js/plugins/jquery.cookie.js', 'version' => 4 ),
7373 array( 'src' => 'js/plugins/jquery.delayedBind.js', 'version' => 1 ),
74 - array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 16 ),
 74+ array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 17 ),
7575 array( 'src' => 'js/plugins/jquery.expandableField.js', 'version' => 15 ),
7676 array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 18 ),
7777 array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 33 ),
@@ -85,10 +85,10 @@
8686 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 5 ),
8787 ),
8888 'combined' => array(
89 - array( 'src' => 'js/plugins.combined.js', 'version' => 400 ),
 89+ array( 'src' => 'js/plugins.combined.js', 'version' => 401 ),
9090 ),
9191 'minified' => array(
92 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 400 ),
 92+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 401 ),
9393 ),
9494 ),
9595 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.suggestions.js
@@ -33,9 +33,6 @@
3434 * Type: Number, Range: 0 - 1200, Default: 120
3535 * submitOnClick: Whether to submit the form containing the textbox when a suggestion is clicked
3636 * Type: Boolean, Default: false
37 - * maxExpandFactor: Maximum suggestions box width relative to the textbox width. If set to e.g. 2, the suggestions box
38 - * will never be grown beyond 2 times the width of the textbox.
39 - * Type: Number, Range: 1 - infinity, Default: 2
4037 * positionFromLeft: Whether to position the suggestion box with the left attribute or the right
4138 * Type: Boolean, Default: true
4239 */
@@ -170,17 +167,19 @@
171168 // Widen results box if needed
172169 // New width is only calculated here, applied later
173170 var $span = $result.children( 'span' );
174 - if ( $span.width() > $result.width() ) {
175 - expWidth = Math.max( expWidth, Math.min( $span.width(),
176 - context.data.$textbox.width()*context.config.maxExpandFactor
177 - ) );
 171+ if ( $span.outerWidth() > $result.width() && $span.outerWidth() > expWidth ) {
 172+ expWidth = $span.outerWidth();
178173 }
179174 $autoEllipseMe = $autoEllipseMe.add( $result );
180175 }
181176 }
182177 // Apply new width for results box, if any
183 - if ( expWidth != -1 ) {
184 - context.data.$container.width( expWidth );
 178+ if ( expWidth > context.data.$container.width() ) {
 179+ // Don't make the container too wide so it runs offscreen
 180+ var maxWidth = context.config.positionFromLeft ?
 181+ $('body').width() - context.data.$container.offset().left :
 182+ context.data.$container.offset().left + context.data.$container.width();
 183+ context.data.$container.width( Math.min( expWidth, maxWidth ) );
185184 }
186185 // autoEllipse the results. Has to be done after changing the width
187186 $autoEllipseMe.autoEllipsis( { hasSpan: true, tooltip: true } );
@@ -193,9 +192,6 @@
194193 case 'delay':
195194 context.config[property] = Math.max( 0, Math.min( 1200, value ) );
196195 break;
197 - case 'maxExpandFactor':
198 - context.config[property] = Math.max( 1, value );
199 - break;
200196 case 'submitOnClick':
201197 case 'positionFromLeft':
202198 context.config[property] = value ? true : false;
@@ -348,7 +344,6 @@
349345 'maxRows': 7,
350346 'delay': 120,
351347 'submitOnClick': false,
352 - 'maxExpandFactor': 2,
353348 'positionFromLeft': true
354349 }
355350 };
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -5790,9 +5790,6 @@
57915791 * Type: Number, Range: 0 - 1200, Default: 120
57925792 * submitOnClick: Whether to submit the form containing the textbox when a suggestion is clicked
57935793 * Type: Boolean, Default: false
5794 - * maxExpandFactor: Maximum suggestions box width relative to the textbox width. If set to e.g. 2, the suggestions box
5795 - * will never be grown beyond 2 times the width of the textbox.
5796 - * Type: Number, Range: 1 - infinity, Default: 2
57975794 * positionFromLeft: Whether to position the suggestion box with the left attribute or the right
57985795 * Type: Boolean, Default: true
57995796 */
@@ -5927,17 +5924,19 @@
59285925 // Widen results box if needed
59295926 // New width is only calculated here, applied later
59305927 var $span = $result.children( 'span' );
5931 - if ( $span.width() > $result.width() ) {
5932 - expWidth = Math.max( expWidth, Math.min( $span.width(),
5933 - context.data.$textbox.width()*context.config.maxExpandFactor
5934 - ) );
 5928+ if ( $span.outerWidth() > $result.width() && $span.outerWidth() > expWidth ) {
 5929+ expWidth = $span.outerWidth();
59355930 }
59365931 $autoEllipseMe = $autoEllipseMe.add( $result );
59375932 }
59385933 }
59395934 // Apply new width for results box, if any
5940 - if ( expWidth != -1 ) {
5941 - context.data.$container.width( expWidth );
 5935+ if ( expWidth > context.data.$container.width() ) {
 5936+ // Don't make the container too wide so it runs offscreen
 5937+ var maxWidth = context.config.positionFromLeft ?
 5938+ $('body').width() - context.data.$container.offset().left :
 5939+ context.data.$container.offset().left + context.data.$container.width();
 5940+ context.data.$container.width( Math.min( expWidth, maxWidth ) );
59425941 }
59435942 // autoEllipse the results. Has to be done after changing the width
59445943 $autoEllipseMe.autoEllipsis( { hasSpan: true, tooltip: true } );
@@ -5950,9 +5949,6 @@
59515950 case 'delay':
59525951 context.config[property] = Math.max( 0, Math.min( 1200, value ) );
59535952 break;
5954 - case 'maxExpandFactor':
5955 - context.config[property] = Math.max( 1, value );
5956 - break;
59575953 case 'submitOnClick':
59585954 case 'positionFromLeft':
59595955 context.config[property] = value ? true : false;
@@ -6105,7 +6101,6 @@
61066102 'maxRows': 7,
61076103 'delay': 120,
61086104 'submitOnClick': false,
6109 - 'maxExpandFactor': 2,
61106105 'positionFromLeft': true
61116106 }
61126107 };
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -397,11 +397,11 @@
398398 if(delayed){context.data.timerID=setTimeout(maybeFetch,context.config.delay);}else{maybeFetch();}
399399 $.suggestions.special(context);},special:function(context){if(typeof context.config.special.render=='function'){setTimeout(function(){$special=context.data.$container.find('.suggestions-special');context.config.special.render.call($special,context.data.$textbox.val());},1);}},configure:function(context,property,value){switch(property){case'fetch':case'cancel':case'special':case'result':case'$region':context.config[property]=value;break;case'suggestions':context.config[property]=value;if(typeof context.data!=='undefined'){if(context.data.$textbox.val().length==0){context.data.$container.hide();}else{context.data.$container.show();var newCSS={'top':context.config.$region.offset().top+context.config.$region.outerHeight(),'bottom':'auto','width':context.config.$region.outerWidth(),'height':'auto'}
400400 if(context.config.positionFromLeft){newCSS['left']=context.config.$region.offset().left;newCSS['right']='auto';}else{newCSS['left']='auto';newCSS['right']=$('body').width()-(context.config.$region.offset().left+context.config.$region.outerWidth());}
401 -context.data.$container.css(newCSS);var $results=context.data.$container.children('.suggestions-results');$results.empty();var expWidth=-1;var $autoEllipseMe=$([]);for(var i=0;i<context.config.suggestions.length;i++){var $result=$('<div />').addClass('suggestions-result').attr('rel',i).data('text',context.config.suggestions[i]).mouseover(function(e){$.suggestions.highlight(context,$(this).closest('.suggestions-results div'),false);}).appendTo($results);if(typeof context.config.result.render=='function'){context.config.result.render.call($result,context.config.suggestions[i]);}else{$result.append($('<span />').css('whiteSpace','nowrap').text(context.config.suggestions[i]));var $span=$result.children('span');if($span.width()>$result.width()){expWidth=Math.max(expWidth,Math.min($span.width(),context.data.$textbox.width()*context.config.maxExpandFactor));}
 401+context.data.$container.css(newCSS);var $results=context.data.$container.children('.suggestions-results');$results.empty();var expWidth=-1;var $autoEllipseMe=$([]);for(var i=0;i<context.config.suggestions.length;i++){var $result=$('<div />').addClass('suggestions-result').attr('rel',i).data('text',context.config.suggestions[i]).mouseover(function(e){$.suggestions.highlight(context,$(this).closest('.suggestions-results div'),false);}).appendTo($results);if(typeof context.config.result.render=='function'){context.config.result.render.call($result,context.config.suggestions[i]);}else{$result.append($('<span />').css('whiteSpace','nowrap').text(context.config.suggestions[i]));var $span=$result.children('span');if($span.outerWidth()>$result.width()&&$span.outerWidth()>expWidth){expWidth=$span.outerWidth();}
402402 $autoEllipseMe=$autoEllipseMe.add($result);}}
403 -if(expWidth!=-1){context.data.$container.width(expWidth);}
 403+if(expWidth>context.data.$container.width()){var maxWidth=context.config.positionFromLeft?$('body').width()-context.data.$container.offset().left:context.data.$container.offset().left+context.data.$container.width();context.data.$container.width(Math.min(expWidth,maxWidth));}
404404 $autoEllipseMe.autoEllipsis({hasSpan:true,tooltip:true});}}
405 -break;case'maxRows':context.config[property]=Math.max(1,Math.min(100,value));break;case'delay':context.config[property]=Math.max(0,Math.min(1200,value));break;case'maxExpandFactor':context.config[property]=Math.max(1,value);break;case'submitOnClick':case'positionFromLeft':context.config[property]=value?true:false;break;}},highlight:function(context,result,updateTextbox){var selected=context.data.$container.find('.suggestions-result-current');if(!result.get||selected.get(0)!=result.get(0)){if(result=='prev'){if(selected.is('.suggestions-special')){result=context.data.$container.find('.suggestions-results div:last')}else{result=selected.prev();if(selected.length==0){if(context.data.$container.find('.suggestions-special').html()!=""){result=context.data.$container.find('.suggestions-special');}else{result=context.data.$container.find('.suggestions-results div:last');}}}}else if(result=='next'){if(selected.length==0){result=context.data.$container.find('.suggestions-results div:first');if(result.length==0&&context.data.$container.find('.suggestions-special').html()!=""){result=context.data.$container.find('.suggestions-special');}}else{result=selected.next();if(selected.is('.suggestions-special')){result=$([]);}else if(result.length==0&&context.data.$container.find('.suggestions-special').html()!=""){result=context.data.$container.find('.suggestions-special');}}}
 405+break;case'maxRows':context.config[property]=Math.max(1,Math.min(100,value));break;case'delay':context.config[property]=Math.max(0,Math.min(1200,value));break;case'submitOnClick':case'positionFromLeft':context.config[property]=value?true:false;break;}},highlight:function(context,result,updateTextbox){var selected=context.data.$container.find('.suggestions-result-current');if(!result.get||selected.get(0)!=result.get(0)){if(result=='prev'){if(selected.is('.suggestions-special')){result=context.data.$container.find('.suggestions-results div:last')}else{result=selected.prev();if(selected.length==0){if(context.data.$container.find('.suggestions-special').html()!=""){result=context.data.$container.find('.suggestions-special');}else{result=context.data.$container.find('.suggestions-results div:last');}}}}else if(result=='next'){if(selected.length==0){result=context.data.$container.find('.suggestions-results div:first');if(result.length==0&&context.data.$container.find('.suggestions-special').html()!=""){result=context.data.$container.find('.suggestions-special');}}else{result=selected.next();if(selected.is('.suggestions-special')){result=$([]);}else if(result.length==0&&context.data.$container.find('.suggestions-special').html()!=""){result=context.data.$container.find('.suggestions-special');}}}
406406 selected.removeClass('suggestions-result-current');result.addClass('suggestions-result-current');}
407407 if(updateTextbox){if(result.length==0){$.suggestions.restore(context);}else{context.data.$textbox.val(result.data('text'));context.data.$textbox.change();}
408408 context.data.$textbox.trigger('change');}
@@ -409,7 +409,7 @@
410410 preventDefault=true;break;case 38:if(wasVisible){$.suggestions.highlight(context,'prev',false);}
411411 preventDefault=wasVisible;break;case 27:context.data.$container.hide();$.suggestions.restore(context);$.suggestions.cancel(context);context.data.$textbox.trigger('change');preventDefault=wasVisible;break;case 13:context.data.$container.hide();preventDefault=wasVisible;selected=context.data.$container.find('.suggestions-result-current');if(selected.size()==0){$.suggestions.cancel(context);context.config.$region.closest('form').submit();}else if(selected.is('.suggestions-special')){if(typeof context.config.special.select=='function'){context.config.special.select.call(selected,context.data.$textbox);}}else{if(typeof context.config.result.select=='function'){$.suggestions.highlight(context,selected,true);context.config.result.select.call(selected,context.data.$textbox);}else{$.suggestions.highlight(context,selected,true);}}
412412 break;default:$.suggestions.update(context,true);break;}
413 -if(preventDefault){e.preventDefault();e.stopImmediatePropagation();}}};$.fn.suggestions=function(){var returnValue=null;var args=arguments;$(this).each(function(){var context=$(this).data('suggestions-context');if(typeof context=='undefined'||context==null){context={config:{'fetch':function(){},'cancel':function(){},'special':{},'result':{},'$region':$(this),'suggestions':[],'maxRows':7,'delay':120,'submitOnClick':false,'maxExpandFactor':2,'positionFromLeft':true}};}
 413+if(preventDefault){e.preventDefault();e.stopImmediatePropagation();}}};$.fn.suggestions=function(){var returnValue=null;var args=arguments;$(this).each(function(){var context=$(this).data('suggestions-context');if(typeof context=='undefined'||context==null){context={config:{'fetch':function(){},'cancel':function(){},'special':{},'result':{},'$region':$(this),'suggestions':[],'maxRows':7,'delay':120,'submitOnClick':false,'positionFromLeft':true}};}
414414 if(args.length>0){if(typeof args[0]=='object'){for(var key in args[0]){$.suggestions.configure(context,key,args[0][key]);}}else if(typeof args[0]=='string'){if(args.length>1){$.suggestions.configure(context,args[0],args[1]);}else if(returnValue==null){returnValue=(args[0]in context.config?undefined:context.config[args[0]]);}}}
415415 if(typeof context.data=='undefined'){context.data={'timerID':null,'prevText':null,'visibleResults':0,'mouseDownOn':$([]),'$textbox':$(this)};var newCSS={'top':Math.round(context.data.$textbox.offset().top+context.data.$textbox.outerHeight()),'width':context.data.$textbox.outerWidth(),'display':'none'}
416416 if(context.config.positionFromLeft){newCSS['left']=context.config.$region.offset().left;newCSS['right']='auto';}else{newCSS['left']='auto';newCSS['right']=$('body').width()-(context.config.$region.offset().left+context.config.$region.outerWidth());}

Follow-up revisions

RevisionCommit summaryAuthorDate
r667081.16wmf4: Merge SimpleSearch fixes from trunk: r66565, rr66623, r66631, r6664...catrope21:00, 20 May 2010

Status & tagging log