瀏覽代碼

fix keystroke dropping when single select is opened by typing in unopened state really fast. fixes #949

Igor Vaynberg 12 年之前
父節點
當前提交
2bf5a763c5
共有 1 個文件被更改,包括 10 次插入13 次删除
  1. 10 13
      select2.js

+ 10 - 13
select2.js

@@ -1135,17 +1135,14 @@ the specific language governing permissions and limitations under the Apache Lic
                 orient = "orientationchange."+cid,
                 mask;
 
-            this.clearDropdownAlignmentPreference();
-
             this.container.addClass("select2-dropdown-open").addClass("select2-container-active");
 
+            this.clearDropdownAlignmentPreference();
 
             if(this.dropdown[0] !== this.body().children().last()[0]) {
                 this.dropdown.detach().appendTo(this.body());
             }
 
-            this.updateResults(true);
-
             // create the dropdown mask if doesnt already exist
             mask = $("#select2-drop-mask");
             if (mask.length == 0) {
@@ -1193,8 +1190,6 @@ the specific language governing permissions and limitations under the Apache Lic
                 });
             });
 
-            this.focusSearch();
-
             function _makeMaskCss() {
                 return {
                     width  : Math.max(document.documentElement.scrollWidth,  $(window).width()),
@@ -1663,8 +1658,12 @@ the specific language governing permissions and limitations under the Apache Lic
         // single
         opening: function () {
             this.parent.opening.apply(this, arguments);
-            this.focusser.attr("disabled", "disabled");
-
+            if (this.showSearchInput !== false) {
+                this.search.val(this.focusser.val());
+            }
+            this.search.focus();
+            this.focusser.attr("disabled", "disabled").val("");
+            this.updateResults(true);
             this.opts.element.trigger($.Event("open"));
         },
 
@@ -1785,13 +1784,9 @@ the specific language governing permissions and limitations under the Apache Lic
 
             installKeyUpChangeEvent(this.focusser);
             this.focusser.bind("keyup-change input", this.bind(function(e) {
+                e.stopPropagation();
                 if (this.opened()) return;
                 this.open();
-                if (this.showSearchInput !== false) {
-                    this.search.val(this.focusser.val());
-                }
-                this.focusser.val("");
-                killEvent(e);
             }));
 
             selection.delegate("abbr", "mousedown", this.bind(function (e) {
@@ -2354,6 +2349,8 @@ the specific language governing permissions and limitations under the Apache Lic
 
             this.focusSearch();
 
+            this.updateResults(true);
+            this.search.focus();
             this.opts.element.trigger($.Event("open"));
         },