Files
iD/js/id/ui/modal.js
Bryan Housel 7930a0bb36 Modal Dialog and Save/Restore improvements
(closes #3036)

1. Fix the modal close button icon - was not visible
2. Use a blocking modal for the Save/Restore dialog
3. Don't allow `context.save()` while modal is visible
   (especially for `onbeforeunload` event - this would wipe user's saved
    history if browser is closed while the Save/Restore modal was visible)
4. Don't allow blocking modals to be dismissed by pressing escape
5. Don't show the close button icon for blocking modals
2016-04-15 23:01:28 -04:00

64 lines
1.4 KiB
JavaScript

iD.ui.modal = function(selection, blocking) {
var keybinding = d3.keybinding('modal');
var previous = selection.select('div.modal');
var animate = previous.empty();
previous.transition()
.duration(200)
.style('opacity', 0)
.remove();
var shaded = selection
.append('div')
.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 modal = shaded.append('div')
.attr('class', 'modal fillL col6');
if (!blocking) {
shaded.on('click.remove-modal', function() {
if (d3.event.target === this) {
shaded.close();
}
});
modal.append('button')
.attr('class', 'close')
.on('click', shaded.close)
.call(iD.svg.Icon('#icon-close'));
keybinding
.on('⌫', shaded.close)
.on('⎋', shaded.close);
d3.select(document).call(keybinding);
}
modal.append('div')
.attr('class', 'content');
if (animate) {
shaded.transition().style('opacity', 1);
} else {
shaded.style('opacity', 1);
}
return shaded;
};