From b33c86e5e4a6c2560bb8eff81de044c3046e6c94 Mon Sep 17 00:00:00 2001 From: tom Date: Mon, 10 Dec 2012 12:46:27 -0500 Subject: [PATCH] Fixes >1 multi-select dropdown being open at the same time Bug was reproduced on latest FF/Chrome/Safari, but IE exibits correct behavior with or without the fix. See: http://jsfiddle.net/tmD7c/2/ --- select2.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/select2.js b/select2.js index d2a2683e..767e4fce 100644 --- a/select2.js +++ b/select2.js @@ -509,17 +509,20 @@ the specific language governing permissions and limitations under the Apache Lic $document.ready(function () { $document.bind("mousedown touchend", function (e) { var target = $(e.target).closest("div.select2-container").get(0), attr; + var targetDropdown = null; if (target) { $document.find("div.select2-container-active").each(function () { if (this !== target) $(this).data("select2").blur(); }); - } else { - target = $(e.target).closest("div.select2-drop").get(0); - $document.find("div.select2-drop-active").each(function () { - if (this !== target) $(this).data("select2").blur(); - }); + targetDropdown = $(target).data('select2').dropdown.get(0); } + // close any other active dropdowns + target = targetDropdown || $(e.target).closest("div.select2-drop").get(0); + $document.find("div.select2-drop-active").each(function () { + if (this !== target) $(this).data("select2").blur(); + }); + target=$(e.target); attr = target.attr("for"); if ("LABEL" === e.target.tagName && attr && attr.length > 0) {