This commit is contained in:
parent
7a006a7259
commit
3f87728f7f
45
select2.js
45
select2.js
@ -622,7 +622,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
search.bind("blur", function () { search.removeClass("select2-focused");});
|
search.bind("blur", function () { search.removeClass("select2-focused");});
|
||||||
|
|
||||||
this.dropdown.delegate(resultsSelector, "mouseup", this.bind(function (e) {
|
this.dropdown.delegate(resultsSelector, "mouseup", this.bind(function (e) {
|
||||||
if ($(e.target).closest(".select2-result-selectable:visible").length > 0) {
|
if ($(e.target).closest(".select2-result-selectable").length > 0) {
|
||||||
this.highlightUnderEvent(e);
|
this.highlightUnderEvent(e);
|
||||||
this.selectHighlighted(e);
|
this.selectHighlighted(e);
|
||||||
} else {
|
} else {
|
||||||
@ -1075,7 +1075,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
children = results.find(".select2-result:visible");
|
children = this.findHighlightableChoices();
|
||||||
|
|
||||||
child = $(children[index]);
|
child = $(children[index]);
|
||||||
|
|
||||||
@ -1101,9 +1101,14 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// abstract
|
||||||
|
findHighlightableChoices: function() {
|
||||||
|
return this.results.find(".select2-result-selectable:not(.select2-selected):not(.select2-disabled)");
|
||||||
|
},
|
||||||
|
|
||||||
// abstract
|
// abstract
|
||||||
moveHighlight: function (delta) {
|
moveHighlight: function (delta) {
|
||||||
var choices = this.results.find(".select2-result:visible"),
|
var choices = this.findHighlightableChoices(),
|
||||||
index = this.highlight();
|
index = this.highlight();
|
||||||
|
|
||||||
while (index > -1 && index < choices.length) {
|
while (index > -1 && index < choices.length) {
|
||||||
@ -1118,7 +1123,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
|
|
||||||
// abstract
|
// abstract
|
||||||
highlight: function (index) {
|
highlight: function (index) {
|
||||||
var choices = this.results.find(".select2-result:visible");
|
var choices = this.findHighlightableChoices();
|
||||||
|
|
||||||
if (arguments.length === 0) {
|
if (arguments.length === 0) {
|
||||||
return indexOf(choices.filter(".select2-highlighted")[0], choices.get());
|
return indexOf(choices.filter(".select2-highlighted")[0], choices.get());
|
||||||
@ -1131,19 +1136,18 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
|
|
||||||
$(choices[index]).addClass("select2-highlighted");
|
$(choices[index]).addClass("select2-highlighted");
|
||||||
this.ensureHighlightVisible();
|
this.ensureHighlightVisible();
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// abstract
|
// abstract
|
||||||
countSelectableResults: function() {
|
countSelectableResults: function() {
|
||||||
return this.results.find(".select2-result-selectable").not(".select2-disabled").not(".select2-selected").length;
|
return this.findHighlightableChoices().length;
|
||||||
},
|
},
|
||||||
|
|
||||||
// abstract
|
// abstract
|
||||||
highlightUnderEvent: function (event) {
|
highlightUnderEvent: function (event) {
|
||||||
var el = $(event.target).closest(".select2-result-selectable");
|
var el = $(event.target).closest(".select2-result-selectable");
|
||||||
if (el.length > 0 && !el.is(".select2-highlighted")) {
|
if (el.length > 0 && !el.is(".select2-highlighted")) {
|
||||||
var choices = this.results.find('.select2-result:visible');
|
var choices = this.findHighlightableChoices();
|
||||||
this.highlight(choices.index(el));
|
this.highlight(choices.index(el));
|
||||||
} else if (el.length == 0) {
|
} else if (el.length == 0) {
|
||||||
// if we are over an unselectable item remove al highlights
|
// if we are over an unselectable item remove al highlights
|
||||||
@ -1346,8 +1350,8 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
// abstract
|
// abstract
|
||||||
selectHighlighted: function (options) {
|
selectHighlighted: function (options) {
|
||||||
var index=this.highlight(),
|
var index=this.highlight(),
|
||||||
highlighted=this.results.find(".select2-highlighted:visible"),
|
highlighted=this.results.find(".select2-highlighted"),
|
||||||
data = highlighted.closest('.select2-result:visible').data("select2-data");
|
data = highlighted.closest('.select2-result').data("select2-data");
|
||||||
if (data) {
|
if (data) {
|
||||||
highlighted.addClass("select2-selected");
|
highlighted.addClass("select2-selected");
|
||||||
this.highlight(index);
|
this.highlight(index);
|
||||||
@ -1694,7 +1698,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
|
|
||||||
// find the selected element in the result list
|
// find the selected element in the result list
|
||||||
|
|
||||||
this.results.find(".select2-result:visible").each2(function (i, elm) {
|
this.findHighlightableChoices().each2(function (i, elm) {
|
||||||
if (equal(self.id(elm.data("select2-data")), self.opts.element.val())) {
|
if (equal(self.id(elm.data("select2-data")), self.opts.element.val())) {
|
||||||
selected = i;
|
selected = i;
|
||||||
return false;
|
return false;
|
||||||
@ -2211,34 +2215,31 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
// multi
|
// multi
|
||||||
postprocessResults: function () {
|
postprocessResults: function () {
|
||||||
var val = this.getVal(),
|
var val = this.getVal(),
|
||||||
choices = this.results.find(".select2-result:visible"),
|
choices = this.results.find(".select2-result"),
|
||||||
compound = this.results.find(".select2-result-with-children"),
|
compound = this.results.find(".select2-result-with-children"),
|
||||||
self = this;
|
self = this;
|
||||||
|
|
||||||
choices.each2(function (i, choice) {
|
choices.each2(function (i, choice) {
|
||||||
var id = self.id(choice.data("select2-data"));
|
var id = self.id(choice.data("select2-data"));
|
||||||
if (indexOf(id, val) >= 0) {
|
if (indexOf(id, val) >= 0) {
|
||||||
choice.addClass("select2-selected").removeClass("select2-result-selectable");
|
choice.addClass("select2-selected");
|
||||||
} else {
|
} else {
|
||||||
choice.removeClass("select2-selected").addClass("select2-result-selectable");
|
choice.removeClass("select2-selected");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
compound.each2(function(i, e) {
|
compound.each2(function(i, choice) {
|
||||||
if (!e.is('.select2-result-selectable') && e.find(".select2-result-selectable").length==0) { // FIX FOR HIERARCHICAL DATA
|
// hide an optgroup if it doesnt have any selectable children
|
||||||
e.addClass("select2-selected");
|
if (!choice.is('.select2-result-selectable')
|
||||||
|
&& choice.find(".select2-result-selectable:not(.select2-selected)").length === 0) {
|
||||||
|
choice.addClass("select2-selected");
|
||||||
} else {
|
} else {
|
||||||
e.removeClass("select2-selected");
|
choice.removeClass("select2-selected");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.highlight() == -1){
|
if (this.highlight() == -1){
|
||||||
choices.each2(function (i, choice) {
|
|
||||||
if (!choice.hasClass("select2-selected") &&!choice.hasClass("select2-disabled") && choice.hasClass("select2-result-selectable")) {
|
|
||||||
self.highlight(0);
|
self.highlight(0);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user