Index: trunk/extensions/UsabilityInitiative/Vector/Modules/SimpleSearch/SimpleSearch.js |
— | — | @@ -74,7 +74,8 @@ |
75 | 75 | $textbox.closest( 'form' ).submit(); |
76 | 76 | } |
77 | 77 | }, |
78 | | - delay: 120 |
| 78 | + delay: 120, |
| 79 | + expandToLeft: !$j( 'body' ).is( 'rtl' ) |
79 | 80 | } ); |
80 | 81 | $j( '#searchInput' ).suggestions( { |
81 | 82 | result: { |
Index: trunk/extensions/UsabilityInitiative/Vector/Vector.hooks.php |
— | — | @@ -16,13 +16,13 @@ |
17 | 17 | array( 'src' => 'Modules/CollapsibleTabs/CollapsibleTabs.js', 'version' => 8 ), |
18 | 18 | array( 'src' => 'Modules/EditWarning/EditWarning.js', 'version' => 8 ), |
19 | 19 | 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 ), |
21 | 21 | ), |
22 | 22 | 'combined' => array( |
23 | | - array( 'src' => 'Vector.combined.js', 'version' => 29 ), |
| 23 | + array( 'src' => 'Vector.combined.js', 'version' => 30 ), |
24 | 24 | ), |
25 | 25 | 'minified' => array( |
26 | | - array( 'src' => 'Vector.combined.min.js', 'version' => 29 ), |
| 26 | + array( 'src' => 'Vector.combined.min.js', 'version' => 30 ), |
27 | 27 | ), |
28 | 28 | ); |
29 | 29 | static $modules = array( |
Index: trunk/extensions/UsabilityInitiative/Vector/Vector.combined.js |
— | — | @@ -335,7 +335,8 @@ |
336 | 336 | $textbox.closest( 'form' ).submit(); |
337 | 337 | } |
338 | 338 | }, |
339 | | - delay: 120 |
| 339 | + delay: 120, |
| 340 | + expandToLeft: !$j( 'body' ).is( 'rtl' ) |
340 | 341 | } ); |
341 | 342 | $j( '#searchInput' ).suggestions( { |
342 | 343 | result: { |
Index: trunk/extensions/UsabilityInitiative/Vector/Vector.combined.min.js |
— | — | @@ -14,5 +14,5 @@ |
15 | 15 | +transclusionCount |
16 | 16 | +'</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=[];} |
17 | 17 | $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() |
19 | 19 | $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 @@ |
65 | 65 | |
66 | 66 | // Core functionality of extension scripts |
67 | 67 | 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 ), |
69 | 69 | array( 'src' => 'js/plugins/jquery.browser.js', 'version' => 6 ), |
70 | 70 | array( 'src' => 'js/plugins/jquery.collapsibleTabs.js', 'version' => 6 ), |
71 | 71 | array( 'src' => 'js/plugins/jquery.color.js', 'version' => 1 ), |
72 | 72 | array( 'src' => 'js/plugins/jquery.cookie.js', 'version' => 4 ), |
73 | 73 | array( 'src' => 'js/plugins/jquery.delayedBind.js', 'version' => 1 ), |
| 74 | + array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 16 ), |
74 | 75 | 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 ), |
76 | 77 | array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 33 ), |
77 | 78 | array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 187 ), |
78 | 79 | array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 53 ), |
— | — | @@ -84,10 +85,10 @@ |
85 | 86 | array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 5 ), |
86 | 87 | ), |
87 | 88 | 'combined' => array( |
88 | | - array( 'src' => 'js/plugins.combined.js', 'version' => 397 ), |
| 89 | + array( 'src' => 'js/plugins.combined.js', 'version' => 398 ), |
89 | 90 | ), |
90 | 91 | 'minified' => array( |
91 | | - array( 'src' => 'js/plugins.combined.min.js', 'version' => 397 ), |
| 92 | + array( 'src' => 'js/plugins.combined.min.js', 'version' => 398 ), |
92 | 93 | ), |
93 | 94 | ), |
94 | 95 | ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.suggestions.js |
— | — | @@ -31,6 +31,13 @@ |
32 | 32 | * Type: Number, Range: 1 - 100, Default: 7 |
33 | 33 | * delay: Number of ms to wait for the user to stop typing |
34 | 34 | * 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 |
35 | 42 | */ |
36 | 43 | ( function( $ ) { |
37 | 44 | |
— | — | @@ -130,8 +137,10 @@ |
131 | 138 | } ); |
132 | 139 | var $results = context.data.$container.children( '.suggestions-results' ); |
133 | 140 | $results.empty(); |
| 141 | + var expWidth = -1; |
| 142 | + var $autoEllipseMe = $( [] ); |
134 | 143 | for ( var i = 0; i < context.config.suggestions.length; i++ ) { |
135 | | - $result = $( '<div />' ) |
| 144 | + var $result = $( '<div />' ) |
136 | 145 | .addClass( 'suggestions-result' ) |
137 | 146 | .attr( 'rel', i ) |
138 | 147 | .data( 'text', context.config.suggestions[i] ) |
— | — | @@ -141,13 +150,40 @@ |
142 | 151 | ); |
143 | 152 | } ) |
144 | 153 | .appendTo( $results ); |
| 154 | + |
145 | 155 | // Allow custom rendering |
146 | 156 | if ( typeof context.config.result.render == 'function' ) { |
147 | 157 | context.config.result.render.call( $result, context.config.suggestions[i] ); |
148 | 158 | } 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 ); |
150 | 174 | } |
151 | 175 | } |
| 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 } ); |
152 | 188 | } |
153 | 189 | } |
154 | 190 | break; |
— | — | @@ -157,7 +193,11 @@ |
158 | 194 | case 'delay': |
159 | 195 | context.config[property] = Math.max( 0, Math.min( 1200, value ) ); |
160 | 196 | break; |
| 197 | + case 'maxExpandFactor': |
| 198 | + context.config[property] = Math.max( 1, value ); |
| 199 | + break; |
161 | 200 | case 'submitOnClick': |
| 201 | + case 'expandToLeft': |
162 | 202 | context.config[property] = value ? true : false; |
163 | 203 | break; |
164 | 204 | } |
— | — | @@ -307,7 +347,9 @@ |
308 | 348 | 'suggestions': [], |
309 | 349 | 'maxRows': 7, |
310 | 350 | 'delay': 120, |
311 | | - 'submitOnClick': false |
| 351 | + 'submitOnClick': false, |
| 352 | + 'maxExpandFactor': 2, |
| 353 | + 'expandToLeft': false |
312 | 354 | } |
313 | 355 | }; |
314 | 356 | } |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.autoEllipsis.js |
— | — | @@ -10,7 +10,8 @@ |
11 | 11 | options = $.extend( { |
12 | 12 | 'position': 'center', |
13 | 13 | 'tooltip': false, |
14 | | - 'restoreText': false |
| 14 | + 'restoreText': false, |
| 15 | + 'hasSpan': false |
15 | 16 | }, options ); |
16 | 17 | $(this).each( function() { |
17 | 18 | var $this = $(this); |
— | — | @@ -23,8 +24,13 @@ |
24 | 25 | } |
25 | 26 | var text = $this.text(); |
26 | 27 | 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 | + } |
29 | 35 | |
30 | 36 | // Try cache |
31 | 37 | if ( !( text in cache ) ) { |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js |
— | — | @@ -5182,7 +5182,8 @@ |
5183 | 5183 | options = $.extend( { |
5184 | 5184 | 'position': 'center', |
5185 | 5185 | 'tooltip': false, |
5186 | | - 'restoreText': false |
| 5186 | + 'restoreText': false, |
| 5187 | + 'hasSpan': false |
5187 | 5188 | }, options ); |
5188 | 5189 | $(this).each( function() { |
5189 | 5190 | var $this = $(this); |
— | — | @@ -5195,8 +5196,13 @@ |
5196 | 5197 | } |
5197 | 5198 | var text = $this.text(); |
5198 | 5199 | 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 | + } |
5201 | 5207 | |
5202 | 5208 | // Try cache |
5203 | 5209 | if ( !( text in cache ) ) { |
— | — | @@ -5782,6 +5788,13 @@ |
5783 | 5789 | * Type: Number, Range: 1 - 100, Default: 7 |
5784 | 5790 | * delay: Number of ms to wait for the user to stop typing |
5785 | 5791 | * 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 |
5786 | 5799 | */ |
5787 | 5800 | ( function( $ ) { |
5788 | 5801 | |
— | — | @@ -5881,8 +5894,10 @@ |
5882 | 5895 | } ); |
5883 | 5896 | var $results = context.data.$container.children( '.suggestions-results' ); |
5884 | 5897 | $results.empty(); |
| 5898 | + var expWidth = -1; |
| 5899 | + var $autoEllipseMe = $( [] ); |
5885 | 5900 | for ( var i = 0; i < context.config.suggestions.length; i++ ) { |
5886 | | - $result = $( '<div />' ) |
| 5901 | + var $result = $( '<div />' ) |
5887 | 5902 | .addClass( 'suggestions-result' ) |
5888 | 5903 | .attr( 'rel', i ) |
5889 | 5904 | .data( 'text', context.config.suggestions[i] ) |
— | — | @@ -5892,13 +5907,40 @@ |
5893 | 5908 | ); |
5894 | 5909 | } ) |
5895 | 5910 | .appendTo( $results ); |
| 5911 | + |
5896 | 5912 | // Allow custom rendering |
5897 | 5913 | if ( typeof context.config.result.render == 'function' ) { |
5898 | 5914 | context.config.result.render.call( $result, context.config.suggestions[i] ); |
5899 | 5915 | } 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 ); |
5901 | 5931 | } |
5902 | 5932 | } |
| 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 } ); |
5903 | 5945 | } |
5904 | 5946 | } |
5905 | 5947 | break; |
— | — | @@ -5908,7 +5950,11 @@ |
5909 | 5951 | case 'delay': |
5910 | 5952 | context.config[property] = Math.max( 0, Math.min( 1200, value ) ); |
5911 | 5953 | break; |
| 5954 | + case 'maxExpandFactor': |
| 5955 | + context.config[property] = Math.max( 1, value ); |
| 5956 | + break; |
5912 | 5957 | case 'submitOnClick': |
| 5958 | + case 'expandToLeft': |
5913 | 5959 | context.config[property] = value ? true : false; |
5914 | 5960 | break; |
5915 | 5961 | } |
— | — | @@ -6058,7 +6104,9 @@ |
6059 | 6105 | 'suggestions': [], |
6060 | 6106 | 'maxRows': 7, |
6061 | 6107 | 'delay': 120, |
6062 | | - 'submitOnClick': false |
| 6108 | + 'submitOnClick': false, |
| 6109 | + 'maxExpandFactor': 2, |
| 6110 | + 'expandToLeft': false |
6063 | 6111 | } |
6064 | 6112 | }; |
6065 | 6113 | } |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js |
— | — | @@ -359,8 +359,9 @@ |
360 | 360 | {var i=0,l=array.length,loop=opts.loop||function(){};$.whileAsync($.extend(opts,{test:function(){return i<l;},loop:function() |
361 | 361 | {var val=array[i];return loop.call(val,i++,val);}}));} |
362 | 362 | $.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]={};} |
365 | 366 | if(w in cache[text]){$text.text(cache[text][w]);return;} |
366 | 367 | $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;}} |
367 | 368 | break;case'left':var r=0;while($text.outerWidth()>w&&r<text.length){$text.text('...'+text.substr(r));r++;} |
— | — | @@ -394,8 +395,13 @@ |
395 | 396 | 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());}}} |
396 | 397 | if(context.data.timerID!=null){clearTimeout(context.data.timerID);} |
397 | 398 | 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');}}} |
400 | 406 | selected.removeClass('suggestions-result-current');result.addClass('suggestions-result-current');} |
401 | 407 | if(updateTextbox){if(result.length==0){$.suggestions.restore(context);}else{context.data.$textbox.val(result.data('text'));context.data.$textbox.change();} |
402 | 408 | context.data.$textbox.trigger('change');} |
— | — | @@ -403,7 +409,7 @@ |
404 | 410 | preventDefault=true;break;case 38:if(wasVisible){$.suggestions.highlight(context,'prev',false);} |
405 | 411 | 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);}} |
406 | 412 | 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}};} |
408 | 414 | 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]]);}}} |
409 | 415 | 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;} |
410 | 416 | $.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);} |