From a6ec8fc4e17e9622202b61ca1b1b6e044bf9fa1a Mon Sep 17 00:00:00 2001 From: Arend van Beelen Date: Mon, 30 Dec 2013 15:33:46 +0100 Subject: [PATCH 1/4] Don't rely on :visible and :not(..., ...) selectors which only work with Sizzle. --- select2.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/select2.js b/select2.js index 67f6b85e..b4b67efc 100644 --- a/select2.js +++ b/select2.js @@ -264,7 +264,8 @@ the specific language governing permissions and limitations under the Apache Lic /* make sure el received focus so we do not error out when trying to manipulate the caret. sometimes modals or others listeners may steal it after its set */ - if ($el.is(":visible") && el === document.activeElement) { + var isVisible = (el.offsetWidth > 0 || el.offsetHeight > 0); + if (isVisible && el === document.activeElement) { /* after the focus is set move the caret to the end, necessary when we val() just before setting focus */ @@ -1431,7 +1432,7 @@ the specific language governing permissions and limitations under the Apache Lic // abstract findHighlightableChoices: function() { - return this.results.find(".select2-result-selectable:not(.select2-disabled, .select2-selected)"); + return this.results.find(".select2-result-selectable:not(.select2-disabled):not(.select2-selected)"); }, // abstract From 84cf134a4e889e5ac85641bb2ac732b015911174 Mon Sep 17 00:00:00 2001 From: jdecuyper Date: Sun, 19 Jan 2014 21:12:39 -0600 Subject: [PATCH 2/4] Add hideSelectionFromResult function --- select2.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/select2.js b/select2.js index 14f6c620..2d3f631d 100644 --- a/select2.js +++ b/select2.js @@ -2257,13 +2257,14 @@ the specific language governing permissions and limitations under the Apache Lic // single postprocessResults: function (data, initial, noHighlightUpdate) { - var selected = 0, self = this, showSearchInput = true; + var selected = 0, selectedElm = null, self = this, showSearchInput = true; // find the selected element in the result list this.findHighlightableChoices().each2(function (i, elm) { if (equal(self.id(elm.data("select2-data")), self.opts.element.val())) { selected = i; + selectedElm = elm; return false; } }); @@ -2271,7 +2272,14 @@ the specific language governing permissions and limitations under the Apache Lic // and highlight it if (noHighlightUpdate !== false) { if (initial === true && selected >= 0) { - this.highlight(selected); + // By default, the selected item is displayed inside the result list from a single select + // User can provide an implementation for 'hideSelectionFromResult' and hide it + if(this.opts.hideSelectionFromResult !== undefined && selectedElm !== null) { + if(this.opts.hideSelectionFromResult(selectedElm)) + selectedElm.addClass("select2-selected"); + } + else + this.highlight(selected); } else { this.highlight(0); } @@ -2995,9 +3003,14 @@ the specific language governing permissions and limitations under the Apache Lic choices.each2(function (i, choice) { var id = self.id(choice.data("select2-data")); if (indexOf(id, val) >= 0) { - choice.addClass("select2-selected"); - // mark all children of the selected parent as selected - choice.find(".select2-result-selectable").addClass("select2-selected"); + // By default, the selected item is hidden from the result list inside a multi select + // User can provide an implementation for 'hideSelectionFromResult' and allow the same + // element to be selected multiple times. + if(self.opts.hideSelectionFromResult === undefined || self.opts.hideSelectionFromResult(choice)) { + choice.addClass("select2-selected"); + // mark all children of the selected parent as selected + choice.find(".select2-result-selectable").addClass("select2-selected"); + } } }); @@ -3313,7 +3326,8 @@ the specific language governing permissions and limitations under the Apache Lic selectOnBlur: false, adaptContainerCssClass: function(c) { return c; }, adaptDropdownCssClass: function(c) { return null; }, - nextSearchTerm: function(selectedObject, currentSearchTerm) { return undefined; } + nextSearchTerm: function(selectedObject, currentSearchTerm) { return undefined; }, + hideSelectionFromResult: function(selectedObject) { return undefined; } }; $.fn.select2.ajaxDefaults = { From 6a3ec3f5de2da2a971f2021726c9fefda2105398 Mon Sep 17 00:00:00 2001 From: Matthias Kurz Date: Mon, 20 Jan 2014 11:46:39 +0100 Subject: [PATCH 3/4] Fix for #2042 Chrome bug: Reset the background position for multiple backgrounds --- select2.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/select2.css b/select2.css index 9b50f24a..8e3c0ddd 100644 --- a/select2.css +++ b/select2.css @@ -236,7 +236,7 @@ Version: @@ver@@ Timestamp: @@timestamp@@ background: url('select2.png') no-repeat 100% -22px, -webkit-gradient(linear, left bottom, left top, color-stop(0.85, #fff), color-stop(0.99, #eee)); background: url('select2.png') no-repeat 100% -22px, -webkit-linear-gradient(center bottom, #fff 85%, #eee 99%); background: url('select2.png') no-repeat 100% -22px, -moz-linear-gradient(center bottom, #fff 85%, #eee 99%); - background: url('select2.png') no-repeat 100% -22px, linear-gradient(to bottom, #fff 85%, #eee 99%); + background: url('select2.png') no-repeat 100% -22px, linear-gradient(to bottom, #fff 85%, #eee 99%) 0 0; } .select2-drop.select2-drop-above .select2-search input { @@ -248,7 +248,7 @@ Version: @@ver@@ Timestamp: @@timestamp@@ background: url('select2-spinner.gif') no-repeat 100%, -webkit-gradient(linear, left bottom, left top, color-stop(0.85, #fff), color-stop(0.99, #eee)); background: url('select2-spinner.gif') no-repeat 100%, -webkit-linear-gradient(center bottom, #fff 85%, #eee 99%); background: url('select2-spinner.gif') no-repeat 100%, -moz-linear-gradient(center bottom, #fff 85%, #eee 99%); - background: url('select2-spinner.gif') no-repeat 100%, linear-gradient(to bottom, #fff 85%, #eee 99%); + background: url('select2-spinner.gif') no-repeat 100%, linear-gradient(to bottom, #fff 85%, #eee 99%) 0 0; } .select2-container-active .select2-choice, From 05efcaf160966d6dab53bd676144ad7f8e0cf5e9 Mon Sep 17 00:00:00 2001 From: Matthias Kurz Date: Mon, 20 Jan 2014 11:50:46 +0100 Subject: [PATCH 4/4] Use dppx instead of non-existing ppx resolution unit --- select2.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/select2.css b/select2.css index 9b50f24a..97e2b1f1 100644 --- a/select2.css +++ b/select2.css @@ -628,7 +628,7 @@ html[dir="rtl"] .select2-search-choice-close { /* Retina-ize icons */ -@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min-resolution: 2ppx) { +@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min-resolution: 2dppx) { .select2-search input, .select2-search-choice-close, .select2-container .select2-choice abbr,