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

Hide attribution container if empty so as not to show in compact maps #6042

Merged
merged 2 commits into from
Jan 24, 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
3 changes: 3 additions & 0 deletions dist/mapbox-gl.css
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ a.mapboxgl-ctrl-logo {
font-weight: bold;
margin-left: 2px;
}
.mapboxgl-attrib-empty {
display: none;
}
/*stylelint-enable*/
.mapboxgl-ctrl-scale {
background-color: rgba(255,255,255,0.75);
Expand Down
7 changes: 6 additions & 1 deletion src/ui/control/attribution_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ class AttributionControl {
}
return true;
});
this._container.innerHTML = attributions.join(' | ');
if (attributions.length) {
this._container.innerHTML = attributions.join(' | ');
this._container.classList.remove('mapboxgl-attrib-empty');
} else {
this._container.classList.add('mapboxgl-attrib-empty');
}
// remove old DOM node from _editLink
this._editLink = null;
}
Expand Down
36 changes: 36 additions & 0 deletions test/unit/ui/control/attribution.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,39 @@ test('AttributionControl has the correct edit map link', (t) => {
});
});
});

test('AttributionControl is hidden if empty', (t) => {
const map = createMap();
const attribution = new AttributionControl();
map.addControl(attribution);
map.on('load', () => {
map.addSource('1', { type: 'vector' });
});

const container = map.getContainer();

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

map.addSource('2', { type: 'vector', attribution: 'Hello World' });
};

const checkNotEmptyLater = () => {
t.equal(attribution._container.innerHTML, 'Hello World');
t.equal(container.querySelectorAll('.mapboxgl-attrib-empty').length, 0, 'removes empty class when source with attribution is added');
t.end();
};

let times = 0;
map.on('data', (e) => {
if (e.dataType === 'source' && e.sourceDataType === 'metadata') {
times++;
if (times === 1) {
checkEmptyFirst();
} else if (times === 2) {
checkNotEmptyLater();
}
}
});
});