Condense modal hiding logic, fixes #1159

This commit is contained in:
Tom MacWright
2013-03-28 16:04:35 -04:00
parent 1677df34c6
commit ab9b8cb2a6
2 changed files with 23 additions and 64 deletions

View File

@@ -3,12 +3,6 @@ iD.ui.modal = function(selection, blocking) {
var previous = selection.select('div.modal');
var animate = previous.empty();
var keybinding = d3.keybinding('modal')
.on('⌫', close)
.on('⎋', close);
d3.select(document).call(keybinding);
previous.transition()
.duration(200)
.style('opacity', 0)
@@ -19,37 +13,36 @@ iD.ui.modal = function(selection, blocking) {
.attr('class', 'shaded')
.style('opacity', 0);
shaded.close = function() {
shaded
.transition()
.duration(200)
.style('opacity',0)
.remove();
modal
.transition()
.duration(200)
.style('top','0px');
keybinding.off();
};
var keybinding = d3.keybinding('modal')
.on('⌫', shaded.close)
.on('⎋', shaded.close);
d3.select(document).call(keybinding);
var modal = shaded.append('div')
.attr('class', 'modal fillL col6');
shaded.on('click.remove-modal', function() {
if (d3.event.target == this && !blocking) {
shaded
.transition()
.duration(200)
.style('opacity',0)
.remove();
modal
.transition()
.duration(200)
.style('top','0px');
}
if (d3.event.target == this && !blocking) shaded.close();
});
modal.append('button')
.attr('class', 'close')
.on('click', function() {
if (!blocking) {
shaded
.transition()
.duration(200)
.style('opacity',0)
.remove();
modal
.transition()
.duration(200)
.style('top','0px');
}
if (!blocking) shaded.close();
})
.append('div')
.attr('class','icon close');
@@ -68,18 +61,6 @@ iD.ui.modal = function(selection, blocking) {
shaded.style('opacity', 1);
}
function close() {
shaded
.transition()
.duration(200)
.style('opacity',0)
.remove();
modal
.transition()
.duration(200)
.style('top','0px');
keybinding.off();
}
return shaded;
};

View File

@@ -34,35 +34,13 @@ iD.ui.Splash = function(context) {
.text(t('splash.walkthrough'))
.on('click', function() {
d3.select(document.body).call(iD.ui.intro(context));
modal
.transition()
.duration(200)
.style('opacity','0')
.remove();
modal.select('.modal')
.transition()
.duration(200)
.style('top','0px')
.remove();
modal.close();
});
buttons.append('button')
.attr('class', 'col6 start')
.text(t('splash.start'))
.on('click', function() {
modal
.transition()
.duration(200)
.style('opacity','0')
.remove();
modal.select('.modal')
.transition()
.duration(200)
.style('top','0px')
.remove();
});
.on('click', modal.close);
modal.select('button.close').attr('class','hide');