From b247191f620abac210f1e40299c79e99a6ec238d Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 26 Feb 2013 10:38:41 -0500 Subject: [PATCH] stop leaving combobox divs lying around --- js/lib/d3.combobox.js | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/js/lib/d3.combobox.js b/js/lib/d3.combobox.js index 815256045..c390392c4 100644 --- a/js/lib/d3.combobox.js +++ b/js/lib/d3.combobox.js @@ -15,15 +15,6 @@ d3.combobox = function() { var idx = -1; input = selection.select('input'); - container = d3.select(document.body) - .insert('div', ':first-child') - .attr('class', 'combobox') - .style({ - position: 'absolute', - display: 'none', - left: '0px' - }); - selection.append('a', selection.select('input')) .attr('class', 'combobox-carat') .on('mousedown', stop) @@ -64,14 +55,26 @@ d3.combobox = function() { } function show() { - container.style('display', 'block'); - shown = true; + if (!shown) { + container = d3.select(document.body) + .insert('div', ':first-child') + .attr('class', 'combobox') + .style({ + position: 'absolute', + display: 'block', + left: '0px' + }); + + shown = true; + } } function hide() { - idx = -1; - container.style('display', 'none'); - shown = false; + if (shown) { + idx = -1; + container.remove(); + shown = false; + } } function slowHide() {