From 81d4036322c0faefabc1db389a5b0cb8a0f980b0 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Thu, 17 Jan 2013 15:20:16 -0500 Subject: [PATCH] Smarter contributors box, links to history when truncated. Fixes #306 --- js/id/id.js | 6 +++++- js/id/ui/contributors.js | 40 +++++++++++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/js/id/id.js b/js/id/id.js index e22a77ca6..828aa45f9 100644 --- a/js/id/id.js +++ b/js/id/id.js @@ -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(), diff --git a/js/id/ui/contributors.js b/js/id/ui/contributors.js index 72dedf1d1..36d1cf432 100644 --- a/js/id/ui/contributors.js +++ b/js/id/ui/contributors.js @@ -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') {