From d8e7936d8ae9e4e551c27c0ccd8921a24e4a28fd Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 5 Mar 2013 14:14:45 -0500 Subject: [PATCH] Fix CORS error catching on save. Fixes #788. Fixes #451 --- index.html | 1 + js/id/behavior/accept.js | 12 ++++++++++++ js/id/presets/collection.js | 5 +---- js/id/ui/preset.js | 15 ++++++++++----- js/id/ui/preset/address.js | 13 +++++++++---- js/id/ui/tag_editor.js | 3 ++- js/lib/d3.combobox.js | 2 +- js/lib/ohauth.js | 1 + 8 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 js/id/behavior/accept.js diff --git a/index.html b/index.html index ad038f359..4894aed75 100644 --- a/index.html +++ b/index.html @@ -120,6 +120,7 @@ + diff --git a/js/id/behavior/accept.js b/js/id/behavior/accept.js new file mode 100644 index 000000000..b73807d89 --- /dev/null +++ b/js/id/behavior/accept.js @@ -0,0 +1,12 @@ +iD.behavior.accept = function() { + var event = d3.dispatch('accept'), + keybinding = d3.keybinding('accept'); + + function accept(selection) { + keybinding.on('↩', function() { + event.accept(); + })(selection); + } + + return d3.rebind(accept, event, "on"); +}; diff --git a/js/id/presets/collection.js b/js/id/presets/collection.js index eec2bddfa..ce683fcb9 100644 --- a/js/id/presets/collection.js +++ b/js/id/presets/collection.js @@ -16,7 +16,6 @@ iD.presets.Collection = function(collection) { }); return iD.presets.Collection(newcollection); - }, matchTags: function(entity) { @@ -34,7 +33,7 @@ iD.presets.Collection = function(collection) { return match; }, - + search: function(value) { if (!value) return this; @@ -59,8 +58,6 @@ iD.presets.Collection = function(collection) { })); } - - }; return presets; diff --git a/js/id/ui/preset.js b/js/id/ui/preset.js index 51f7007ec..46e3f4a60 100644 --- a/js/id/ui/preset.js +++ b/js/id/ui/preset.js @@ -1,5 +1,5 @@ iD.ui.preset = function(context) { - var event = d3.dispatch('change', 'setTags'), + var event = d3.dispatch('change', 'setTags', 'close'), taginfo = iD.taginfo(), entity, type, @@ -56,25 +56,29 @@ iD.ui.preset = function(context) { case 'text': i = this.append('input') .attr('type', 'text') - .attr('id', 'input-' + d.key); + .attr('id', 'input-' + d.key) + .call(iD.behavior.accept().on('accept', event.close)); break; case 'tel': i = this.append('input') .attr('type', 'tel') .attr('id', 'input-' + d.key) - .attr('placeholder', '1-555-555-5555'); + .attr('placeholder', '1-555-555-5555') + .call(iD.behavior.accept().on('accept', event.close)); break; case 'email': i = this.append('input') .attr('type', 'email') .attr('id', 'input-' + d.key) - .attr('placeholder', 'email@domain.com'); + .attr('placeholder', 'email@domain.com') + .call(iD.behavior.accept().on('accept', event.close)); break; case 'url': i = this.append('input') .attr('type', 'url') .attr('id', 'input-' + d.key) - .attr('placeholder', 'http://example.com/'); + .attr('placeholder', 'http://example.com/') + .call(iD.behavior.accept().on('accept', event.close)); break; case 'check': wrap = this.append('span').attr('class', 'input-wrap-position'), @@ -155,6 +159,7 @@ iD.ui.preset = function(context) { .attr('class', 'col9 preset-input', d) .call(iD.ui.preset.address(context) .on('change', key) + .on('close', event.close) .entity(entity)); } } diff --git a/js/id/ui/preset/address.js b/js/id/ui/preset/address.js index f102715de..57cf1a89a 100644 --- a/js/id/ui/preset/address.js +++ b/js/id/ui/preset/address.js @@ -1,6 +1,6 @@ iD.ui.preset.address = function(context) { - var event = d3.dispatch('change'), + var event = d3.dispatch('change', 'close'), entity; function getStreets() { @@ -37,13 +37,16 @@ iD.ui.preset.address = function(context) { function change() { event.change(); } + function close() { return iD.behavior.accept().on('accept', event.close); } + selection.append('input') .property('type', 'text') .attr('placeholder', 'Housename') .attr('class', 'addr-housename') .datum({ 'key': 'addr:housename' }) .on('blur', change) - .on('change', change); + .on('change', change) + .call(close()); selection.append('input') .property('type', 'text') @@ -51,7 +54,8 @@ iD.ui.preset.address = function(context) { .attr('class', 'addr-number') .datum({ 'key': 'addr:housenumber' }) .on('blur', change) - .on('change', change); + .on('change', change) + .call(close()); var streetwrap = selection.append('span') .attr('class', 'input-wrap-position') @@ -70,7 +74,8 @@ iD.ui.preset.address = function(context) { .attr('class', 'addr-city') .datum({ 'key': 'addr:city' }) .on('blur', change) - .on('change', change); + .on('change', change) + .call(close()); streetwrap.call(d3.combobox().data(getStreets())); } diff --git a/js/id/ui/tag_editor.js b/js/id/ui/tag_editor.js index f609168b4..8a0d94b00 100644 --- a/js/id/ui/tag_editor.js +++ b/js/id/ui/tag_editor.js @@ -78,7 +78,8 @@ iD.ui.TagEditor = function(context) { .entity(entity) .on('change', function() { event.changeTags(); - }); + }) + .on('close', event.close); tagList = iD.ui.Taglist(context) .on('change', function() { diff --git a/js/lib/d3.combobox.js b/js/lib/d3.combobox.js index 1e2ae0a28..eaefaf2fc 100644 --- a/js/lib/d3.combobox.js +++ b/js/lib/d3.combobox.js @@ -264,7 +264,7 @@ d3.combobox = function() { w.on('mousemove.typeahead', null); }); } - + input .on('blur.typeahead', blur) .on('keydown.typeahead', keydown) diff --git a/js/lib/ohauth.js b/js/lib/ohauth.js index f447e9cdc..1d6852268 100644 --- a/js/lib/ohauth.js +++ b/js/lib/ohauth.js @@ -30,6 +30,7 @@ ohauth.xhr = function(method, url, auth, data, options, callback) { } } }; + xhr.onerror = function(e) { return callback(e, null); }; var headers = (options && options.header) || { 'Content-Type': 'application/x-www-form-urlencoded' }; xhr.open(method, url, true); xhr.setRequestHeader('Authorization', 'OAuth ' + ohauth.authHeader(auth));