From a7d0849d235216836c63ecb750209ce59a8362d9 Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Sat, 4 Aug 2012 11:28:02 -0700 Subject: [PATCH] close any opened select2s when the window is scrolled or resized. fixes #296 and potentially #149 --- select2.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/select2.js b/select2.js index c0a54cce..e67f3039 100755 --- a/select2.js +++ b/select2.js @@ -400,6 +400,10 @@ throw new Error("formatterName must be a function or a falsy value"); } + function evaluate(val) { + return $.isFunction(val) ? val() : val; + } + /** * blurs any Select2 container that has focus when an element outside them was clicked or received focus * @@ -429,9 +433,20 @@ }); }); - function evaluate(val) { - return $.isFunction(val) ? val() : val; - } + /** + * Closes any opened Select2s when the window is resized + */ + $(window).resize(debounce(100, function() { + $(".select2-container.select2-dropdown-open").select2('close'); + })); + + /** + * Closes any opened Select2s when the window is scrolled + */ + $(window).scroll(debounce(100, function() { + $(".select2-container.select2-dropdown-open").select2('close'); + })); + /** * Creates a new class