Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix custom attribution strings in compact mode #7444

Merged
merged 2 commits into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/css/mapbox-gl.css
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ a.mapboxgl-ctrl-logo.mapboxgl-compact {
visibility: visible;
}

.mapboxgl-ctrl-attrib.mapboxgl-compact > a {
.mapboxgl-ctrl-attrib.mapboxgl-compact > * {
display: none;
}

.mapboxgl-ctrl-attrib.mapboxgl-compact:hover > a {
.mapboxgl-ctrl-attrib.mapboxgl-compact:hover > * {
display: inline;
}

Expand Down
11 changes: 8 additions & 3 deletions src/ui/control/attribution_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,14 @@ class AttributionControl {
let attributions: Array<string> = [];
if (this.options.customAttribution) {
if (Array.isArray(this.options.customAttribution)) {
attributions = attributions.concat(this.options.customAttribution);
attributions = attributions.concat(
this.options.customAttribution.map(attribution => {
if (typeof attribution !== 'string') return '';
return `<p>${attribution}</p>`;
})
);
} else if (typeof this.options.customAttribution === 'string') {
attributions.push(this.options.customAttribution);
attributions.push(`<p>${this.options.customAttribution}</p>`);
}
}

Expand Down Expand Up @@ -150,7 +155,7 @@ class AttributionControl {
return true;
});
if (attributions.length) {
this._container.innerHTML = attributions.join(' | ');
this._container.innerHTML = attributions.join('<p> | </p>');
this._container.classList.remove('mapboxgl-attrib-empty');
} else {
this._container.classList.add('mapboxgl-attrib-empty');
Expand Down
19 changes: 16 additions & 3 deletions test/unit/ui/control/attribution.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ test('AttributionControl dedupes attributions that are substrings of others', (t
map.on('data', (e) => {
if (e.dataType === 'source' && e.sourceDataType === 'metadata') {
if (++times === 7) {
t.equal(attribution._container.innerHTML, 'Hello World | Another Source | GeoJSON Source');
t.equal(attribution._container.innerHTML, 'Hello World<p> | </p>Another Source<p> | </p>GeoJSON Source');
t.end();
}
}
Expand Down Expand Up @@ -171,10 +171,23 @@ test('AttributionControl shows custom attribution if customAttribution option is
});
map.addControl(attributionControl);

t.equal(attributionControl._container.innerHTML, 'Custom string');
t.equal(attributionControl._container.innerHTML, '<p>Custom string</p>');
t.end();
});

test('AttributionControl in compact mode shows custom attribution if customAttribution option is provided', (t) => {
const map = createMap(t);
const attributionControl = new AttributionControl({
customAttribution: 'Custom string',
compact: true
});
map.addControl(attributionControl);

t.equal(attributionControl._container.innerHTML, '<p>Custom string</p>');
t.end();
});


test('AttributionControl shows all custom attributions if customAttribution array of strings is provided', (t) => {
const map = createMap(t);
const attributionControl = new AttributionControl({
Expand All @@ -184,7 +197,7 @@ test('AttributionControl shows all custom attributions if customAttribution arra

t.equal(
attributionControl._container.innerHTML,
'Custom string | Another custom string | Some very long custom string'
'<p>Custom string</p><p> | </p><p>Another custom string</p><p> | </p><p>Some very long custom string</p>'
);
t.end();
});
Expand Down