Files
iD/js/id/ui/modal.js
Tom MacWright db7f42145e Continue removing any non-scoped selectors. Refs #595
Last hits will be combobox and layerswitcher.
2013-02-05 12:00:10 -05:00

48 lines
1.1 KiB
JavaScript

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()
.style('opacity', 0).remove();
var shaded = selection
.append('div')
.attr('class', 'shaded')
.style('opacity', 0)
.on('click.remove-modal', function() {
if (d3.event.target == this && !blocking) d3.select(this).remove();
});
var modal = shaded.append('div')
.attr('class', 'modal');
modal.append('button')
.attr('class', 'icon close-modal')
.on('click', function() {
if (!blocking) shaded.remove();
});
modal.append('div')
.attr('class', 'content');
if (animate) {
shaded.transition().style('opacity', 1);
} else {
shaded.style('opacity', 1);
}
function close() {
shaded.remove();
keybinding.off();
}
return shaded;
};