From 69868bfd228de638fc0385ec889f2e6d60706cd6 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 23 Apr 2013 16:43:59 -0700 Subject: [PATCH] Keep generic amenity preset choice (fixes #1354) --- js/id/ui/inspector.js | 23 +------------------ js/id/ui/tag_editor.js | 50 ++++++++++++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 38 deletions(-) diff --git a/js/id/ui/inspector.js b/js/id/ui/inspector.js index bca353227..57d733717 100644 --- a/js/id/ui/inspector.js +++ b/js/id/ui/inspector.js @@ -16,13 +16,6 @@ iD.ui.Inspector = function(context, entity) { context.enter(iD.modes.Browse(context)); } - function update() { - var entity = context.entity(id); - if (entity) { - tagEditor.tags(entity.tags); - } - } - function inspector(selection) { var reselect = selection.html(); @@ -61,7 +54,6 @@ iD.ui.Inspector = function(context, entity) { }); tagEditor = iD.ui.TagEditor(context, entity) - .tags(entity.tags) .on('changeTags', changeTags) .on('close', browse) .on('choose', function(preset) { @@ -98,16 +90,10 @@ iD.ui.Inspector = function(context, entity) { context.map().centerEase(context.projection.invert([center, mapSize[1]/2])); } } - - context.history() - .on('change.inspector', update); } inspector.close = function(selection) { - - // Blur focused element so that tag changes are dispatched - // See #1295 - document.activeElement.blur(); + tagEditor.close(); selection.transition() .style('right', '-500px') @@ -116,13 +102,6 @@ iD.ui.Inspector = function(context, entity) { .style('display', 'none') .html(''); }); - - // Firefox incorrectly implements blur, so typeahead elements - // are not correctly removed. Remove any stragglers manually. - d3.selectAll('div.typeahead').remove(); - - context.history() - .on('change.inspector', null); }; inspector.newFeature = function(_) { diff --git a/js/id/ui/tag_editor.js b/js/id/ui/tag_editor.js index cb8eca31e..6d0fe5605 100644 --- a/js/id/ui/tag_editor.js +++ b/js/id/ui/tag_editor.js @@ -1,12 +1,30 @@ iD.ui.TagEditor = function(context, entity) { var event = d3.dispatch('changeTags', 'choose', 'close'), presets = context.presets(), - tags, + id = entity.id, + tags = entity.tags, preset, selection_, presetUI, tagList; + function update() { + var entity = context.entity(id); + if (!entity) return; + + tags = entity.tags; + + // change preset if necessary (undos/redos) + var newmatch = presets.match(entity, context.graph()); + if (newmatch !== preset) { + tageditor(selection_, newmatch); + return; + } + + presetUI.change(tags); + tagList.tags(tags); + } + function tageditor(selection, newpreset) { selection_ = selection; var geometry = entity.geometry(context.graph()); @@ -83,8 +101,13 @@ iD.ui.TagEditor = function(context, entity) { osmLink.append('span').text(t('inspector.view_on_osm')); } - tageditor.tags(tags); + presetUI.change(tags); + tagList.tags(tags); + changeTags(); + + context.history() + .on('change.tag-editor', update); } function clean(o) { @@ -101,22 +124,17 @@ iD.ui.TagEditor = function(context, entity) { event.changeTags(_.clone(tags)); } - tageditor.tags = function(newtags) { - tags = _.clone(newtags); - if (presetUI && tagList) { + tageditor.close = function() { + // Blur focused element so that tag changes are dispatched + // See #1295 + document.activeElement.blur(); - // change preset if necessary (undos/redos) - var newmatch = presets - .matchGeometry(entity, context.graph()) - .matchTags(entity.update({ tags: tags })); - if (newmatch !== preset) { - return tageditor(selection_, newmatch); - } + // Firefox incorrectly implements blur, so typeahead elements + // are not correctly removed. Remove any stragglers manually. + d3.selectAll('div.typeahead').remove(); - presetUI.change(tags); - tagList.tags(tags); - } - return tageditor; + context.history() + .on('change.tag-editor', null); }; return d3.rebind(tageditor, event, 'on');