Henning Snater has uploaded a new change for review.

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


Change subject: (bug 45236) Optimizing entity selector's "blur" event handling
......................................................................

(bug 45236) Optimizing entity selector's "blur" event handling

Change-Id: Ie2b8246328da66a8f35d5b376df66a3dfaf23f12
---
M lib/resources/jquery.wikibase/jquery.wikibase.entityselector.js
M lib/tests/qunit/jquery.wikibase/jquery.wikibase.entityselector.tests.js
2 files changed, 7 insertions(+), 11 deletions(-)


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

diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.entityselector.js 
b/lib/resources/jquery.wikibase/jquery.wikibase.entityselector.js
index 99254a7..bf12508 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.entityselector.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.entityselector.js
@@ -182,11 +182,6 @@
                                        self._renderMoreLink();
                                }
                        } )
-                       .on( this.widgetName + 'close.' + this.widgetName, 
function( event ) {
-                               // Since it is possible to trigger the same 
search again after closing the
-                               // suggestion list, clear the cache to avoid 
concatenating the same results.
-                               self._cache = {};
-                       } )
                        .on( 'keydown.' + this.widgetName, function( event ) {
                                // when pressing enter, check if the current 
input matches any of the suggested item
                                // and select it
@@ -198,7 +193,10 @@
                                }
                        } )
                        .on( 'blur.' + this.widgetName, function( event ) {
-                               if ( self.validateInput() ) {
+                               if (
+                                       ( !self.menu.active || 
!self.menu.active.hasClass( 'ui-suggester-custom' ) )
+                                       && self.validateInput()
+                               ) {
                                        self._trigger(
                                                'select',
                                                0,
@@ -341,7 +339,7 @@
 
                                if ( searchTerm === this.element.val() ) {
                                        // clear cached results
-                                       if ( !this._cache || 
!this._cache[searchTerm] ) {
+                                       if ( !this._cache || 
!this._cache[searchTerm] || this.offset === 0 ) {
                                                this._cache = {};
                                                this._cache[searchTerm] = [];
                                        }
diff --git 
a/lib/tests/qunit/jquery.wikibase/jquery.wikibase.entityselector.tests.js 
b/lib/tests/qunit/jquery.wikibase/jquery.wikibase.entityselector.tests.js
index ac02b6b..55e9900 100644
--- a/lib/tests/qunit/jquery.wikibase/jquery.wikibase.entityselector.tests.js
+++ b/lib/tests/qunit/jquery.wikibase/jquery.wikibase.entityselector.tests.js
@@ -120,16 +120,14 @@
                        'Appended "more" link.'
                );
 
-               // Closing will trigger clearing the result cache avoiding 
duplicate results when issuing
-               // the same search query.
-               entityselector.close();
+               entityselector.offset = 0;
                input.val( 'ab' );
                entityselector._success( exampleResponse );
 
                assert.equal(
                        entityselector.menu.element.children( 'li' ).length,
                        ( exampleResponse.search.length + 1 ),
-                       'Cleared result cache after closing the menu.'
+                       'Cleared result cache after resetting the offset.'
                );
 
        } );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie2b8246328da66a8f35d5b376df66a3dfaf23f12
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