From 1ae1ff26a0f5683f563488ed21e35be7a0b3d96d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Fri, 4 Mar 2022 20:04:30 +0100 Subject: [PATCH] Initialize variable before use in FullScreen control isInFullscreen_ was not initialized in the constructor when setClassName_ is called. - Only remove the unnecessary classes when state changes instead of removing all and then adding the necessary classes again --- src/ol/control/FullScreen.js | 68 ++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/ol/control/FullScreen.js b/src/ol/control/FullScreen.js index 8e3b685412..f6f97196f8 100644 --- a/src/ol/control/FullScreen.js +++ b/src/ol/control/FullScreen.js @@ -105,6 +105,29 @@ class FullScreen extends Control { */ this.un; + /** + * @private + * @type {boolean} + */ + this.keys_ = options.keys !== undefined ? options.keys : false; + + /** + * @private + * @type {HTMLElement|string|undefined} + */ + this.source_ = options.source; + + /** + * @type {boolean} + * @private + */ + this.isInFullscreen_ = false; + + /** + * @private + */ + this.boundHandleMapTargetChange_ = this.handleMapTargetChange_.bind(this); + /** * @private * @type {string} @@ -157,49 +180,25 @@ class FullScreen extends Control { ? document.createTextNode(labelActive) : labelActive; + const tipLabel = options.tipLabel ? options.tipLabel : 'Toggle full-screen'; + /** * @private * @type {HTMLElement} */ this.button_ = document.createElement('button'); - - const tipLabel = options.tipLabel ? options.tipLabel : 'Toggle full-screen'; - this.button_.setAttribute('type', 'button'); - this.setClassName_(this.button_, this.isInFullscreen_); this.button_.title = tipLabel; + this.button_.setAttribute('type', 'button'); this.button_.appendChild(this.labelNode_); - this.button_.addEventListener( EventType.CLICK, this.handleClick_.bind(this), false ); + this.setClassName_(this.button_, this.isInFullscreen_); this.element.className = `${this.cssClassName_} ${CLASS_UNSELECTABLE} ${CLASS_CONTROL}`; this.element.appendChild(this.button_); - - /** - * @private - * @type {boolean} - */ - this.keys_ = options.keys !== undefined ? options.keys : false; - - /** - * @private - * @type {HTMLElement|string|undefined} - */ - this.source_ = options.source; - - /** - * @type {boolean} - * @private - */ - this.isInFullscreen_ = false; - - /** - * @private - */ - this.boundHandleMapTargetChange_ = this.handleMapTargetChange_.bind(this); } /** @@ -272,12 +271,13 @@ class FullScreen extends Control { * @private */ setClassName_(element, fullscreen) { - const activeClassName = this.activeClassName_; - const inactiveClassName = this.inactiveClassName_; - const nextClassName = fullscreen ? activeClassName : inactiveClassName; - element.classList.remove(...activeClassName); - element.classList.remove(...inactiveClassName); - element.classList.add(...nextClassName); + if (fullscreen) { + element.classList.remove(...this.inactiveClassName_); + element.classList.add(...this.activeClassName_); + } else { + element.classList.remove(...this.activeClassName_); + element.classList.add(...this.inactiveClassName_); + } } /**