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
This commit is contained in:
@@ -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_);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user