r66623 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66622‎ | r66623 | r66624 >
Date:20:02, 18 May 2010
Author:catrope
Status:deferred
Tags:accessibility 
Comment:
UsabilityInitiative: Make SimpleSearch suggestion box expand to the left (or right in RTL) up to twice the width of the search box. Also enable tooltips on trimmed suggestions and refactor the adding of <span> tags a little bit
Modified paths:
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/Vector/Modules/SimpleSearch/SimpleSearch.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/js/plugins.combined.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.autoEllipsis.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.suggestions.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/Vector/Modules/SimpleSearch/SimpleSearch.js
@@ -74,7 +74,8 @@
7575 $textbox.closest( 'form' ).submit();
7676 }
7777 },
78 - delay: 120
 78+ delay: 120,
 79+ expandToLeft: !$j( 'body' ).is( 'rtl' )
7980 } );
8081 $j( '#searchInput' ).suggestions( {
8182 result: {
Index: trunk/extensions/UsabilityInitiative/Vector/Vector.hooks.php
@@ -16,13 +16,13 @@
1717 array( 'src' => 'Modules/CollapsibleTabs/CollapsibleTabs.js', 'version' => 8 ),
1818 array( 'src' => 'Modules/EditWarning/EditWarning.js', 'version' => 8 ),
1919 array( 'src' => 'Modules/FooterCleanup/FooterCleanup.js', 'version' => 5 ),
20 - array( 'src' => 'Modules/SimpleSearch/SimpleSearch.js', 'version' => 9 ),
 20+ array( 'src' => 'Modules/SimpleSearch/SimpleSearch.js', 'version' => 10 ),
2121 ),
2222 'combined' => array(
23 - array( 'src' => 'Vector.combined.js', 'version' => 29 ),
 23+ array( 'src' => 'Vector.combined.js', 'version' => 30 ),
2424 ),
2525 'minified' => array(
26 - array( 'src' => 'Vector.combined.min.js', 'version' => 29 ),
 26+ array( 'src' => 'Vector.combined.min.js', 'version' => 30 ),
2727 ),
2828 );
2929 static $modules = array(
Index: trunk/extensions/UsabilityInitiative/Vector/Vector.combined.js
@@ -335,7 +335,8 @@
336336 $textbox.closest( 'form' ).submit();
337337 }
338338 },
339 - delay: 120
 339+ delay: 120,
 340+ expandToLeft: !$j( 'body' ).is( 'rtl' )
