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 layout of attribution control #7608

Merged
merged 1 commit into from
Nov 21, 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
6 changes: 3 additions & 3 deletions src/css/mapbox-gl.css
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@ a.mapboxgl-ctrl-logo.mapboxgl-compact {
border-radius: 12px 3px 3px 12px;
}

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

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

.mapboxgl-ctrl-attrib.mapboxgl-compact::after {
Expand Down
8 changes: 5 additions & 3 deletions src/ui/control/attribution_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AttributionControl {
options: Options;
_map: Map;
_container: HTMLElement;
_innerContainer: HTMLElement;
_editLink: ?HTMLAnchorElement;
styleId: string;
styleOwner: string;
Expand All @@ -51,6 +52,7 @@ class AttributionControl {

this._map = map;
this._container = DOM.create('div', 'mapboxgl-ctrl mapboxgl-ctrl-attrib');
this._innerContainer = DOM.create('div', 'mapboxgl-ctrl-attrib-inner', this._container);

if (compact) {
this._container.classList.add('mapboxgl-compact');
Expand Down Expand Up @@ -120,11 +122,11 @@ class AttributionControl {
attributions = attributions.concat(
this.options.customAttribution.map(attribution => {
if (typeof attribution !== 'string') return '';
return `<p>${attribution}</p>`;
return attribution;
})
);
} else if (typeof this.options.customAttribution === 'string') {
attributions.push(`<p>${this.options.customAttribution}</p>`);
attributions.push(this.options.customAttribution);
}
}

Expand Down Expand Up @@ -155,7 +157,7 @@ class AttributionControl {
return true;
});
if (attributions.length) {
this._container.innerHTML = attributions.join('<p> | </p>');
this._innerContainer.innerHTML = attributions.join(' | ');
this._container.classList.remove('mapboxgl-attrib-empty');
} else {
this._container.classList.add('mapboxgl-attrib-empty');
Expand Down
16 changes: 8 additions & 8 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<p> | </p>Another Source<p> | </p>GeoJSON Source');
t.equal(attribution._innerContainer.innerHTML, 'Hello World | Another Source | GeoJSON Source');
t.end();
}
}
Expand Down Expand Up @@ -138,15 +138,15 @@ test('AttributionControl is hidden if empty', (t) => {
const container = map.getContainer();

const checkEmptyFirst = () => {
t.equal(attribution._container.innerHTML, '');
t.equal(attribution._innerContainer.innerHTML, '');
t.equal(container.querySelectorAll('.mapboxgl-attrib-empty').length, 1, 'includes empty class when no attribution strings are provided');

map.addSource('2', { type: 'geojson', data: { type: 'FeatureCollection', features: [] }, attribution: 'Hello World'});
map.addLayer({ id: '2', type: 'fill', source: '2' });
};

const checkNotEmptyLater = () => {
t.equal(attribution._container.innerHTML, 'Hello World');
t.equal(attribution._innerContainer.innerHTML, 'Hello World');
t.equal(container.querySelectorAll('.mapboxgl-attrib-empty').length, 0, 'removes empty class when source with attribution is added');
t.end();
};
Expand All @@ -171,7 +171,7 @@ test('AttributionControl shows custom attribution if customAttribution option is
});
map.addControl(attributionControl);

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

Expand All @@ -183,7 +183,7 @@ test('AttributionControl in compact mode shows custom attribution if customAttri
});
map.addControl(attributionControl);

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

Expand All @@ -196,8 +196,8 @@ test('AttributionControl shows all custom attributions if customAttribution arra
map.addControl(attributionControl);

t.equal(
attributionControl._container.innerHTML,
'<p>Custom string</p><p> | </p><p>Another custom string</p><p> | </p><p>Some very long custom string</p>'
attributionControl._innerContainer.innerHTML,
'Custom string | Another custom string | Some very long custom string'
);
t.end();
});
Expand All @@ -219,7 +219,7 @@ test('AttributionControl hides attributions for sources that are not currently v
map.on('data', (e) => {
if (e.dataType === 'source' && e.sourceDataType === 'metadata') {
if (++times === 3) {
t.equal(attribution._container.innerHTML, 'Used');
t.equal(attribution._innerContainer.innerHTML, 'Used');
t.end();
}
}
Expand Down