From d56f43092be88d5cfdaae2b5602609003fb0d3b9 Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Sat, 9 Feb 2013 00:45:14 -0800 Subject: [PATCH] introduce highlight event. fixes #529. fixes #762 --- select2.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/select2.js b/select2.js index 09d6da1d..e2fd91e7 100644 --- a/select2.js +++ b/select2.js @@ -1180,7 +1180,9 @@ the specific language governing permissions and limitations under the Apache Lic // abstract highlight: function (index) { - var choices = this.findHighlightableChoices(); + var choices = this.findHighlightableChoices(), + choice, + data; if (arguments.length === 0) { return indexOf(choices.filter(".select2-highlighted")[0], choices.get()); @@ -1191,8 +1193,15 @@ the specific language governing permissions and limitations under the Apache Lic this.results.find(".select2-highlighted").removeClass("select2-highlighted"); - $(choices[index]).addClass("select2-highlighted"); + choice = $(choices[index]); + choice.addClass("select2-highlighted"); + this.ensureHighlightVisible(); + + data = choice.data("select2-data"); + if (data) { + this.opts.element.trigger({ type: "highlight", val: this.id(data), choice: data }); + } }, // abstract