From b96060baf5af255db2082d8f7775056e1d6203e5 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 27 Nov 2012 12:13:21 -0500 Subject: [PATCH] Hide modals with click on outer. Fixes #120 --- js/iD/OAuth.js | 7 ++++++- js/iD/id.js | 23 ++++++++++++----------- js/iD/ui/commit.js | 8 ++++---- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/js/iD/OAuth.js b/js/iD/OAuth.js index 572b2b624..5d03500ca 100644 --- a/js/iD/OAuth.js +++ b/js/iD/OAuth.js @@ -21,6 +21,7 @@ iD.OAuth = function() { return o; } + // token getter/setter, namespaced to the current `apibase` value. function token(k, x) { if (arguments.length == 2) { localStorage[keyclean(apibase) + k] = x; @@ -58,7 +59,11 @@ iD.OAuth = function() { if (oauth.authenticated()) return callback(); var shaded = d3.select(document.body) - .append('div').attr('class', 'shaded'); + .append('div') + .attr('class', 'shaded') + .on('click', function() { + if (d3.event.target == this) shaded.remove(); + }); var modal = shaded.append('div').attr('class', 'modal'); var ifr = modal.append('iframe') .attr({ width: 640, height: 550, frameborder: 'no' }); diff --git a/js/iD/id.js b/js/iD/id.js index 7ea88839a..d4e457824 100644 --- a/js/iD/id.js +++ b/js/iD/id.js @@ -68,22 +68,23 @@ var iD = function(container) { .attr('class', 'save') .html("Save") .on('click', function() { + function save() { + connection.putChangeset(map.history.changes(), e.comment, function() { + shaded.remove(); + }); + } connection.authenticate(function() { - var commitpane = iD.Commit(); var shaded = d3.select(document.body) - .append('div').attr('class', 'shaded'); + .append('div').attr('class', 'shaded') + .on('click', function() { + if (d3.event.target == this) shaded.remove(); + }); var modal = shaded.append('div') .attr('class', 'modal commit-pane') .datum(map.history.changes()); - modal.call(commitpane); - commitpane.on('cancel', function() { - shaded.remove(); - }); - commitpane.on('save', function(e) { - connection.putChangeset(map.history.changes(), e.comment, function() { - shaded.remove(); - }); - }); + modal.call(iD.commit() + .on('cancel', shaded.remove) + .on('save', save)); }); }); diff --git a/js/iD/ui/commit.js b/js/iD/ui/commit.js index b0b83853c..8028cd5cb 100644 --- a/js/iD/ui/commit.js +++ b/js/iD/ui/commit.js @@ -1,10 +1,10 @@ -iD.Commit = function() { +iD.commit = function() { var event = d3.dispatch('cancel', 'save'); function commit(selection) { - var changes = selection.datum(); - var header = selection.append('div').attr('class', 'header'); - var body = selection.append('div').attr('class', 'body'); + var changes = selection.datum(), + header = selection.append('div').attr('class', 'header'), + body = selection.append('div').attr('class', 'body'); header.append('h2').text('Save Changes to OpenStreetMap');