diff --git a/select2.js b/select2.js index de29b2d6..56688689 100644 --- a/select2.js +++ b/select2.js @@ -633,7 +633,7 @@ the specific language governing permissions and limitations under the Apache Lic search.bind("blur", function () { search.removeClass("select2-focused");}); this.dropdown.delegate(resultsSelector, "mouseup", this.bind(function (e) { - if ($(e.target).closest(".select2-result-selectable:not(.select2-disabled)").length > 0) { + if ($(e.target).closest(".select2-result-selectable:visible").length > 0) { this.highlightUnderEvent(e); this.selectHighlighted(e); } else { @@ -1079,7 +1079,7 @@ the specific language governing permissions and limitations under the Apache Lic return; } - children = results.find(".select2-result-selectable"); + children = results.find(".select2-result:visible"); child = $(children[index]); @@ -1107,13 +1107,13 @@ the specific language governing permissions and limitations under the Apache Lic // abstract moveHighlight: function (delta) { - var choices = this.results.find(".select2-result-selectable"), + var choices = this.results.find(".select2-result:visible"), index = this.highlight(); while (index > -1 && index < choices.length) { index += delta; var choice = $(choices[index]); - if (choice.hasClass("select2-result-selectable") && !choice.hasClass("select2-disabled")) { + if (choice.hasClass("select2-result-selectable") && !choice.hasClass("select2-disabled") && !choice.hasClass("select2-selected")) { this.highlight(index); break; } @@ -1122,7 +1122,7 @@ the specific language governing permissions and limitations under the Apache Lic // abstract highlight: function (index) { - var choices = this.results.find(".select2-result-selectable").not(".select2-disabled"); + var choices = this.results.find(".select2-result:visible"); if (arguments.length === 0) { return indexOf(choices.filter(".select2-highlighted")[0], choices.get()); @@ -1140,14 +1140,14 @@ the specific language governing permissions and limitations under the Apache Lic // abstract countSelectableResults: function() { - return this.results.find(".select2-result-selectable").not(".select2-disabled").length; + return this.results.find(".select2-result-selectable").not(".select2-disabled").not(".select2-selected").length; }, // abstract highlightUnderEvent: function (event) { var el = $(event.target).closest(".select2-result-selectable"); if (el.length > 0 && !el.is(".select2-highlighted")) { - var choices = this.results.find('.select2-result-selectable'); + var choices = this.results.find('.select2-result'); this.highlight(choices.index(el)); } else if (el.length == 0) { // if we are over an unselectable item remove al highlights @@ -1350,10 +1350,10 @@ the specific language governing permissions and limitations under the Apache Lic // abstract selectHighlighted: function (options) { var index=this.highlight(), - highlighted=this.results.find(".select2-highlighted").not(".select2-disabled"), - data = highlighted.closest('.select2-result-selectable').data("select2-data"); + highlighted=this.results.find(".select2-highlighted:visible"), + data = highlighted.closest('.select2-result:visible').data("select2-data"); if (data) { - highlighted.addClass("select2-disabled"); + highlighted.addClass("select2-selected"); this.highlight(index); this.onSelect(data, options); } @@ -1698,7 +1698,7 @@ the specific language governing permissions and limitations under the Apache Lic // find the selected element in the result list - this.results.find(".select2-result-selectable").each2(function (i, elm) { + this.results.find(".select2-result:visible").each2(function (i, elm) { if (equal(self.id(elm.data("select2-data")), self.opts.element.val())) { selected = i; return false;