@@ -286,46 +286,50 @@ define([
286
286
$ . getJSON ( this . options . url , {
287
287
q : value
288
288
} , $ . proxy ( function ( data ) {
289
- $ . each ( data , function ( index , element ) {
290
- var html ;
291
-
292
- element . index = index ;
293
- html = template ( {
294
- data : element
289
+ if ( data . length ) {
290
+ $ . each ( data , function ( index , element ) {
291
+ var html ;
292
+
293
+ element . index = index ;
294
+ html = template ( {
295
+ data : element
296
+ } ) ;
297
+ dropdown . append ( html ) ;
295
298
} ) ;
296
- dropdown . append ( html ) ;
297
- } ) ;
298
- this . responseList . indexList = this . autoComplete . html ( dropdown )
299
- . css ( clonePosition )
300
- . show ( )
301
- . find ( this . options . responseFieldElements + ':visible' ) ;
302
-
303
- this . _resetResponseList ( false ) ;
304
- this . element . removeAttr ( 'aria-activedescendant' ) ;
305
-
306
- if ( this . responseList . indexList . length ) {
307
- this . _updateAriaHasPopup ( true ) ;
308
- } else {
309
- this . _updateAriaHasPopup ( false ) ;
310
- }
311
299
312
- this . responseList . indexList
313
- . on ( 'click' , function ( e ) {
314
- this . responseList . selected = $ ( e . currentTarget ) ;
315
- this . searchForm . trigger ( 'submit' ) ;
316
- } . bind ( this ) )
317
- . on ( 'mouseenter mouseleave' , function ( e ) {
318
- this . responseList . indexList . removeClass ( this . options . selectClass ) ;
319
- $ ( e . target ) . addClass ( this . options . selectClass ) ;
320
- this . responseList . selected = $ ( e . target ) ;
321
- this . element . attr ( 'aria-activedescendant' , $ ( e . target ) . attr ( 'id' ) ) ;
322
- } . bind ( this ) )
323
- . on ( 'mouseout' , function ( e ) {
324
- if ( ! this . _getLastElement ( ) && this . _getLastElement ( ) . hasClass ( this . options . selectClass ) ) {
325
- $ ( e . target ) . removeClass ( this . options . selectClass ) ;
326
- this . _resetResponseList ( false ) ;
327
- }
328
- } . bind ( this ) ) ;
300
+ this . responseList . indexList = this . autoComplete . html ( dropdown )
301
+ . css ( clonePosition )
302
+ . show ( )
303
+ . find ( this . options . responseFieldElements + ':visible' ) ;
304
+
305
+ this . _resetResponseList ( false ) ;
306
+ this . element . removeAttr ( 'aria-activedescendant' ) ;
307
+
308
+ if ( this . responseList . indexList . length ) {
309
+ this . _updateAriaHasPopup ( true ) ;
310
+ } else {
311
+ this . _updateAriaHasPopup ( false ) ;
312
+ }
313
+
314
+ this . responseList . indexList
315
+ . on ( 'click' , function ( e ) {
316
+ this . responseList . selected = $ ( e . currentTarget ) ;
317
+ this . searchForm . trigger ( 'submit' ) ;
318
+ } . bind ( this ) )
319
+ . on ( 'mouseenter mouseleave' , function ( e ) {
320
+ this . responseList . indexList . removeClass ( this . options . selectClass ) ;
321
+ $ ( e . target ) . addClass ( this . options . selectClass ) ;
322
+ this . responseList . selected = $ ( e . target ) ;
323
+ this . element . attr ( 'aria-activedescendant' , $ ( e . target ) . attr ( 'id' ) ) ;
324
+ } . bind ( this ) )
325
+ . on ( 'mouseout' , function ( e ) {
326
+ if ( ! this . _getLastElement ( ) &&
327
+ this . _getLastElement ( ) . hasClass ( this . options . selectClass ) ) {
328
+ $ ( e . target ) . removeClass ( this . options . selectClass ) ;
329
+ this . _resetResponseList ( false ) ;
330
+ }
331
+ } . bind ( this ) ) ;
332
+ }
329
333
} , this ) ) ;
330
334
} else {
331
335
this . _resetResponseList ( true ) ;
0 commit comments