From 1605a631e5e35e920fecc57ff24c84056be705fc Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Sun, 15 Jul 2012 22:22:38 +0300 Subject: [PATCH] reworked how dropdown is managed in singleselect so the search field has focus even when the dropdown is not opened and can capture te first keypress. fixes #196 --- select2.js | 139 +++++++++++++++++++++++++++++------------------------ 1 file changed, 76 insertions(+), 63 deletions(-) diff --git a/select2.js b/select2.js index 6fbfa62e..981f1d85 100755 --- a/select2.js +++ b/select2.js @@ -806,26 +806,34 @@ if (!this.shouldOpen()) return false; + window.setTimeout(this.bind(this.opening), 1); + + return true; + }, + + /** + * Performs the opening of the dropdown + */ + // abstract + opening: function() { this.clearDropdownAlignmentPreference(); if (this.search.val() === " ") { this.search.val(""); } - this.container.addClass("select2-dropdown-open").addClass("select2-container-active"); - if(this.dropdown[0] !== this.body.children().last()[0]) { - // ensure the dropdown is the last child of body, so the z-index is always respected correctly - this.dropdown.detach().appendTo(this.body); - } - this.dropdown.addClass("select2-drop-active"); this.positionDropdown(); this.updateResults(true); + + if(this.dropdown[0] !== this.body.children().last()[0]) { + this.dropdown.detach().appendTo(this.body); + } + this.dropdown.show(); this.ensureHighlightVisible(); this.focusSearch(); - - return true; + this.container.addClass("select2-dropdown-open").addClass("select2-container-active"); }, // abstract @@ -1132,11 +1140,11 @@ "class": "select2-container", "style": "width: " + this.getContainerWidth() }).html([ - " ", + " ", " ", "
" , "
", - "