340341 } );
341342 $j( '#searchInput' ).suggestions( {
342343 result: {
Index: trunk/extensions/UsabilityInitiative/Vector/Vector.combined.min.js
@@ -14,5 +14,5 @@
1515 +transclusionCount
1616 +'</strong> other pages.</label>');$j('.mw-templatesUsedExplanation').remove();$j('.collapsible-list label').click(function(){$j(this).parent().toggleClass('expanded').toggleClass('collapsed').find('ul').slideToggle('fast');return false;}).trigger('click');$j('#wpPreview, #wpDiff, .editHelp, #editpage-specialchars').remove();$j('#mw-editform-cancel').remove().appendTo('.editButtons');});if(wgVectorEnabledModules.simplesearch&&skin=='vector'&&typeof os_autoload_inputs!=='undefined'&&os_autoload_forms!=='undefined'){os_autoload_inputs=[];os_autoload_forms=[];}
1717 $j(document).ready(function(){if(!wgVectorEnabledModules.simplesearch||skin!='vector'){return true;}
18 -$j('div#simpleSearch > input#searchInput').each(function(){$j('<label />').text(mw.usability.getMsg('vector-simplesearch-search')).css({'display':'none','position':'absolute','bottom':0,'padding':'0.25em','color':'#999999','cursor':'text'}).css(($j('body').is('.rtl')?'right':'left'),0).click(function(){$j(this).parent().find('input#searchInput').focus();}).appendTo($j(this).parent());if($j(this).val()==''){$j(this).parent().find('label').fadeIn(100);}}).focus(function(){$j(this).parent().find('label').fadeOut(100);}).blur(function(){if($j(this).val()==''){$j(this).parent().find('label').fadeIn(100);}});$j('#searchInput, #searchInput2, #powerSearchText, #searchText').suggestions({fetch:function(query){var $this=$j(this);var request=$j.ajax({url:wgScriptPath+'/api.php',data:{'action':'opensearch','search':query,'namespace':0,'suggest':''},dataType:'json',success:function(data){$this.suggestions('suggestions',data[1]);}});$j(this).data('request',request);},cancel:function(){var request=$j(this).data('request');if(request&&typeof request.abort=='function'){request.abort();$j(this).removeData('request');}},result:{select:function($textbox){$textbox.closest('form').submit();}},delay:120});$j('#searchInput').suggestions({result:{select:function($textbox){$textbox.closest('form').submit();}},special:{render:function(query){if($j(this).children().size()==0){$j(this).show()
 18+$j('div#simpleSearch > input#searchInput').each(function(){$j('<label />').text(mw.usability.getMsg('vector-simplesearch-search')).css({'display':'none','position':'absolute','bottom':0,'padding':'0.25em','color':'#999999','cursor':'text'}).css(($j('body').is('.rtl')?'right':'left'),0).click(function(){$j(this).parent().find('input#searchInput').focus();}).appendTo($j(this).parent());if($j(this).val()==''){$j(this).parent().find('label').fadeIn(100);}}).focus(function(){$j(this).parent().find('label').fadeOut(100);}).blur(function(){if($j(this).val()==''){$j(this).parent().find('label').fadeIn(100);}});$j('#searchInput, #searchInput2, #powerSearchText, #searchText').suggestions({fetch:function(query){var $this=$j(this);var request=$j.ajax({url:wgScriptPath+'/api.php',data:{'action':'opensearch','search':query,'namespace':0,'suggest':''},dataType:'json',success:function(data){$this.suggestions('suggestions',data[1]);}});$j(this).data('request',request);},cancel:function(){var request=$j(this).data('request');if(request&&typeof request.abort=='function'){request.abort();$j(this).removeData('request');}},result:{select:function($textbox){$textbox.closest('form').submit();}},delay:120,expandToLeft:!$j('body').is('rtl')});$j('#searchInput').suggestions({result:{select:function($textbox){$textbox.closest('form').submit();}},special:{render:function(query){if($j(this).children().size()==0){$j(this).show()
1919 $label=$j('<div />').addClass('special-label').text(mw.usability.getMsg('vector-simplesearch-containing')).appendTo($j(this));$query=$j('<div />').addClass('special-query').text(query).appendTo($j(this));$query.autoEllipsis();}else{$j(this).find('.special-query').empty().text(query).autoEllipsis();}},select:function($textbox){$textbox.closest('form').append($j('<input />').attr({'type':'hidden','name':'fulltext','value':1}));$textbox.closest('form').submit();}},$region:$j('#simpleSearch')});});
\ No newline at end of file
Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -64,14 +64,15 @@
6565
6666 // Core functionality of extension scripts
6767 array( 'src' => 'js/plugins/jquery.async.js', 'version' => 3 ),
68 - array( 'src' => 'js/plugins/jquery.autoEllipsis.js', 'version' => 7 ),
 68+ array( 'src' => 'js/plugins/jquery.autoEllipsis.js', 'version' => 8 ),
6969 array( 'src' => 'js/plugins/jquery.browser.js', 'version' => 6 ),
7070 array( 'src' => 'js/plugins/jquery.collapsibleTabs.js', 'version' => 6 ),
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 ),
7475 array( 'src' => 'js/plugins/jquery.expandableField.js', 'version' => 15 ),
75 - array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 15 ),
 76+ array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 16 ),
7677 array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 33 ),
7778 array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 187 ),
7879 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 53 ),
@@ -84,10 +85,10 @@
8586 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 5 ),
8687 ),
8788 'combined' => array(
88 - array( 'src' => 'js/plugins.combined.js', 'version' => 397 ),
 89+ array( 'src' => 'js/plugins.combined.js', 'version' => 398 ),
8990 ),
9091 'minified' => array(
91 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 397 ),
 92+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 398 ),
