Smarter contributors box, links to history when truncated. Fixes #306

This commit is contained in:
Tom MacWright
2013-01-17 15:20:16 -05:00
parent cfc5ad6c02
commit 81d4036322
2 changed files with 38 additions and 8 deletions

View File

@@ -156,8 +156,12 @@ window.iD = function(container) {
.attr('class','about-block fillD pad1');
contributors.append('span')
.attr('class', 'icon nearby icon-pre-text');
contributors.append('pan')
contributors.append('span')
.text('Viewing contributions by ');
contributors.append('span')
.attr('class', 'contributor-list');
contributors.append('span')
.attr('class', 'contributor-count');
history.on('change.buttons', function() {
var undo = history.undoAnnotation(),

View File

@@ -3,22 +3,48 @@ iD.ui.contributors = function(map) {
function contributors(selection) {
var users = {},
limit = 3,
entities = map.history().graph().intersects(map.extent());
for (var i in entities) {
if (entities[i].user) {
users[entities[i].user] = true;
if (Object.keys(users).length > 10) break;
}
if (entities[i].user) users[entities[i].user] = true;
}
var u = Object.keys(users);
var l = selection.selectAll('a.user-link').data(u);
var u = Object.keys(users),
subset = u.slice(0, limit);
var l = selection
.select('.contributor-list')
.selectAll('a.user-link')
.data(subset);
l.enter().append('a')
.attr('class', 'user-link')
.attr('href', function(d) { return map.connection().userUrl(d); })
.attr('href', function(d) { console.log(d); return map.connection().userUrl(d); })
.attr('target', '_blank')
.text(String);
l.exit().remove();
selection
.select('.contributor-count')
.html('');
if (u.length > limit) {
selection
.select('.contributor-count')
.append('a')
.attr('target', '_blank')
.attr('href', function() {
var ext = map.extent();
return 'http://www.openstreetmap.org/browse/changesets?bbox=' + [
ext[0][0], ext[1][1],
ext[1][0], ext[0][1]];
})
.text(' and ' + (u.length - limit) + ' others');
}
if (!u.length) {
selection.transition().style('opacity', 0);
} else if (selection.style('opacity') === '0') {