From 96657a16aa911c21f9e87d21ba85b1d844b66d1a Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Mon, 10 Sep 2012 17:05:11 -0700 Subject: [PATCH] fix for dropdown closing as soon as its opened in IE8. fixes #369. fixes #354 --- select2.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/select2.js b/select2.js index e2e2191c..521629dc 100644 --- a/select2.js +++ b/select2.js @@ -972,13 +972,18 @@ }); }); - $(window).bind(resize, function() { - var s2 = $(selector); - if (s2.length == 0) { - $(window).unbind(resize); - } - s2.select2("close"); - }); + window.setTimeout(function() { + // this is done inside a timeout because IE will sometimes fire a resize event while opening + // the dropdown and that causes this handler to immediately close it. this way the dropdown + // has a chance to fully open before we start listening to resize events + $(window).bind(resize, function() { + var s2 = $(selector); + if (s2.length == 0) { + $(window).unbind(resize); + } + s2.select2("close"); + }) + }, 10); this.clearDropdownAlignmentPreference();