From a8fcfb4a14caf54c1c4d1c895d9e53b3906c549a Mon Sep 17 00:00:00 2001 From: Trevor Parscal Date: Tue, 18 Jun 2013 14:25:56 -0700 Subject: [PATCH] Handle media select widget empty queries properly If the query is cleared, we should still clear all items and abort any loading that may be going on. We should still not try and load results for an empty query though. Change-Id: If23c6e0469247b1c1c47ab85b9a5a010e8a4fe26 --- .../ui/widgets/ve.ui.MWMediaSelectWidget.js | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/modules/ve/ui/widgets/ve.ui.MWMediaSelectWidget.js b/modules/ve/ui/widgets/ve.ui.MWMediaSelectWidget.js index 422e19a794..93ae3f91b2 100755 --- a/modules/ve/ui/widgets/ve.ui.MWMediaSelectWidget.js +++ b/modules/ve/ui/widgets/ve.ui.MWMediaSelectWidget.js @@ -80,8 +80,8 @@ ve.inheritClass( ve.ui.MWMediaSelectWidget, ve.ui.Widget ); ve.ui.MWMediaSelectWidget.prototype.onInputChange = function () { var i, len; - if ( this.loading || this.input.getValue() === '' ) { - return; + if ( this.loading ) { + this.request.abort(); } // Reset @@ -124,7 +124,12 @@ ve.ui.MWMediaSelectWidget.prototype.onResultsScroll = function () { * @method */ ve.ui.MWMediaSelectWidget.prototype.queryMediaSources = function () { - var i, len, source; + var i, len, source, + value = this.input.getValue(); + + if ( value === '' ) { + return; + } for ( i = 0, len = this.sources.length; i < len; i++ ) { source = this.sources[i]; @@ -141,7 +146,7 @@ ve.ui.MWMediaSelectWidget.prototype.queryMediaSources = function () { 'format': 'json', 'action': 'query', 'generator': 'search', - 'gsrsearch': this.input.getValue(), + 'gsrsearch': value, 'gsrnamespace': 6, 'gsrlimit': 15, 'gsroffset': source.gsroffset, @@ -181,7 +186,12 @@ ve.ui.MWMediaSelectWidget.prototype.onMediaQueryDone = function ( source, data ) var page, title, items = [], - pages = data.query.pages; + pages = data.query.pages, + value = this.input.getValue(); + + if ( value === '' ) { + return; + } if ( data['query-continue'] && data['query-continue'].search ) { source.gsroffset = data['query-continue'].search.gsroffset;