Henning Snater has uploaded a new change for review.
https://gerrit.wikimedia.org/r/51662
Change subject: (bug 44674) Entity search: Prevent closing suggestion list
......................................................................
(bug 44674) Entity search: Prevent closing suggestion list
The change set prevents the suggestion list of the entity selector replacing
the native
search box from closing if there are no actual suggestions. If there are no
suggestions,
the link to the full-text search will remain visible.
Change-Id: I0069a6b1ae1f6264c2a59c29bafffbb6b520a946
---
M lib/resources/jquery.wikibase/jquery.wikibase.entityselector.js
M repo/resources/wikibase.ui.entitysearch.js
2 files changed, 24 insertions(+), 10 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/62/51662/1
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.entityselector.js
b/lib/resources/jquery.wikibase/jquery.wikibase.entityselector.js
index 55cfd66..59cd1a7 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.entityselector.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.entityselector.js
@@ -51,7 +51,7 @@
* @option messages['more'] {String} (optional) Label of the link to display
more suggestions.
* Default value: 'more'
*
- * @option emulateSearch {boolean} (optional) Allows emulating the behaviour
of a search box by
+ * @option emulateSearchBox {boolean} (optional) Allows emulating the
behaviour of a search box by
* linking the entities to their corresponding pages. Instead of
selecting an entity, the
* whole page will be redirected to the entity page.
* Default value: false
@@ -117,7 +117,7 @@
'aliases-label': mwMsgOrString(
'wikibase-aliases-label', 'also known as:' ),
'more': mwMsgOrString(
'wikibase-entityselector-more', 'more' )
},
- emulateSearch: false // TODO: Allow setting a custom
target to trigger the redirect on
+ emulateSearchBox: false // TODO: Allow setting a custom
target to trigger the redirect on
},
/**
@@ -193,7 +193,7 @@
// and select it
if ( event.keyCode === $.ui.keyCode.ENTER ) {
- if ( self.options.emulateSearch &&
self.selectedEntity() ) {
+ if ( self.options.emulateSearchBox &&
self.selectedEntity() ) {
// Prevent submitting search
form since we want to redirect directly to the
// entity.
event.stopImmediatePropagation();
@@ -231,7 +231,7 @@
$( event.target ).closest(
'.ui-menu-item' ).data( 'item.autocomplete' );
self._setEntity( item );
- if ( self.options.emulateSearch ) {
+ if ( self.options.emulateSearchBox ) {
window.location.href = item.url;
}
@@ -344,7 +344,21 @@
* @see ui.suggester.close
*/
close: function( event ) {
- if ( !event || !event.originalEvent ||
event.originalEvent.type !== 'programmatic' ) {
+ var originalType = ( event && event.originalEvent &&
event.originalEvent.type )
+ ? event.originalEvent.type
+ : null;
+
+ // When emulating a search box and there is a custom
item, only close the list of
+ // suggestions when blurring or when there is no text
in the input box.
+ if (
+ this.options.emulateSearchBox &&
this.options.customListItem
+ && originalType !== 'blur' &&
this.element.val() !== ''
+ ) {
+ // Reset list content leaving just the custom
item.
+ this.offset = 0;
+ this.menu.element.children().remove();
+ this.menu.refresh();
+ } else {
// Do not close the list of suggestions when
programmatically selecting an entity
// (e.g by typing an exact, unique entity
label), allowing the user to check that
// the typed string actually matches a single
entity.
@@ -486,13 +500,13 @@
}
} else {
this._setEntity( null );
- if ( this.options.emulateSearch ) {
+ if ( this.options.emulateSearchBox ) {
this._hiddenInput(
this.element.val() );
}
}
return true;
}
- if ( this.options.emulateSearch ) {
+ if ( this.options.emulateSearchBox ) {
this._hiddenInput( this.element.val() );
}
return false;
@@ -523,7 +537,7 @@
),
$section = $( '<li/>' ).data(
'item.autocomplete', item ).append( $link );
- if ( this.options.emulateSearch ) {
+ if ( this.options.emulateSearchBox ) {
$link.attr( 'href', item.url );
}
@@ -607,7 +621,7 @@
found = true;
}
- if ( !found && !alreadySelected &&
!this.options.emulateSearch ) {
+ if ( !found && !alreadySelected &&
!this.options.emulateSearchBox ) {
this._setEntity( null );
}
return found;
diff --git a/repo/resources/wikibase.ui.entitysearch.js
b/repo/resources/wikibase.ui.entitysearch.js
index ca56e69..bcf3157 100644
--- a/repo/resources/wikibase.ui.entitysearch.js
+++ b/repo/resources/wikibase.ui.entitysearch.js
@@ -43,7 +43,7 @@
.entityselector( {
url: mw.config.get( 'wgServer' ) + mw.config.get(
'wgScriptPath' ) + '/api.php',
language: mw.config.get( 'wgUserLanguage' ),
- emulateSearch: true
+ emulateSearchBox: true
} );
} );
--
To view, visit https://gerrit.wikimedia.org/r/51662
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0069a6b1ae1f6264c2a59c29bafffbb6b520a946
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