Index: trunk/phase3/resources/mediawiki.page/mediawiki.page.mwsuggest.js |
— | — | @@ -1,18 +1,18 @@ |
2 | 2 | jQuery( document ).ready( function( $ ) { |
3 | | - var $container = $('<div>', {'class' : 'open-search-suggestions'}), |
| 3 | + var $container = $( '<div>', { 'class' : 'open-search-suggestions' } ), |
4 | 4 | cache = {}, |
5 | 5 | $suggestionList, |
6 | | - url = mw.config.get('wgScriptPath') + '/api.php?format=json&action=opensearch&search=', |
| 6 | + url = mw.config.get( 'wgScriptPath' ) + '/api.php?format=json&action=opensearch&search=', |
7 | 7 | maxRowWindow; |
8 | 8 | |
9 | 9 | //Append the container which will hold the menu to the body |
10 | | - $('body').append( $container ); |
| 10 | + $( 'body' ).append( $container ); |
11 | 11 | |
12 | 12 | /* Grabs namespaces from search form or |
13 | 13 | * in case we're not on a search page, take it from wgSearchNamespaces. |
14 | 14 | * @return Array: List of Namespaces that should be searched |
15 | 15 | */ |
16 | | - getNamespaces = function() { |
| 16 | + var getNamespaces = function() { |
17 | 17 | var namespaces = []; |
18 | 18 | $('form#powersearch, form#search').find( '[name^="ns"]' ).each(function() { |
19 | 19 | if ( this.checked || ( this.type == 'hidden' && this.value == '1' ) ) { |
— | — | @@ -26,7 +26,7 @@ |
27 | 27 | }; |
28 | 28 | |
29 | 29 | /* Helper function to make sure that the list doesn't expand below the visible part of the window */ |
30 | | - deliverResult = function( obj, response, maxRowWindow ) { |
| 30 | + var deliverResult = function( obj, response, maxRowWindow ) { |
31 | 31 | if ( obj && obj.length > 1 ) { |
32 | 32 | response( obj[1] ); |
33 | 33 | // Get the lowest from multiple numbers using fn.apply |
— | — | @@ -38,33 +38,33 @@ |
39 | 39 | }; |
40 | 40 | |
41 | 41 | /* The actual autocomplete setup */ |
42 | | - $("#searchInput").autocomplete({ |
| 42 | + $( "#searchInput" ).autocomplete({ |
43 | 43 | minLength: 2, |
44 | 44 | source: function ( request, response ) { |
45 | 45 | var namespaces = getNamespaces(); |
46 | 46 | // We're caching queries for performance |
47 | 47 | var term = request.term + namespaces; |
48 | | - if (term in cache) { |
| 48 | + if ( term in cache ) { |
49 | 49 | deliverResult( cache[term], response, maxRowWindow ); |
50 | 50 | return; |
51 | 51 | } |
52 | | - $.getJSON(url + mw.util.rawurlencode( request.term ) + '&namespace=' + namespaces, function ( obj ) { |
| 52 | + $.getJSON( url + mw.util.rawurlencode( request.term ) + '&namespace=' + namespaces, function ( obj ) { |
53 | 53 | // Save to cache |
54 | | - cache[term] = obj; |
| 54 | + cache[ term ] = obj; |
55 | 55 | deliverResult( obj, response, maxRowWindow ); |
56 | 56 | }); |
57 | 57 | }, |
58 | | - select: function() { |
59 | | - $('#searchGoButton').click(); |
| 58 | + select : function() { |
| 59 | + $( '#searchGoButton' ).click(); |
60 | 60 | }, |
61 | 61 | create : function() { |
62 | | - $suggestionList = $container.find('ul'); |
| 62 | + $suggestionList = $container.find( 'ul' ); |
63 | 63 | }, |
64 | | - appendTo: '.open-search-suggestions', |
65 | | - open: function() { |
66 | | - maxRowWindow = Math.floor( |
67 | | - ( $(window).height() - $suggestionList.offset().top + $(window).scrollTop() ) / |
68 | | - $suggestionList.find( '.ui-menu-item' ).eq( 0 ).height() |
| 64 | + appendTo : '.open-search-suggestions', |
| 65 | + open : function() { |
| 66 | + maxRowWindow = Math.floor( |
| 67 | + ( $( window ).height() - $suggestionList.offset().top + $( window ).scrollTop() ) / |
| 68 | + $suggestionList.find( '.ui-menu-item' ).eq( 0 ).height() |
69 | 69 | ); |
70 | 70 | } |
71 | 71 | }); |