From 9796d4027d1fea719b2e2a00409e774ebbc53108 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 21 Mar 2013 15:05:56 -0700 Subject: [PATCH] Cleanup --- js/id/ui/preset.js | 69 ++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/js/id/ui/preset.js b/js/id/ui/preset.js index e47ab3f17..ceb73734e 100644 --- a/js/id/ui/preset.js +++ b/js/id/ui/preset.js @@ -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() {