9293 ),
9394 ),
9495 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.suggestions.js
@@ -31,6 +31,13 @@
3232 * Type: Number, Range: 1 - 100, Default: 7
3333 * delay: Number of ms to wait for the user to stop typing
3434 * Type: Number, Range: 0 - 1200, Default: 120
 35+ * submitOnClick: Whether to submit the form containing the textbox when a suggestion is clicked
 36+ * 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
 40+ * expandToLeft: Whether to expand the suggestion box to the left rather than to the right
 41+ * Type: Boolean, Default: false
3542 */
3643 ( function( $ ) {
3744
@@ -130,8 +137,10 @@
131138 } );
132139 var $results = context.data.$container.children( '.suggestions-results' );
133140 $results.empty();
 141+ var expWidth = -1;
 142+ var $autoEllipseMe = $( [] );
134143 for ( var i = 0; i < context.config.suggestions.length; i++ ) {
135 - $result = $( '<div />' )
 144+ var $result = $( '<div />' )
136145 .addClass( 'suggestions-result' )
137146 .attr( 'rel', i )
138147 .data( 'text', context.config.suggestions[i] )
@@ -141,13 +150,40 @@
142151 );
143152 } )
144153 .appendTo( $results );
 154+
145155 // Allow custom rendering
146156 if ( typeof context.config.result.render == 'function' ) {
147157 context.config.result.render.call( $result, context.config.suggestions[i] );
148158 } else {
149 - $result.text( context.config.suggestions[i] ).autoEllipsis();
 159+ // Add <span> with text
 160+ $result.append( $( '<span />' )
 161+ .css( 'whiteSpace', 'nowrap' )
 162+ .text( context.config.suggestions[i] )
 163+ );
 164+
 165+ // Widen results box if needed
 166+ // New width is only calculated here, applied later
 167+ var $span = $result.children( 'span' );
 168+ if ( $span.width() > $result.width() ) {
 169+ expWidth = Math.max( expWidth, Math.min( $span.width(),
 170+ context.data.$textbox.width()*context.config.maxExpandFactor
 171+ ) );
 172+ }
 173+ $autoEllipseMe = $autoEllipseMe.add( $result );
150174 }
151175 }
 176+ // Apply new width for results box, if any
 177+ if ( expWidth != -1 ) {
 178+ if ( context.config.expandToLeft ) {
 179+ context.data.$container.css( 'left',
 180+ context.data.$container.offset().left -
 181+ ( expWidth - context.data.$container.width() )
 182+ );
 183+ }
 184+ context.data.$container.width( expWidth );
 185+ }
 186+ // autoEllipse the results. Has to be done after changing the width
 187+ $autoEllipseMe.autoEllipsis( { hasSpan: true, tooltip: true } );
152188 }
153189 }
154190 break;
@@ -157,7 +193,11 @@
158194 case 'delay':
159195 context.config[property] = Math.max( 0, Math.min( 1200, value ) );
160196 break;
 197+ case 'maxExpandFactor':
 198+ context.config[property] = Math.max( 1, value );
 199+ break;
161200 case 'submitOnClick':
 201+ case 'expandToLeft':
162202 context.config[property] = value ? true : false;
163203 break;
164204 }
@@ -307,7 +347,9 @@
308348 'suggestions': [],
309349 'maxRows': 7,
310350 'delay': 120,
311 - 'submitOnClick': false
 351+ 'submitOnClick': false,
 352+ 'maxExpandFactor': 2,
 353+ 'expandToLeft': false
