From ebf0d87aa8661155fcc5c5e398dc5a223f744e0f Mon Sep 17 00:00:00 2001 From: Mihai CAZACU Date: Thu, 6 Aug 2020 20:06:28 +0300 Subject: [PATCH] add CSS class name support for attribution button --- src/ol/control/Attribution.js | 16 ++++++++++++++++ src/ol/control/Zoom.js | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/ol/control/Attribution.js b/src/ol/control/Attribution.js index 12eb3c570d..9405c58193 100644 --- a/src/ol/control/Attribution.js +++ b/src/ol/control/Attribution.js @@ -23,9 +23,13 @@ import {removeChildren, replaceNode} from '../dom.js'; * @property {string} [label='i'] Text label to use for the * collapsed attributions button. * Instead of text, also an element (e.g. a `span` element) can be used. + * @property {string} [expandClassName==className + '-expand'] CSS class name for the + * collapsed attributions button. * @property {string|HTMLElement} [collapseLabel='ยป'] Text label to use * for the expanded attributions button. * Instead of text, also an element (e.g. a `span` element) can be used. + * @property {string} [collapseClassName==className + '-collapse'] CSS class name for the + * expanded attributions button. * @property {function(import("../MapEvent.js").default):void} [render] Function called when * the control should be re-rendered. This is called in a `requestAnimationFrame` * callback. @@ -89,9 +93,19 @@ class Attribution extends Control { const tipLabel = options.tipLabel !== undefined ? options.tipLabel : 'Attributions'; + const expandClassName = + options.expandClassName !== undefined + ? options.expandClassName + : (className + '-expand'); + const collapseLabel = options.collapseLabel !== undefined ? options.collapseLabel : '\u00BB'; + const collapseClassName = + options.collapseClassName !== undefined + ? options.collapseClassName + : (className + '-collpase'); + if (typeof collapseLabel === 'string') { /** * @private @@ -99,6 +113,7 @@ class Attribution extends Control { */ this.collapseLabel_ = document.createElement('span'); this.collapseLabel_.textContent = collapseLabel; + this.collapseLabel_.className = collapseClassName; } else { this.collapseLabel_ = collapseLabel; } @@ -112,6 +127,7 @@ class Attribution extends Control { */ this.label_ = document.createElement('span'); this.label_.textContent = label; + this.label_.className = expandClassName; } else { this.label_ = label; } diff --git a/src/ol/control/Zoom.js b/src/ol/control/Zoom.js index 27a37db573..886dca9e86 100644 --- a/src/ol/control/Zoom.js +++ b/src/ol/control/Zoom.js @@ -51,11 +51,11 @@ class Zoom extends Control { const zoomInClassName = options.zoomInClassName !== undefined ? options.zoomInClassName - : className + '-in'; + : (className + '-in'); const zoomOutClassName = options.zoomOutClassName !== undefined ? options.zoomOutClassName - : className + '-out'; + : (className + '-out'); const zoomInLabel = options.zoomInLabel !== undefined ? options.zoomInLabel : '+';