Index: trunk/extensions/Vector/modules/ext.vector.simpleSearch.js |
— | — | @@ -40,26 +40,33 @@ |
41 | 41 | |
42 | 42 | // General suggestions functionality for all search boxes |
43 | 43 | $( '#searchInput, #searchInput2, #powerSearchText, #searchText' ) |
| 44 | + .mouseover( function() { $(this).focus() |
| 45 | + }) |
44 | 46 | .suggestions( { |
45 | 47 | fetch: function( query ) { |
46 | 48 | var $this = $(this); |
47 | | - var request = $.ajax( { |
48 | | - url: mw.config.get( 'wgScriptPath' ) + '/api.php', |
49 | | - data: { |
50 | | - action: 'opensearch', |
51 | | - search: query, |
52 | | - limit: 10, |
53 | | - namespace: 0, |
54 | | - suggest: '' |
55 | | - }, |
56 | | - dataType: 'json', |
57 | | - success: function( data ) { |
58 | | - if ( $.isArray( data ) && 1 in data ) { |
59 | | - $this.suggestions( 'suggestions', data[1] ); |
| 49 | + if ( query.length != 0 ) { |
| 50 | + var request = $.ajax( { |
| 51 | + url: mw.config.get( 'wgScriptPath' ) + '/api.php', |
| 52 | + data: { |
| 53 | + action: 'opensearch', |
| 54 | + search: query, |
| 55 | + namespace: 0, |
| 56 | + suggest: '' |
| 57 | + }, |
| 58 | + dataType: 'json', |
| 59 | + success: function( data ) { |
| 60 | + if ( $.isArray( data ) && 1 in data ) { |
| 61 | + $this.suggestions( 'suggestions', data[1] ); |
| 62 | + } |
60 | 63 | } |
61 | | - } |
62 | | - }); |
63 | | - $(this).data( 'request', request ); |
| 64 | + }); |
| 65 | + $this.data( 'request', request ); |
| 66 | + } else { |
| 67 | + // no need to send ajax request for empty input but clear the result div |
| 68 | + var context = $this.data( 'suggestions-context' ); |
| 69 | + context.data.$container.hide(); |
| 70 | + } |
64 | 71 | }, |
65 | 72 | cancel: function () { |
66 | 73 | var request = $(this).data( 'request' ); |