312354 }
313355 };
314356 }
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.autoEllipsis.js
@@ -10,7 +10,8 @@
1111 options = $.extend( {
1212 'position': 'center',
1313 'tooltip': false,
14 - 'restoreText': false
 14+ 'restoreText': false,
 15+ 'hasSpan': false
1516 }, options );
1617 $(this).each( function() {
1718 var $this = $(this);
@@ -23,8 +24,13 @@
2425 }
2526 var text = $this.text();
2627 var w = $this.width();
27 - var $text = $( '<span />' ).css( 'whiteSpace', 'nowrap' );
28 - $this.empty().append( $text );
 28+ var $text;
 29+ if ( options.hasSpan ) {
 30+ $text = $this.children( 'span' );
 31+ } else {
 32+ $text = $( '<span />' ).css( 'whiteSpace', 'nowrap' );
 33+ $this.empty().append( $text );
 34+ }
2935
3036 // Try cache
3137 if ( !( text in cache ) ) {
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -5182,7 +5182,8 @@
51835183 options = $.extend( {
51845184 'position': 'center',
51855185 'tooltip': false,
5186 - 'restoreText': false
 5186+ 'restoreText': false,
 5187+ 'hasSpan': false
51875188 }, options );
51885189 $(this).each( function() {
51895190 var $this = $(this);
@@ -5195,8 +5196,13 @@
51965197 }
51975198 var text = $this.text();
51985199 var w = $this.width();
5199 - var $text = $( '<span />' ).css( 'whiteSpace', 'nowrap' );
5200 - $this.empty().append( $text );
 5200+ var $text;
 5201+ if ( options.hasSpan ) {
 5202+ $text = $this.children( 'span' );
 5203+ } else {
 5204+ $text = $( '<span />' ).css( 'whiteSpace', 'nowrap' );
 5205+ $this.empty().append( $text );
 5206+ }
52015207
52025208 // Try cache
52035209 if ( !( text in cache ) ) {
@@ -5782,6 +5788,13 @@
57835789 * Type: Number, Range: 1 - 100, Default: 7
57845790 * delay: Number of ms to wait for the user to stop typing
57855791 * Type: Number, Range: 0 - 1200, Default: 120
 5792+ * submitOnClick: Whether to submit the form containing the textbox when a suggestion is clicked
 5793+ * 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
 5797+ * expandToLeft: Whether to expand the suggestion box to the left rather than to the right
 5798+ * Type: Boolean, Default: false
57865799 */
57875800 ( function( $ ) {
57885801
@@ -5881,8 +5894,10 @@
58825895 } );
58835896 var $results = context.data.$container.children( '.suggestions-results' );
58845897 $results.empty();
 5898+ var expWidth = -1;
 5899+ var $autoEllipseMe = $( [] );
58855900 for ( var i = 0; i < context.config.suggestions.length; i++ ) {
5886 - $result = $( '<div />' )
 5901+ var $result = $( '<div />' )
58875902 .addClass( 'suggestions-result' )
58885903 .attr( 'rel', i )
58895904 .data( 'text', context.config.suggestions[i] )
@@ -5892,13 +5907,40 @@
58935908 );
58945909 } )
58955910 .appendTo( $results );
 5911+
58965912 // Allow custom rendering
58975913 if ( typeof context.config.result.render == 'function' ) {
58985914 context.config.result.render.call( $result, context.config.suggestions[i] );
58995915 } else {
5900 - $result.text( context.config.suggestions[i] ).autoEllipsis();
 5916+ // Add <span> with text
 5917+ $result.append( $( '<span />' )
 5918+ .css( 'whiteSpace', 'nowrap' )
 5919+ .text( context.config.suggestions[i] )
 5920+ );
 5921+
 5922+ // Widen results box if needed
 5923+ // New width is only calculated here, applied later
 5924+ var $span = $result.children( 'span' );
 5925+ if ( $span.width() > $result.width() ) {
 5926+ expWidth = Math.max( expWidth, Math.min( $span.width(),
 5927+ context.data.$textbox.width()*context.config.maxExpandFactor
 5928+ ) );
 5929+ }
 5930+ $autoEllipseMe = $autoEllipseMe.add( $result );
59015931 }
59025932 }
 5933+ // Apply new width for results box, if any
 5934+ if ( expWidth != -1 ) {
 5935+ if ( context.config.expandToLeft ) {
 5936+ context.data.$container.css( 'left',
 5937+ context.data.$container.offset().left -
 5938+ ( expWidth - context.data.$container.width() )
 5939+ );
 5940+ }
 5941+ context.data.$container.width( expWidth );
 5942+ }
 5943+ // autoEllipse the results. Has to be done after changing the width
 5944+ $autoEllipseMe.autoEllipsis( { hasSpan: true, tooltip: true } );
59035945 }
59045946 }
59055947 break;
@@ -5908,7 +5950,11 @@
59095951 case 'delay':
59105952 context.config[property] = Math.max( 0, Math.min( 1200, value ) );
59115953 break;
 5954+ case 'maxExpandFactor':
 5955+ context.config[property] = Math.max( 1, value );
 5956+ break;
