From 2bf5a763c5e884cdf0295aa0d5072968bab941e2 Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Tue, 9 Apr 2013 18:58:30 -0700 Subject: [PATCH] fix keystroke dropping when single select is opened by typing in unopened state really fast. fixes #949 --- select2.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/select2.js b/select2.js index 810764ee..d0727091 100644 --- a/select2.js +++ b/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")); },