diff --git a/js/id/ui/attribution.js b/js/id/ui/attribution.js
index 9c4ecb7a7..eb3182e46 100644
--- a/js/id/ui/attribution.js
+++ b/js/id/ui/attribution.js
@@ -2,34 +2,53 @@ iD.ui.Attribution = function(context) {
var selection;
function update() {
- var d = context.background().source();
+ if (!context.background().source()) {
+ selection.html('');
+ return
+ }
- var provided_by = selection
- .html('')
+ var attribution = selection.selectAll('.provided-by')
+ .data([context.background().source()], function(d) { return d.data.name; });
+
+ attribution.enter()
.append('span')
- .attr('class', 'provided-by');
+ .attr('class', 'provided-by')
+ .each(function(d) {
+ var source = d.data.sourcetag || d.data.name;
- if (!d) return;
+ if (d.data.logo) {
+ source = '
';
+ }
- var source = d.data.sourcetag || d.data.name;
- if (d.data.logo) {
- source = '
';
- }
+ if (d.data.terms_url) {
+ d3.select(this)
+ .append('a')
+ .attr('href', d.data.terms_url)
+ .attr('target', '_blank')
+ .html(source);
+ } else {
+ d3.select(this)
+ .text(source);
+ }
+ });
- if (d.data.terms_url) {
- provided_by.append('a')
- .attr('href', d.data.terms_url)
- .attr('target', '_blank')
- .html(source);
- } else {
- provided_by.text(source);
- }
+ attribution.exit()
+ .remove();
- var copyright = d.copyrightNotices(context.map().zoom(), context.map().extent());
- if (copyright) {
- provided_by.append('span')
- .text(copyright);
- }
+ var copyright = attribution.selectAll('.copyright-notice')
+ .data(function(d) {
+ var notice = d.copyrightNotices(context.map().zoom(), context.map().extent());
+ return notice ? [notice] : [];
+ });
+
+ copyright.enter()
+ .append('span')
+ .attr('class', 'copyright-notice');
+
+ copyright.text(String);
+
+ copyright.exit()
+ .remove();
}
return function(select) {