add radio preset input

This commit is contained in:
Ansis Brammanis
2013-03-10 00:22:05 -05:00
parent a1a77d25cd
commit 335265590f
+45
View File
@@ -0,0 +1,45 @@
iD.ui.preset.radio = function(form) {
var event = d3.dispatch('change', 'close'),
buttons,
input;
function radio(selection) {
selection.classed('preset-radio', true);
buttons = selection.selectAll('button')
.data(form.options)
.enter()
.append('button')
.text(function(d) { return d; })
.on('click', function() {
buttons.classed('active', false);
d3.select(this).classed('active', true);
change();
});
selection.append('button')
.on('click', function() {
buttons.classed('active', false);
change();
})
.append('span')
.attr('class', 'icon remove');
}
function change() {
var t = {};
buttons.each(function(d) {
t[d] = d3.select(this).classed('active') ? 'yes' : '';
});
event.change(t);
}
radio.tags = function(tags) {
buttons.classed('active', function(d) {
return tags[d] && tags[d] !== 'no';
});
};
return d3.rebind(radio, event, 'on');
};