From 7401bc431c9003a486555ce5f82fa8d4d6dc421b Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Mon, 11 Feb 2013 15:38:39 -0500 Subject: [PATCH] Fade lasso in and out --- js/id/ui/lasso.js | 15 ++++++--------- js/id/ui/toggle.js | 3 ++- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/js/id/ui/lasso.js b/js/id/ui/lasso.js index 338fa2f2d..511df2a7e 100644 --- a/js/id/ui/lasso.js +++ b/js/id/ui/lasso.js @@ -8,21 +8,18 @@ iD.ui.lasso = function() { function lasso(selection) { group = selection.append('g') - .attr('class', 'lasso') - .attr('opacity', 0); + .attr('class', 'lasso hide'); box = group.append('rect') .attr('class', 'lasso-box'); - group.transition() - .style('opacity', 1); + group.call(iD.ui.toggle(true)); } // top-left function topLeft(d) { - return 'translate(' + - [Math.min(d[0][0], d[1][0]), Math.min(d[0][1], d[1][1])].join(',') + ')'; + return 'translate(' + Math.min(d[0][0], d[1][0]) + ',' + Math.min(d[0][1], d[1][1]) + ')'; } function width(d) { return Math.abs(d[0][0] - d[1][0]); } @@ -53,9 +50,9 @@ iD.ui.lasso = function() { lasso.close = function(selection) { if (group) { - group.transition() - .attr('opacity', 0) - .remove(); + group.call(iD.ui.toggle(false, function() { + d3.select(this).remove(); + })); } }; diff --git a/js/id/ui/toggle.js b/js/id/ui/toggle.js index 96c6af645..3a7500023 100644 --- a/js/id/ui/toggle.js +++ b/js/id/ui/toggle.js @@ -2,7 +2,7 @@ // hide class, which sets display=none, and a d3 transition for opacity. // this will cause blinking when called repeatedly, so check that the // value actually changes between calls. -iD.ui.toggle = function(show) { +iD.ui.toggle = function(show, callback) { return function(selection) { selection.style('opacity', show ? 0 : 1) .classed('hide', false) @@ -10,6 +10,7 @@ iD.ui.toggle = function(show) { .style('opacity', show ? 1 : 0) .each('end', function() { d3.select(this).classed('hide', !show); + if (callback) callback.apply(this); }); }; };