This commit is contained in:
John Firebaugh
2013-03-21 15:05:56 -07:00
parent 96056c5c0a
commit 9796d4027d
+33 -36
View File
@@ -6,27 +6,10 @@ iD.ui.preset = function(context, entity) {
formwrap,
formbuttonwrap;
function input(d) {
var i = iD.ui.preset[d.type](d, context)
.on('close', event.close)
.on('change', event.change);
event.on('setTags.' + d.key || d.type, function(tags) {
i.tags(_.clone(tags));
});
if (d.type === 'address') i.entity(entity);
keys = keys.concat(d.key ? [d.key] : d.keys);
d3.select(this).call(i);
}
function presets(selection) {
selection.html('');
keys = [];
keys = [];
formwrap = selection.append('div');
var geometry = entity.geometry(context.graph());
@@ -44,32 +27,31 @@ iD.ui.preset = function(context, entity) {
.data(context.presets().universal().filter(notInForm))
.enter()
.append('button')
.attr('class', 'preset-add-field')
.on('click', addForm)
.each(tooltip)
.append('span')
.attr('class', function(d) { return 'icon ' + d.icon; });
.attr('class', 'preset-add-field')
.on('click', addForm)
.call(bootstrap.tooltip()
.placement('top')
.title(function(d) { return d.label(); }))
.append('span')
.attr('class', function(d) { return 'icon ' + d.icon; });
function notInForm(p) {
return preset.fields.indexOf(p) < 0;
}
function tooltip(d) {
d3.select(this).call(bootstrap.tooltip()
.placement('top')
.title(d.label()));
}
function addForm(d) {
draw(formwrap, [d]);
d3.select(this)
.style('opacity', 1)
.transition().style('opacity', 0).each('end', function() {
d3.select(this).remove();
});
if (!wrap.selectAll('button').node()) wrap.remove();
}
.transition()
.style('opacity', 0)
.remove();
if (!wrap.selectAll('button').node()) {
wrap.remove();
}
}
}
function draw(selection, fields) {
@@ -86,9 +68,24 @@ iD.ui.preset = function(context, entity) {
.attr('for', function(d) { return 'input-' + d.key; })
.text(function(d) { return d.label(); });
sections.transition().style('opacity', 1);
sections.transition()
.style('opacity', 1);
sections.each(input);
sections.each(function(field) {
var i = iD.ui.preset[field.type](field, context)
.on('close', event.close)
.on('change', event.change);
event.on('setTags.' + field.key || field.type, function (tags) {
i.tags(_.clone(tags));
});
if (field.type === 'address') i.entity(entity);
keys = keys.concat(field.key ? [field.key] : field.keys);
d3.select(this).call(i);
});
}
presets.rendered = function() {