Refactor source menu into proper control and fill it in intially.

Fixes #1084
This commit is contained in:
Tom MacWright
2013-03-19 13:47:39 -04:00
parent 4ecf143f12
commit 96cef1d3cb
5 changed files with 29 additions and 21 deletions

View File

@@ -182,3 +182,5 @@ en:
zoom:
in: Zoom In
out: Zoom Out
imagery:
provided_by: "Imagery provided by {source}"

View File

@@ -156,7 +156,7 @@ iD.Background = function() {
return background;
};
function setPermalink(source) {
function setHash(source) {
var tag = source.data.sourcetag;
var q = iD.util.stringQs(location.hash.substring(1));
if (tag) {
@@ -173,7 +173,7 @@ iD.Background = function() {
source = _;
cache = {};
tile.scaleExtent((source.data && source.data.scaleExtent) || [1, 20]);
setPermalink(source);
setHash(source);
return background;
};

View File

@@ -100,6 +100,7 @@ iD.ui = function(context) {
linkList.append('li')
.attr('class', 'attribution')
.attr('tabindex', -1)
.data([context.background().source()])
.call(iD.ui.Attribution(context));
linkList.append('li')

View File

@@ -1,10 +1,26 @@
iD.ui.Attribution = function(context) {
return function(selection) {
selection.append('span')
.text('imagery');
return function attribution(selection) {
var d = selection.data()[0];
selection
var provided_by = selection
.html('')
.append('span')
.attr('class', 'provided-by');
if (!d) return;
var desc = t('imagery.provided_by', {
source: (d.data.sourcetag || d.data.name)
});
if (d.data.terms_url) {
provided_by.append('a')
.attr('href', (d.data.terms_url || ''))
.attr('target', '_blank')
.classed('disabled', !d.data.terms_url)
.text(desc);
} else {
provided_by.text(desc);
}
};
};

View File

@@ -110,21 +110,10 @@ iD.ui.Background = function(context) {
return d.data.name === context.background().source().data.name;
});
var provided_by = context.container()
.select('.attribution .provided-by')
.html('');
if (d.data.terms_url) {
provided_by.append('a')
.attr('href', (d.data.terms_url || ''))
.attr('target', '_blank')
.classed('disabled', !d.data.terms_url)
.text(' provided by ' + (d.data.sourcetag || d.data.name));
} else {
provided_by
.text(' provided by ' + (d.data.sourcetag || d.data.name));
}
context.container()
.select('.attribution')
.data([d])
.call(iD.ui.Attribution(context));
}
function clickSetSource(d) {