build: Enable jscs rules 'requireSpacesInside*Brackets' and make pass
[lhc/web/wiklou.git] / resources / src / mediawiki / mediawiki.searchSuggest.js
index b620e05..3c4f32e 100644 (file)
@@ -2,6 +2,20 @@
  * Add search suggestions to the search form.
  */
 ( function ( mw, $ ) {
+       mw.searchSuggest = {
+               request: function ( api, query, response, maxRows ) {
+                       return api.get( {
+                               action: 'opensearch',
+                               search: query,
+                               namespace: 0,
+                               limit: maxRows,
+                               suggest: ''
+                       } ).done( function ( data ) {
+                               response( data[ 1 ] );
+                       } );
+               }
+       };
+
        $( function () {
                var api, map, searchboxesSelectors,
                        // Region where the suggestions box will appear directly below
                // Compatibility map
                map = {
                        // SimpleSearch is broken in Opera < 9.6
-                       opera: [['>=', 9.6]],
+                       opera: [ [ '>=', 9.6 ] ],
                        // Older Konquerors are unable to position the suggestions correctly (bug 50805)
-                       konqueror: [['>=', '4.11']],
+                       konqueror: [ [ '>=', '4.11' ] ],
                        docomo: false,
                        blackberry: false,
                        // Support for iOS 6 or higher. It has not been tested on iOS 5 or lower
-                       ipod: [['>=', 6]],
-                       iphone: [['>=', 6]]
+                       ipod: [ [ '>=', 6 ] ],
+                       iphone: [ [ '>=', 6 ] ]
                };
 
                if ( !$.client.test( map ) ) {
                searchboxesSelectors = [
                        // Primary searchbox on every page in standard skins
                        '#searchInput',
+                       // Special:Search
+                       '#powerSearchText',
+                       '#searchText',
                        // Generic selector for skins with multiple searchboxes (used by CologneBlue)
                        // and for MediaWiki itself (special pages with page title inputs)
                        '.mw-searchInput'
                $( searchboxesSelectors.join( ', ' ) )
                        .suggestions( {
                                fetch: function ( query, response, maxRows ) {
-                                       var node = this[0];
+                                       var node = this[ 0 ];
 
                                        api = api || new mw.Api();
 
-                                       $.data( node, 'request', api.get( {
-                                               action: 'opensearch',
-                                               search: query,
-                                               namespace: 0,
-                                               limit: maxRows,
-                                               suggest: ''
-                                       } ).done( function ( data ) {
-                                               response( data[ 1 ] );
-                                       } ) );
+                                       $.data( node, 'request', mw.searchSuggest.request( api, query, response, maxRows ) );
                                },
                                cancel: function () {
-                                       var node = this[0],
+                                       var node = this[ 0 ],
                                                request = $.data( node, 'request' );
 
                                        if ( request ) {