From 8608a013f75b1b6ad13fb21f69289579905be06a Mon Sep 17 00:00:00 2001 From: Molly Lloyd Date: Thu, 18 Oct 2018 13:50:14 -0700 Subject: [PATCH 1/2] fix custom attributions in compact mode --- src/css/mapbox-gl.css | 4 ++-- src/ui/control/attribution_control.js | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/css/mapbox-gl.css b/src/css/mapbox-gl.css index 03d57dd22cd..f80bbe13e03 100644 --- a/src/css/mapbox-gl.css +++ b/src/css/mapbox-gl.css @@ -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; } diff --git a/src/ui/control/attribution_control.js b/src/ui/control/attribution_control.js index 133945a7c1d..e7a5d42e90b 100644 --- a/src/ui/control/attribution_control.js +++ b/src/ui/control/attribution_control.js @@ -117,9 +117,14 @@ class AttributionControl { let attributions: Array = []; 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 `${attribution}` + }) + ); } else if (typeof this.options.customAttribution === 'string') { - attributions.push(this.options.customAttribution); + attributions.push(`

${this.options.customAttribution}

`); } } @@ -150,7 +155,7 @@ class AttributionControl { return true; }); if (attributions.length) { - this._container.innerHTML = attributions.join(' | '); + this._container.innerHTML = attributions.join('

|

'); this._container.classList.remove('mapboxgl-attrib-empty'); } else { this._container.classList.add('mapboxgl-attrib-empty'); From 7e95dc894535f1c3f0bdf8f1816a3d9741009521 Mon Sep 17 00:00:00 2001 From: Molly Lloyd Date: Thu, 18 Oct 2018 14:06:05 -0700 Subject: [PATCH 2/2] fix custom attribution in compact mode --- src/ui/control/attribution_control.js | 2 +- test/unit/ui/control/attribution.test.js | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/ui/control/attribution_control.js b/src/ui/control/attribution_control.js index e7a5d42e90b..d27ae6b7ead 100644 --- a/src/ui/control/attribution_control.js +++ b/src/ui/control/attribution_control.js @@ -120,7 +120,7 @@ class AttributionControl { attributions = attributions.concat( this.options.customAttribution.map(attribution => { if (typeof attribution !== 'string') return ''; - return `${attribution}` + return `

${attribution}

`; }) ); } else if (typeof this.options.customAttribution === 'string') { diff --git a/test/unit/ui/control/attribution.test.js b/test/unit/ui/control/attribution.test.js index cf4a7f68fe3..d0933f44f8c 100644 --- a/test/unit/ui/control/attribution.test.js +++ b/test/unit/ui/control/attribution.test.js @@ -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

|

Another Source

|

GeoJSON Source'); t.end(); } } @@ -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, '

Custom string

'); 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, '

Custom string

'); + t.end(); +}); + + test('AttributionControl shows all custom attributions if customAttribution array of strings is provided', (t) => { const map = createMap(t); const attributionControl = new AttributionControl({ @@ -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' + '

Custom string

|

Another custom string

|

Some very long custom string

' ); t.end(); });