From 2afb5fc517400128529303072bdd5c85765a92e1 Mon Sep 17 00:00:00 2001 From: Tomas Kirda Date: Sun, 20 Jan 2013 14:36:27 -0600 Subject: [PATCH] Deselect active element when mouse leaves suggestions container --- src/jquery.autocomplete.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/jquery.autocomplete.js b/src/jquery.autocomplete.js index 7b6be77..227ac13 100644 --- a/src/jquery.autocomplete.js +++ b/src/jquery.autocomplete.js @@ -141,6 +141,7 @@ initialize: function () { var that = this, suggestionSelector = '.' + that.classes.suggestion, + selected = that.classes.selected, container; // Remove autocomplete attribute to prevent native suggestions: @@ -169,6 +170,12 @@ that.activate($(this).data('index')); }); + // Deselect active element when mouse leaves suggestions container: + container.on('mouseout', function() { + that.selectedIndex = -1; + container.children('.' + selected).removeClass(selected); + }); + // Listen for click event on suggestions list: container.on('click', suggestionSelector, function () { that.select($(this).data('index'));