59125957 case 'submitOnClick':
 5958+ case 'expandToLeft':
59135959 context.config[property] = value ? true : false;
59145960 break;
59155961 }
@@ -6058,7 +6104,9 @@
60596105 'suggestions': [],
60606106 'maxRows': 7,
60616107 'delay': 120,
6062 - 'submitOnClick': false
 6108+ 'submitOnClick': false,
 6109+ 'maxExpandFactor': 2,
 6110+ 'expandToLeft': false
60636111 }
60646112 };
60656113 }
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -359,8 +359,9 @@
360360 {var i=0,l=array.length,loop=opts.loop||function(){};$.whileAsync($.extend(opts,{test:function(){return i<l;},loop:function()
361361 {var val=array[i];return loop.call(val,i++,val);}}));}
362362 $.fn.eachAsync=function(opts)
363 -{$.eachAsync(this,opts);return this;}})(jQuery);(function($){var cache={};$.fn.autoEllipsis=function(options){options=$.extend({'position':'center','tooltip':false,'restoreText':false},options);$(this).each(function(){var $this=$(this);if(options.restoreText){if(!$this.data('autoEllipsis.originalText')){$this.data('autoEllipsis.originalText',$this.text());}else{$this.text($this.data('autoEllipsis.originalText'));}}
364 -var text=$this.text();var w=$this.width();var $text=$('<span />').css('whiteSpace','nowrap');$this.empty().append($text);if(!(text in cache)){cache[text]={};}
 363+{$.eachAsync(this,opts);return this;}})(jQuery);(function($){var cache={};$.fn.autoEllipsis=function(options){options=$.extend({'position':'center','tooltip':false,'restoreText':false,'hasSpan':false},options);$(this).each(function(){var $this=$(this);if(options.restoreText){if(!$this.data('autoEllipsis.originalText')){$this.data('autoEllipsis.originalText',$this.text());}else{$this.text($this.data('autoEllipsis.originalText'));}}
 364+var text=$this.text();var w=$this.width();var $text;if(options.hasSpan){$text=$this.children('span');}else{$text=$('<span />').css('whiteSpace','nowrap');$this.empty().append($text);}
 365+if(!(text in cache)){cache[text]={};}
365366 if(w in cache[text]){$text.text(cache[text][w]);return;}
366367 $text.text(text);if($text.width()>w){switch(options.position){case'right':var l=0,r=text.length;do{var m=Math.ceil((l+r)/2);$text.text(text.substr(0,m)+'...');if($text.width()>w){r=m-1;}else{l=m;}}while(l<r);$text.text(text.substr(0,l)+'...');break;case'center':var i=[Math.round(text.length/2),Math.round(text.length/2)];var side=1;while($text.outerWidth()>w&&i[0]>0){$text.text(text.substr(0,i[0])+'...'+text.substr(i[1]));if(side==0){i[0]--;side=1;}else{i[1]++;side=0;}}
367368 break;case'left':var r=0;while($text.outerWidth()>w&&r<text.length){$text.text('...'+text.substr(r));r++;}
@@ -394,8 +395,13 @@
395396 if(typeof context.config.cancel=='function'){context.config.cancel.call(context.data.$textbox);}},restore:function(context){context.data.$textbox.val(context.data.prevText);},update:function(context,delayed){function maybeFetch(){if(context.data.$textbox.val()!==context.data.prevText){context.data.prevText=context.data.$textbox.val();if(typeof context.config.fetch=='function'){context.config.fetch.call(context.data.$textbox,context.data.$textbox.val());}}}
396397 if(context.data.timerID!=null){clearTimeout(context.data.timerID);}
397398 if(delayed){context.data.timerID=setTimeout(maybeFetch,context.config.delay);}else{maybeFetch();}
398 -$.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();context.data.$container.css({'top':context.config.$region.offset().top+context.config.$region.outerHeight(),'bottom':'auto','width':context.config.$region.outerWidth(),'height':'auto','left':context.config.$region.offset().left,'right':'auto'});var $results=context.data.$container.children('.suggestions-results');$results.empty();for(var i=0;i<context.config.suggestions.length;i++){$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.text(context.config.suggestions[i]).autoEllipsis();}}}}
399 -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':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');}}}
 399+$.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();context.data.$container.css({'top':context.config.$region.offset().top+context.config.$region.outerHeight(),'bottom':'auto','width':context.config.$region.outerWidth(),'height':'auto','left':context.config.$region.offset().left,'right':'auto'});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));}
 400+$autoEllipseMe=$autoEllipseMe.add($result);}}
 401+if(expWidth!=-1){if(context.config.expandToLeft){context.data.$container.css('left',context.data.$container.offset().left-
 402+(expWidth-context.data.$container.width()));}
 403+context.data.$container.width(expWidth);}
 404+$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'expandToLeft':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');}}}
