jenkins-bot has submitted this change and it was merged.

Change subject: jquery.suggestions, mediawiki.searchSuggest: Fix form submission
......................................................................


jquery.suggestions, mediawiki.searchSuggest: Fix form submission

Don't override form submission behavior (by capturing the Enter key on
search box, preventing default behavior, and then manually submitting
the form); just let it happen if it's wanted.

Then swap out a few unjustified stopImmediatePropagation() calls to
stopPropagation() so that the event can be actually fired. Add some
comments while we're at it.

This allows the user to use Ctrl+Enter (or Shift+Enter) to submit the
form into a new tab (or new window) on browsers that support this
(currently Opera and Chrome).

Bug: 34756
Bug: 35974
Change-Id: I49ef7cc89400032505bc444f21d522d5b5d47586
---
M resources/jquery/jquery.suggestions.js
M resources/mediawiki/mediawiki.searchSuggest.js
2 files changed, 21 insertions(+), 15 deletions(-)

Approvals:
  Yuvipanda: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/resources/jquery/jquery.suggestions.js 
b/resources/jquery/jquery.suggestions.js
index c4e95a4..f967a1d 100644
--- a/resources/jquery/jquery.suggestions.js
+++ b/resources/jquery/jquery.suggestions.js
@@ -421,20 +421,26 @@
                                selected = context.data.$container.find( 
'.suggestions-result-current' );
                                $.suggestions.hide( context );
                                if ( selected.length === 0 || 
context.data.selectedWithMouse ) {
-                                       // if nothing is selected OR if 
something was selected with the mouse,
-                                       // cancel any current requests and 
submit the form
+                                       // If nothing is selected or if 
something was selected with the mouse
+                                       // cancel any current requests and 
allow the form to be submitted
+                                       // (simply don't prevent default 
behavior).
                                        $.suggestions.cancel( context );
-                                       context.config.$region.closest( 'form' 
).submit();
+                                       preventDefault = false;
                                } else if ( selected.is( '.suggestions-special' 
) ) {
                                        if ( typeof 
context.config.special.select === 'function' ) {
-                                               
context.config.special.select.call( selected, context.data.$textbox );
+                                               // Allow the callback to decide 
whether to prevent default or not
+                                               if ( 
context.config.special.select.call( selected, context.data.$textbox ) === true 
) {
+                                                       preventDefault = false;
+                                               }
                                        }
                                } else {
+                                       $.suggestions.highlight( context, 
selected, true );
+
                                        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 );
+                                               // Allow the callback to decide 
whether to prevent default or not
+                                               if ( 
context.config.result.select.call( selected, context.data.$textbox ) === true ) 
{
+                                                       preventDefault = false;
+                                               }
                                        }
                                }
                                break;
@@ -444,7 +450,7 @@
                }
                if ( preventDefault ) {
                        e.preventDefault();
-                       e.stopImmediatePropagation();
+                       e.stopPropagation();
                }
        }
 };
diff --git a/resources/mediawiki/mediawiki.searchSuggest.js 
b/resources/mediawiki/mediawiki.searchSuggest.js
index 8d950a0..e22a3d3 100644
--- a/resources/mediawiki/mediawiki.searchSuggest.js
+++ b/resources/mediawiki/mediawiki.searchSuggest.js
@@ -153,8 +153,8 @@
                                },
                                result: {
                                        render: renderFunction,
-                                       select: function ( $input ) {
-                                               $input.closest( 'form' 
).submit();
+                                       select: function () {
+                                               return true; // allow the form 
to be submitted
                                        }
                                },
                                delay: 120,
@@ -178,16 +178,16 @@
                $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"/>' ) )
-                                               .submit();
+                                               .append( $( '<input 
type="hidden" name="fulltext" value="1"/>' ) );
+                                       return true; // allow the form to be 
submitted
                                }
                        },
                        $region: $searchRegion

-- 
To view, visit https://gerrit.wikimedia.org/r/48252
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I49ef7cc89400032505bc444f21d522d5b5d47586
Gerrit-PatchSet: 10
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <matma....@gmail.com>
Gerrit-Reviewer: Bartosz Dziewoński <matma....@gmail.com>
Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org>
Gerrit-Reviewer: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: Mattflaschen <mflasc...@wikimedia.org>
Gerrit-Reviewer: Matthias Mullie <mmul...@wikimedia.org>
Gerrit-Reviewer: Ori.livneh <o...@wikimedia.org>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: Yuvipanda <yuvipa...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to