From 693b54136126427e3152b383255dd76b69653b48 Mon Sep 17 00:00:00 2001 From: Aziz Gazanchiyan Date: Sun, 17 Jun 2012 16:47:56 +0300 Subject: [PATCH] Improve performance on dropdown detaching Signed-off-by: Igor Vaynberg --- select2.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/select2.js b/select2.js index c73534f5..a76836a7 100755 --- a/select2.js +++ b/select2.js @@ -483,6 +483,8 @@ prepareOpts: function (opts) { var element, select, idKey; + + opts.elementBody = opts.element.closest("body"); // cache for future access element = opts.element; @@ -686,7 +688,11 @@ this.clearPlaceholder(); this.container.addClass("select2-dropdown-open").addClass("select2-container-active"); - this.dropdown.detach().appendTo(this.opts.element.parents("body")).addClass("select2-drop-active"); + if(this.dropdown[0] !== this.opts.elementBody.children().last()[0]) { // ensure our dropdown is the last eleemnt, so the z-index is always respected correctly + this.dropdown.detach().appendTo(this.opts.elementBody); + } + + this.dropdown.addClass("select2-drop-active"); this.positionDropdown();