r66655 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66654‎ | r66655 | r66656 >
Date:20:46, 19 May 2010
Author:catrope
Status:deferred
Tags:
Comment:
Suggestions plugin: Go back to using maxExpandFactor, but set it to 3
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' => 17 ),
 74+ array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 18 ),
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' => 401 ),
 89+ array( 'src' => 'js/plugins.combined.js', 'version' => 402 ),
9090 ),
9191 'minified' => array(
92 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 401 ),
 92+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 402 ),
9393 ),
9494 ),
9595 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.suggestions.js
@@ -33,6 +33,9 @@
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: 3
3740 * positionFromLeft: Whether to position the suggestion box with the left attribute or the right
3841 * Type: Boolean, Default: true
3942 */
@@ -175,10 +178,7 @@
176179 }
177180 // Apply new width for results box, if any
178181 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();
 182+ var maxWidth = context.config.maxExpandFactor*context.data.$textbox.width();
183183 context.data.$container.width( Math.min( expWidth, maxWidth ) );
184184 }
185185 // autoEllipse the results. Has to be done after changing the width
@@ -192,6 +192,9 @@
193193 case 'delay':
194194 context.config[property] = Math.max( 0, Math.min( 1200, value ) );
195195 break;
 196+ case 'maxExpandFactor':
 197+ context.config[property] = Math.max( 1, value );
 198+ break;
196199 case 'submitOnClick':
197200 case 'positionFromLeft':
198201 context.config[property] = value ? true : false;
@@ -344,6 +347,7 @@
345348 'maxRows': 7,
346349 'delay': 120,
347350 'submitOnClick': false,
 351+ 'maxExpandFactor': 3,
348352 'positionFromLeft': true
349353 }
350354 };
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -5790,6 +5790,9 @@
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: 3
57945797 * positionFromLeft: Whether to position the suggestion box with the left attribute or the right
57955798 * Type: Boolean, Default: true
57965799 */
@@ -5932,10 +5935,7 @@
59335936 }
59345937 // Apply new width for results box, if any
59355938 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();
 5939+ var maxWidth = context.config.maxExpandFactor*context.data.$textbox.width();
59405940 context.data.$container.width( Math.min( expWidth, maxWidth ) );
59415941 }
59425942 // autoEllipse the results. Has to be done after changing the width
@@ -5949,6 +5949,9 @@
59505950 case 'delay':
59515951 context.config[property] = Math.max( 0, Math.min( 1200, value ) );
59525952 break;
 5953+ case 'maxExpandFactor':
 5954+ context.config[property] = Math.max( 1, value );
 5955+ break;
59535956 case 'submitOnClick':
59545957 case 'positionFromLeft':
59555958 context.config[property] = value ? true : false;
@@ -6101,6 +6104,7 @@
61026105 'maxRows': 7,
61036106 'delay': 120,
61046107 'submitOnClick': false,
 6108+ 'maxExpandFactor': 3,
61056109 'positionFromLeft': true
61066110 }
61076111 };
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -399,9 +399,9 @@
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());}
401401 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>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));}
 403+if(expWidth>context.data.$container.width()){var maxWidth=context.config.maxExpandFactor*context.data.$textbox.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'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'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');}}}
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,'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,'maxExpandFactor':3,'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