Skip to content

Commit 59ac32c

Browse files
mgermeriegchoqueux
authored andcommitted
feature(Widgets): add show and hide methods
1 parent 9bd81ce commit 59ac32c

File tree

6 files changed

+31
-0
lines changed

6 files changed

+31
-0
lines changed

docs/config.json

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
],
129129

130130
"Widgets": [
131+
"Widget",
131132
"Navigation",
132133
"Minimap",
133134
"Scale",

utils/gui/Minimap.js

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const DEFAULT_OPTIONS = {
1818
/**
1919
* A widget for minimap
2020
*
21+
* @extends Widget
22+
*
2123
* @property {HTMLElement} domElement An html div containing the minimap.
2224
* @property {HTMLElement} parentElement The parent HTML container of `this.domElement`.
2325
*/

utils/gui/Navigation.js

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const DEFAULT_OPTIONS = {
1616
/**
1717
* A widget menu manager for navigation.
1818
*
19+
* @extends Widget
20+
*
1921
* @property {HTMLElement} domElement An html div containing all navigation widgets.
2022
* @property {HTMLElement} parentElement The parent HTML container of `this.domElement`.
2123
* @property {Object} onClick An object containing methods which are executed when clicking one of the

utils/gui/Scale.js

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const DEFAULT_OPTIONS = {
1515
/**
1616
* A widget for scale
1717
*
18+
* @extends Widget
19+
*
1820
* @property {HTMLElement} domElement An html div containing the scale.
1921
* @property {HTMLElement} parentElement The parent HTML container of `this.domElement`.
2022
*/

utils/gui/Searchbar.js

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ function eraseSuggestionList(form) {
4545
/**
4646
* A widget for searchbar
4747
*
48+
* @extends Widget
49+
*
4850
* @property {HTMLElement} domElement An html div containing the searchbar.
4951
* @property {HTMLElement} parentElement The parent HTML container of `this.domElement`.
5052
*/

utils/gui/Widget.js

+22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
/**
2+
* An interface that stores common methods for all specific widgets.
3+
*
4+
* @hideconstructor
5+
*/
16
class Widget {
7+
#_display;
8+
29
constructor(view, options = {}, defaultOptions) {
310
this.parentElement = options.parentElement || view.domElement;
411

@@ -58,6 +65,21 @@ class Widget {
5865
this.domElement.addEventListener('pointerdown', (e) => { e.stopPropagation(); });
5966
this.domElement.addEventListener('mousedown', (e) => { e.stopPropagation(); });
6067
}
68+
69+
/**
70+
* Change the widget style `display` property so that the widget becomes visible.
71+
*/
72+
show() {
73+
this.domElement.style.display = this.#_display;
74+
}
75+
76+
/**
77+
* Change the widget style `display` property so that the widget becomes invisible.
78+
*/
79+
hide() {
80+
this.#_display = window.getComputedStyle(this.domElement).display;
81+
this.domElement.style.display = 'none';
82+
}
6183
}
6284

6385

0 commit comments

Comments
 (0)