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