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

Change subject: Added suggestions placeholder to $.wikibase.entitysearch
......................................................................


Added suggestions placeholder to $.wikibase.entitysearch

Change-Id: I340de9cc0556def5ab99b718084fe5395126ca31
---
M composer.json
M repo/resources/Resources.php
A repo/resources/jquery.wikibase/jquery.wikibase.entitysearch.js
R repo/resources/jquery.wikibase/themes/default/jquery.wikibase.entitysearch.css
M repo/resources/wikibase.ui.entitysearch.js
5 files changed, 156 insertions(+), 42 deletions(-)

Approvals:
  Thiemo Mättig (WMDE): Looks good to me, approved
  jenkins-bot: Verified



diff --git a/composer.json b/composer.json
index 1f70d8d..19562d0 100644
--- a/composer.json
+++ b/composer.json
@@ -33,7 +33,7 @@
                "data-values/data-types": "~0.4.0",
                "data-values/serialization": "~1.0",
                "data-values/javascript": "~0.6.0",
-               "data-values/value-view": "~0.8.0",
+               "data-values/value-view": "~0.8.1",
 
                "wikibase/data-model": "~2.0",
                "wikibase/data-model-javascript": "~1.0",
diff --git a/repo/resources/Resources.php b/repo/resources/Resources.php
index d93cba0..4c950c8 100644
--- a/repo/resources/Resources.php
+++ b/repo/resources/Resources.php
@@ -24,6 +24,21 @@
        );
 
        $modules = array(
+
+               'jquery.wikibase.entitysearch' => $moduleTemplate + array(
+                       'scripts' => array(
+                               
'jquery.wikibase/jquery.wikibase.entitysearch.js',
+                       ),
+                       'styles' => array(
+                               
'jquery.wikibase/themes/default/jquery.wikibase.entitysearch.css',
+                       ),
+                       'dependencies' => array(
+                               'jquery.event.special.eachchange',
+                               'jquery.ui.ooMenu',
+                               'jquery.wikibase.entityselector',
+                       ),
+               ),
+
                'wikibase.ui.entityViewInit' => $moduleTemplate + array(
                        'scripts' => array(
                                'wikibase.ui.entityViewInit.js' // should 
probably be adjusted for more modularity
@@ -82,11 +97,11 @@
                        'scripts' => array(
                                'wikibase.ui.entitysearch.js',
                        ),
-                       'styles' => array(
-                               'themes/default/wikibase.ui.entitysearch.css',
-                       ),
                        'dependencies' => array(
                                'jquery.event.special.eachchange',
+                               'jquery.spinner',
+                               'jquery.ui.ooMenu',
+                               'jquery.wikibase.entitysearch',
                                'jquery.wikibase.entityselector',
                        ),
                        'messages' => array(
diff --git a/repo/resources/jquery.wikibase/jquery.wikibase.entitysearch.js 
b/repo/resources/jquery.wikibase/jquery.wikibase.entitysearch.js
new file mode 100644
index 0000000..c18c727
--- /dev/null
+++ b/repo/resources/jquery.wikibase/jquery.wikibase.entitysearch.js
@@ -0,0 +1,130 @@
+/**
+ * @license GNU GPL v2+
+ * @author H. Snater < [email protected] >
+ */
+( function( $ ) {
+       'use strict';
+
+       var PARENT = $.wikibase.entityselector;
+
+/**
+ * Entity selector widget enhanced to be used as global search element.
+ * @extends jQuery.wikibase.entityselector
+ *
+ * @option {jQuery.ui.ooMenu.CustomItem} [suggestionsPlaceholder]
+ *         Suggestions list item to be displayed while suggestions are 
retrieved.
+ */
+$.widget( 'wikibase.entitysearch', PARENT, {
+
+       /**
+        * @see jQuery.wikibase.entityselector.options
+        */
+       options: {
+               suggestionsPlaceholder: null
+       },
+
+       /**
+        * @see jQuery.wikibase.entityselector._create
+        */
+       _create: function() {
+               var self = this;
+
+               PARENT.prototype._create.call( this );
+
+               this.element
+               .on( 'eachchange.' + this.widgetName, function() {
+                       var menu = self.options.menu;
+                       if(
+                               self.options.suggestionsPlaceholder
+                               && ( !menu.option( 'items' ).length || 
!menu.element.is( ':visible' ) )
+                       ) {
+                               
self.options.suggestionsPlaceholder.setVisibility( true );
+                               self._updateMenu( [] );
+                       }
+               } );
+       },
+
+       /**
+        *@see jQuery.wikibase.entityselector._createMenuItemFromSuggestion
+        */
+       _createMenuItemFromSuggestion: function( suggestion ) {
+               var $label = this._createLabelFromSuggestion( suggestion ),
+                       value = suggestion.label || suggestion.id;
+
+               return new PARENT.Item( $label, value, suggestion );
+       },
+
+       /**
+        * @see jQuery.ui.suggester._setOption
+        */
+       _setOption: function( key, value ) {
+               if( key === 'suggestionsPlaceholder' ) {
+                       var customItems = this.options.menu.option( 
'customItems' );
+
+                       customItems.splice( $.inArray( 
this.options.suggestionsPlaceholder, customItems ), 1 );
+
+                       if( value instanceof $.ui.ooMenu.CustomItem ) {
+                               customItems.unshift( value );
+                       }
+
+                       this._close();
+               }
+               return PARENT.prototype._setOption.apply( this,  arguments );
+       },
+
+       /**
+        * @see jQuery.wikibase.entityselector._initMenu
+        */
+       _initMenu: function( ooMenu ) {
+               PARENT.prototype._initMenu.apply( this, arguments );
+
+               if( this.options.suggestionsPlaceholder ) {
+                       ooMenu.option( 'customItems' ).unshift( 
this.options.suggestionsPlaceholder );
+               }
+
+               ooMenu.element.addClass( 'wikibase-entitysearch-list' );
+
+               $( ooMenu )
+               .off( 'selected' )
+               .on( 'selected.entitysearch', function( event, item ) {
+                       if(
+                               event.originalEvent
+                               && /^key/.test( event.originalEvent.type )
+                               && !( item instanceof $.ui.ooMenu.CustomItem )
+                       ) {
+                               window.location.href = item.getEntityStub().url;
+                       }
+               } );
+
+               return ooMenu;
+       },
+
+       /**
+        * @see jQuery.ui.suggester._updateMenuVisibility
+        */
+       _updateMenuVisibility: function() {
+               if( !this._term.length ) {
+                       this._close();
+               } else {
+                       this._open();
+                       this.repositionMenu();
+               }
+       },
+
+       /**
+        * @see jQuery.wikibase.entityselector._getSuggestions
+        */
+       _getSuggestions: function( term ) {
+               var self = this,
+                       promise = PARENT.prototype._getSuggestions.call( this, 
term );
+
+               return promise.done( function( suggestions, searchTerm ) {
+                       if( self.options.suggestionsPlaceholder ) {
+                               
self.options.suggestionsPlaceholder.setVisibility( false );
+                       }
+               } );
+       }
+
+} );
+
+}( jQuery ) );
diff --git a/repo/resources/themes/default/wikibase.ui.entitysearch.css 
b/repo/resources/jquery.wikibase/themes/default/jquery.wikibase.entitysearch.css
similarity index 100%
rename from repo/resources/themes/default/wikibase.ui.entitysearch.css
rename to 
repo/resources/jquery.wikibase/themes/default/jquery.wikibase.entitysearch.css
diff --git a/repo/resources/wikibase.ui.entitysearch.js 
b/repo/resources/wikibase.ui.entitysearch.js
index bf69c95..5461f22 100644
--- a/repo/resources/wikibase.ui.entitysearch.js
+++ b/repo/resources/wikibase.ui.entitysearch.js
@@ -1,47 +1,11 @@
 /**
- * Replacing the native MediaWiki search suggestions with Wikibase's entity 
selector widget.
+ * Replacing the native MediaWiki search suggestions with the 
jQuery.wikibase.entitysearch widget.
  *
  * @license GNU GPL v2+
  * @author H. Snater < [email protected] >
  */
 ( function( $, mw ) {
        'use strict';
-
-       $.widget( 'wikibase.entitysearch', $.wikibase.entityselector, {
-               /**
-                *@see 
jQuery.wikibase.entityselector._createMenuItemFromSuggestion
-                */
-               _createMenuItemFromSuggestion: function( suggestion ) {
-                       var $label = this._createLabelFromSuggestion( 
suggestion ),
-                               value = suggestion.label || suggestion.id;
-
-                       return new $.wikibase.entityselector.Item( $label, 
value, suggestion );
-               },
-
-               /**
-                * @see 
jQuery.wikibase.entityselector._createMenuItemFromSuggestion
-                */
-               _initMenu: function( ooMenu ) {
-                       $.wikibase.entityselector.prototype._initMenu.apply( 
this, arguments );
-
-                       ooMenu.element.addClass( 'wikibase-entitysearch-list' );
-
-                       $( ooMenu )
-                       .off( 'selected' )
-                       .on( 'selected.entitysearch', function( event, item ) {
-                               if(
-                                       event.originalEvent
-                                       && /^key/.test( 
event.originalEvent.type )
-                                       && !( item instanceof 
$.ui.ooMenu.CustomItem )
-                               ) {
-                                       window.location.href = 
item.getEntityStub().url;
-                               }
-                       } );
-
-                       return ooMenu;
-               }
-
-       } );
 
        $( function() {
                var $form = $( '#searchform ' ),
@@ -90,6 +54,10 @@
                        $.removeData( input, 'suggestionsContext' );
                }
 
+               var suggestionsPlaceholder = new $.ui.ooMenu.CustomItem(
+                       $( '<div/>' ).append( $.createSpinner() )
+               );
+
                var $searchContaining = $( '<div>' )
                        .addClass( 'suggestions-special' )
                        .append(
@@ -136,7 +104,8 @@
                                
$.wikibase.entityselector.prototype.options.position,
                                { offset: '-1 2' }
                        ),
-                       confineMinWidthTo: $form
+                       confineMinWidthTo: $form,
+                       suggestionsPlaceholder: suggestionsPlaceholder
                } )
                .on( 'entityselectoropen', function( event ) {
                        updateSuggestionSpecial( searchContaining );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I340de9cc0556def5ab99b718084fe5395126ca31
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>
Gerrit-Reviewer: Adrian Lang <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to