Keep generic amenity preset choice (fixes #1354)

This commit is contained in:
John Firebaugh
2013-04-23 16:43:59 -07:00
parent 5ea93539ad
commit 69868bfd22
2 changed files with 35 additions and 38 deletions

View File

@@ -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(_) {

View File

@@ -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');