From 20950e0f0cbbaa2ed9ddb3306320a69d4691c87d Mon Sep 17 00:00:00 2001 From: Amanda Myer Date: Thu, 24 Jan 2013 08:59:09 -0500 Subject: [PATCH 1/4] Update select2.js Fixed issues with select2 and disabled options, most of it having to do with incorrectly determining the index of an option when disabled options were being displayed. --- select2.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) 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; From 1949f4ce3158ae89d93320c05cff924c63e396cf Mon Sep 17 00:00:00 2001 From: Amanda Myer Date: Thu, 24 Jan 2013 09:04:05 -0500 Subject: [PATCH 2/4] Update select2.css Made disabled results show up disabled, and added a class "selected" for elements that have already been selected (by default, these elements are hidden). --- select2.css | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/select2.css b/select2.css index 3eae7318..8bfd9ce4 100644 --- a/select2.css +++ b/select2.css @@ -343,7 +343,8 @@ Version: @@ver@@ Timestamp: @@timestamp@@ } /* -disabled look for already selected choices in the results dropdown +disabled look for disabled choices in the results dropdown +*/ .select2-results .select2-disabled.select2-highlighted { color: #666; background: #f4f4f4; @@ -355,8 +356,8 @@ disabled look for already selected choices in the results dropdown display: list-item; cursor: default; } -*/ -.select2-results .select2-disabled { + +.select2-results .select2-selected { display: none; } @@ -570,4 +571,4 @@ disabled look for already selected choices in the results dropdown .select2-search input { background-position: 100% -21px !important; } -} \ No newline at end of file +} From 1c183ef23b3c48b359c591b55d8d853ea15b4b9b Mon Sep 17 00:00:00 2001 From: Amanda Myer Date: Thu, 24 Jan 2013 11:09:30 -0500 Subject: [PATCH 3/4] Update select2.js --- select2.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/select2.js b/select2.js index 56688689..a8f3070e 100644 --- a/select2.js +++ b/select2.js @@ -2209,30 +2209,30 @@ the specific language governing permissions and limitations under the Apache Lic // multi postprocessResults: function () { var val = this.getVal(), - choices = this.results.find(".select2-result-selectable"), + choices = this.results.find(".select2-result:visible"), compound = this.results.find(".select2-result-with-children"), self = this; choices.each2(function (i, choice) { var id = self.id(choice.data("select2-data")); if (indexOf(id, val) >= 0) { - choice.addClass("select2-disabled").removeClass("select2-result-selectable"); + choice.addClass("select2-selected").removeClass("select2-result-selectable"); } else { - choice.removeClass("select2-disabled").addClass("select2-result-selectable"); + choice.removeClass("select2-selected").addClass("select2-result-selectable"); } }); compound.each2(function(i, e) { if (!e.is('.select2-result-selectable') && e.find(".select2-result-selectable").length==0) { // FIX FOR HIERARCHICAL DATA - e.addClass("select2-disabled"); + e.addClass("select2-selected"); } else { - e.removeClass("select2-disabled"); + e.removeClass("select2-selected"); } }); if (this.highlight() == -1){ choices.each2(function (i, choice) { - if (!choice.hasClass("select2-disabled") && choice.hasClass("select2-result-selectable")) { + if (!choice.hasClass("select2-selected") &&!choice.hasClass("select2-disabled") && choice.hasClass("select2-result-selectable")) { self.highlight(0); return false; } From 795bd884a6a6abbb8cab89949e899c28c813b0fc Mon Sep 17 00:00:00 2001 From: Amanda Myer Date: Thu, 24 Jan 2013 11:11:44 -0500 Subject: [PATCH 4/4] Update select2.css --- select2.css | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/select2.css b/select2.css index 8bfd9ce4..e011d508 100644 --- a/select2.css +++ b/select2.css @@ -548,11 +548,8 @@ disabled look for disabled choices in the results dropdown .select2-result-selectable .select2-match, -.select2-result-unselectable .select2-result-selectable .select2-match { - text-decoration: underline; -} .select2-result-unselectable .select2-match { - text-decoration: none; + text-decoration: underline; } .select2-offscreen {