Просмотр исходного кода

close any opened select2s when the window is scrolled or resized. fixes #296 and potentially #149

Igor Vaynberg 12 лет назад
Родитель
Сommit
a7d0849d23
1 измененных файлов с 18 добавлено и 3 удалено
  1. 18 3
      select2.js

+ 18 - 3
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