Henning Snater has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/51351


Change subject: Entity search: Allow random text input in entity selector
......................................................................

Entity search: Allow random text input in entity selector

With this change set, the text typed into the entity selector search box will
not get lost when triggering a full-text search (when entering text that does
not match an entity).

Change-Id: Ie27da6cf8f7f2294a228f6357dc85e2fdafa5c23
---
M repo/resources/wikibase.ui.entitysearch.js
1 file changed, 35 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/51/51351/1

diff --git a/repo/resources/wikibase.ui.entitysearch.js 
b/repo/resources/wikibase.ui.entitysearch.js
index ca56e69..2858e0d 100644
--- a/repo/resources/wikibase.ui.entitysearch.js
+++ b/repo/resources/wikibase.ui.entitysearch.js
@@ -12,6 +12,8 @@
        'use strict';
 
        $( document ).ready( function() {
+               var $form = $( '#searchform ' ),
+                       $input = $( '#searchInput' );
 
                /**
                 * Removes the native search box suggestion list.
@@ -24,7 +26,7 @@
                        $.removeData( input, 'suggestionsContext' );
                }
 
-               $( '#searchInput' )
+               $input
                .one( 'focus', function( event ) {
                        if ( $.data( this, 'suggestionsContext' ) ) {
                                removeSuggestionContext( this );
@@ -46,6 +48,38 @@
                        emulateSearch: true
                } );
 
+               // TODO: Re-evaluate entity selector input (e.g. hitting "Go" 
after having hit "Search"
+               // before. However, this will require triggering the entity 
selector's API call and waiting
+               // for its response.
+
+               $( '#searchGoButton' ).on( 'click keydown', function( event ) {
+                       if ( !$input.data( 'entityselector' ) ) {
+                               return;
+                       }
+
+                       // If an entity is selected, redirect to that entity's 
page.
+                       if (
+                               event.type === 'click'
+                               || event.keyCode === $.ui.keyCode.ENTER || 
event.keyCode === $.ui.keyCode.SPACE
+                       ) {
+                               var entity = $input.data( 'entityselector' 
).selectedEntity();
+                               if ( entity && entity.url ){
+                                       event.preventDefault(); // Prevent 
default form sumit action.
+                                       window.location.href = entity.url;
+                               }
+                       }
+
+               } );
+
+               // Default form submit action: Imitate full-text search.
+               // Since we are using the entity selector, if an entity is 
selected, the entity id is stored
+               // in a hidden input element (which has ripped the "name" 
attribute from the original search
+               // box). Therefore, the entity id needs to be replaced by the 
actual search box (entity
+               // selector) content.
+               $form.on( 'submit', function( event ) {
+                       $( this ).find( 'input[name="search"]' ).val( 
$input.val() );
+               } );
+
        } );
 
 }( jQuery, mediaWiki ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie27da6cf8f7f2294a228f6357dc85e2fdafa5c23
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to