Toggle ui elements gracefully. Refs #449

This commit is contained in:
Tom MacWright
2013-02-11 11:02:58 -05:00
parent 38b327fefe
commit d34863bfc2
5 changed files with 37 additions and 9 deletions
+1
View File
@@ -78,6 +78,7 @@
<script src='js/id/ui/key_reference.js'></script>
<script src='js/id/ui/lasso.js'></script>
<script src='js/id/ui/source_switch.js'></script>
<script src='js/id/ui/toggle.js'></script>
<script src='js/id/actions.js'></script>
<script src="js/id/actions/add_midpoint.js"></script>
+11 -5
View File
@@ -6,6 +6,9 @@ iD.ui.geocoder = function(context) {
}
function geocoder(selection) {
var shown = false;
function keydown() {
if (d3.event.keyCode !== 13) return;
d3.event.preventDefault();
@@ -59,11 +62,14 @@ iD.ui.geocoder = function(context) {
function toggle() { setVisible(gcForm.classed('hide')); }
function setVisible(show) {
button.classed('active', show);
gcForm.classed('hide', !show);
if (!show) resultsList.classed('hide', !show);
if (show) inputNode.node().focus();
else inputNode.node().blur();
if (show !== shown) {
button.classed('active', show);
gcForm.call(iD.ui.toggle(show));
if (!show) resultsList.classed('hide', !show);
if (show) inputNode.node().focus();
else inputNode.node().blur();
shown = show;
}
}
var button = selection.append('button')
+3 -1
View File
@@ -9,7 +9,7 @@ iD.ui.inspector = function() {
var entity = selection.datum();
var inspector = selection.append('div')
.attr('class','inspector content');
.attr('class','inspector content hide');
inspector.append('div')
.attr('class', 'head inspector-inner fillL')
@@ -42,6 +42,8 @@ iD.ui.inspector = function() {
inspectorbody.append('div')
.attr('class', 'inspector-buttons pad1 fillD')
.call(drawButtons);
inspector.call(iD.ui.toggle(true));
}
function drawHead(selection) {
+7 -3
View File
@@ -15,7 +15,8 @@ iD.ui.layerswitcher = function(context) {
function layerswitcher(selection) {
var content = selection
.append('div').attr('class', 'content fillD map-overlay hide');
.append('div').attr('class', 'content fillD map-overlay hide'),
shown = false;
var button = selection
.append('button')
@@ -30,8 +31,11 @@ iD.ui.layerswitcher = function(context) {
function toggle() { setVisible(content.classed('hide')); }
function setVisible(show) {
button.classed('active', show);
content.classed('hide', !show);
if (show !== shown) {
button.classed('active', show);
content.call(iD.ui.toggle(show));
shown = show;
}
}
function clickoutside(selection) {
+15
View File
@@ -0,0 +1,15 @@
// toggles the visibility of ui elements, using a combination of the
// 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) {
return function(selection) {
selection.style('opacity', show ? 0 : 1)
.classed('hide', false)
.transition()
.style('opacity', show ? 1 : 0)
.each('end', function() {
d3.select(this).classed('hide', !show);
});
};
};