Merge "Check validity and availability of usernames during signup via AJAX"
[lhc/web/wiklou.git] / resources / mediawiki / mediawiki.searchSuggest.js
index 9fcd42a..6999610 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*!
  * Add search suggestions to the search form.
  */
 ( function ( mw, $ ) {
 
                // Compute form data for search suggestions functionality.
                function computeResultRenderCache( context ) {
-                       var $form, formAction, baseHref, linkParams;
+                       var $form, baseHref, linkParams;
 
                        // Compute common parameters for links' hrefs
                        $form = context.config.$region.closest( 'form' );
 
-                       formAction = $form.attr( 'action' );
-                       baseHref = formAction + ( formAction.match( /\?/ ) ? '&' : '?' );
+                       baseHref = $form.attr( 'action' );
+                       baseHref += baseHref.indexOf( '?' ) > -1 ? '&' : '?';
 
                        linkParams = {};
                        $.each( $form.serializeArray(), function ( idx, obj ) {
                                },
                                result: {
                                        render: renderFunction,
-                                       select: function ( $input ) {
-                                               $input.closest( 'form' ).submit();
+                                       select: function () {
+                                               return true; // allow the form to be submitted
                                        }
                                },
                                delay: 120,
                                // make sure paste and cut events from the mouse and drag&drop events
                                // trigger the keypress handler and cause the suggestions to update
                                $( this ).trigger( 'keypress' );
-                       } )
-                       // If the forms include any fulltext search thingies, remove them as they
-                       // would interfere with selecting suggestions
-                       .closest( 'form' ).find( '[name="fulltext"]' ).remove();
+                       } );
 
                // Ensure that the thing is actually present!
                if ( $searchRegion.length === 0 ) {
                $searchInput.suggestions( {
                        result: {
                                render: renderFunction,
-                               select: function ( $input ) {
-                                       $input.closest( 'form' ).submit();
+                               select: function () {
+                                       return true; // allow the form to be submitted
                                }
                        },
                        special: {
                                render: specialRenderFunction,
                                select: function ( $input ) {
-                                       $input.closest( 'form' ).append(
-                                               $( '<input type="hidden" name="fulltext" value="1"/>' )
-                                       );
-                                       $input.closest( 'form' ).submit();
+                                       $input.closest( 'form' )
+                                               .append( $( '<input type="hidden" name="fulltext" value="1"/>' ) );
+                                       return true; // allow the form to be submitted
                                }
                        },
                        $region: $searchRegion
                } );
 
+               // If the form includes any fallback fulltext search buttons, remove them
+               $searchInput.closest( 'form' ).find( '.mw-fallbackSearchButton' ).remove();
+
                // In most skins (at least Monobook and Vector), the font-size is messed up in <body>.
                // (they use 2 elements to get a sane font-height). So, instead of making exceptions for
                // each skin or adding more stylesheets, just copy it from the active element so auto-fit.