400406 selected.removeClass('suggestions-result-current');result.addClass('suggestions-result-current');}
401407 if(updateTextbox){if(result.length==0){$.suggestions.restore(context);}else{context.data.$textbox.val(result.data('text'));context.data.$textbox.change();}
402408 context.data.$textbox.trigger('change');}
@@ -403,7 +409,7 @@
404410 preventDefault=true;break;case 38:if(wasVisible){$.suggestions.highlight(context,'prev',false);}
405411 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);}}
406412 break;default:$.suggestions.update(context,true);break;}
407 -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}};}
 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,'expandToLeft':false}};}
408414 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]]);}}}
409415 if(typeof context.data=='undefined'){context.data={'timerID':null,'prevText':null,'visibleResults':0,'mouseDownOn':$([]),'$textbox':$(this)};context.data.$container=$('<div />').css({'top':Math.round(context.data.$textbox.offset().top+context.data.$textbox.outerHeight()),'left':Math.round(context.data.$textbox.offset().left),'width':context.data.$textbox.outerWidth(),'display':'none'}).addClass('suggestions').append($('<div />').addClass('suggestions-results').mousedown(function(e){context.data.mouseDownOn=$(e.target).closest('.suggestions-results div');}).mouseup(function(e){var $result=$(e.target).closest('.suggestions-results div');var $other=context.data.mouseDownOn;context.data.mouseDownOn=$([]);if($result.get(0)!=$other.get(0)){return;}
410416 $.suggestions.highlight(context,$result,true);context.data.$container.hide();if(typeof context.config.result.select=='function'){context.config.result.select.call($result,context.data.$textbox);}

Follow-up revisions

RevisionCommit summaryAuthorDate
r66631CSS change to compliment r66623adam22:07, 18 May 2010

Status & tagging log